class RHAI(Base): def view_registered_systems(self): """To view the number of registered systems""" result = self.wait_until_element( locators['insights.registered_systems'] ).text return result def register_client_to_rhai(self, activation_key, org): self.vm = VirtualMachine(distro='rhel67') self.vm.create() # Download and Install ketello-ca rpm self.vm.install_katello_cert() self.vm.register_contenthost(activation_key, org) # Red Hat Access Insights requires RHEL 6/7 repo and it not # possible to sync the repo during the tests, # adding a file in /etc/yum.repos.d/rhel6/7.repo rhel6_repo = conf.properties['insights.rhel6_repo'] repo_file = ( '[rhel6-rpms]\n' 'name=RHEL6\n' 'baseurl={0}\n' 'enabled=1\n' .format(rhel6_repo) ) self.vm.run( 'echo "{0}" >> /etc/yum.repos.d/rhel6.repo' .format(repo_file) ) # Install redhat-access-insights package package_name = 'redhat-access-insights' result = self.vm.run('yum install -y {0}'.format(package_name)) if result.return_code != 0: raise AccessInsightsError( 'Unable to install redhat-access-insights rpm' ) # Verify if package is installed by query it result = self.vm.run('rpm -q {0}'.format(package_name)) if result.return_code != 0: raise AccessInsightsError( 'Unable to install redhat-access-insights rpm' ) # Register client with Red Hat Access Insights result = self.vm.run('redhat-access-insights --register') if result.return_code != 0: raise AccessInsightsError( 'Unable to register client to Access Insights through ' 'Satellite')
class TestCHKatelloAgent(CLITestCase): """Content-host tests, which require VM with installed katello-agent.""" org = None env = None cv = None activation_key = None org_is_set_up = False def setUp(self): """Create VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages """ super(TestCHKatelloAgent, self).setUp() # Create new org, environment, CV and activation key if TestCHKatelloAgent.org is None: TestCHKatelloAgent.org = make_org() if TestCHKatelloAgent.env is None: TestCHKatelloAgent.env = make_lifecycle_environment({ u'organization-id': TestCHKatelloAgent.org['id'], }) if TestCHKatelloAgent.cv is None: TestCHKatelloAgent.cv = make_content_view({ u'organization-id': TestCHKatelloAgent.org['id'], }) if TestCHKatelloAgent.activation_key is None: TestCHKatelloAgent.activation_key = make_activation_key({ u'lifecycle-environment-id': TestCHKatelloAgent.env['id'], u'organization-id': TestCHKatelloAgent.org['id'], }) # Add subscription to Satellite Tools repo to activation key if not TestCHKatelloAgent.org_is_set_up: setup_org_for_a_rh_repo({ u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': TestCHKatelloAgent.org['id'], u'content-view-id': TestCHKatelloAgent.cv['id'], u'lifecycle-environment-id': TestCHKatelloAgent.env['id'], u'activationkey-id': TestCHKatelloAgent.activation_key['id'], }) TestCHKatelloAgent.org_is_set_up = True # Create VM and register content host self.vm = VirtualMachine(distro='rhel71') self.vm.create() self.vm.install_katello_cert() # Create custom repo, add subscription to activation key setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': TestCHKatelloAgent.org['id'], u'content-view-id': TestCHKatelloAgent.cv['id'], u'lifecycle-environment-id': TestCHKatelloAgent.env['id'], u'activationkey-id': TestCHKatelloAgent.activation_key['id'], }) # Register content host, install katello-agent self.vm.register_contenthost( TestCHKatelloAgent.activation_key['name'], TestCHKatelloAgent.org['label'] ) self.vm.enable_repo(REPOS['rhst7']['id']) self.vm.install_katello_agent() def tearDown(self): self.vm.destroy() super(TestCHKatelloAgent, self).tearDown() def test_contenthost_get_errata_info(self): """@Test: Get errata info @Feature: Content Host - Errata @Assert: Errata info was displayed """ self.vm.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) result = ContentHost.errata_info({ u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, u'id': FAKE_0_ERRATA_ID, }) self.assertEqual(result.return_code, 0) self.assertEqual(result.stdout[0]['errata-id'], FAKE_0_ERRATA_ID) self.assertEqual(result.stdout[0]['packages'], FAKE_0_CUSTOM_PACKAGE) def test_contenthost_apply_errata(self): """@Test: Apply errata to content host @Feature: Content Host - Errata @Assert: Errata is scheduled for installation """ self.vm.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) result = ContentHost.errata_apply({ u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, u'errata-ids': FAKE_0_ERRATA_ID, }) self.assertEqual(result.return_code, 0) def test_contenthost_package_install(self): """@Test: Install package to content host remotely @Feature: Content Host - Package @Assert: Package was successfully installed """ result = ContentHost.package_install({ u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) self.assertEqual(result.return_code, 0) result = self.vm.run('rpm -q {}'.format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertEqual(result.return_code, 0) def test_contenthost_package_remove(self): """@Test: Remove package from content host remotely @Feature: Content Host - Package @Assert: Package was successfully removed """ self.vm.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) result = ContentHost.package_remove({ u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) self.assertEqual(result.return_code, 0) result = self.vm.run('rpm -q {}'.format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertNotEqual(result.return_code, 0) def test_contenthost_package_upgrade(self): """@Test: Upgrade content host package remotely @Feature: Content Host - Package @Assert: Package was successfully upgraded """ self.vm.run('yum install -y {}'.format(FAKE_1_CUSTOM_PACKAGE)) result = ContentHost.package_upgrade({ u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, u'packages': FAKE_1_CUSTOM_PACKAGE_NAME, }) self.assertEqual(result.return_code, 0) result = self.vm.run('rpm -q {}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) def test_contenthost_package_upgrade_all(self): """@Test: Upgrade all the content host packages remotely @Feature: Content Host - Package @Assert: Packages (at least 1 with newer version available) were successfully upgraded """ self.vm.run('yum install -y {}'.format(FAKE_1_CUSTOM_PACKAGE)) result = ContentHost.package_upgrade_all({ u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, }) self.assertEqual(result.return_code, 0) result = self.vm.run('rpm -q {}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) def test_contenthost_package_group_install(self): """@Test: Install package group to content host remotely @Feature: Content Host - Package group @Assert: Package group was successfully installed """ result = ContentHost.package_group_install({ u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, }) self.assertEqual(result.return_code, 0) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.vm.run('rpm -q {}'.format(package)) self.assertEqual(result.return_code, 0) def test_contenthost_package_group_remove(self): """@Test: Remove package group from content host remotely @Feature: Content Host - Package group @Assert: Package group was successfully removed """ hammer_args = { u'organization-id': TestCHKatelloAgent.org['id'], u'content-host': self.vm.hostname, u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, } result = ContentHost.package_group_install(hammer_args) self.assertEqual(result.return_code, 0) result = ContentHost.package_group_remove(hammer_args) self.assertEqual(result.return_code, 0) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.vm.run('rpm -q {}'.format(package)) self.assertNotEqual(result.return_code, 0)
class RHAI(Base): def view_registered_systems(self): """To view the number of registered systems""" result = self.wait_until_element( locators['insights.registered_systems'] ).text return result def register_client_to_rhai(self, activation_key, org, rhel_distro): self.vm = VirtualMachine(distro=rhel_distro) self.vm.create() # Download and Install ketello-ca rpm self.vm.install_katello_cert() self.vm.register_contenthost(activation_key, org) # Red Hat Access Insights requires RHEL 6/7 repo and it is not # possible to sync the repo during the tests, Adding repo file. if rhel_distro == 'rhel67': rhel_repo = conf.properties['clients.rhel6_repo'] if rhel_distro == 'rhel71': rhel_repo = conf.properties['clients.rhel7_repo'] try: if rhel_distro == 'rhel67': insights_repo = conf.properties['insights.insights_el6repo'] if rhel_distro == 'rhel71': insights_repo = conf.properties['insights.insights_el7repo'] except KeyError: pass self.logger.info('RHEL repo {0}'.format(rhel_repo)) self.logger.info('Insights client repo {0}'.format(insights_repo)) self.vm.configure_rhel_repo(rhel_repo) self.vm.run('wget -O /etc/yum.repos.d/insights.repo {0}'. format(insights_repo)) # Install redhat-access-insights package package_name = 'redhat-access-insights' result = self.vm.run('yum install -y {0}'.format(package_name)) if result.return_code != 0: raise AccessInsightsError( 'Unable to install redhat-access-insights rpm' ) # Verify if package is installed by query it result = self.vm.run('rpm -qi {0}'.format(package_name)) self.logger.info('Insights client rpm version: {0}'.format( result.stdout)) if result.return_code != 0: raise AccessInsightsError( 'Unable to install redhat-access-insights rpm' ) # Register client with Red Hat Access Insights result = self.vm.run('redhat-access-insights --register') if result.return_code != 0: test_connection = self.vm.run( 'redhat-access-insights --test-connection') if test_connection.return_code != 0: raise AccessInsightsError( 'Unable to register client, --test-connection not ' 'successful') raise AccessInsightsError( 'Unable to register client to Access Insights through ' 'Satellite')