def test_positive_delete_activation_key_1(self, test_data): """ @Test: Create Activation key and delete it for all variations of Activation key name @Feature: Activation key - Positive Delete @Steps: 1. Create Activation key for all valid Activation Key names in [1] using valid Description, Environment, Content View, Usage limit 2. Delete the Activation key @Assert: Activation key is deleted @bz: 1109650 """ try: activation_key = self._make_activation_key({ u'name': test_data['name'], u'organization-id': self.org['id'], }) except CLIFactoryError as err: self.fail(err) result = ActivationKey.delete({'id': activation_key['id']}) self.assertEqual( result.return_code, 0, 'Failed to delete activation key') self.assertEqual( len(result.stderr), 0, 'There should not be an error here') # Can we find the object? result = ActivationKey.info({'id': activation_key['id']}) self.assertNotEqual( result.return_code, 0, 'Activation key should be deleted') self.assertGreater( len(result.stderr), 0, 'There should be an error here') self.assertEqual( len(result.stdout), 0, 'Output should be blank')
def test_positive_update_activation_key_5(self, test_data): """@Test: Update Content View in an Activation key @Feature: Activation key - Positive Update @Steps: 1. Create Activation key 2. Update Content View for all variations in [1] and include both RH and custom products @Assert: Activation key is updated """ try: activation_key = self._make_activation_key({u"organization-id": self.org["id"]}) con_view = make_content_view({u"organization-id": self.org["id"], u"name": test_data["content-view"]}) except CLIFactoryError as err: self.fail(err) result = ActivationKey.update( {u"name": activation_key["name"], u"content-view": con_view["name"], u"organization-id": self.org["id"]} ) self.assertEqual(result.return_code, 0, "Failed to update activation key") self.assertEqual(len(result.stderr), 0, "There should not be an error here") result = ActivationKey.info({u"id": activation_key["id"]}) self.assertEqual(result.return_code, 0, "Failed to get info for activation key") self.assertEqual(len(result.stderr), 0, "There should not be an error here") self.assertEqual( result.stdout["content-view"], test_data["content-view"], "Activation key content-view was not updated" )
def test_positive_delete_activation_key_2(self, test_data): """@Test: Create Activation key and delete it for all variations of Description @Feature: Activation key - Positive Delete @Steps: 1. Create Activation key for all valid Description in [1] using valid Name, Environment, Content View, Usage limit 2. Delete the Activation key @Assert: Activation key is deleted @bz: 1109650 """ try: activation_key = self._make_activation_key( {u"description": test_data["description"], u"organization-id": self.org["id"]} ) except CLIFactoryError as err: self.fail(err) result = ActivationKey.delete({"id": activation_key["id"]}) self.assertEqual(result.return_code, 0, "Failed to delete activation key") self.assertEqual(len(result.stderr), 0, "There should not be an error here") # Can we find the object? result = ActivationKey.info({"id": activation_key["id"]}) self.assertNotEqual(result.return_code, 0, "Activation key should be deleted") self.assertGreater(len(result.stderr), 0, "There should be an error here") self.assertEqual(len(result.stdout), 0, "Output should be blank")
def setup_content(request): """Pytest fixture for setting up an organization, manifest, content-view, lifecycle environment, and activation key with subscriptions""" org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) new_product = make_product({'organization-id': org['id']}) new_repo = make_repository({'product-id': new_product['id']}) Repository.synchronize({'id': new_repo['id']}) content_view = make_content_view({'organization-id': org['id']}) ContentView.add_repository( {'id': content_view['id'], 'organization-id': org['id'], 'repository-id': new_repo['id']} ) ContentView.publish({'id': content_view['id']}) env = make_lifecycle_environment({'organization-id': org['id']}) cvv = ContentView.info({'id': content_view['id']})['versions'][0] ContentView.version_promote({'id': cvv['id'], 'to-lifecycle-environment-id': env['id']}) new_ak = make_activation_key( { 'lifecycle-environment-id': env['id'], 'content-view': content_view['name'], 'organization-id': org['id'], 'auto-attach': False, } ) subs_id = Subscription.list({'organization-id': org['id']}, per_page=False) ActivationKey.add_subscription({'id': new_ak['id'], 'subscription-id': subs_id[0]['id']}) request.cls.setup_org = org request.cls.setup_new_ak = new_ak request.cls.setup_subs_id = subs_id request.cls.setup_env = env request.cls.setup_content_view = content_view
def test_positive_update_host_collection(self): """Test that host collection can be associated to Activation Keys @Feature: Activation key - Host @BZ: 1110476 @Assert: Hosts are successfully associated to Activation key """ for host_col_name in valid_data_list(): with self.subTest(host_col_name): activation_key = self._make_activation_key() new_host_col_name = make_host_collection({ 'name': host_col_name, })['name'] # Assert that name matches data passed self.assertEqual(new_host_col_name, host_col_name) ActivationKey.add_host_collection({ u'host-collection': new_host_col_name, u'name': activation_key['name'], u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({ u'id': activation_key['id'], }) self.assertEqual( activation_key['host-collection'], host_col_name)
def test_positive_content_override(self): """Positive content override @Feature: Activation key copy @Steps: 1. Create activation key and add content 2. Get the first product's label 3. Override the product's content enabled state 4. Verify that the command succeeded @BZ: 1180282 @Assert: Activation key content override was successful """ result = setup_org_for_a_custom_repo({u"url": FAKE_0_YUM_REPO, u"organization-id": self.org["id"]}) content = ActivationKey.product_content({u"id": result["activationkey-id"], u"organization-id": self.org["id"]}) for override_value in (u"1", u"0"): with self.subTest(override_value): ActivationKey.content_override( { u"content-label": content[0]["label"], u"id": result["activationkey-id"], u"organization-id": self.org["id"], u"value": override_value, } ) # Retrieve the product content enabled flag content = ActivationKey.product_content( {u"id": result["activationkey-id"], u"organization-id": self.org["id"]} ) self.assertEqual(content[0]["enabled?"], override_value)
def test_positive_update_activation_key_3(self, test_data): """@Test: Update Description in an Activation key @Feature: Activation key - Positive Update @Steps: 1. Create Activation key 2. Update Description for all variations in [1] @Assert: Activation key is updated @bz: 1109649 """ try: activation_key = self._make_activation_key({u"organization-id": self.org["id"]}) except CLIFactoryError as err: self.fail(err) result = ActivationKey.update( { u"name": activation_key["name"], u"description": test_data["description"], u"organization-id": self.org["id"], } ) self.assertEqual(result.return_code, 0, "Failed to update activation key") self.assertEqual(len(result.stderr), 0, "There should not be an error here") result = ActivationKey.info({u"id": activation_key["id"]}) self.assertEqual(result.return_code, 0, "Failed to get info for activation key") self.assertEqual(len(result.stderr), 0, "There should not be an error here") self.assertEqual( result.stdout["description"], test_data["description"], "Activation key description was not updated" )
def setup_activation_key(org_id, content_view_id, lce_id, subscription_names=None): # type: (int, int, int, Optional[List[str]], Optional[str]) -> Dict """Create activation and associate content-view, lifecycle environment and subscriptions""" if subscription_names is None: subscription_names = [] activation_key = make_activation_key({ 'organization-id': org_id, 'lifecycle-environment-id': lce_id, 'content-view-id': content_view_id, }) # Add subscriptions to activation-key # Get organization subscriptions subscriptions = Subscription.list({'organization-id': org_id}, per_page=False) added_subscription_names = [] for subscription in subscriptions: if (subscription['name'] in subscription_names and subscription['name'] not in added_subscription_names): ActivationKey.add_subscription({ 'id': activation_key['id'], 'subscription-id': subscription['id'], 'quantity': 1, }) added_subscription_names.append(subscription['name']) if len(added_subscription_names) == len(subscription_names): break missing_subscription_names = set(subscription_names).difference( set(added_subscription_names)) if missing_subscription_names: raise ValueError('Missing subscriptions: {0}'.format(missing_subscription_names)) return activation_key
def test_positive_update_autoattach_toggle(self): """Update Activation key with inverse auto-attach value :id: de3b5fb7-7963-420a-b4c9-c66e78a111dc :Steps: 1. Get the key's current auto attach value. 2. Update the key with the value's inverse. 3. Verify key was updated. :expectedresults: Activation key is successfully copied :CaseImportance: Critical """ new_ak = self._make_activation_key() attach_value = new_ak['auto-attach'] # invert value new_value = u'false' if attach_value == u'true' else u'true' ActivationKey.update({ u'auto-attach': new_value, u'id': new_ak['id'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': new_ak['id']}) self.assertEqual(updated_ak['auto-attach'], new_value)
def test_positive_update_lce(self): """Update Environment in an Activation key :id: 55aaee60-b8c8-49f0-995a-6c526b9b653b :expectedresults: Activation key is updated :CaseLevel: Integration """ ak_env = self._make_activation_key({ u'lifecycle-environment-id': self.get_default_env()['id'], }) env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) ActivationKey.update({ u'id': ak_env['id'], u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': ak_env['id']}) self.assertEqual(updated_ak['lifecycle-environment'], env['name'])
def test_positive_update_host_collection_with_default_org(self): """Test that host collection can be associated to Activation Keys with specified default organization setting in config :id: 01e830e9-91fd-4e45-9aaf-862e1fe134df :expectedresults: Host collection is successfully associated to Activation key :BZ: 1364876 """ Defaults.add({ u'param-name': 'organization_id', u'param-value': self.org['id'], }) try: activation_key = self._make_activation_key() host_col = make_host_collection() ActivationKey.add_host_collection({ u'host-collection': host_col['name'], u'name': activation_key['name'], }) activation_key = ActivationKey.info({ u'id': activation_key['id'], }) self.assertEqual( activation_key['host-collections'][0]['name'], host_col['name'] ) finally: Defaults.delete({u'param-name': 'organization_id'})
def test_delete_ak_by_name(self): """@Test: Create Activation key and delete it for all variations of Activation key name @Feature: Activation key - Positive Delete @Steps: 1. Create Activation key for all valid Activation Key names 2. Delete the Activation key @Assert: Activation key is deleted """ for name in valid_data_list(): with self.subTest(name): activation_key = self._make_activation_key({ u'name': name, u'organization-id': self.org['id'], }) ActivationKey.delete({ 'name': activation_key['name'], 'organization-id': self.org['id'], }) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': activation_key['id']})
def test_positive_update_ak_3(self): """@Test: Update Description in an Activation key @Feature: Activation key - Positive Update @Steps: 1. Create Activation key 2. Update Description for all variations in [1] @Assert: Activation key is updated """ for description in valid_data_list(): with self.subTest(description): activation_key = self._make_activation_key() ActivationKey.update({ u'description': description, u'name': activation_key['name'], u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({ 'id': activation_key['id'], }) self.assertEqual(activation_key['description'], description)
def test_negative_update_auto_attach(self): """@Test: Attempt to update Activation key with bad auto-attach value @Feature: Activation key update / info @Steps: 1. Attempt to update a key with incorrect auto-attach value 2. Verify that an appropriate error message was returned @Assert: Activation key is successfully copied """ org_id = make_org(cached=True)['id'] key_id = make_activation_key( {u'organization-id': org_id}, cached=True, )['id'] with self.assertRaises(CLIReturnCodeError) as exe: ActivationKey.update({ u'auto-attach': gen_string('utf8'), u'id': key_id, u'organization-id': org_id, }) self.assertIn( u"'--auto-attach': value must be one of", exe.exception.stderr)
def test_positive_copy_subscription(self): """Copy Activation key and verify contents @Feature: Activation key copy @Steps: 1. Create parent key and add content 2. Copy Activation key by passing id of parent 3. Verify content was successfully copied @Assert: Activation key is successfully copied """ # Begin test setup parent_ak = self._make_activation_key() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({"file": manifest.filename, "organization-id": self.org["id"]}) subscription_result = Subscription.list({"organization-id": self.org["id"]}, per_page=False) ActivationKey.add_subscription({u"id": parent_ak["id"], u"subscription-id": subscription_result[0]["id"]}) # End test setup new_name = gen_string("utf8") result = ActivationKey.copy({u"id": parent_ak["id"], u"new-name": new_name, u"organization-id": self.org["id"]}) self.assertEqual(result[0], u"Activation key copied") result = ActivationKey.subscriptions({u"name": new_name, u"organization-id": self.org["id"]}) # Verify that the subscription copied over self.assertIn(subscription_result[0]["name"], result[3]) # subscription name # subscription list
def test_update_autoattach_1(self): """@Test: Update Activation key with inverse auto-attach value @Feature: Activation key update / info @Steps: 1. Get the key's current auto attach value. 2. Update the key with the value's inverse. 3. Verify key was updated. @Assert: Activation key is sucessfully copied """ org_id = make_org(cached=True)['id'] key = make_activation_key( {u'organization-id': org_id}, cached=True, ) attach_value = key['auto-attach'] # invert value new_value = u'false' if attach_value == u'true' else u'true' ActivationKey.update({ u'auto-attach': new_value, u'id': key['id'], u'organization-id': org_id, }) attach_value = ActivationKey.info({ u'id': key['id'], u'organization-id': org_id, })['auto-attach'] self.assertEqual(attach_value, new_value)
def test_positive_update_host_collection(self): """Test that host collection can be associated to Activation Keys :id: 2114132a-fede-4791-98e7-a463ad79f398 :BZ: 1110476 :expectedresults: Hosts are successfully associated to Activation key :CaseLevel: Integration """ for host_col_name in valid_data_list(): with self.subTest(host_col_name): activation_key = self._make_activation_key() new_host_col_name = make_host_collection({ 'name': host_col_name, })['name'] # Assert that name matches data passed self.assertEqual(new_host_col_name, host_col_name) ActivationKey.add_host_collection({ u'host-collection': new_host_col_name, u'name': activation_key['name'], u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({ u'id': activation_key['id'], }) self.assertEqual( activation_key['host-collection'], host_col_name)
def test_positive_update_lce(self): """@Test: Update Environment in an Activation key @Feature: Activation key - Positive Update @Assert: Activation key is updated """ ak_env = self._make_activation_key({ u'lifecycle-environment-id': self.get_default_env()['id'], }) env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) ActivationKey.update({ u'id': ak_env['id'], u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': ak_env['id']}) self.assertEqual(updated_ak['lifecycle-environment'], env['name'])
def test_positive_update_host_collection(self): """Test that host collections can be associated to Activation Keys :id: 2114132a-fede-4791-98e7-a463ad79f398 :BZ: 1110476 :expectedresults: Host collections are successfully associated to Activation key :CaseLevel: Integration """ for host_col_name in valid_data_list(): with self.subTest(host_col_name): activation_key = self._make_activation_key() new_host_col_name = make_host_collection({ u'name': host_col_name, u'organization-id': self.org['id'], })['name'] # Assert that name matches data passed self.assertEqual(new_host_col_name, host_col_name) ActivationKey.add_host_collection({ u'host-collection': new_host_col_name, u'name': activation_key['name'], u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({ u'id': activation_key['id'], }) self.assertEqual( activation_key['host-collections'][0]['name'], host_col_name )
def test_positive_create_using_old_name(self): """Create activation key, rename it and create another with the initial name :id: 9801319a-f42c-41a4-9ea4-3718e544c8e0 :expectedresults: Activation key is created :CaseImportance: Critical """ name = gen_string('utf8') activation_key = self._make_activation_key({'name': name}) new_name = gen_string('utf8') ActivationKey.update({ u'id': activation_key['id'], u'new-name': new_name, u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({'id': activation_key['id']}) self.assertEqual(activation_key['name'], new_name) new_activation_key = self._make_activation_key({ u'name': name, u'organization-id': self.org['id'], }) self.assertEqual(new_activation_key['name'], name)
def test_positive_update_host_collection(self): """Test that host collection can be associated to Activation Keys @Feature: Activation key - Host @BZ: 1110476 @Assert: Hosts are successfully associated to Activation key """ for host_col_name in valid_data_list(): with self.subTest(host_col_name): activation_key = self._make_activation_key() new_host_col_name = make_host_collection({"name": host_col_name})["name"] # Assert that name matches data passed self.assertEqual(new_host_col_name, host_col_name) ActivationKey.add_host_collection( { u"host-collection": new_host_col_name, u"name": activation_key["name"], u"organization-id": self.org["id"], } ) activation_key = ActivationKey.info({u"id": activation_key["id"]}) self.assertEqual(activation_key["host-collection"], host_col_name)
def test_delete_ak_with_env(self): """@Test: Create activation key with lifecycle environment assigned to it and delete it using activation key id @Feature: Activation key - Positive Delete @Steps: 1. Create Activation key with lifecycle environment assigned to it 2. Delete Activation key using activation key id @Assert: Activation key is deleted """ self.update_env() env = make_lifecycle_environment({ u'organization-id': self.org['id'], }) activation_key = self._make_activation_key({ u'lifecycle-environment': env['name'], u'name': gen_string('alpha'), }) ActivationKey.delete({'id': activation_key['id']}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': activation_key['id']})
def test_positive_update_lce(self): """Update Environment in an Activation key @Feature: Activation key - Positive Update @Assert: Activation key is updated """ ak_env = self._make_activation_key({ u'lifecycle-environment-id': self.get_default_env()['id'], }) env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) ActivationKey.update({ u'id': ak_env['id'], u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': ak_env['id']}) self.assertEqual(updated_ak['lifecycle-environment'], env['name'])
def test_bugzilla_1111723(self): """@test: Create activation key, rename it and create another with the initial name @feature: Activation key - Positive Create @steps: 1. Create an activation key 2. Rename it 3. Create another activation key with the same name from step 1 @assert: Activation key is created """ name = gen_string('utf8') activation_key = self._make_activation_key({'name': name}) new_name = gen_string('utf8') ActivationKey.update({ u'id': activation_key['id'], u'new-name': new_name, u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({'id': activation_key['id']}) self.assertEqual(activation_key['name'], new_name) new_activation_key = self._make_activation_key({ u'name': name, u'organization-id': self.org['id'], }) self.assertEqual(new_activation_key['name'], name)
def test_associate_host(self): """@Test: Test that host collection can be associated to Activation Keys @Feature: Activation key - Host @Steps: 1. Create Activation key 2. Create host collection 3. Associate the host collection to Activation key @Assert: Hosts are successfully associated to Activation key """ for host_col_name in valid_data_list(): with self.subTest(host_col_name): activation_key = self._make_activation_key() new_host_col_name = make_host_collection({ 'name': host_col_name, })['name'] # Assert that name matches data passed self.assertEqual(new_host_col_name, host_col_name) ActivationKey.add_host_collection({ u'host-collection': new_host_col_name, u'name': activation_key['name'], u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({ u'id': activation_key['id'], }) self.assertEqual( activation_key['host-collection'], host_col_name)
def test_positive_update_ak5(self): """@Test: Update Content View in an Activation key @Feature: Activation key - Positive Update @Steps: 1. Create Activation key 2. Update Content View for all variations in [1] and include both RH and custom products @Assert: Activation key is updated """ activation_key = self._make_activation_key() for content_view_name in valid_data_list(): with self.subTest(content_view_name): con_view = make_content_view({ u'name': content_view_name, u'organization-id': self.org['id'], }) ActivationKey.update({ u'content-view': con_view['name'], u'name': activation_key['name'], u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({ 'id': activation_key['id'], }) self.assertEqual( activation_key['content-view'], content_view_name)
def test_positive_update_ak_2(self): """@Test: Update Activation Key Name in an Activation key searching by name @Feature: Activation key - Positive Update @Steps: 1. Create Activation key 2. Update Activation key name for all variations in [1] @Assert: Activation key is updated """ for name in valid_data_list(): with self.subTest(name): activation_key = self._make_activation_key() ActivationKey.update({ u'name': activation_key['name'], u'new-name': name, u'organization-id': self.org['id'], }) activation_key = ActivationKey.info({ 'id': activation_key['id'], }) self.assertEqual(activation_key['name'], name)
def local_subscription(local_org, local_ak): subscription = Subscription.list({'organization-id': local_org['id']}, per_page=False)[0] ActivationKey.add_subscription({ 'id': local_ak['id'], 'subscription-id': subscription['id'] }) return subscription
def test_positive_register_host_ak_with_host_collection( katello_agent_client, module_cv, module_lce, module_org, rhel7_contenthost, default_sat): """Attempt to register a host using activation key with host collection :id: 7daf4e40-3fa6-42af-b3f7-1ca1a5c9bfeb :BZ: 1385814 :expectedresults: Host successfully registered and listed in host collection :CaseLevel: System """ # client = katello_agent_client['client'] host_info = katello_agent_client['host_info'] # create a new activation key activation_key = make_activation_key({ 'lifecycle-environment-id': module_lce.id, 'organization-id': module_org.id, 'content-view-id': module_cv.id, }) hc = make_host_collection({'organization-id': module_org.id}) ActivationKey.add_host_collection({ 'id': activation_key['id'], 'organization-id': module_org.id, 'host-collection-id': hc['id'], }) # add the registered instance host to collection HostCollection.add_host({ 'id': hc['id'], 'organization-id': module_org.id, 'host-ids': host_info['id'] }) with VMBroker(nick='rhel7', host_classes={'host': ContentHost}) as vm: vm.install_katello_ca(default_sat) # register the client host with the current activation key vm.register_contenthost(module_org.name, activation_key=activation_key['name']) assert vm.subscribed # note: when registering the host, it should be automatically added to the host-collection client_host = Host.info({'name': vm.hostname}) hosts = HostCollection.hosts({ 'id': hc['id'], 'organization-id': module_org.id }) assert len(hosts) == 2 expected_hosts_ids = {host_info['id'], client_host['id']} hosts_ids = {host['id'] for host in hosts} assert hosts_ids == expected_hosts_ids
def test_negative_update_name(self): """Try to update Activation Key using invalid value for its name @Feature: Activation key - Negative Update @Assert: Activation key is not updated. Appropriate error shown. """ new_ak = self._make_activation_key() for name in invalid_values_list(): with self.subTest(name): with self.assertRaises(CLIReturnCodeError): ActivationKey.update({u"id": new_ak["id"], u"new-name": name, u"organization-id": self.org["id"]})
def _add_ak_to_subscription(self, ak_id, sub_id): """Add activation key to subscription""" try: ActivationKey.add_subscription({ 'id': ak_id, 'quantity': self.add_ak_subscription_qty, 'subscription-id': sub_id, }) except CLIReturnCodeError: self.logger.error('Fail to add activation-key to subscription') return self.logger.info('Subscription added to this activation key.')
def test_positive_delete_with_lce(self): """Create activation key with lifecycle environment assigned to it and delete it using activation key id @Feature: Activation key - Positive Delete @Assert: Activation key is deleted """ new_ak = self._make_activation_key({u"lifecycle-environment": self.get_default_env()["name"]}) ActivationKey.delete({"id": new_ak["id"]}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({"id": new_ak["id"]})
def test_positive_delete_by_org_label(self): """Create Activation key and delete it using organization label for which that key was created @Feature: Activation key - Positive Delete @Assert: Activation key is deleted """ new_ak = self._make_activation_key() ActivationKey.delete({"name": new_ak["name"], "organization-label": self.org["label"]}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({"id": new_ak["id"]})
def test_positive_delete_with_cv(self): """Create activation key with content view assigned to it and delete it using activation key id @Feature: Activation key - Positive Delete @Assert: Activation key is deleted """ new_cv = make_content_view({u"organization-id": self.org["id"]}) new_ak = self._make_activation_key({u"content-view": new_cv["name"]}) ActivationKey.delete({"id": new_ak["id"]}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({"id": new_ak["id"]})
def test_positive_delete_with_cv(self): """Create activation key with content view assigned to it and delete it using activation key id @Feature: Activation key - Positive Delete @Assert: Activation key is deleted """ new_cv = make_content_view({u'organization-id': self.org['id']}) new_ak = self._make_activation_key({u'content-view': new_cv['name']}) ActivationKey.delete({'id': new_ak['id']}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': new_ak['id']})
def test_negative_copy_with_same_name(self): """Copy activation key with duplicate name @Feature: Activation key copy @Assert: Activation key is not successfully copied """ parent_ak = self._make_activation_key() with self.assertRaises(CLIReturnCodeError) as exception: ActivationKey.copy( {u"name": parent_ak["name"], u"new-name": parent_ak["name"], u"organization-id": self.org["id"]} ) self.assertEqual(exception.exception.return_code, 65)
def test_positive_delete_subscription(self): """Check if deleting a subscription removes it from Activation key :id: bbbe4641-bfb0-48d6-acfc-de4294b18c15 :expectedresults: Deleting subscription removes it from the Activation key :CaseLevel: Integration """ new_ak = self._make_activation_key() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': self.org['id'], }) subscription_result = Subscription.list( { 'organization-id': self.org['id'], 'order': 'id desc' }, per_page=False) result = ActivationKey.add_subscription({ u'id': new_ak['id'], u'subscription-id': subscription_result[-1]['id'], }) self.assertIn('Subscription added to activation key', result) ak_subs_info = ActivationKey.subscriptions({ u'id': new_ak['id'], u'organization-id': self.org['id'], }) self.assertEqual(len(ak_subs_info), 6) result = ActivationKey.remove_subscription({ u'id': new_ak['id'], u'subscription-id': subscription_result[-1]['id'], }) self.assertIn('Subscription removed from activation key', result) ak_subs_info = ActivationKey.subscriptions({ u'id': new_ak['id'], u'organization-id': self.org['id'], }) self.assertEqual(len(ak_subs_info), 4)
def test_associate_host(self, test_data): """@Test: Test that hosts can be associated to Activation Keys @Feature: Activation key - Host @Steps: 1. Create Activation key 2. Create different hosts 3. Associate the hosts to Activation key @Assert: Hosts are successfully associated to Activation key """ try: activation_key = self._make_activation_key({ u'organization-id': self.org['id'], }) new_host_col = make_host_collection({ 'name': test_data['host-col'] }) except CLIFactoryError as err: self.fail(err) # Assert that name matches data passed self.assertEqual( new_host_col['name'], test_data['host-col'], "Names don't match" ) result = ActivationKey.add_host_collection({ u'name': activation_key['name'], u'host-collection': new_host_col['name'], u'organization-id': self.org['id'], }) self.assertEqual( result.return_code, 0, 'Failed to add host-col activation key') self.assertEqual( len(result.stderr), 0, 'There should not be an error here') result = ActivationKey.info({ u'id': activation_key['id'], }) self.assertEqual( result.return_code, 0, 'Failed to get info for activation key') self.assertEqual( len(result.stderr), 0, 'There should not be an error here') self.assertEqual( result.stdout['host-collection'], test_data['host-col'], 'Activation key host-collection added')
def test_positive_register_host_ak_with_host_collection(self): """Attempt to register a host using activation key with host collection :id: 7daf4e40-3fa6-42af-b3f7-1ca1a5c9bfeb :BZ: 1385814 :expectedresults: Host successfully registered and listed in host collection :CaseLevel: System """ # create a new activation key activation_key = make_activation_key({ 'lifecycle-environment-id': self.env['id'], 'organization-id': self.org['id'], 'content-view-id': self.content_view['id'], }) hc = make_host_collection({'organization-id': self.org['id']}) ActivationKey.add_host_collection({ 'id': activation_key['id'], 'organization-id': self.org['id'], 'host-collection-id': hc['id'], }) # add the registered instance host to collection HostCollection.add_host({ 'id': hc['id'], 'organization-id': self.org['id'], 'host-ids': self.host['id'] }) with VirtualMachine() as client: client.create() client.install_katello_ca() # register the client host with the current activation key client.register_contenthost(self.org['name'], activation_key=activation_key['name']) assert client.subscribed # note: when registering the host, it should be automatically added # to the host collection client_host = Host.info({'name': client.hostname}) hosts = HostCollection.hosts({ 'id': hc['id'], 'organization-id': self.org['id'] }) assert len(hosts) == 2 expected_hosts_ids = {self.host['id'], client_host['id']} hosts_ids = {host['id'] for host in hosts} assert hosts_ids == expected_hosts_ids
def test_positive_delete_with_lce(self): """Create activation key with lifecycle environment assigned to it and delete it using activation key id @Feature: Activation key - Positive Delete @Assert: Activation key is deleted """ new_ak = self._make_activation_key({ u'lifecycle-environment': self.get_default_env()['name'], }) ActivationKey.delete({'id': new_ak['id']}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': new_ak['id']})
def test_positive_copy_subscription(self): """Copy Activation key and verify contents :id: f4ee8096-4120-4d06-8c9a-57ac1eaa8f68 :Steps: 1. Create parent key and add content 2. Copy Activation key by passing id of parent 3. Verify content was successfully copied :expectedresults: Activation key is successfully copied :CaseLevel: Integration """ # Begin test setup parent_ak = self._make_activation_key() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': self.org['id'], }) subscription_result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) ActivationKey.add_subscription({ u'id': parent_ak['id'], u'subscription-id': subscription_result[0]['id'], }) # End test setup new_name = gen_string('utf8') result = ActivationKey.copy({ u'id': parent_ak['id'], u'new-name': new_name, u'organization-id': self.org['id'], }) self.assertEqual(result[0], u'Activation key copied') result = ActivationKey.subscriptions({ u'name': new_name, u'organization-id': self.org['id'], }) # Verify that the subscription copied over self.assertIn( subscription_result[0]['name'], # subscription name result[3] # subscription list )
def test_positive_content_override(self): """Positive content override :id: a4912cc0-3bf7-4e90-bb51-ec88b2fad227 :Steps: 1. Create activation key and add content 2. Get the first product's label 3. Override the product's content enabled state 4. Verify that the command succeeded :expectedresults: Activation key content override was successful :CaseLevel: System """ result = setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': self.org['id'], }) content = ActivationKey.product_content({ u'id': result['activationkey-id'], u'organization-id': self.org['id'], }) for override_value in (True, False): with self.subTest(override_value): ActivationKey.content_override({ u'content-label': content[0]['label'], u'id': result['activationkey-id'], u'organization-id': self.org['id'], u'value': int(override_value), }) # Retrieve the product content enabled flag content = ActivationKey.product_content({ u'id': result['activationkey-id'], u'organization-id': self.org['id'], }) self.assertEqual(content[0]['enabled?'], str(override_value).lower())
def test_negative_update_usage_limit(self): """Try to update Activation Key using invalid value for its usage limit attribute @Feature: Activation key - Negative Update @Assert: Activation key is not updated. Appropriate error shown. """ new_ak = self._make_activation_key() with self.assertRaises(CLIReturnCodeError): ActivationKey.update({ u'max-content-hosts': int('9' * 20), u'id': new_ak['id'], u'organization-id': self.org['id'], })
def test_positive_delete_by_org_name(self): """Create Activation key and delete it using organization name for which that key was created @id: 006cbe5c-fb72-43a1-9760-30c97043c36b @Assert: Activation key is deleted """ new_ak = self._make_activation_key() ActivationKey.delete({ 'name': new_ak['name'], 'organization': self.org['name'], }) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': new_ak['id']})
def test_positive_delete_by_org_label(self): """Create Activation key and delete it using organization label for which that key was created @id: f66e5a42-b531-4290-a907-9f5c01305885 @Assert: Activation key is deleted """ new_ak = self._make_activation_key() ActivationKey.delete({ 'name': new_ak['name'], 'organization-label': self.org['label'], }) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': new_ak['id']})
def test_positive_delete_with_cv(self): """Create activation key with content view assigned to it and delete it using activation key id :id: bba323fa-0362-4a9b-97af-560d446cbb6c :expectedresults: Activation key is deleted :CaseLevel: Integration """ new_cv = make_content_view({u'organization-id': self.org['id']}) new_ak = self._make_activation_key({u'content-view': new_cv['name']}) ActivationKey.delete({'id': new_ak['id']}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': new_ak['id']})
def test_negative_copy_with_same_name(self): """Copy activation key with duplicate name @Feature: Activation key copy @Assert: Activation key is not successfully copied """ parent_ak = self._make_activation_key() with self.assertRaises(CLIReturnCodeError) as exception: ActivationKey.copy({ u'name': parent_ak['name'], u'new-name': parent_ak['name'], u'organization-id': self.org['id'], }) self.assertEqual(exception.exception.return_code, 65)
def test_positive_add_subscription_by_id(self): """Test that subscription can be added to activation key :id: b884be1c-b35d-440a-9a9d-c854c83e10a7 :Steps: 1. Create Activation key 2. Upload manifest and add subscription 3. Associate the activation key to subscription :expectedresults: Subscription successfully added to activation key :CaseLevel: Integration """ with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) org_id = make_org()['id'] ackey_id = self._make_activation_key()['id'] Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }) subs_id = Subscription.list( {'organization-id': org_id}, per_page=False ) result = ActivationKey.add_subscription({ u'id': ackey_id, u'subscription-id': subs_id[0]['id'], }) self.assertIn('Subscription added to activation key', result)
def test_positive_add_subscription_by_id(self): """Test that subscription can be added to activation key @Feature: Activation key - Subscription @Steps: 1. Create Activation key 2. Upload manifest and add subscription 3. Associate the activation key to subscription @Assert: Subscription successfully added to activation key """ with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) org_id = make_org()['id'] ackey_id = self._make_activation_key()['id'] Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }) subs_id = Subscription.list( {'organization-id': org_id}, per_page=False ) result = ActivationKey.add_subscription({ u'id': ackey_id, u'subscription-id': subs_id[0]['id'], }) self.assertIn('Subscription added to activation key', result)
def test_negative_update_name(self): """Try to update Activation Key using invalid value for its name @Feature: Activation key - Negative Update @Assert: Activation key is not updated. Appropriate error shown. """ new_ak = self._make_activation_key() for name in invalid_values_list(): with self.subTest(name): with self.assertRaises(CLIReturnCodeError): ActivationKey.update({ u'id': new_ak['id'], u'new-name': name, u'organization-id': self.org['id'], })
def test_positive_add_redhat_product(self): """Test that RH product can be associated to Activation Keys :id: 7b15de8e-edde-41aa-937b-ad6aa529891a :expectedresults: RH products are successfully associated to Activation key :CaseLevel: System """ org = make_org() # Using CDN as we need this repo to be RH one no matter are we in # downstream or cdn result = setup_org_for_a_rh_repo( { u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': org['id'], }, force_use_cdn=True) content = ActivationKey.product_content({ u'id': result['activationkey-id'], u'organization-id': org['id'], }) self.assertEqual(content[0]['name'], REPOSET['rhst7'])
def test_positive_add_custom_product(self): """Test that custom product can be associated to Activation Keys :id: 96ace967-e165-4069-8ff7-f54c4c822de0 :expectedresults: Custom products are successfully associated to Activation key :CaseLevel: System :BZ: 1426386 """ result = setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': self.org['id'], }) repo = Repository.info({u'id': result['repository-id']}) content = ActivationKey.product_content({ u'id': result['activationkey-id'], u'organization-id': self.org['id'], }) self.assertEqual(content[0]['name'], repo['name'])
def test_positive_update_usage_limit_to_finite_number(self): """Update Usage limit from Unlimited to a finite number @id: a55bb8dc-c7d8-4a6a-ac0f-1d5a377da543 @Assert: Activation key is updated """ new_ak = self._make_activation_key() self.assertEqual(new_ak['host-limit'], u'Unlimited') ActivationKey.update({ u'max-hosts': '2147483647', u'name': new_ak['name'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': new_ak['id']}) self.assertEqual(updated_ak['host-limit'], u'2147483647')
def test_positive_delete_with_lce(self): """Create activation key with lifecycle environment assigned to it and delete it using activation key id :id: e1830e52-5b1a-4ac4-8d0a-df6efb218a8b :expectedresults: Activation key is deleted :CaseLevel: Integration """ new_ak = self._make_activation_key({ u'lifecycle-environment': self.get_default_env()['name'], }) ActivationKey.delete({'id': new_ak['id']}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': new_ak['id']})
def _make_activation_key(self, options=None): """ Make a new activation key and assert its success""" if options is None: options = {} # Use default organization if None are provided if (not options.get('organization', None) and not options.get('organization-label', None) and not options.get('organization-id', None)): options['organization-id'] = self.org['id'] # Create activation key ackey = make_activation_key(options) # Fetch it result = ActivationKey.info({'id': ackey['id']}) self.assertEqual( result.return_code, 0, "Activation key was not found: %s" % str(result.stderr)) self.assertEqual(len(result.stderr), 0, "No error was expected %s" % str(result.stderr)) # Return the activation key dictionary return ackey