From f08ec5d3c84b8a74d02548ea239ea3cb9c2faaf3 Mon Sep 17 00:00:00 2001 From: Lukas Ruzicka Date: Jul 30 2019 14:16:05 +0000 Subject: Add tests for yaml sanity. --- diff --git a/modular_functions.py b/modular_functions.py index 0504215..5331d5e 100755 --- a/modular_functions.py +++ b/modular_functions.py @@ -378,28 +378,15 @@ class TestSuite: self.yamldb = yamldb return yamldb - def test_yaml(self, module): + def check_yaml_exists(self, module): key = f"{module}.yaml" - print(self.yamldb.keys()) try: yamldata = self.yamldb[key] + return yamldata except KeyError: - print(f"The {key} seems not to exist for {module}.") + print(f"{key}") logging.error(f"The {key} seems not to exist for {module}.") - results = [] - try: - document = yamldata['document'] - version = yamldata['version'] - module = yamldata['data'] - name = module['module'] - profiles = module['profiles'] - if 'stream' in module.keys(): - stream = module['stream'] - else: - stream = 'no default' - except KeyError: - results.append('fail') - logging.error("Some required fields are missing from the {key} file.") + return None class ModuleTest: # These are various test methods that do the actual testing. @@ -786,11 +773,79 @@ class ModuleTest: self.overall[key] = 'fail' def testyaml(self): + """Test the sanity of the module yaml file.""" + # This makes sure that there is yaml file defined for every module in the system defined + # and published in https://pagure.io/releng/fedora-module-defaults.git, and that the yaml + # files do have all their requirements set. modules = self.suite.module_list() self.suite.create_yamldb('/home/lruzicka/todelete/yaml/') + whitelist = self.suite.load_whitelist() + print("------- Non-existing yaml files --------") + results = [] + parsed_results = {} for module in modules.keys(): - self.suite.test_yaml(module) + parsed = {'pass':[], 'fail':[]} + yamldata = self.suite.check_yaml_exists(module) + if yamldata: + results.append('pass') + if yamldata['document'] == 'modulemd-defaults': + parsed['pass'].append('document') + else: + parsed['fail'].append('document') + print("The document field does not contain correct value.") + logging.error("The document field does not contain correct value.") + if str(yamldata['version']) == '1': + parsed['pass'].append('version') + else: + parsed['fail'].append('version') + print("The version field does not contain correct value.") + logging.error("The version field does not contain correct value.") + if yamldata['data'] != '': + parsed['pass'].append('data') + modata = yamldata['data'] + else: + parsed['fail'].append('data') + modata = None + print("The data field does not contain correct value.") + logging.error("The data field does not contain correct value.") + if modata: + if modata['module'] == module: + parsed['pass'].append('module') + else: + parsed['fail'].append('module') + print("The module field value does not match the module name." ) + logging.error("The module field value does not match the module name." ) + if modata['profiles']: + profiles = modata['profiles'] + for key in profiles.keys(): + if profiles[key]: + parsed['pass'].append(f"profile-{key}") + else: + parsed['fail'].append(f"profile-{key}") + if 'stream' in modata.keys(): + defstr = modata['stream'] + if defstr in profiles.keys(): + parsed['pass'].append(f"default-stream-{defstr}") + else: + parsed['fail'].append(f"default-stream-{defstr}") + if len(parsed['fail']) > 0 and module not in whitelist: + parsed_results[module] = parsed['fail'] + else: + if module not in whitelist: + results.append('fail') + + if parsed_results: + print(f"There are problems with some of the yaml files. Check logs.") + logging.error(f"Problems with yaml files found.") + self.overall['yaml_sanity'] = 'fail' + else: + self.overall['yaml_sanity'] = 'pass' + + if 'fail' in results: + self.overall['yaml_exists'] = 'fail' + else: + self.overall['yaml_exists'] = 'pass' def run_test(self, module, fail, newer, stream, profile): """Run a particular test."""