def test_actor_with_grep_package(current_actor_context): rpms = [ RPM(name='wireshark', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch', pgpsig= 'RSA/SHA256, Mon 01 Jan 1970 00:00:00 AM -03, Key ID 199e2f91fd431d51' ), RPM(name='powertop', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch', pgpsig= 'RSA/SHA256, Mon 01 Jan 1970 00:00:00 AM -03, Key ID 199e2f91fd431d51' ) ] current_actor_context.feed(InstalledRedHatSignedRPM(items=rpms)) current_actor_context.run() assert current_actor_context.consume(Report)
def process(self): RH_SIGS = [ '199e2f91fd431d51', '5326810137017186', '938a80caf21541eb', 'fd372689897da07a', '45689c882fa658e0' ] signed_pkgs = InstalledRedHatSignedRPM() unsigned_pkgs = InstalledUnsignedRPM() for rpm_pkgs in self.consume(InstalledRPM): for pkg in rpm_pkgs.items: env_vars = self.configuration.leapp_env_vars # if we start upgrade with LEAPP_DEVEL_RPMS_ALL_SIGNED=1, we consider all packages to be signed all_signed = [ env for env in env_vars if env.name == 'LEAPP_DEVEL_RPMS_ALL_SIGNED' and env.value == '1' ] # "gpg-pubkey" is not signed as it would require another package to verify its signature if any(key in pkg.pgpsig for key in RH_SIGS) or \ (pkg.name == 'gpg-pubkey' and pkg.packager.startswith('Red Hat, Inc.') or all_signed): signed_pkgs.items.append(pkg) continue unsigned_pkgs.items.append(pkg) self.produce(signed_pkgs) self.produce(unsigned_pkgs)
def get_pkgs(pkg_name): """ Get all installed packages of the given name signed by Red Hat. """ rpms = next(api.consume(InstalledRedHatSignedRPM), InstalledRedHatSignedRPM()).items return [pkg for pkg in rpms if pkg.name == pkg_name]
def test_actor_execution(monkeypatch, has_server): """ Parametrized helper function for test_actor_* functions. First generate list of RPM models based on set arguments. Then, run the actor feeded with our RPM list. Finally, assert Reports according to set arguments. Parameters: has_server (bool): postgresql-server installed """ # Couple of random packages rpms = [_generate_rpm_with_name('sed'), _generate_rpm_with_name('htop')] if has_server: # Add postgresql-server rpms += [_generate_rpm_with_name('postgresql-server')] curr_actor_mocked = CurrentActorMocked( msgs=[InstalledRedHatSignedRPM(items=rpms)]) monkeypatch.setattr(api, 'current_actor', curr_actor_mocked) monkeypatch.setattr(reporting, "create_report", create_report_mocked()) # Executed actor feeded with out fake RPMs report_installed_packages(_context=api) if has_server: # Assert for postgresql-server package installed assert reporting.create_report.called == 1 else: # Assert for no postgresql packages installed assert not reporting.create_report.called
def test_is_processable_vsftpd_installed(): installed_rpms = [ RPM(name='sendmail', version='8.14.7', release='5.el7', epoch='0', packager='foo', arch='x86_64', pgpsig='bar'), RPM(name='vsftpd', version='3.0.2', release='25.el7', epoch='0', packager='foo', arch='x86_64', pgpsig='bar'), RPM(name='postfix', version='2.10.1', release='7.el7', epoch='0', packager='foo', arch='x86_64', pgpsig='bar') ] installed_rpm_facts = InstalledRedHatSignedRPM(items=installed_rpms) res = vsftpdconfigread.is_processable(installed_rpm_facts) assert res is True
def test_actor_execution_with_sample_data(current_actor_context): installed_rpm = [ RPM(name='sample01', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch', pgpsig='SOME_PGP_SIG'), RPM(name='sample02', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch', pgpsig='SOME_PGP_SIG') ] current_actor_context.feed(InstalledRedHatSignedRPM(items=installed_rpm)) current_actor_context.feed( RpmTransactionTasks(to_remove=[rpm.name for rpm in installed_rpm], to_keep=[installed_rpm[0].name])) current_actor_context.run() result = current_actor_context.consume(FilteredRpmTransactionTasks) assert len(result) == 1 assert result[0].to_keep == [installed_rpm[0].name] assert result[0].to_remove == [installed_rpm[1].name]
def get_kernel_rpms(): """ Get all installed kernel packages ordered by release number (ascending). """ rpms = next(api.consume(InstalledRedHatSignedRPM), InstalledRedHatSignedRPM()) return sorted([pkg for pkg in rpms.items if pkg.name == 'kernel'], key=get_kernel_rpm_release)
def test_process_devel_kernels(current_actor_context, n): current_actor_context.feed( InstalledRedHatSignedRPM(items=ballast1 + devel_kernels[:n] + ballast2)) current_actor_context.run() if n < 2: assert not current_actor_context.consume(Report) else: assert current_actor_context.consume(Report)
def get_kernel_rpms(): """ Get all installed kernel packages ordered first by version, then release number (ascending). """ rpms = next(api.consume(InstalledRedHatSignedRPM), InstalledRedHatSignedRPM()) return sorted([pkg for pkg in rpms.items if pkg.name == 'kernel'], key=lambda k: (get_kernel_rpm_version(k), get_kernel_rpm_release(k)))
def process(self): RH_SIGS = [ '199e2f91fd431d51', '5326810137017186', '938a80caf21541eb', 'fd372689897da07a', '45689c882fa658e0' ] signed_pkgs = InstalledRedHatSignedRPM() unsigned_pkgs = InstalledUnsignedRPM() env_vars = self.configuration.leapp_env_vars # if we start upgrade with LEAPP_DEVEL_RPMS_ALL_SIGNED=1, we consider # all packages to be signed all_signed = [ env for env in env_vars if env.name == 'LEAPP_DEVEL_RPMS_ALL_SIGNED' and env.value == '1' ] def has_rhsig(pkg): return any(key in pkg.pgpsig for key in RH_SIGS) def is_gpg_pubkey(pkg): """Check if gpg-pubkey pkg exists or LEAPP_DEVEL_RPMS_ALL_SIGNED=1 gpg-pubkey is not signed as it would require another package to verify its signature """ return ( # pylint: disable-msg=consider-using-ternary pkg.name == 'gpg-pubkey' and pkg.packager.startswith('Red Hat, Inc.') or all_signed) def has_katello_prefix(pkg): """Whitelist the katello package.""" return pkg.name.startswith('katello-ca-consumer') def is_azure_pkg(pkg): """Whitelist Azure config package.""" arch = self.configuration.architecture el7_pkg = rhui.RHUI_CLOUD_MAP[arch]['azure']['el7_pkg'] el8_pkg = rhui.RHUI_CLOUD_MAP[arch]['azure']['el8_pkg'] return pkg.name in [el7_pkg, el8_pkg] for rpm_pkgs in self.consume(InstalledRPM): for pkg in rpm_pkgs.items: if any([ has_rhsig(pkg), is_gpg_pubkey(pkg), has_katello_prefix(pkg), is_azure_pkg(pkg), ]): signed_pkgs.items.append(pkg) continue unsigned_pkgs.items.append(pkg) self.produce(signed_pkgs) self.produce(unsigned_pkgs)
def consume_message_mocked(*models): pkgs = [ RPM(name='original', epoch='', packager='', version='', release='', arch='', pgpsig='') ] yield InstalledRedHatSignedRPM(items=pkgs)
def test_actor_execution_with_sample_data(current_actor_context): installed_rpm = [ RPM(name='sample01', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch', pgpsig='SOME_PGP_SIG'), RPM(name='sample02', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch', pgpsig='SOME_PGP_SIG') ] modules_to_enable = [ Module(name='enable', stream='1'), Module(name='enable', stream='2') ] modules_to_reset = [ Module(name='reset', stream='1'), Module(name='reset', stream='2') ] current_actor_context.feed(InstalledRedHatSignedRPM(items=installed_rpm)) current_actor_context.feed( RpmTransactionTasks( to_remove=[rpm.name for rpm in installed_rpm], to_keep=[installed_rpm[0].name], modules_to_enable=modules_to_enable, modules_to_reset=modules_to_reset, )) current_actor_context.feed( RpmTransactionTasks( modules_to_enable=modules_to_enable, modules_to_reset=modules_to_reset, )) current_actor_context.run() result = current_actor_context.consume(FilteredRpmTransactionTasks) assert len(result) == 1 assert result[0].to_keep == [installed_rpm[0].name] assert result[0].to_remove == [installed_rpm[1].name] assert len(result[0].modules_to_enable) == 2 assert all(m.name == 'enable' for m in result[0].modules_to_enable) assert '1' in {m.stream for m in result[0].modules_to_enable} assert '2' in {m.stream for m in result[0].modules_to_enable} assert len(result[0].modules_to_reset) == 2 assert all(m.name == 'reset' for m in result[0].modules_to_reset) assert '1' in {m.stream for m in result[0].modules_to_reset} assert '2' in {m.stream for m in result[0].modules_to_reset}
def consume_signed_rpms_mocked(*models): installed = [ RPM(name='c', version='0.1', release='1.sm01', epoch='1', packager=RH_PACKAGER, arch='noarch', pgpsig= 'RSA/SHA256, Mon 01 Jan 1970 00:00:00 AM -03, Key ID 199e2f91fd431d51' ) ] yield InstalledRedHatSignedRPM(items=installed)
def process(self): RH_SIGS = [ '199e2f91fd431d51', '5326810137017186', '938a80caf21541eb', 'fd372689897da07a', '45689c882fa658e0' ] signed_pkgs = InstalledRedHatSignedRPM() unsigned_pkgs = InstalledUnsignedRPM() for rpm_pkgs in self.consume(InstalledRPM): for pkg in rpm_pkgs.items: if any(key in pkg.pgpsig for key in RH_SIGS): signed_pkgs.items.append(pkg) continue unsigned_pkgs.items.append(pkg) self.produce(signed_pkgs) self.produce(unsigned_pkgs)
def process(self): RH_SIGS = [ '199e2f91fd431d51', '5326810137017186', '938a80caf21541eb', 'fd372689897da07a', '45689c882fa658e0' ] signed_pkgs = InstalledRedHatSignedRPM() unsigned_pkgs = InstalledUnsignedRPM() for rpm_pkgs in self.consume(InstalledRPM): for pkg in rpm_pkgs.items: # "gpg-pubkey" is not signed as it would require another package to verify its signature if any(key in pkg.pgpsig for key in RH_SIGS) or \ (pkg.name == 'gpg-pubkey' and pkg.packager.startswith('Red Hat, Inc.')): signed_pkgs.items.append(pkg) continue unsigned_pkgs.items.append(pkg) self.produce(signed_pkgs) self.produce(unsigned_pkgs)
def get_sample_installed_pkgs(pkgs): return InstalledRedHatSignedRPM(items=[get_sample_rpm(*p) for p in pkgs])
def create_rpms(pkgs): installed_rpms = InstalledRedHatSignedRPM() for pkg in pkgs: installed_rpms.items.append( create_rpm(name=pkg[0], version=pkg[1], release=pkg[2])) return installed_rpms
def create_modulesfacts(installed_rpm): return InstalledRedHatSignedRPM(items=installed_rpm)
def mock_rpms(*names): return InstalledRedHatSignedRPM(items=[mock_rpm(name) for name in names])
def _get_kernel_rpms(): rpms = next(api.consume(InstalledRedHatSignedRPM), InstalledRedHatSignedRPM()) return [pkg for pkg in rpms.items if pkg.name == 'kernel']
def f(*a): yield InstalledRedHatSignedRPM(items=installed_rpms)