def read_installed_rpms(self): installed_rpms = [] yum_rpms = YumInfoParser().parse_installed(self.yum_info_installed) rpm_rpms = RpmInfoParser().parse_multiple(self.rpm_info_installed) self._validate_rpm_lists_identical(yum_rpms, rpm_rpms) yum_rpms_dict = {rpm['Name']: rpm for rpm in yum_rpms} for rpm_data in rpm_rpms: yum_data = yum_rpms_dict[rpm_data['Name']] combined_data = self._combine_rpm_data(rpm_data, yum_data) installed_rpms.append(combined_data) logging.debug('One parsed RPM data as example:\n{}'.format(pformat(installed_rpms[0]))) return installed_rpms
def _read_available_rpms(self, repos): Yum.clean_and_remove_cache() yum = Yum() for repo in repos: name = repo['name'] if name == 'localrepo': if self.remote: url = self.repoconfig.get_localrepo(remote=True)['baseurl'] yum.add_repo(name, apply_jenkins_auth(url)) else: url = self.repoconfig.get_localrepo(remote=False)['baseurl'] yum.add_repo(name, url) else: yum.add_repo(name, repo['baseurl']) yum_available_output = yum.read_all_packages() available_rpms = YumInfoParser().parse_available(yum_available_output) rpms_per_repo = {} for rpm in available_rpms: repo = rpm.get('Repo') if repo not in rpms_per_repo: rpms_per_repo[repo] = [] rpms_per_repo[repo].append(rpm) return rpms_per_repo
def test_parse_file(): test_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'yum_info_installed.sample') parsed = YumInfoParser().parse_file(test_file) assert len(parsed) == 14
def test_parse_available(available_header): fake_out = '\n'.join( [available_header, bash_yum_info, conntrack_tools_yum_info]) parsed = YumInfoParser().parse_available(fake_out) expected = [bash_expected, conntrack_tools_expected] assert parsed == expected
def test_parse_installed(): fake_out = '\n'.join( [yum_info_installed_header, bash_yum_info, conntrack_tools_yum_info]) parsed = YumInfoParser().parse_installed(fake_out) expected = [bash_expected, conntrack_tools_expected] assert parsed == expected
def test_parse_package(yum_info, expected_output): parsed = YumInfoParser().parse_package(yum_info) expected = expected_output assert parsed == expected