Skip to content

Commit

Permalink
Merge branch 'develop' into fenoyc-bjobs-format
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarak authored Aug 25, 2023
2 parents 604a43d + eda6b23 commit 6c18139
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
62 changes: 62 additions & 0 deletions hpctestlib/system/ssh/host_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2016-2023 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
# ReFrame Project Developers. See the top-level LICENSE file for details.
#
# SPDX-License-Identifier: BSD-3-Clause

import time

import reframe as rfm
import reframe.utility.sanity as sn
import reframe.utility.typecheck as typ


@rfm.simple_test
class ssh_host_keys_check(rfm.RunOnlyRegressionTest):
'''SSH host keys age check
The ssh host keys should be renewed regularly.
In this case, we are checking against the
max_key_age variable
'''

#: Parameter list with all host keys to check
#:
#: The test is skipped if a key is not found
#:
#: :type: :class:`str`
#: :values: ``['/etc/ssh/ssh_host_rsa_key',
#: '/etc/ssh/ssh_host_ecdsa_key',
#: '/etc/ssh/ssh_host_ed25519_key']``
ssh_host_keys = parameter([
'/etc/ssh/ssh_host_rsa_key',
'/etc/ssh/ssh_host_ecdsa_key',
'/etc/ssh/ssh_host_ed25519_key',
], fmt=lambda x: x.split('_')[2], loggable=True)

#: The max age of the keys in ReFrame duration format
#:
#: :type: :class:`str`
#: :default: ``'365d'``
max_key_age = variable(str, value='365d', loggable=True)

executable = 'stat'
executable_opts = ['-c', '%Y']
tags = {'system', 'ssh'}

@run_after('init')
def set_hosts_keys(self):
self.executable_opts += [self.host_keys]

@sanity_function
def assert_file_age(self):
current_time = time.time()

skip_me = sn.extractall('No such file or directory', self.stderr)
self.skip_if(skip_me, msg=f'Skipping test because {self.host_keys}'
f' was not found')

return sn.assert_lt(current_time -
sn.extractsingle(r'\d+', self.stdout, 0, int),
typ.Duration(self.max_key_age),
msg=f'File {self.host_keys} is older than '
f'{self.max_key_age}')
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pytest-forked==1.4.0; python_version == '3.6'
pytest-forked==1.6.0; python_version >= '3.7'
pytest-parallel==0.1.1
pytest-rerunfailures==10.3; python_version == '3.6'
pytest-rerunfailures==11.1.2; python_version >= '3.7'
pytest-rerunfailures==12.0; python_version >= '3.7'
PyYAML==6.0.1
requests==2.27.1; python_version == '3.6'
requests==2.31.0; python_version >= '3.7'
Expand Down

0 comments on commit 6c18139

Please sign in to comment.