def test_destroy(self, ssh_command): """Check if destroy runs the required ssh commands""" self.configure_provisioning_server() image_dir = '/opt/robottelo/images' vm = VirtualMachine() with patch.multiple( vm, image_dir=image_dir, _created=True ): vm.destroy() self.assertEqual(ssh_command.call_count, 3) ssh_command_args_list = [ call('virsh destroy {0}'.format(vm.hostname), hostname=self.provisioning_server, connection_timeout=30), call('virsh undefine {0}'.format(vm.hostname), hostname=self.provisioning_server, connection_timeout=30), call('rm {0}/{1}.img'.format(image_dir, vm.hostname), hostname=self.provisioning_server, connection_timeout=30), ] self.assertListEqual(ssh_command.call_args_list, ssh_command_args_list)
def test_destroy(self, ssh_command, config_provisioning_server, host_os_version_patch): """Check if destroy runs the required ssh commands""" image_dir = '/opt/robottelo/images' vm = VirtualMachine() with patch.multiple(vm, image_dir=image_dir, _created=True): vm.destroy() assert ssh_command.call_count == 3 ssh_command_args_list = [ call( f'virsh destroy {vm.hostname}', hostname=PROV_SERVER_DEFAULT, connection_timeout=30, ), call( f'virsh undefine {vm.hostname}', hostname=PROV_SERVER_DEFAULT, connection_timeout=30, ), call( f'rm {image_dir}/{vm.hostname}.img', hostname=PROV_SERVER_DEFAULT, connection_timeout=30, ), ] assert ssh_command.call_args_list == ssh_command_args_list
def test_destroy(self, ssh_command): """Check if destroy runs the required ssh commands""" self.configure_provisoning_server() image_dir = '/opt/robottelo/images' vm = VirtualMachine() with patch.multiple( vm, image_dir=image_dir, _created=True ): vm.destroy() self.assertEqual(ssh_command.call_count, 3) ssh_command_args_list = [ call('virsh destroy {0}'.format(vm.hostname), hostname=self.provisioning_server), call('virsh undefine {0}'.format(vm.hostname), hostname=self.provisioning_server), call('rm {0}/{1}.img'.format(image_dir, vm.hostname), hostname=self.provisioning_server), ] self.assertListEqual(ssh_command.call_args_list, ssh_command_args_list)
def _vm_cleanup(self, hostname=None): """ Cleanup the VM from provisioning server :param str hostname: The content host hostname """ if hostname: vm = VirtualMachine( hostname=hostname, target_image=hostname, provisioning_server=settings.clients.provisioning_server, ) vm._created = True vm.destroy()
def _vm_cleanup(self, hostname=None): """ Cleanup the VM from provisioning server :param str hostname: The content host hostname """ if hostname: vm = VirtualMachine( hostname=hostname, target_image=hostname, provisioning_server=self.libvirt_vm, distro=DISTRO_RHEL7, ) vm._created = True vm.destroy()
def cleanup_of_provisioned_server(hostname=None, provisioning_server=None, distro=None): """ Cleanup the VM from provisioning server :param: str hostname: The content host hostname :param: str provisioning_server: provision server name :param: str distro: distro type """ if hostname: vm = VirtualMachine( hostname=hostname, target_image=hostname, provisioning_server=provisioning_server, distro=distro, ) vm._created = True vm.destroy()
def fixture_vmsetup(request, fixture_org): """Create Org, Lifecycle Environment, Content View, Activation key, VM, install katello-ca, register it, add remote execution key """ # Create VM and register content host client = VirtualMachine(distro=request.param) try: client.create() if request.param in [DISTRO_SLES11, DISTRO_SLES12]: # SLES hostname in subscription-manager facts doesn't include domain client._hostname = client.hostname.split(".")[0] client.install_katello_ca() # Register content host client.register_contenthost(org=fixture_org.label, lce='Library') assert client.subscribed add_remote_execution_ssh_key(client.ip_addr) yield client finally: client._hostname = None client.destroy()
def fixture_vmsetup(request, fixture_org): """Create Org, Lifecycle Environment, Content View, Activation key, VM, install katello-ca, register it, add remote execution key """ # Create VM and register content host client = VirtualMachine(distro=request.param) try: client.create() if request.param in [DISTRO_SLES11, DISTRO_SLES12]: # SLES hostname in subscription-manager facts doesn't include domain client._hostname = client.hostname.split(".")[0] client.install_katello_ca() # Register content host client.register_contenthost( org=fixture_org.label, lce='Library' ) assert client.subscribed add_remote_execution_ssh_key(client.ip_addr) yield client finally: client._hostname = None client.destroy()
def test_destroy(self, ssh_command): """Check if destroy runs the required ssh commands""" image_dir = '/opt/robottelo/images' provisioning_server = 'provisioning.server.com' vm = VirtualMachine() with patch.multiple(vm, image_dir=image_dir, provisioning_server=provisioning_server, _created=True): vm.destroy() self.assertEqual(ssh_command.call_count, 3) ssh_command_args_list = [ call('virsh destroy {0}'.format(vm.target_image), hostname=provisioning_server), call('virsh undefine {0}'.format(vm.target_image), hostname=provisioning_server), call('rm {0}/{1}.img'.format(image_dir, vm.target_image), hostname=provisioning_server), ] self.assertListEqual(ssh_command.call_args_list, ssh_command_args_list)
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 KatelloAgentTestCase(CLITestCase): """Host tests, which require VM with installed katello-agent.""" org = None env = None content_view = None activation_key = None @classmethod @skip_if_not_set('clients', 'fake_manifest') def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(KatelloAgentTestCase, cls).setUpClass() # Create new org, environment, CV and activation key KatelloAgentTestCase.org = make_org() KatelloAgentTestCase.env = make_lifecycle_environment({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.content_view = make_content_view({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.activation_key = make_activation_key({ u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'organization-id': KatelloAgentTestCase.org['id'], }) # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo({ u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) # Create custom repo, add subscription to activation key setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) def setUp(self): """Create VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages """ super(KatelloAgentTestCase, self).setUp() # Create VM and register content host self.client = VirtualMachine(distro='rhel71') self.client.create() self.client.install_katello_ca() # Register content host, install katello-agent self.client.register_contenthost( KatelloAgentTestCase.org['label'], KatelloAgentTestCase.activation_key['name'], ) self.host = Host.info({'name': self.client.hostname}) self.client.enable_repo(REPOS['rhst7']['id']) self.client.install_katello_agent() def tearDown(self): """Destroy the VM""" self.client.destroy() super(KatelloAgentTestCase, self).tearDown() @tier3 @run_only_on('sat') def test_positive_get_errata_info(self): """Get errata info @id: afb5ab34-1703-49dc-8ddc-5e032c1b86d7 @Assert: Errata info was displayed @CaseLevel: System """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) result = Host.errata_info({ u'host-id': self.host['id'], u'id': FAKE_0_ERRATA_ID, }) self.assertEqual(result[0]['errata-id'], FAKE_0_ERRATA_ID) self.assertEqual(result[0]['packages'], FAKE_0_CUSTOM_PACKAGE) @tier3 @run_only_on('sat') def test_positive_apply_errata(self): """Apply errata to a host @id: 8d0e5c93-f9fd-4ec0-9a61-aa93082a30c5 @Assert: Errata is scheduled for installation @CaseLevel: System """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) Host.errata_apply({ u'errata-ids': FAKE_0_ERRATA_ID, u'host-id': self.host['id'], }) @tier3 @run_only_on('sat') def test_positive_install_package(self): """Install a package to a host remotely @id: b1009bba-0c7e-4b00-8ac4-256e5cfe4a78 @Assert: Package was successfully installed @CaseLevel: System """ Host.package_install({ u'host-id': self.host['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_remove_package(self): """Remove a package from a host remotely @id: 573dec11-8f14-411f-9e41-84426b0f23b5 @Assert: Package was successfully removed @CaseLevel: System """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) Host.package_remove({ u'host-id': self.host['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertNotEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_upgrade_package(self): """Upgrade a host package remotely @id: ad751c63-7175-40ae-8bc4-800462cd9c29 @Assert: Package was successfully upgraded @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) Host.package_upgrade({ u'host-id': self.host['id'], u'packages': FAKE_1_CUSTOM_PACKAGE_NAME, }) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_upgrade_packages_all(self): """Upgrade all the host packages remotely @id: 003101c7-bb95-4e51-a598-57977b2858a9 @Assert: Packages (at least 1 with newer version available) were successfully upgraded @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) Host.package_upgrade_all({'host-id': self.host['id']}) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_install_package_group(self): """Install a package group to a host remotely @id: 8c28c188-2903-44d1-ab1e-b74f6d6affcf @Assert: Package group was successfully installed @CaseLevel: System """ Host.package_group_install({ u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'host-id': self.host['id'], }) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_remove_package_group(self): """Remove a package group from a host remotely @id: c80dbeff-93b4-4cd4-8fae-6a4d1bfc94f0 @Assert: Package group was successfully removed @CaseLevel: System """ hammer_args = { u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'host-id': self.host['id'], } Host.package_group_install(hammer_args) Host.package_group_remove(hammer_args) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertNotEqual(result.return_code, 0) @tier3 def test_negative_unregister_and_pull_content(self): """Attempt to retrieve content after host has been unregistered from Satellite @id: de0d0d91-b1e1-4f0e-8a41-c27df4d6b6fd @assert: Host can no longer retrieve content from satellite @CaseLevel: System """ result = self.client.run('subscription-manager unregister') self.assertEqual(result.return_code, 0) result = self.client.run( 'yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) self.assertNotEqual(result.return_code, 0)
class KatelloAgentTestCase(CLITestCase): """Content-host tests, which require VM with installed katello-agent.""" org = None env = None content_view = None activation_key = None @classmethod @skip_if_not_set("clients", "fake_manifest") def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(KatelloAgentTestCase, cls).setUpClass() # Create new org, environment, CV and activation key KatelloAgentTestCase.org = make_org() KatelloAgentTestCase.env = make_lifecycle_environment({u"organization-id": KatelloAgentTestCase.org["id"]}) KatelloAgentTestCase.content_view = make_content_view({u"organization-id": KatelloAgentTestCase.org["id"]}) KatelloAgentTestCase.activation_key = make_activation_key( { u"lifecycle-environment-id": KatelloAgentTestCase.env["id"], u"organization-id": KatelloAgentTestCase.org["id"], } ) # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo( { u"product": PRDS["rhel"], u"repository-set": REPOSET["rhst7"], u"repository": REPOS["rhst7"]["name"], u"organization-id": KatelloAgentTestCase.org["id"], u"content-view-id": KatelloAgentTestCase.content_view["id"], u"lifecycle-environment-id": KatelloAgentTestCase.env["id"], u"activationkey-id": KatelloAgentTestCase.activation_key["id"], } ) # Create custom repo, add subscription to activation key setup_org_for_a_custom_repo( { u"url": FAKE_0_YUM_REPO, u"organization-id": KatelloAgentTestCase.org["id"], u"content-view-id": KatelloAgentTestCase.content_view["id"], u"lifecycle-environment-id": KatelloAgentTestCase.env["id"], u"activationkey-id": KatelloAgentTestCase.activation_key["id"], } ) def setUp(self): """Create VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages """ super(KatelloAgentTestCase, self).setUp() # Create VM and register content host self.client = VirtualMachine(distro="rhel71") self.client.create() self.client.install_katello_ca() # Register content host, install katello-agent self.client.register_contenthost(KatelloAgentTestCase.activation_key["name"], KatelloAgentTestCase.org["label"]) self.client.enable_repo(REPOS["rhst7"]["id"]) self.client.install_katello_agent() def tearDown(self): self.client.destroy() super(KatelloAgentTestCase, self).tearDown() @tier3 @run_only_on("sat") def test_positive_get_errata_info(self): """Get errata info @Feature: Content Host - Errata @Assert: Errata info was displayed """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) result = ContentHost.errata_info( { u"content-host": self.client.hostname, u"id": FAKE_0_ERRATA_ID, u"organization-id": KatelloAgentTestCase.org["id"], } ) self.assertEqual(result[0]["errata-id"], FAKE_0_ERRATA_ID) self.assertEqual(result[0]["packages"], FAKE_0_CUSTOM_PACKAGE) @tier3 @run_only_on("sat") def test_positive_apply_errata(self): """Apply errata to content host @Feature: Content Host - Errata @Assert: Errata is scheduled for installation """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) ContentHost.errata_apply( { u"content-host": self.client.hostname, u"errata-ids": FAKE_0_ERRATA_ID, u"organization-id": KatelloAgentTestCase.org["id"], } ) @tier3 @run_only_on("sat") def test_positive_install_package(self): """Install package to content host remotely @Feature: Content Host - Package @Assert: Package was successfully installed """ ContentHost.package_install( { u"content-host": self.client.hostname, u"organization-id": KatelloAgentTestCase.org["id"], u"packages": FAKE_0_CUSTOM_PACKAGE_NAME, } ) result = self.client.run("rpm -q {0}".format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on("sat") def test_positive_remove_package(self): """Remove package from content host remotely @Feature: Content Host - Package @Assert: Package was successfully removed """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) ContentHost.package_remove( { u"content-host": self.client.hostname, u"organization-id": KatelloAgentTestCase.org["id"], u"packages": FAKE_0_CUSTOM_PACKAGE_NAME, } ) result = self.client.run("rpm -q {0}".format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertNotEqual(result.return_code, 0) @tier3 @run_only_on("sat") def test_positive_upgrade_package(self): """Upgrade content host package remotely @Feature: Content Host - Package @Assert: Package was successfully upgraded """ self.client.run("yum install -y {0}".format(FAKE_1_CUSTOM_PACKAGE)) ContentHost.package_upgrade( { u"content-host": self.client.hostname, u"organization-id": KatelloAgentTestCase.org["id"], u"packages": FAKE_1_CUSTOM_PACKAGE_NAME, } ) result = self.client.run("rpm -q {0}".format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on("sat") def test_positive_upgrade_packages_all(self): """Upgrade all the content host packages remotely @Feature: Content Host - Package @Assert: Packages (at least 1 with newer version available) were successfully upgraded """ self.client.run("yum install -y {0}".format(FAKE_1_CUSTOM_PACKAGE)) ContentHost.package_upgrade_all( {u"content-host": self.client.hostname, u"organization-id": KatelloAgentTestCase.org["id"]} ) result = self.client.run("rpm -q {0}".format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on("sat") def test_positive_install_package_group(self): """Install package group to content host remotely @Feature: Content Host - Package group @Assert: Package group was successfully installed """ ContentHost.package_group_install( { u"content-host": self.client.hostname, u"groups": FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u"organization-id": KatelloAgentTestCase.org["id"], } ) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run("rpm -q {0}".format(package)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on("sat") def test_positive_remove_package_group(self): """Remove package group from content host remotely @Feature: Content Host - Package group @Assert: Package group was successfully removed """ hammer_args = { u"content-host": self.client.hostname, u"groups": FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u"organization-id": KatelloAgentTestCase.org["id"], } ContentHost.package_group_install(hammer_args) ContentHost.package_group_remove(hammer_args) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run("rpm -q {0}".format(package)) self.assertNotEqual(result.return_code, 0) @tier3 def test_negative_unregister_and_pull_content(self): """Attempt to retrieve content after Content host has been unregistered from Satellite @feature: Content host @assert: Content host can no longer retrieve content from satellite """ result = self.client.run("subscription-manager unregister") self.assertEqual(result.return_code, 0) result = self.client.run("yum install -y {0}".format(FAKE_1_CUSTOM_PACKAGE)) self.assertNotEqual(result.return_code, 0)
class ContentHostTestCase(UITestCase): """Implements Content Host tests in UI""" @classmethod def set_session_org(cls): """Create an organization for tests, which will be selected automatically""" cls.session_org = entities.Organization().create() @classmethod @skip_if_not_set('clients', 'fake_manifest') def setUpClass(cls): """Create Lifecycle Environment, Content View and Activation key """ super(ContentHostTestCase, cls).setUpClass() cls.env = entities.LifecycleEnvironment( organization=cls.session_org).create() cls.content_view = entities.ContentView( organization=cls.session_org).create() cls.activation_key = entities.ActivationKey( environment=cls.env, organization=cls.session_org, ).create() setup_org_for_a_rh_repo({ 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': cls.session_org.id, 'content-view-id': cls.content_view.id, 'lifecycle-environment-id': cls.env.id, 'activationkey-id': cls.activation_key.id, }) setup_org_for_a_custom_repo({ 'url': FAKE_6_YUM_REPO, 'organization-id': cls.session_org.id, 'content-view-id': cls.content_view.id, 'lifecycle-environment-id': cls.env.id, 'activationkey-id': cls.activation_key.id, }) def setUp(self): """Create a VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages""" super(ContentHostTestCase, self).setUp() self.client = VirtualMachine(distro='rhel71') self.client.create() self.client.install_katello_ca() result = self.client.register_contenthost( self.session_org.label, self.activation_key.name) self.assertEqual(result.return_code, 0) self.client.enable_repo(REPOS['rhst7']['id']) self.client.install_katello_agent() def tearDown(self): """Destroy the VM""" self.client.destroy() super(ContentHostTestCase, self).tearDown() @tier3 def test_positive_install_package(self): """Install a package to a host remotely @id: 13b9422d-4b7a-4068-9a57-a94602cd6410 @assert: Package was successfully installed @CaseLevel: System """ with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Package Install', FAKE_0_CUSTOM_PACKAGE_NAME, ) self.assertEqual(result, 'success') self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, FAKE_0_CUSTOM_PACKAGE_NAME)) @tier3 def test_positive_remove_package(self): """Remove a package from a host remotely @id: 86d8896b-06d9-4c99-937e-f3aa07b4eb69 @Assert: Package was successfully removed @CaseLevel: System """ self.client.download_install_rpm( FAKE_6_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Package Remove', FAKE_0_CUSTOM_PACKAGE_NAME, ) self.assertEqual(result, 'success') self.assertIsNone(self.contenthost.package_search( self.client.hostname, FAKE_0_CUSTOM_PACKAGE_NAME)) @tier3 def test_positive_upgrade_package(self): """Upgrade a host package remotely @id: 1969db93-e7af-4f5f-973d-23c222224db6 @Assert: Package was successfully upgraded @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Package Update', FAKE_1_CUSTOM_PACKAGE_NAME, ) self.assertEqual(result, 'success') self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, FAKE_2_CUSTOM_PACKAGE)) @tier3 def test_positive_install_package_group(self): """Install a package group to a host remotely @id: a43fb21b-5f6a-4f14-8cd6-114ec287540c @Assert: Package group was successfully installed @CaseLevel: System """ with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Group Install', FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, ) self.assertEqual(result, 'success') for package in FAKE_0_CUSTOM_PACKAGE_GROUP: self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, package)) @tier3 def test_positive_remove_package_group(self): """Remove a package group from a host remotely @id: dbeea1f2-adf4-4ad8-a989-efad8ce21b98 @Assert: Package group was successfully removed @CaseLevel: System """ with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Group Install', FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, ) self.assertEqual(result, 'success') result = self.contenthost.execute_package_action( self.client.hostname, 'Group Remove', FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, ) self.assertEqual(result, 'success') for package in FAKE_0_CUSTOM_PACKAGE_GROUP: self.assertIsNone(self.contenthost.package_search( self.client.hostname, package)) @tier3 def test_positive_install_errata(self): """Install a errata to a host remotely @id: 13b9422d-4b7a-4068-9a57-a94602cd6410 @assert: Errata was successfully installed @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) with Session(self.browser): result = self.contenthost.install_errata( self.client.hostname, FAKE_2_ERRATA_ID, ) self.assertEqual(result, 'success') self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, FAKE_2_CUSTOM_PACKAGE))
def test_positive_delete_activation_key_5(self): """@Test: Delete an Activation key which has registered systems @Feature: Activation key - Positive Delete @Steps: 1. Create an Activation key 2. Register systems to it 3. Delete the Activation key @Assert: Activation key is deleted """ name = gen_string("alpha", 8) cv_name = gen_string("alpha", 8) env_name = gen_string("alpha", 8) product_name = gen_string("alpha", 8) # Helper function to create and promote CV to next environment self.create_cv(cv_name, env_name, product_name) with Session(self.browser) as session: make_activationkey( session, org=self.org_name, name=name, env=env_name, description=gen_string("alpha", 16), content_view=cv_name ) self.assertIsNotNone(self.activationkey.search_key(name)) self.activationkey.associate_product(name, [product_name]) self.assertIsNotNone(self.activationkey.wait_until_element (common_locators["alert.success"])) # Create VM vm = VirtualMachine(distro='rhel65') vm.create() # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(self.server_name) ) self.assertEqual( result.return_code, 0, "failed to fetch katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) result = vm.run( 'rpm -i katello-ca-consumer*.noarch.rpm' ) self.assertEqual( result.return_code, 0, "failed to install katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) # Register client with foreman server using activation-key result = vm.run( 'subscription-manager register --activationkey {0} ' '--org {1} --force' .format(name, self.org_label) ) self.assertEqual( result.return_code, 0, "failed to register client:: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Delete the activation key self.activationkey.delete(name, True) self.assertIsNone(self.activationkey.search_key(name)) # Delete the virtual machine vm.destroy()
def test_usage_limit(self): """@Test: Test that Usage limit actually limits usage @Feature: Activation key - Usage limit @Steps: 1. Create Activation key 2. Update Usage Limit to a finite number 3. Register Systems to match the Usage Limit 4. Attempt to register an other system after reaching the Usage Limit @Assert: System Registration fails. Appropriate error shown """ name = gen_string("alpha", 10) host_limit = "1" with Session(self.browser) as session: make_activationkey(session, org=self.org_name, name=name, env=ENVIRONMENT) self.assertIsNotNone(self.activationkey.search_key(name)) self.activationkey.update(name, limit=host_limit) self.assertIsNotNone(self.activationkey.wait_until_element (common_locators["alert.success"])) # Create VM1 vm1 = VirtualMachine(distro='rhel65') vm1.create() # Download and Install rpm result = vm1.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(self.server_name) ) self.assertEqual( result.return_code, 0, "failed to fetch katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) result = vm1.run( 'rpm -i katello-ca-consumer*.noarch.rpm' ) self.assertEqual( result.return_code, 0, "failed to install katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) # Register client1 with foreman server using activation-key result = vm1.run( 'subscription-manager register --activationkey {0} ' '--org {1} --force' .format(name, self.org_label) ) self.assertEqual( result.return_code, 0, "failed to register client:: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create VM2 vm2 = VirtualMachine(distro='rhel65') vm2.create() # Download and Install rpm result = vm2.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(self.server_name) ) self.assertEqual( result.return_code, 0, "failed to fetch katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) result = vm2.run( 'rpm -i katello-ca-consumer*.noarch.rpm' ) self.assertEqual( result.return_code, 0, "failed to install katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) # Register client2 with foreman server using activation-key result = vm2.run( 'subscription-manager register --activationkey {0} ' '--org {1} --force' .format(name, self.org_label) ) # Assert system registration fails for client2 and # appropriate error raised self.assertNotEqual(result.return_code, 0) self.assertGreater(len(result.stderr), 0, "There should be an exception here.") self.assertIn('Max Content Hosts ({0}) reached for activation key' .format(host_limit), result.stderr) # Destroy both VM's vm1.destroy() vm2.destroy()
class KatelloAgentTestCase(CLITestCase): """Host tests, which require VM with installed katello-agent.""" org = None env = None content_view = None activation_key = None @classmethod @skip_if_not_set('clients', 'fake_manifest') def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(KatelloAgentTestCase, cls).setUpClass() # Create new org, environment, CV and activation key KatelloAgentTestCase.org = make_org() KatelloAgentTestCase.env = make_lifecycle_environment({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.content_view = make_content_view({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.activation_key = make_activation_key({ u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'organization-id': KatelloAgentTestCase.org['id'], }) # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo({ u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) # Create custom repo, add subscription to activation key setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) def setUp(self): """Create VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages """ super(KatelloAgentTestCase, self).setUp() # Create VM and register content host self.client = VirtualMachine(distro='rhel71') self.client.create() self.client.install_katello_ca() # Register content host, install katello-agent self.client.register_contenthost( KatelloAgentTestCase.activation_key['name'], KatelloAgentTestCase.org['label'] ) self.host = Host.info({'name': self.client.hostname}) self.client.enable_repo(REPOS['rhst7']['id']) self.client.install_katello_agent() def tearDown(self): self.client.destroy() super(KatelloAgentTestCase, self).tearDown() @tier3 @run_only_on('sat') def test_positive_get_errata_info(self): """Get errata info @id: afb5ab34-1703-49dc-8ddc-5e032c1b86d7 @Assert: Errata info was displayed @CaseLevel: System """ self.client.download_install_rpm( FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) result = Host.errata_info({ u'host-id': self.host['id'], u'id': FAKE_0_ERRATA_ID, }) self.assertEqual(result[0]['errata-id'], FAKE_0_ERRATA_ID) self.assertEqual(result[0]['packages'], FAKE_0_CUSTOM_PACKAGE) @tier3 @run_only_on('sat') def test_positive_apply_errata(self): """Apply errata to a host @id: 8d0e5c93-f9fd-4ec0-9a61-aa93082a30c5 @Assert: Errata is scheduled for installation @CaseLevel: System """ self.client.download_install_rpm( FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) Host.errata_apply({ u'errata-ids': FAKE_0_ERRATA_ID, u'host-id': self.host['id'], }) @tier3 @run_only_on('sat') def test_positive_install_package(self): """Install a package to a host remotely @id: b1009bba-0c7e-4b00-8ac4-256e5cfe4a78 @Assert: Package was successfully installed @CaseLevel: System """ Host.package_install({ u'host-id': self.host['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME) ) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_remove_package(self): """Remove a package from a host remotely @id: 573dec11-8f14-411f-9e41-84426b0f23b5 @Assert: Package was successfully removed @CaseLevel: System """ self.client.download_install_rpm( FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) Host.package_remove({ u'host-id': self.host['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME) ) self.assertNotEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_upgrade_package(self): """Upgrade a host package remotely @id: ad751c63-7175-40ae-8bc4-800462cd9c29 @Assert: Package was successfully upgraded @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) Host.package_upgrade({ u'host-id': self.host['id'], u'packages': FAKE_1_CUSTOM_PACKAGE_NAME, }) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_upgrade_packages_all(self): """Upgrade all the host packages remotely @id: 003101c7-bb95-4e51-a598-57977b2858a9 @Assert: Packages (at least 1 with newer version available) were successfully upgraded @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) Host.package_upgrade_all({'host-id': self.host['id']}) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_install_package_group(self): """Install a package group to a host remotely @id: 8c28c188-2903-44d1-ab1e-b74f6d6affcf @Assert: Package group was successfully installed @CaseLevel: System """ Host.package_group_install({ u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'host-id': self.host['id'], }) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_remove_package_group(self): """Remove a package group from a host remotely @id: c80dbeff-93b4-4cd4-8fae-6a4d1bfc94f0 @Assert: Package group was successfully removed @CaseLevel: System """ hammer_args = { u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'host-id': self.host['id'], } Host.package_group_install(hammer_args) Host.package_group_remove(hammer_args) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertNotEqual(result.return_code, 0) @tier3 def test_negative_unregister_and_pull_content(self): """Attempt to retrieve content after host has been unregistered from Satellite @id: de0d0d91-b1e1-4f0e-8a41-c27df4d6b6fd @assert: Host can no longer retrieve content from satellite @CaseLevel: System """ result = self.client.run('subscription-manager unregister') self.assertEqual(result.return_code, 0) result = self.client.run( 'yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) self.assertNotEqual(result.return_code, 0)
def test_multiple_activation_keys_to_system(self): """@Test: Check if multiple Activation keys can be attached to a system @Feature: Activation key - System @Steps: 1. Create multiple Activation keys 2. Attach all the created Activation keys to a System @Assert: Multiple Activation keys are attached to a system """ key_1_name = gen_string("alpha", 8) key_2_name = gen_string("alpha", 8) cv_1_name = gen_string("alpha", 8) cv_2_name = gen_string("alpha", 8) env_1_name = gen_string("alpha", 8) env_2_name = gen_string("alpha", 8) product_1_name = gen_string("alpha", 8) product_2_name = gen_string("alpha", 8) # Helper function to create and promote CV to next environment self.create_cv(cv_1_name, env_1_name, product_1_name) self.create_cv(cv_2_name, env_2_name, product_2_name, repo_url=FAKE_2_YUM_REPO) with Session(self.browser) as session: # Create activation_key_1 make_activationkey( session, org=self.org_name, name=key_1_name, env=env_1_name, description=gen_string("alpha", 16), content_view=cv_1_name ) self.assertIsNotNone(self.activationkey.search_key(key_1_name)) self.activationkey.associate_product(key_1_name, [product_1_name]) self.assertIsNotNone(self.activationkey.wait_until_element (common_locators["alert.success"])) # Create activation_key_2 make_activationkey( session, org=self.org_name, name=key_2_name, env=env_2_name, description=gen_string("alpha", 16), content_view=cv_2_name ) self.assertIsNotNone(self.activationkey.search_key(key_2_name)) self.activationkey.associate_product(key_2_name, [product_2_name]) self.assertIsNotNone(self.activationkey.wait_until_element (common_locators["alert.success"])) # Create VM vm = VirtualMachine(distro='rhel65') vm.create() vm_name = vm.run('hostname') # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(self.server_name) ) self.assertEqual( result.return_code, 0, "failed to fetch katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) result = vm.run( 'rpm -i katello-ca-consumer*.noarch.rpm' ) self.assertEqual( result.return_code, 0, "failed to install katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) # Register client with foreman server using activation-key result = vm.run( 'subscription-manager register --activationkey {0},{1} ' '--org {2} --force' .format(key_1_name, key_2_name, self.org_label) ) self.assertEqual( result.return_code, 0, "failed to register client:: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Assert the content-host association with activation-key for key_name in [key_1_name, key_2_name]: host_name = self.activationkey.fetch_associated_content_host( key_name) self.assertEqual(vm_name.stdout[0], host_name) # Delete the virtual machine vm.destroy()
class KatelloAgentTestCase(CLITestCase): """Content-host tests, which require VM with installed katello-agent.""" org = None env = None content_view = None activation_key = None @classmethod @skip_if_not_set('clients', 'fake_manifest') def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(KatelloAgentTestCase, cls).setUpClass() # Create new org, environment, CV and activation key KatelloAgentTestCase.org = make_org() KatelloAgentTestCase.env = make_lifecycle_environment({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.content_view = make_content_view({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.activation_key = make_activation_key({ u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'organization-id': KatelloAgentTestCase.org['id'], }) # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo({ u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) # Create custom repo, add subscription to activation key setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) def setUp(self): """Create VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages """ super(KatelloAgentTestCase, self).setUp() # Create VM and register content host self.client = VirtualMachine(distro='rhel71') self.client.create() self.client.install_katello_ca() # Register content host, install katello-agent self.client.register_contenthost( KatelloAgentTestCase.activation_key['name'], KatelloAgentTestCase.org['label'] ) self.client.enable_repo(REPOS['rhst7']['id']) self.client.install_katello_agent() def tearDown(self): self.client.destroy() super(KatelloAgentTestCase, self).tearDown() @tier2 @run_only_on('sat') def test_positive_get_errata_info(self): """@Test: Get errata info @Feature: Content Host - Errata @Assert: Errata info was displayed """ self.client.download_install_rpm( FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) result = ContentHost.errata_info({ u'content-host': self.client.hostname, u'id': FAKE_0_ERRATA_ID, u'organization-id': KatelloAgentTestCase.org['id'], }) self.assertEqual(result[0]['errata-id'], FAKE_0_ERRATA_ID) self.assertEqual(result[0]['packages'], FAKE_0_CUSTOM_PACKAGE) @tier2 @run_only_on('sat') def test_positive_apply_errata(self): """@Test: Apply errata to content host @Feature: Content Host - Errata @Assert: Errata is scheduled for installation """ self.client.download_install_rpm( FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) ContentHost.errata_apply({ u'content-host': self.client.hostname, u'errata-ids': FAKE_0_ERRATA_ID, u'organization-id': KatelloAgentTestCase.org['id'], }) @tier2 @run_only_on('sat') def test_positive_install_package(self): """@Test: Install package to content host remotely @Feature: Content Host - Package @Assert: Package was successfully installed """ ContentHost.package_install({ u'content-host': self.client.hostname, u'organization-id': KatelloAgentTestCase.org['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME) ) self.assertEqual(result.return_code, 0) @tier2 @run_only_on('sat') def test_positive_remove_package(self): """@Test: Remove package from content host remotely @Feature: Content Host - Package @Assert: Package was successfully removed """ self.client.download_install_rpm( FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) ContentHost.package_remove({ u'content-host': self.client.hostname, u'organization-id': KatelloAgentTestCase.org['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME) ) self.assertNotEqual(result.return_code, 0) @tier2 @run_only_on('sat') def test_positive_upgrade_package(self): """@Test: Upgrade content host package remotely @Feature: Content Host - Package @Assert: Package was successfully upgraded """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) ContentHost.package_upgrade({ u'content-host': self.client.hostname, u'organization-id': KatelloAgentTestCase.org['id'], u'packages': FAKE_1_CUSTOM_PACKAGE_NAME, }) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier2 @run_only_on('sat') def test_positive_upgrade_packages_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.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) ContentHost.package_upgrade_all({ u'content-host': self.client.hostname, u'organization-id': KatelloAgentTestCase.org['id'], }) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier2 @run_only_on('sat') def test_positive_install_package_group(self): """@Test: Install package group to content host remotely @Feature: Content Host - Package group @Assert: Package group was successfully installed """ ContentHost.package_group_install({ u'content-host': self.client.hostname, u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'organization-id': KatelloAgentTestCase.org['id'], }) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertEqual(result.return_code, 0) @tier2 @run_only_on('sat') def test_positive_remove_package_group(self): """@Test: Remove package group from content host remotely @Feature: Content Host - Package group @Assert: Package group was successfully removed """ hammer_args = { u'content-host': self.client.hostname, u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'organization-id': KatelloAgentTestCase.org['id'], } ContentHost.package_group_install(hammer_args) ContentHost.package_group_remove(hammer_args) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertNotEqual(result.return_code, 0)
class IncrementalUpdateTestCase(TestCase): """Tests for the Incremental Update feature""" @classmethod @skip_if_not_set("clients") def setUpClass(cls): """Creates the pre-requisites for the Incremental updates that used in all test""" super(IncrementalUpdateTestCase, cls).setUpClass() # Create a new Organization cls.org = Organization(name=gen_alpha()).create() # Create two lifecycle environments - DEV, QE cls.dev_lce = LifecycleEnvironment(name="DEV", organization=cls.org).create() cls.qe_lce = LifecycleEnvironment(name="QE", prior=cls.dev_lce, organization=cls.org).create() # Upload manifest with manifests.clone() as manifest: upload_manifest(cls.org.id, manifest.content) # Enable repositories - RHE Virtualization Agents and rhel6 sat6tools rhva_6_repo_id = enable_rhrepo_and_fetchid( basearch=DEFAULT_ARCHITECTURE, org_id=cls.org.id, product=PRDS["rhel"], repo=REPOS["rhva6"]["name"], reposet=REPOSET["rhva6"], releasever=DEFAULT_RELEASE_VERSION, ) rhel6_sat6tools_repo_id = enable_rhrepo_and_fetchid( basearch=DEFAULT_ARCHITECTURE, org_id=cls.org.id, product=PRDS["rhel"], repo=REPOS["rhst6"]["name"], reposet=REPOSET["rhst6"], releasever=None, ) # Read the repositories cls.rhva_6_repo = Repository(id=rhva_6_repo_id).read() cls.rhel6_sat6tools_repo = Repository(id=rhel6_sat6tools_repo_id).read() # Sync the enabled repositories try: cls.old_task_timeout = entity_mixins.TASK_TIMEOUT # Update timeout to 15 minutes to finish sync entity_mixins.TASK_TIMEOUT = 900 for repo in [cls.rhva_6_repo, cls.rhel6_sat6tools_repo]: assert Repository(id=repo.id).sync()["result"] == u"success" finally: entity_mixins.TASK_TIMEOUT = cls.old_task_timeout def setUp(self): """Creates the pre-requisites for the Incremental updates that used per each test""" super(IncrementalUpdateTestCase, self).setUp() # Create content view that will be used filtered erratas self.rhel_6_partial_cv = ContentView( organization=self.org, name=gen_alpha(), repository=[self.rhva_6_repo, self.rhel6_sat6tools_repo] ).create() # Create a content view filter to filter out errata rhel_6_partial_cvf = ErratumContentViewFilter( content_view=self.rhel_6_partial_cv, type="erratum", name="rhel_6_partial_cv_filter", repository=[self.rhva_6_repo], ).create() # Create a content view filter rule - filtering out errata in the last # 365 days start_date = (date.today() - timedelta(days=365)).strftime("%Y-%m-%d") ContentViewFilterRule( content_view_filter=rhel_6_partial_cvf, types=["security", "enhancement", "bugfix"], start_date=start_date, end_date=date.today().strftime("%Y-%m-%d"), ).create() # Publish content view and re-read it self.rhel_6_partial_cv.publish() self.rhel_6_partial_cv = self.rhel_6_partial_cv.read() # Promote content view to 'DEV' and 'QE' assert len(self.rhel_6_partial_cv.version) == 1 for env in (self.dev_lce, self.qe_lce): promote(self.rhel_6_partial_cv.version[0], env.id) # Create host collection self.rhel_6_partial_hc = HostCollection(organization=self.org, name=gen_alpha(), max_hosts=5).create() # Create activation key for content view kwargs = {"organization": self.org, "environment": self.qe_lce.id} rhel_6_partial_ak = ActivationKey( name=gen_alpha(), content_view=self.rhel_6_partial_cv, host_collection=[self.rhel_6_partial_hc], **kwargs ).create() # Assign subscription to activation key. Fetch available subscriptions subs = Subscription(organization=self.org).search() assert len(subs) > 0 # Add subscription to activation key sub_found = False for sub in subs: if sub.read_json()["product_name"] == DEFAULT_SUBSCRIPTION_NAME: rhel_6_partial_ak.add_subscriptions(data={u"subscription_id": sub.id}) sub_found = True assert sub_found # Enable product content in activation key rhel_6_partial_ak.content_override( data={"content_override": {u"content_label": REPOS["rhst6"]["id"], u"value": u"1"}} ) # Create client machine and register it to satellite with # rhel_6_partial_ak self.vm = VirtualMachine(distro="rhel67", tag="incupdate") self.setup_vm(self.vm, rhel_6_partial_ak.name, self.org.label) self.vm.enable_repo(REPOS["rhva6"]["id"]) self.vm.run("yum install -y {0}".format(REAL_0_RH_PACKAGE)) # Find the content hosts and save them hosts = Host(organization=str(self.org.id)).search() self.partial_hosts = [] for host in hosts: self.partial_hosts.append(host) def tearDown(self): """Destroys provisioned vm""" self.vm.destroy() super(IncrementalUpdateTestCase, self).tearDown() @staticmethod def setup_vm(client, act_key, org_name): """Creates the vm and registers it to the satellite""" client.create() client.install_katello_ca() # Register content host, install katello-agent result = client.register_contenthost(org_name, act_key, releasever=DEFAULT_RELEASE_VERSION) assert result.return_code == 0 result = client.install_katello_agent() client.run("katello-package-upload") @staticmethod def get_applicable_errata(repo): """Retrieves applicable errata for the given repo""" return Errata(repository=repo).search(query={"errata_restrict_applicable": True}) @run_only_on("sat") @tier4 def test_positive_noapply_api(self): """Check if api incremental update can be done without actually applying it @id: 481c5ff2-801f-4eff-b1e0-95ea5bb37f95 @Setup: The prerequisites are already covered in the setUpClass() but for easy debug, get the content view id, Repository id and Lifecycle environment id using hammer and plug these statements on the top of the test. For example:: self.rhel_6_partial_cv = ContentView(id=38).read() self.rhva_6_repo = Repository(id=164).read() self.qe_lce = LifecycleEnvironment(id=46).read() @Assert: Incremental update completed with no errors and Content view has a newer version @CaseLevel: System """ # Get the content view versions and use the recent one. API always # returns the versions in ascending order so it is safe to assume the # last one in the list is the recent cv_versions = self.rhel_6_partial_cv.version # Get the applicable errata errata_list = self.get_applicable_errata(self.rhva_6_repo) self.assertGreater(len(errata_list), 0) # Apply incremental update using the first applicable errata ContentViewVersion().incremental_update( data={ "content_view_version_environments": [ {"content_view_version_id": cv_versions[-1].id, "environment_ids": [self.qe_lce.id]} ], "add_content": {"errata_ids": [errata_list[0].id]}, } ) # Re-read the content view to get the latest versions self.rhel_6_partial_cv = self.rhel_6_partial_cv.read() self.assertGreater(len(self.rhel_6_partial_cv.version), len(cv_versions)) @run_only_on("sat") @tier4 def test_positive_noapply_cli(self): """Check if cli incremental update can be done without actually applying it @id: f25b0919-74cb-4e2c-829e-482558990b3c @Assert: Incremental update completed with no errors and Content view has a newer version @CaseLevel: System """ # Get the content view versions and use the recent one. API always # returns the versions in ascending order so it is safe to assume the # last one in the list is the recent cv_versions = self.rhel_6_partial_cv.version # Get the applicable errata errata_list = self.get_applicable_errata(self.rhva_6_repo) self.assertGreater(len(errata_list), 0) # Apply incremental update using the first applicable errata ContentViewCLI.version_incremental_update( { u"content-view-version-id": cv_versions[-1].id, u"lifecycle-environment-ids": self.qe_lce.id, u"errata-ids": errata_list[0].id, } ) # Re-read the content view to get the latest versions self.rhel_6_partial_cv = self.rhel_6_partial_cv.read() self.assertGreater(len(self.rhel_6_partial_cv.version), len(cv_versions))
class KatelloAgentTestCase(CLITestCase): """Host tests, which require VM with installed katello-agent.""" org = None env = None content_view = None activation_key = None @classmethod @skip_if_not_set('clients', 'fake_manifest') def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(KatelloAgentTestCase, cls).setUpClass() # Create new org, environment, CV and activation key KatelloAgentTestCase.org = make_org() KatelloAgentTestCase.env = make_lifecycle_environment({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.content_view = make_content_view({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.activation_key = make_activation_key({ u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'organization-id': KatelloAgentTestCase.org['id'], }) # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo({ u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) # Create custom repo, add subscription to activation key setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) def setUp(self): """Create VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages """ super(KatelloAgentTestCase, self).setUp() # Create VM and register content host self.client = VirtualMachine(distro='rhel71') self.client.create() self.client.install_katello_ca() # Register content host, install katello-agent self.client.register_contenthost( KatelloAgentTestCase.activation_key['name'], KatelloAgentTestCase.org['label']) self.host = Host.info({'name': self.client.hostname}) self.client.enable_repo(REPOS['rhst7']['id']) self.client.install_katello_agent() def tearDown(self): self.client.destroy() super(KatelloAgentTestCase, self).tearDown() @tier3 @run_only_on('sat') def test_positive_get_errata_info(self): """Get errata info @Feature: Host - Errata @Assert: Errata info was displayed """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) result = Host.errata_info({ u'host-id': self.host['id'], u'id': FAKE_0_ERRATA_ID, }) self.assertEqual(result[0]['errata-id'], FAKE_0_ERRATA_ID) self.assertEqual(result[0]['packages'], FAKE_0_CUSTOM_PACKAGE) @tier3 @run_only_on('sat') def test_positive_apply_errata(self): """Apply errata to a host @Feature: Host - Errata @Assert: Errata is scheduled for installation """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) Host.errata_apply({ u'errata-ids': FAKE_0_ERRATA_ID, u'host-id': self.host['id'], }) @tier3 @run_only_on('sat') def test_positive_install_package(self): """Install a package to a host remotely @Feature: Host - Package @Assert: Package was successfully installed """ Host.package_install({ u'host-id': self.host['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_remove_package(self): """Remove a package from a host remotely @Feature: Host - Package @Assert: Package was successfully removed """ self.client.download_install_rpm(FAKE_0_YUM_REPO, FAKE_0_CUSTOM_PACKAGE) Host.package_remove({ u'host-id': self.host['id'], u'packages': FAKE_0_CUSTOM_PACKAGE_NAME, }) result = self.client.run( 'rpm -q {0}'.format(FAKE_0_CUSTOM_PACKAGE_NAME)) self.assertNotEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_upgrade_package(self): """Upgrade a host package remotely @Feature: Host - Package @Assert: Package was successfully upgraded """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) Host.package_upgrade({ u'host-id': self.host['id'], u'packages': FAKE_1_CUSTOM_PACKAGE_NAME, }) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_upgrade_packages_all(self): """Upgrade all the host packages remotely @Feature: Host - Package @Assert: Packages (at least 1 with newer version available) were successfully upgraded """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) Host.package_upgrade_all({'host-id': self.host['id']}) result = self.client.run('rpm -q {0}'.format(FAKE_2_CUSTOM_PACKAGE)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_install_package_group(self): """Install a package group to a host remotely @Feature: Host - Package group @Assert: Package group was successfully installed """ Host.package_group_install({ u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'host-id': self.host['id'], }) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertEqual(result.return_code, 0) @tier3 @run_only_on('sat') def test_positive_remove_package_group(self): """Remove a package group from a host remotely @Feature: Host - Package group @Assert: Package group was successfully removed """ hammer_args = { u'groups': FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, u'host-id': self.host['id'], } Host.package_group_install(hammer_args) Host.package_group_remove(hammer_args) for package in FAKE_0_CUSTOM_PACKAGE_GROUP: result = self.client.run('rpm -q {0}'.format(package)) self.assertNotEqual(result.return_code, 0) @tier3 def test_negative_unregister_and_pull_content(self): """Attempt to retrieve content after host has been unregistered from Satellite @feature: Host @assert: Host can no longer retrieve content from satellite """ result = self.client.run('subscription-manager unregister') self.assertEqual(result.return_code, 0) result = self.client.run( 'yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) self.assertNotEqual(result.return_code, 0)
class IncrementalUpdateTestCase(TestCase): """Tests for the Incremental Update feature""" @classmethod @skip_if_not_set('clients') def setUpClass(cls): """Creates the pre-requisites for the Incremental updates that used in all test""" super(IncrementalUpdateTestCase, cls).setUpClass() # Create a new Organization cls.org = Organization(name=gen_alpha()).create() # Create two lifecycle environments - DEV, QE cls.dev_lce = LifecycleEnvironment(name='DEV', organization=cls.org).create() cls.qe_lce = LifecycleEnvironment(name='QE', prior=cls.dev_lce, organization=cls.org).create() # Upload manifest with manifests.clone() as manifest: upload_manifest(cls.org.id, manifest.content) # Enable repositories - RHE Virtualization Agents and rhel6 sat6tools rhva_6_repo_id = enable_rhrepo_and_fetchid( basearch=DEFAULT_ARCHITECTURE, org_id=cls.org.id, product=PRDS['rhel'], repo=REPOS['rhva6']['name'], reposet=REPOSET['rhva6'], releasever=DEFAULT_RELEASE_VERSION, ) rhel6_sat6tools_repo_id = enable_rhrepo_and_fetchid( basearch=DEFAULT_ARCHITECTURE, org_id=cls.org.id, product=PRDS['rhel'], repo=REPOS['rhst6']['name'], reposet=REPOSET['rhst6'], releasever=None, ) # Read the repositories cls.rhva_6_repo = Repository(id=rhva_6_repo_id).read() cls.rhel6_sat6tools_repo = Repository( id=rhel6_sat6tools_repo_id).read() # Sync the enabled repositories try: cls.old_task_timeout = entity_mixins.TASK_TIMEOUT # Update timeout to 15 minutes to finish sync entity_mixins.TASK_TIMEOUT = 900 for repo in [cls.rhva_6_repo, cls.rhel6_sat6tools_repo]: assert Repository(id=repo.id).sync()['result'] == u'success' finally: entity_mixins.TASK_TIMEOUT = cls.old_task_timeout def setUp(self): """Creates the pre-requisites for the Incremental updates that used per each test""" super(IncrementalUpdateTestCase, self).setUp() # Create content view that will be used filtered erratas self.rhel_6_partial_cv = ContentView( organization=self.org, name=gen_alpha(), repository=[self.rhva_6_repo, self.rhel6_sat6tools_repo]).create() # Create a content view filter to filter out errata rhel_6_partial_cvf = ErratumContentViewFilter( content_view=self.rhel_6_partial_cv, type='erratum', name='rhel_6_partial_cv_filter', repository=[self.rhva_6_repo]).create() # Create a content view filter rule - filtering out errata in the last # 365 days start_date = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d') ContentViewFilterRule( content_view_filter=rhel_6_partial_cvf, types=['security', 'enhancement', 'bugfix'], start_date=start_date, end_date=date.today().strftime('%Y-%m-%d')).create() # Publish content view and re-read it self.rhel_6_partial_cv.publish() self.rhel_6_partial_cv = self.rhel_6_partial_cv.read() # Promote content view to 'DEV' and 'QE' assert len(self.rhel_6_partial_cv.version) == 1 for env in (self.dev_lce, self.qe_lce): promote(self.rhel_6_partial_cv.version[0], env.id) # Create host collection self.rhel_6_partial_hc = HostCollection(organization=self.org, name=gen_alpha(), max_hosts=5).create() # Create activation key for content view kwargs = {'organization': self.org, 'environment': self.qe_lce.id} rhel_6_partial_ak = ActivationKey( name=gen_alpha(), content_view=self.rhel_6_partial_cv, host_collection=[self.rhel_6_partial_hc], **kwargs).create() # Assign subscription to activation key. Fetch available subscriptions subs = Subscription(organization=self.org).search() assert len(subs) > 0 # Add subscription to activation key sub_found = False for sub in subs: if sub.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME: rhel_6_partial_ak.add_subscriptions( data={u'subscription_id': sub.id}) sub_found = True assert sub_found # Enable product content in activation key rhel_6_partial_ak.content_override( data={ 'content_override': { u'content_label': REPOS['rhst6']['id'], u'value': u'1' } }) # Create client machine and register it to satellite with # rhel_6_partial_ak self.vm = VirtualMachine(distro='rhel67', tag='incupdate') self.setup_vm(self.vm, rhel_6_partial_ak.name, self.org.label) self.vm.enable_repo(REPOS['rhva6']['id']) self.vm.run('yum install -y {0}'.format(REAL_0_RH_PACKAGE)) # Find the content hosts and save them hosts = Host(organization=str(self.org.id)).search() self.partial_hosts = [] for host in hosts: self.partial_hosts.append(host) def tearDown(self): """Destroys provisioned vm""" self.vm.destroy() super(IncrementalUpdateTestCase, self).tearDown() @staticmethod def setup_vm(client, act_key, org_name): """Creates the vm and registers it to the satellite""" client.create() client.install_katello_ca() # Register content host, install katello-agent result = client.register_contenthost( org_name, act_key, releasever=DEFAULT_RELEASE_VERSION) assert result.return_code == 0 result = client.install_katello_agent() client.run('katello-package-upload') @staticmethod def get_applicable_errata(repo): """Retrieves applicable errata for the given repo""" return Errata(repository=repo).search( query={'errata_restrict_applicable': True}) @run_only_on('sat') @tier4 def test_positive_noapply_api(self): """Check if api incremental update can be done without actually applying it @id: 481c5ff2-801f-4eff-b1e0-95ea5bb37f95 @Setup: The prerequisites are already covered in the setUpClass() but for easy debug, get the content view id, Repository id and Lifecycle environment id using hammer and plug these statements on the top of the test. For example:: self.rhel_6_partial_cv = ContentView(id=38).read() self.rhva_6_repo = Repository(id=164).read() self.qe_lce = LifecycleEnvironment(id=46).read() @Assert: Incremental update completed with no errors and Content view has a newer version @CaseLevel: System """ # Get the content view versions and use the recent one. API always # returns the versions in ascending order so it is safe to assume the # last one in the list is the recent cv_versions = self.rhel_6_partial_cv.version # Get the applicable errata errata_list = self.get_applicable_errata(self.rhva_6_repo) self.assertGreater(len(errata_list), 0) # Apply incremental update using the first applicable errata ContentViewVersion().incremental_update( data={ 'content_view_version_environments': [{ 'content_view_version_id': cv_versions[-1].id, 'environment_ids': [self.qe_lce.id] }], 'add_content': { 'errata_ids': [errata_list[0].id] } }) # Re-read the content view to get the latest versions self.rhel_6_partial_cv = self.rhel_6_partial_cv.read() self.assertGreater(len(self.rhel_6_partial_cv.version), len(cv_versions)) @run_only_on('sat') @tier4 def test_positive_noapply_cli(self): """Check if cli incremental update can be done without actually applying it @id: f25b0919-74cb-4e2c-829e-482558990b3c @Assert: Incremental update completed with no errors and Content view has a newer version @CaseLevel: System """ # Get the content view versions and use the recent one. API always # returns the versions in ascending order so it is safe to assume the # last one in the list is the recent cv_versions = self.rhel_6_partial_cv.version # Get the applicable errata errata_list = self.get_applicable_errata(self.rhva_6_repo) self.assertGreater(len(errata_list), 0) # Apply incremental update using the first applicable errata ContentViewCLI.version_incremental_update({ u'content-view-version-id': cv_versions[-1].id, u'lifecycle-environment-ids': self.qe_lce.id, u'errata-ids': errata_list[0].id, }) # Re-read the content view to get the latest versions self.rhel_6_partial_cv = self.rhel_6_partial_cv.read() self.assertGreater(len(self.rhel_6_partial_cv.version), len(cv_versions))
class ContentHostTestCase(UITestCase): """Implements Content Host tests in UI""" @classmethod def set_session_org(cls): """Create an organization for tests, which will be selected automatically""" cls.session_org = entities.Organization().create() @classmethod @skip_if_not_set('clients', 'fake_manifest') def setUpClass(cls): """Create Lifecycle Environment, Content View and Activation key """ super(ContentHostTestCase, cls).setUpClass() cls.env = entities.LifecycleEnvironment( organization=cls.session_org).create() cls.content_view = entities.ContentView( organization=cls.session_org).create() cls.activation_key = entities.ActivationKey( environment=cls.env, organization=cls.session_org, ).create() setup_org_for_a_rh_repo({ 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': cls.session_org.id, 'content-view-id': cls.content_view.id, 'lifecycle-environment-id': cls.env.id, 'activationkey-id': cls.activation_key.id, }) setup_org_for_a_custom_repo({ 'url': FAKE_6_YUM_REPO, 'organization-id': cls.session_org.id, 'content-view-id': cls.content_view.id, 'lifecycle-environment-id': cls.env.id, 'activationkey-id': cls.activation_key.id, }) def setUp(self): """Create a VM, subscribe it to satellite-tools repo, install katello-ca and katello-agent packages""" super(ContentHostTestCase, self).setUp() self.client = VirtualMachine(distro=DISTRO_RHEL7) self.client.create() self.client.install_katello_ca() result = self.client.register_contenthost( self.session_org.label, self.activation_key.name) self.assertEqual(result.return_code, 0) self.client.enable_repo(REPOS['rhst7']['id']) self.client.install_katello_agent() def tearDown(self): """Destroy the VM""" self.client.destroy() super(ContentHostTestCase, self).tearDown() @tier3 def test_positive_install_package(self): """Install a package to a host remotely @id: 13b9422d-4b7a-4068-9a57-a94602cd6410 @assert: Package was successfully installed @CaseLevel: System """ with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Package Install', FAKE_0_CUSTOM_PACKAGE_NAME, ) self.assertEqual(result, 'success') self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, FAKE_0_CUSTOM_PACKAGE_NAME)) @tier3 def test_positive_remove_package(self): """Remove a package from a host remotely @id: 86d8896b-06d9-4c99-937e-f3aa07b4eb69 @Assert: Package was successfully removed @CaseLevel: System """ self.client.download_install_rpm( FAKE_6_YUM_REPO, FAKE_0_CUSTOM_PACKAGE ) with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Package Remove', FAKE_0_CUSTOM_PACKAGE_NAME, ) self.assertEqual(result, 'success') self.assertIsNone(self.contenthost.package_search( self.client.hostname, FAKE_0_CUSTOM_PACKAGE_NAME)) @tier3 def test_positive_upgrade_package(self): """Upgrade a host package remotely @id: 1969db93-e7af-4f5f-973d-23c222224db6 @Assert: Package was successfully upgraded @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Package Update', FAKE_1_CUSTOM_PACKAGE_NAME, ) self.assertEqual(result, 'success') self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, FAKE_2_CUSTOM_PACKAGE)) @tier3 def test_positive_install_package_group(self): """Install a package group to a host remotely @id: a43fb21b-5f6a-4f14-8cd6-114ec287540c @Assert: Package group was successfully installed @CaseLevel: System """ with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Group Install', FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, ) self.assertEqual(result, 'success') for package in FAKE_0_CUSTOM_PACKAGE_GROUP: self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, package)) @tier3 def test_positive_remove_package_group(self): """Remove a package group from a host remotely @id: dbeea1f2-adf4-4ad8-a989-efad8ce21b98 @Assert: Package group was successfully removed @CaseLevel: System """ with Session(self.browser): result = self.contenthost.execute_package_action( self.client.hostname, 'Group Install', FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, ) self.assertEqual(result, 'success') result = self.contenthost.execute_package_action( self.client.hostname, 'Group Remove', FAKE_0_CUSTOM_PACKAGE_GROUP_NAME, ) self.assertEqual(result, 'success') for package in FAKE_0_CUSTOM_PACKAGE_GROUP: self.assertIsNone(self.contenthost.package_search( self.client.hostname, package)) @tier3 def test_positive_install_errata(self): """Install a errata to a host remotely @id: b69b9797-3c0c-42cd-94ed-3f751bb9b24c @assert: Errata was successfully installed @CaseLevel: System """ self.client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE)) with Session(self.browser): result = self.contenthost.install_errata( self.client.hostname, FAKE_2_ERRATA_ID, ) self.assertEqual(result, 'success') self.assertIsNotNone(self.contenthost.package_search( self.client.hostname, FAKE_2_CUSTOM_PACKAGE))