def phase_5(phase_4_output, runtime_vars, yaml): phase_4_output_file = open(phase_4_output.name, 'r') phase_5_output_file = open("./.temp/phase_5_output.yaml", 'w') data = yaml.load(phase_4_output_file) phase_5_output = {} for data_section in data: if data_section == 'lightweight_components': updated_components = [] for lightweight_component in data[data_section]: print "Component: " + lightweight_component['name'] updated_component = {} for component_section in lightweight_component: if component_section == 'config': repo_url = lightweight_component['repository_url'] repo_processor.get_repository_file( repo_url, 'config-schema.yaml') repo_processor.get_repository_file( repo_url, 'meta-info.yaml', True) repo_info = repo_processor.analyse_repo_url(repo_url) config_schema_file_name = repo_processor.generate_file_name( repo_info, 'config-schema.yaml') config_schema_file = open(config_schema_file_name, 'r') meta_info_file = repo_processor.generate_file_name( repo_info, 'meta-info.yaml') meta_info_parent_name = repo_processor.generate_meta_info_parent_name( meta_info_file) meta_info = data[meta_info_parent_name] default_data_file_name = repo_processor.generate_file_name( repo_info, 'default-data.yaml') default_data_runtime_file = open( default_data_file_name + ".runtime", 'w') default_data_file = open(default_data_file_name, 'r') default_data_runtime_file.write(runtime_vars) for l in default_data_file.readlines(): default_data_runtime_file.write(l) default_data_file.close() default_data_runtime_file.close() config_schema_file.close() augmented_config = processor_config_schemas.process_config_schema( lightweight_component[component_section], config_schema_file, default_data_runtime_file, meta_info) updated_component[component_section] = augmented_config else: updated_component[ component_section] = lightweight_component[ component_section] updated_components.append(updated_component) phase_5_output[data_section] = updated_components else: phase_5_output[data_section] = data[data_section] yaml.dump(phase_5_output, phase_5_output_file) phase_5_output_file.close() return phase_5_output_file
def test_get_meta_info(self): repo_url = "https://github.com/WLCG-Lightweight-Sites/wlcg_lightweight_site_ce_cream" get_repository_file(repo_url, "meta-info.yaml",True) repo_info = analyse_repo_url(repo_url) fname = generate_file_name(repo_info, "meta-info.yaml") with open(fname, "r") as file: output = file.read() file_name = "meta_info.expected" file_url = "https://raw.githubusercontent.com/WLCG-Lightweight-Sites/wlcg_lightweight_site_ce_cream/master/meta-info.yaml" meta_info_output = urlopen(file_url).read() with open(file_name, "w") as file: file.write(meta_info_output) augment_meta_info(file_name) with open(file_name, "r") as file: expected_output = file.read() self.assertEqual(output, expected_output)
def test_generate_meta_info_file_name(self): repo_info = { "org_name": "WLCG-Lightweight-Sites", "repo_name": "simple_grid_yaml_compiler", "branch_name": "master" } expected_output = "./.temp/simple_grid_yaml_compiler_info.yaml" self.assertEqual(generate_file_name(repo_info, "meta-info.yaml"), expected_output)
def test_generate_default_file_name(self): repo_info = { "org_name": "WLCG-Lightweight-Sites", "repo_name": "simple_grid_yaml_compiler", "branch_name": "master" } expected_output = "./.temp/simple_grid_yaml_compiler_defaults.yaml" self.assertEqual(generate_file_name(repo_info, "site_level_configuration_defaults.yaml"), expected_output)
def test_get_config_schema(self): repo_url = "https://github.com/WLCG-Lightweight-Sites/wlcg_lightweight_site_ce_cream" get_repository_file(repo_url, "config-schema.yaml") repo_info = analyse_repo_url(repo_url) fname = generate_file_name(repo_info, "config-schema.yaml") with open(fname, "r") as file: output = file.read() file_url = "https://raw.githubusercontent.com/WLCG-Lightweight-Sites/wlcg_lightweight_site_ce_cream/master/config-schema.yaml" expected_output = urlopen(file_url).read() self.assertEqual(output, expected_output)