def iso_version(self) -> config.ISOVersion: """ Return version of ISO bundle scheme for the release Returns ------- config.ISOVersion: return version of ISO bundle scheme for the release """ if self._iso_version is None: if self.is_factory: # FIXME improve to support newer versions for deployment self._iso_version = config.ISOVersion.VERSION1 else: # search in upgrade releases pillar_path = f'release/upgrade/repos/{self.version}' pillars = PillarResolver(local_minion_id()).get( [PillarKey(pillar_path)], fail_on_undefined=True) upgrade_release = pillars[local_minion_id()][PillarKey( pillar_path)] release_data = upgrade_release.get(self.version) # NOTE: release_data can be None after applying # remove_swupgrade_repo command if (isinstance(release_data, dict) and 'version' in release_data): self._iso_version = config.ISOVersion( release_data['version']) else: # FIXME: it may be remote repo self._iso_version = config.ISOVersion.VERSION1 return self._iso_version
def plan_upgrade(self, sw_list=None): if sw_list is None: pi_key = PillarKey('upgrade/sw_list') sw_list = PillarResolver(local_minion_id()).get( [pi_key], fail_on_undefined=True)[local_minion_id()][pi_key] logger.debug(f"Resolved sw list: {sw_list}") # TODO plan the sw order # - (if not provided) plan according to upgrade ISO data pi_key = PillarKey('commons/sw_data') sw_data = PillarResolver(local_minion_id()).get( [pi_key], fail_on_undefined=True)[local_minion_id()][pi_key] logger.debug(f"Resolved sw data: {sw_data}") diff = set(sw_list) - set(sw_data) if diff: raise ValueError(f"Unexpected sw to upgrade: {diff}") sw_data = { _sw: _data for _sw, _data in sw_data.items() if _sw in sw_list } # FIXME return list of objects, e.g. SWData return sw_data
def test_param_Param_init(): name = '1/2/3' kp = '6/7/8' fp = 'q/w/e' for _kp in (kp, Path(kp), KeyPath(kp)): assert Param(name, _kp) == Param(name, PillarKey(kp)) assert Param(name, (kp, fp)) == Param(name, PillarKey(kp, fp))
def test_pillar_PillarKey_init(): keypath = '1/2/3/4/5' assert PillarKey(keypath) == PillarKey(keypath, '1.sls') assert PillarKey(keypath, 'some.sls').fpath == Path('some.sls') assert PillarKey(keypath, Path('some.sls')).fpath == Path('some.sls') assert PillarKey(keypath) == PillarKey(KeyPath(keypath)) # short keypath assert PillarKey('1') == PillarKey('1', '1.sls') # incorrect keypaths with pytest.raises(TypeError): PillarKey(None) for kp in ('', '.', '/'): with pytest.raises(ValueError): PillarKey(kp)
def get_pillar_data(key: str): """ Get pillar_value for the specific key provided Parameters ---------- key: str keypath for which value to be fetched. 'key1/key2/key3' """ pillar_key = PillarKey(key) pillar = PillarResolver(local_minion_id(), local=True).get([pillar_key]) pillar = next(iter(pillar.values())) return pillar[PillarKey(key)]
def pillar(self): # XXX uses the pillar only if self._pillar is None: rc_key = PillarKey(self.resource_name) pillar = PillarResolverNew(client=self.client).get((rc_key, )) self._pillar = { target: (_pillar[rc_key] if _pillar[rc_key] and _pillar[rc_key] is not values.MISSED else {}) for target, _pillar in pillar.items() } return self._pillar
def _get_release_info_path(self): release_info = None update_repo = PillarKey('release/upgrade') pillar = PillarResolver(local_minion_id()).get([update_repo]) pillar = next(iter(pillar.values())) upgrade_data = pillar[update_repo] base_dir = Path(upgrade_data['base_dir']) repos = upgrade_data['repos'] for version in reversed(list(repos)): if version == config.REPO_CANDIDATE_NAME: continue release_info = base_dir / f'{version}/RELEASE.INFO' # Note. upgrade iso now may lack release file on top level if not release_info.exists(): release_info = ( base_dir / f'{version}/{config.CORTX_ISO_DIR}/RELEASE.INFO') if release_info.exists(): release_rpms = self._get_rpms_from_release(release_info) if self._compare_rpms_info(release_rpms): return release_info
def test_inputs_PillarInputBase_iter(param_spec_mocked): keypath = '1/2/3' value = 567 fpath = '890.sls' test = PillarInputBase.from_args(keypath, value, fpath=fpath) assert test.pillar_items() == ((PillarKey(keypath, fpath), value), )
def test_inputs_PillarKeysList_from_args(): PillarKeysList.from_args('1', ('2', '3')) == PillarKeysList( [PillarKey('1'), PillarKey('2', '3')]) with pytest.raises(TypeError): PillarKeysList.from_args(['1', '2'])
def test_inputs_PillarKeysList_iter(): pi_keys = [PillarKey('1'), PillarKey('2')] pi_keys_list = PillarKeysList(pi_keys) assert pi_keys == list(pi_keys_list)
def test_inputs_PillarKeysList_len(): assert len(PillarKeysList()) == 0 assert len(PillarKeysList([PillarKey('1'), PillarKey('2')])) == 2
def test_pillar_PillarKey_to_str(): keypath = '1/2/3/4/5' assert str(PillarKey(keypath)) == keypath
def run(self, iso_path: str = None, release: str = None) -> Union[CortxISOInfo, None]: """ Main function for Get SW Upgrade Repo command. Command returns information about CORTX packages and their versions. Parameters ---------- iso_path: str Path to SW upgrade single ISO bundle release: str SW upgrade repository release version Returns ------- CortxISOInfo: return instance of CortxISOInfo with CORTX packages versions and Cortx repo metadata """ run_args = self._run_args_type(iso_path, release) local_minion = local_minion_id() set_swupgrade_repo = self._get_set_swupgrade_repo_obj() iso_version = None if run_args.iso_path is not None: # if the `iso_path` is set up, we ignore the `release` parameter return set_swupgrade_repo.run(run_args.iso_path, dry_run=True) if run_args.release is not None: cortx_release = CortxRelease(version=run_args.release) else: # NOTE: take the latest release from SW upgrade repositories # TODO: make get pillar API public and available for others to # avoid code duplication pillar_path = 'release/upgrade/repos' pillars = PillarResolver(local_minion).get( [PillarKey(pillar_path)], fail_on_undefined=True ) repos_info = pillars[local_minion][PillarKey(pillar_path)] upgrade_releases = list(repos_info.keys()) upgrade_releases.remove(REPO_CANDIDATE_NAME) if not upgrade_releases: logger.warning("There are no set up SW upgrade repositories") return None # NOTE: Assumption: we expect that SW Upgrade release version # is formatted according to PEP-440 run_args.release = max(upgrade_releases, key=version.parse) cortx_release = CortxRelease(version=run_args.release) iso_version = cortx_release.iso_version set_swupgrade_repo.set_source_version(iso_version) packages = set_swupgrade_repo.get_packages_version(run_args.release) return CortxISOInfo( packages=packages, metadata=cortx_release.metadata )