def test_load_yaml_input_check(mocker): data_file = 'some-file' data_file_content = 'some-file-content' path_m = mocker.patch.object(utils, 'Path', autospec=True) path_m().read_text.return_value = data_file_content run_m = mocker.patch.object(utils, 'load_yaml_str', autospec=True) utils.load_yaml(data_file) run_m.assert_called_once_with(data_file_content)
def test_load_yaml_raises_exception(mocker, patch_logging): data_file = 'some-file' data_file_content = 'some-file-content' path_m = mocker.patch.object(utils, 'Path', autospec=True) path_m().read_text.return_value = data_file_content mocker.patch.object( utils, 'load_yaml_str', autospec=True, side_effect=yaml.YAMLError ) with pytest.raises(errors.BadPillarDataError): utils.load_yaml(data_file)
def test_load_yaml_output_check(mocker): out_data = 'some-out-data' data_file = 'some-file' data_file_content = 'some-file-content' path_m = mocker.patch.object(utils, 'Path', autospec=True) path_m().read_text.return_value = data_file_content mocker.patch.object( utils, 'load_yaml_str', autospec=True, return_value=out_data ) assert utils.load_yaml(data_file) == out_data
def load_metadata(self): """ Load the metadata from metadata url Returns ------- dict: dictionary with Cortx repository metadata (content of RELEASE.INFO file) """ try: if self.metadata_uri.is_local: metadata = utils.load_yaml(self.metadata_uri.path) else: r = requests.get(str(self.metadata_uri)) metadata = utils.load_yaml_str(r.content.decode("utf-8")) except Exception as exc: raise errors.SWUpdateRepoSourceError( str(self.metadata_uri), f"Failed to load '{self.metadata_uri}' file: {exc}") return metadata
def _get_rpms_from_release(self, source): return utils.load_yaml(source)['COMPONENTS']
def test_pillar_updater_update_rollback_dump(targets, some_param_gr, some_param_di, pillar_dir, pillar_host_dir_tmpl): if targets != ALL_MINIONS: pillar_dir = Path(pillar_host_dir_tmpl.format(minion_id=targets)) pillar_dir.mkdir(parents=True) input_param_group = some_param_gr('new-value1', 'new-value2') input_param_di = some_param_di('some_key', 'new-value3') attr1_param = some_param_gr.param_spec('attr1') attr2_param = some_param_gr.param_spec('attr2') attr3_param = input_param_di.param_spec() f1 = add_pillar_merge_prefix(pillar_dir / attr1_param.fpath.name) f2 = add_pillar_merge_prefix(pillar_dir / attr2_param.fpath.name) f3 = add_pillar_merge_prefix(pillar_dir / attr3_param.fpath.name) pillar_data = {'1': {'2': {'3': '4', '5': '6'}, 'di_parent': {}}} dump_yaml(f1, pillar_data) dump_yaml(f2, pillar_data) dump_yaml(f3, pillar_data) pu = PillarUpdater(targets=targets) # update (in memory only) pu.update(input_param_group, input_param_di) p1 = deepcopy(pillar_data) p1['1']['2']['3'] = input_param_group.attr1 assert pu.pillar(f1.name) == p1 assert load_yaml(f1) == pillar_data p2 = deepcopy(pillar_data) p2['1']['2']['5'] = input_param_group.attr2 assert pu.pillar(f2.name) == p2 assert load_yaml(f2) == pillar_data p3 = deepcopy(pillar_data) p3['1']['di_parent'] = {input_param_di.key_attr: input_param_di.value_attr} assert pu.pillar(f3.name) == p3 assert load_yaml(f3) == pillar_data # update on disk pu.dump() assert load_yaml(f1) == p1 assert load_yaml(f2) == p2 assert load_yaml(f3) == p3 # rolllback (in memory only) pu.rollback() assert pu.pillar(f1.name) == pillar_data assert load_yaml(f1) == p1 assert pu.pillar(f2.name) == pillar_data assert load_yaml(f2) == p2 assert pu.pillar(f3.name) == pillar_data assert load_yaml(f3) == p3 # rollback on disk pu.dump() assert load_yaml(f1) == pillar_data assert load_yaml(f2) == pillar_data assert load_yaml(f3) == pillar_data
def __source_iso(self): if not self.iso_cortx: raise ValueError("ISO for CORTX is undefined") iso_names = [] if self.iso_os: if self.iso_os.suffix != '.iso': raise ValueError( ".iso extension is expected for OS ISO" ) iso_names.append(self.iso_os.name) if self.iso_cortx.suffix != '.iso': raise ValueError(".iso extension is expected for CORTX ISO") iso_names.append(self.iso_cortx.name) if self.iso_cortx_deps: if self.iso_cortx_deps.suffix != '.iso': raise ValueError( ".iso extension is expected for CORTX deps ISO" ) if not self.pypi_repo: logger.warning( "Custom python repo can be used only " "for single ISO based setup " "hence pip will be configured to install from pypi.org" ) self.pypi_repo = True iso_names.append(self.iso_cortx_deps.name) if len(iso_names) != len(set(iso_names)): raise ValueError( "ISO files have collision in names" ) if self.dist_type != config.DistrType.BUNDLE: logger.info( "The type of distribution would be set to " f"{config.DistrType.BUNDLE}" ) self.dist_type = config.DistrType.BUNDLE if ( self.target_build != attr.fields(type(self)).target_build.default ): logger.warning( "`target_build` value would be ignored " "for ISO based installation" ) release_sls = ( config.BUNDLED_SALT_PILLAR_DIR / 'groups/all/release.sls' ) # iso files will be mounted into dirs inside that directory base_dir = Path( utils.load_yaml(release_sls)['release']['base']['base_dir'] ) if not self.iso_cortx_deps: base_dir /= config.CORTX_SINGLE_ISO_DIR self.target_build = f'file://{base_dir}' if ( self.url_cortx_deps != attr.fields(type(self)).url_cortx_deps.default ): logger.warning( "`url_cortx_deps` value would be ignored " "for ISO based installation" ) self.url_cortx_deps = None