in image_test/configuration/linux/generic_distro.py [0:0]
def TestSshdConfig(self):
"""
Ensure sshd config has sane default settings
"""
def ParseSshdConfig(path):
configs = {}
with open(path) as f:
# Avoid log output overload on centos-6
time.sleep(0.1)
for line in filter(RemoveCommentAndStrip, f.read().split('\n')):
if line:
# use line separator for key and # values
entry = line.split(' ')
# strip dictionary value
configs[entry[0]] = ' '.join(entry[1:]).strip()
return configs
actual_sshd_configs = ParseSshdConfig('/etc/ssh/sshd_config')
for desired_key, desired_value in self.GetSshdConfig().items():
if actual_sshd_configs[desired_key] != desired_value:
raise Exception('Sshd key "%s" should be "%s" and not "%s"' % (
desired_key, desired_value, actual_sshd_configs[desired_key]))