def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(RemoteExecutionTestCase, cls).setUpClass() cls.org = make_org() ssh.command( '''echo 'getenforce' > {0}'''.format(TEMPLATE_FILE) ) cls.env = make_lifecycle_environment({ u'organization-id': cls.org['id'], }) cls.content_view = make_content_view({ u'organization-id': cls.org['id'], }) cls.activation_key = make_activation_key({ u'lifecycle-environment-id': cls.env['id'], u'organization-id': cls.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': cls.org['id'], u'content-view-id': cls.content_view['id'], u'lifecycle-environment-id': cls.env['id'], u'activationkey-id': cls.activation_key['id'], })
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_aks_to_chost(self): """Check if multiple Activation keys can be attached to a Content host :id: 24fddd9c-03ae-41a7-8649-72296cbbafdf :expectedresults: Multiple Activation keys are attached to a Content host :CaseLevel: System """ 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'], }) new_aks = [ make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) for _ in range(2) ] with VirtualMachine(distro=DISTRO_RHEL6) as vm: vm.install_katello_ca() for i in range(2): vm.register_contenthost( self.org['label'], new_aks[i]['name']) self.assertTrue(vm.subscribed)
def test_positive_update_aks_to_chost(self): """Check if multiple Activation keys can be attached to a Content host @Feature: Activation key - Content host @Assert: Multiple Activation keys are attached to a Content host """ 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'], }) new_aks = [ make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) for _ in range(2) ] with VirtualMachine(distro='rhel65') as vm: vm.install_katello_ca() for i in range(2): result = vm.register_contenthost( new_aks[i]['name'], self.org['label']) self.assertEqual(result.return_code, 0)
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
def test_positive_copy_ak1(self): """@Test: Copy Activation key for all valid Activation Key name variations @Feature: Activation key copy @Steps: 1. Copy Activation key for all valid Activation Key name variations @Assert: Activation key is sucessfully copied """ parent_id = make_activation_key( {u'organization-id': self.org['id']}, cached=True, )['id'] for new_name in valid_data_list(): with self.subTest(new_name): result = ActivationKey.copy({ u'id': parent_id, u'new-name': new_name, u'organization-id': self.org['id'], }) self.assertEqual(result[0], u'Activation key copied')
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
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_aks_to_chost(self): """Check if multiple Activation keys can be attached to a Content host @Feature: Activation key - Content host @Assert: Multiple Activation keys are attached to a Content host """ 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"]}) new_aks = [ make_activation_key( { u"lifecycle-environment-id": env["id"], u"content-view": new_cv["name"], u"organization-id": self.org["id"], } ) for _ in range(2) ] with VirtualMachine(distro="rhel65") as vm: vm.install_katello_ca() for i in range(2): result = vm.register_contenthost(new_aks[i]["name"], self.org["label"]) self.assertEqual(result.return_code, 0)
def test_negative_register_twice(self): """Attempt to register a Content host twice to Satellite @feature: Content host @assert: Content host cannot be registered twice """ activation_key = make_activation_key({ 'content-view-id': self.PROMOTED_CV['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], 'organization-id': self.NEW_ORG['id'], }) with VirtualMachine(distro='rhel71') as client: client.install_katello_ca() client.register_contenthost( activation_key['name'], self.NEW_ORG['label'], ) result = client.register_contenthost( activation_key['name'], self.NEW_ORG['label'], force=False, ) # Depending on distro version, successful return_code may be 0 or # 1, so we can't verify CH wasn't registered by return_code != 0 # check. Verifying return_code == 64 here, which stands for content # host being already registered. self.assertEqual(result.return_code, 64)
def test_positive_update_aks_to_chost(self): """@Test: Check if multiple Activation keys can be attached to a Content host @Feature: Activation key - Content host @Assert: Multiple Activation keys are attached to a Content host """ 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'], }) new_aks = [ make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) for _ in range(2) ] with VirtualMachine(distro='rhel65') as vm: vm.install_katello_ca() for i in range(2): result = vm.register_contenthost( new_aks[i]['name'], self.org['label']) self.assertEqual(result.return_code, 0)
def test_positive_list(self): """List Content hosts for a given org @id: b9c056cd-11ca-4870-bac4-0ebc4a782cb0 @Assert: Content hosts are listed for the given org @CaseLevel: System """ activation_key = make_activation_key({ 'content-view-id': self.PROMOTED_CV['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], 'organization-id': self.NEW_ORG['id'], }) with VirtualMachine(distro='rhel71') as client: client.install_katello_ca() client.register_contenthost( self.NEW_ORG['label'], activation_key['name'], ) result = ContentHost.list({ 'organization-id': self.NEW_ORG['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], }) self.assertGreaterEqual(len(result), 1) self.assertIn(client.hostname, [chost['name'] for chost in result])
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 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_unregister(self): """Unregister Content host @feature: Content host @assert: After unregistering, Content hosts list for the org does not show the Content host """ activation_key = make_activation_key({ 'content-view-id': self.PROMOTED_CV['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], 'organization-id': self.NEW_ORG['id'], }) with VirtualMachine(distro='rhel71') as client: client.install_katello_ca() client.register_contenthost( activation_key['name'], self.NEW_ORG['label'], ) result = ContentHost.list({'organization-id': self.NEW_ORG['id']}) self.assertGreaterEqual(len(result), 1) self.assertIn(client.hostname, [chost['name'] for chost in result]) result = client.run('subscription-manager unregister') self.assertEqual(result.return_code, 0) result = ContentHost.list({'organization-id': self.NEW_ORG['id']}) self.assertNotIn( client.hostname, [chost['name'] for chost in result])
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_list(self): """List Content hosts for a given org @id: b9c056cd-11ca-4870-bac4-0ebc4a782cb0 @Assert: Content hosts are listed for the given org @CaseLevel: System """ activation_key = make_activation_key({ 'content-view-id': self.PROMOTED_CV['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], 'organization-id': self.NEW_ORG['id'], }) with VirtualMachine(distro='rhel71') as client: client.install_katello_ca() client.register_contenthost( activation_key['name'], self.NEW_ORG['label'], ) result = ContentHost.list({ 'organization-id': self.NEW_ORG['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], }) self.assertGreaterEqual(len(result), 1) self.assertIn(client.hostname, [chost['name'] for chost in result])
def test_update_autoattach_2(self): """@Test: Update Activation key with valid auto-attach values @Feature: Activation key update / info @Steps: 1. Update the key with a valid value 2. Verify key was updated. @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'] for new_value in (u'1', u'0', u'true', u'false', u'yes', u'no'): with self.subTest(new_value): result = ActivationKey.update({ u'auto-attach': new_value, u'id': key_id, u'organization-id': org_id, }) self.assertEqual( u'Activation key updated', result[0]['message'])
def _create_activation_key(self): """Create a new activation key named ak-1""" make_activation_key({ 'organization-id': self.org_id, 'content-view': self.content_view, 'lifecycle-environment': self.life_cycle_env, 'name': self.ak_name }) # output activation key information self.logger.info('Retrieve activation keys info list:') try: result = ActivationKey.list({'organization-id': self.org_id}, per_page=False) except CLIReturnCodeError: self.logger.error('Fail to make new activation key!') return return result[0]['id'], result[0]['name']
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 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 _create_activation_key(self): """Create a new activation key named ak-1""" make_activation_key({ 'organization-id': self.org_id, 'content-view': self.content_view, 'lifecycle-environment': self.life_cycle_env, 'name': self.ak_name }) # output activation key informatin self.logger.info('Retrieve activation keys info list:') result = ActivationKey.list({'organization-id': self.org_id}, per_page=False) if result.return_code != 0: self.logger.error('Fail to make new activation key!') return self.logger.info('New activation key is: {}.'.format( result.stdout[0]['name'])) return result.stdout[0]['id'], result.stdout[0]['name']
def _create_activation_key(self): """Create a new activation key named ak-1""" make_activation_key({ 'organization-id': self.org_id, 'content-view': self.content_view, 'lifecycle-environment': self.life_cycle_env, 'name': self.ak_name }) # output activation key information self.logger.info('Retrieve activation keys info list:') try: result = ActivationKey.list( {'organization-id': self.org_id}, per_page=False ) except CLIReturnCodeError: self.logger.error('Fail to make new activation key!') return return result[0]['id'], result[0]['name']
def golden_ticket_host_setup(request, module_org): with manifests.clone(name='golden_ticket') as manifest: upload_manifest(module_org.id, manifest.content) new_product = make_product({'organization-id': module_org.id}) new_repo = make_repository({'product-id': new_product['id']}) Repository.synchronize({'id': new_repo['id']}) new_ak = make_activation_key({ 'lifecycle-environment': 'Library', 'content-view': 'Default Organization View', 'organization-id': module_org.id, 'auto-attach': False, }) return new_ak
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 return make_activation_key(options)
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_copy_subscription(self): """@Test: 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 sucessfully copied @Assert: Activation key is sucessfully copied """ # Begin test setup org_id = make_org()['id'] parent_id = make_activation_key({ u'organization-id': org_id })['id'] manifest = manifests.clone() upload_file(manifest, remote_file=manifest) Subscription.upload({ 'file': manifest, 'organization-id': org_id, }) subscription_result = Subscription.list( {'organization-id': org_id}, per_page=False) ActivationKey.add_subscription({ u'id': parent_id, u'subscription-id': subscription_result[0]['id'], }) # End test setup new_name = gen_string('utf8') result = ActivationKey.copy({ u'id': parent_id, u'new-name': new_name, u'organization-id': org_id, }) self.assertEqual(result[0], u'Activation key copied') result = ActivationKey.subscriptions({ u'name': new_name, u'organization-id': org_id, }) # Verify that the subscription copied over self.assertIn( subscription_result[0]['name'], # subscription name result[3] # subscription list )
def test_add_docker_repo_composite_view_to_activation_key(self): """@Test: Add Docker-type repository to a non-composite content view and publish it. Then add this content view to a composite content view and publish it. Create an activation key and associate it with the composite Docker content view. @Assert: Docker-based content view can be added to activation key @Feature: Docker """ comp_content_view = make_content_view({ 'composite': True, 'organization-id': self.org['id'], }) ContentView.update({ 'component-ids': self.content_view['versions'][0]['id'], 'id': comp_content_view['id'], }) comp_content_view = ContentView.info({ 'id': comp_content_view['id'], }) self.assertIn( self.content_view['versions'][0]['id'], [ component['id'] for component in comp_content_view['components'] ], ) ContentView.publish({'id': comp_content_view['id']}) comp_content_view = ContentView.info({ 'id': comp_content_view['id'], }) comp_cvv = ContentView.version_info({ 'id': comp_content_view['versions'][0]['id'], }) ContentView.version_promote({ 'id': comp_cvv['id'], 'lifecycle-environment-id': self.lce['id'], }) activation_key = make_activation_key({ 'content-view-id': comp_content_view['id'], 'lifecycle-environment-id': self.lce['id'], 'organization-id': self.org['id'], }) self.assertEqual( activation_key['content-view'], comp_content_view['name'])
def test_add_docker_repo_to_activation_key(self): """@Test: Add Docker-type repository to a non-composite content view and publish it. Then create an activation key and associate it with the Docker content view. @Assert: Docker-based content view can be added to activation key @Feature: Docker """ activation_key = make_activation_key({ 'content-view-id': self.content_view['id'], 'lifecycle-environment-id': self.lce['id'], 'organization-id': self.org['id'], }) self.assertEqual( activation_key['content-view'], self.content_view['name'])
def test_positive_usage_limit(self): """Test that Usage limit actually limits usage :id: 00ded856-e939-4140-ac84-91b6a8643623 :Steps: 1. Create Activation key 2. Update Usage Limit to a finite number 3. Register Content hosts to match the Usage Limit 4. Attempt to register an other Content host after reaching the Usage Limit :expectedresults: Content host Registration fails. Appropriate error shown :CaseLevel: System """ 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'], }) new_ak = make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], u'max-hosts': '1', }) with VirtualMachine(distro=DISTRO_RHEL6) as vm1: with VirtualMachine(distro=DISTRO_RHEL6) as vm2: vm1.install_katello_ca() result = vm1.register_contenthost( self.org['label'], new_ak['name']) self.assertTrue(vm1.subscribed) vm2.install_katello_ca() result = vm2.register_contenthost( self.org['label'], new_ak['name']) self.assertFalse(vm2.subscribed) self.assertEqual(result.return_code, 70) self.assertGreater(len(result.stderr), 0)
def ContentHostSetup(request): org = make_org() with manifests.clone(name='golden_ticket') as manifest: upload_manifest(org['id'], manifest.content) new_product = make_product({'organization-id': org['id']}) new_repo = make_repository({'product-id': new_product['id']}) Repository.synchronize({'id': new_repo['id']}) new_ak = make_activation_key( { 'lifecycle-environment': 'Library', 'content-view': 'Default Organization View', '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.org_setup = org request.cls.ak_setup = new_ak
def test_remove_docker_repo_to_activation_key(self): """@Test: Add Docker-type repository to a non-composite content view and publish it. Create an activation key and associate it with the Docker content view. Then remove this content view from the activation key. @Assert: Docker-based content view can be added and then removed from the activation key. @Feature: Docker """ activation_key = make_activation_key({ 'content-view-id': self.content_view['id'], 'lifecycle-environment-id': self.lce['id'], 'organization-id': self.org['id'], }) self.assertEqual( activation_key['content-view'], self.content_view['name']) # Create another content view replace with another_cv = make_content_view({ 'composite': False, 'organization-id': self.org['id'], }) ContentView.publish({'id': another_cv['id']}) another_cv = ContentView.info({ 'id': another_cv['id']}) ContentView.version_promote({ 'id': another_cv['versions'][0]['id'], 'lifecycle-environment-id': self.lce['id'], }) ActivationKey.update({ 'id': activation_key['id'], 'organization-id': self.org['id'], 'content-view-id': another_cv['id'], }) activation_key = ActivationKey.info({ 'id': activation_key['id'], }) self.assertNotEqual( activation_key['content-view'], self.content_view['name'])
def local_ak(local_org, local_environment, local_content_view): """Promote a content view version and create an activation key with CLI Factory""" cvv = ContentView.info({'id': local_content_view['id']})['versions'][0] ContentView.version_promote({ 'id': cvv['id'], 'to-lifecycle-environment-id': local_environment['id'] }) return make_activation_key({ 'lifecycle-environment-id': local_environment['id'], 'content-view': local_content_view['name'], 'organization-id': local_org['id'], 'auto-attach': False, })
def test_positive_unregister(self): """Unregister Content host @id: c5ce988d-d0ea-4958-9956-5a4b039b285c @Assert: After unregistering, content hosts list for the org does not show the content host @CaseLevel: System """ activation_key = make_activation_key({ 'content-view-id': self.PROMOTED_CV['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], 'organization-id': self.NEW_ORG['id'], }) with VirtualMachine(distro=DISTRO_RHEL7) as client: client.install_katello_ca() client.register_contenthost( self.NEW_ORG['label'], activation_key['name'], ) result = ContentHost.list({ 'organization-id': self.NEW_ORG['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], }) self.assertGreaterEqual(len(result), 1) self.assertIn(client.hostname, [chost['name'] for chost in result]) result = client.run('subscription-manager unregister') self.assertEqual(result.return_code, 0) result = ContentHost.list({ 'organization-id': self.NEW_ORG['id'], 'lifecycle-environment-id': self.NEW_LIFECYCLE['id'], }) self.assertNotIn(client.hostname, [chost['name'] for chost in result])
def test_positive_list(self): """List Content hosts for a given org @feature: Content host @assert: Content hosts are listed for the given org """ activation_key = make_activation_key( { "content-view-id": self.PROMOTED_CV["id"], "lifecycle-environment-id": self.NEW_LIFECYCLE["id"], "organization-id": self.NEW_ORG["id"], } ) with VirtualMachine(distro="rhel71") as client: client.install_katello_ca() client.register_contenthost(activation_key["name"], self.NEW_ORG["label"]) result = ContentHost.list({"organization-id": self.NEW_ORG["id"]}) self.assertGreaterEqual(len(result), 1) self.assertIn(client.hostname, [chost["name"] for chost in result])
def test_positive_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 Content hosts to match the Usage Limit 4. Attempt to register an other Content host after reaching the Usage Limit @Assert: Content host Registration fails. Appropriate error shown """ 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'], }) new_ak = make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], u'unlimited-content-hosts': '0', u'max-content-hosts': '1', }) with VirtualMachine(distro='rhel65') as vm1: with VirtualMachine(distro='rhel65') as vm2: vm1.install_katello_ca() result = vm1.register_contenthost( new_ak['name'], self.org['label']) self.assertEqual(result.return_code, 0) vm2.install_katello_ca() result = vm2.register_contenthost( new_ak['name'], self.org['label']) self.assertEqual(result.return_code, 255) self.assertGreater(len(result.stderr), 0)
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_usage_limit(self): """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 Content hosts to match the Usage Limit 4. Attempt to register an other Content host after reaching the Usage Limit @Assert: Content host Registration fails. Appropriate error shown """ 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'], }) new_ak = make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], u'max-content-hosts': '1', }) with VirtualMachine(distro='rhel65') as vm1: with VirtualMachine(distro='rhel65') as vm2: vm1.install_katello_ca() result = vm1.register_contenthost( new_ak['name'], self.org['label']) self.assertEqual(result.return_code, 0) vm2.install_katello_ca() result = vm2.register_contenthost( new_ak['name'], self.org['label']) self.assertEqual(result.return_code, 255) self.assertGreater(len(result.stderr), 0)
def test_positive_copy_ak2(self): """@Test: Copy Activation key by passing name of parent @Feature: Activation key copy @Steps: 1. Copy Activation key by passing name of parent @Assert: Activation key is sucessfully copied """ parent_name = make_activation_key( {u'organization-id': self.org['id']}, cached=True, )['name'] result = ActivationKey.copy({ u'name': parent_name, u'new-name': gen_string('alpha'), u'organization-id': self.org['id'], }) self.assertEqual(result[0], u'Activation key copied')
def test_positive_usage_limit(self): """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 Content hosts to match the Usage Limit 4. Attempt to register an other Content host after reaching the Usage Limit @Assert: Content host Registration fails. Appropriate error shown """ 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"]}) new_ak = make_activation_key( { u"lifecycle-environment-id": env["id"], u"content-view": new_cv["name"], u"organization-id": self.org["id"], u"unlimited-content-hosts": "0", u"max-content-hosts": "1", } ) with VirtualMachine(distro="rhel65") as vm1: with VirtualMachine(distro="rhel65") as vm2: vm1.install_katello_ca() result = vm1.register_contenthost(new_ak["name"], self.org["label"]) self.assertEqual(result.return_code, 0) vm2.install_katello_ca() result = vm2.register_contenthost(new_ak["name"], self.org["label"]) self.assertEqual(result.return_code, 255) self.assertGreater(len(result.stderr), 0)
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 test_negative_copy_ak(self): """@Test: Copy activation key with duplicate name @Feature: Activation key copy @Steps: 1. Attempt to copy an activation key with a duplicate name @Assert: Activation key not successfully copied """ parent_name = make_activation_key( {u'organization-id': self.org['id']}, cached=True, )['name'] with self.assertRaises(CLIReturnCodeError) as exe: ActivationKey.copy({ u'name': parent_name, u'new-name': parent_name, u'organization-id': self.org['id'], }) self.assertEqual(exe.exception.return_code, 65) self.assertIn(u'Name has already been taken', exe.exception.stderr)
def test_end_to_end(self): """@Test: Perform end to end smoke tests using RH repos. 1. Create new organization and environment 2. Upload manifest 3. Sync a RedHat repository 4. Create content-view 5. Add repository to contet-view 6. Promote/publish content-view 7. Create an activation-key 8. Add product to activation-key 9. Create new virtualmachine 10. Pull rpm from Foreman server and install on client 11. Register client with foreman server using activation-key 12. Install rpm on client @Feature: Smoke test @Assert: All tests should succeed and Content should be successfully fetched by client """ # Product, RepoSet and repository variables rhel_product_name = 'Red Hat Enterprise Linux Server' rhel_repo_set = ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Server (RPMs)' ) rhel_repo_name = ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Server ' 'RPMs x86_64 6Server' ) org_name = random.choice(generate_strings_list()) # Create new org and environment new_org = make_org({u'name': org_name}) new_env = make_lifecycle_environment({ u'organization-id': new_org['id'], u'name': gen_alphanumeric(), }) # Clone manifest and upload it manifest = manifests.clone() upload_file(manifest, remote_file=manifest) result = Subscription.upload({ u'file': manifest, u'organization-id': new_org['id'], }) self.assertEqual( result.return_code, 0, "Failed to upload manifest: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Enable repo from Repository Set result = RepositorySet.enable({ u'name': rhel_repo_set, u'organization-id': new_org['id'], u'product': rhel_product_name, u'releasever': '6Server', u'basearch': 'x86_64', }) self.assertEqual( result.return_code, 0, "Repo was not enabled: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Fetch repository info result = Repository.info({ u'name': rhel_repo_name, u'product': rhel_product_name, u'organization-id': new_org['id'], }) rhel_repo = result.stdout # Synchronize the repository result = Repository.synchronize({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) self.assertEqual( result.return_code, 0, "Repo was not synchronized: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create CV and associate repo to it new_cv = make_content_view({u'organization-id': new_org['id']}) result = ContentView.add_repository({ u'id': new_cv['id'], u'repository-id': rhel_repo['id'], u'organization-id': new_org['id'], }) self.assertEqual( result.return_code, 0, "Failed repository association: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Publish a version1 of CV result = ContentView.publish({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, "Version1 publishing failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Get the CV info result = ContentView.info({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, "ContentView was not found: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Store the version1 id version1_id = result.stdout['versions'][0]['id'] # Promotion of version1 to next env result = ContentView.version_promote({ u'id': version1_id, u'to-lifecycle-environment-id': new_env['id'], }) self.assertEqual( result.return_code, 0, "version1 promotion failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create activation key activation_key = make_activation_key({ u'name': gen_alphanumeric(), u'lifecycle-environment-id': new_env['id'], u'organization-id': new_org['id'], u'content-view': new_cv['name'], }) # List the subscriptions in given org result = Subscription.list( {u'organization-id': new_org['id']}, per_page=False ) self.assertEqual( result.return_code, 0, "Failed to list subscriptions: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Get the subscription ID from subscriptions list for subscription in result.stdout: if subscription['name'] == "Red Hat Employee Subscription": subscription_id = subscription['id'] subscription_quantity = int(subscription['quantity']) self.assertGreater( int(subscription_quantity), 0, 'Unexpected subscription quantity {0}' .format(subscription_quantity) ) # Add the subscriptions to activation-key result = ActivationKey.add_subscription({ u'id': activation_key['id'], u'subscription-id': subscription_id, u'quantity': 1, }) self.assertEqual( result.return_code, 0, "Failed to add subscription: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create VM package_name = "python-kitchen" server_name = conf.properties['main.server.hostname'] with VirtualMachine(distro='rhel66') as vm: # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(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} and return code: {1}" .format(result.stderr, result.return_code) ) # Register client with foreman server using activation-key result = vm.run( u'subscription-manager register --activationkey {0} ' '--org {1} --force' .format(activation_key['name'], new_org['label']) ) self.assertEqual( result.return_code, 0, "failed to register client:: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Enable Red Hat Enterprise Virtualization Agents repo via cli # As the below repo is disabled by default under ak's prd-content result = vm.run( 'subscription-manager repos --enable ' 'rhel-6-server-rhev-agent-rpms' ) self.assertEqual( result.return_code, 0, "Enabling repo failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Install contents from sat6 server result = vm.run('yum install -y {0}'.format(package_name)) self.assertEqual( result.return_code, 0, "Package install failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Verify if package is installed by query it result = vm.run('rpm -q {0}'.format(package_name)) self.assertIn(package_name, result.stdout[0])
def test_positive_list_hosts(self): """Verify only hosts registered by specific activation key are listed on Activation Key -> Associations -> Content Hosts page @id: 9364bfcc-ef69-4183-9ca8-e2904b3f4068 @Steps: 1. Create 2 activation keys 2. Register 2 hosts, one for each activation key @Assert: Activation Key -> Associations -> Content Hosts page should show only hosts registered via the key @BZ: 1372826 """ org = make_org() env = make_lifecycle_environment({'organization-id': org['id']}) content_view = make_content_view({'organization-id': org['id']}) activation_key = make_activation_key({ 'lifecycle-environment-id': env['id'], 'organization-id': org['id'], }) setup_org_for_a_rh_repo({ 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': org['id'], 'content-view-id': content_view['id'], 'lifecycle-environment-id': env['id'], 'activationkey-id': activation_key['id'], }) another_ak = make_activation_key({ 'content-view-id': content_view['id'], 'lifecycle-environment-id': env['id'], 'organization-id': org['id'], }) activationkey_add_subscription_to_repo({ 'activationkey-id': another_ak['id'], 'organization-id': org['id'], 'subscription': DEFAULT_SUBSCRIPTION_NAME, }) with VirtualMachine(distro=DISTRO_RHEL7) as client1, VirtualMachine( distro=DISTRO_RHEL7) as client2: client1.install_katello_ca() client2.install_katello_ca() result = client1.register_contenthost(org['label'], activation_key['name']) self.assertEqual(result.return_code, 0) result = client2.register_contenthost(org['label'], another_ak['name']) self.assertEqual(result.return_code, 0) with Session(self.browser) as session: set_context(session, org=org['name']) self.assertIsNotNone( self.activationkey.search_host(activation_key['name'], client1.hostname)) self.assertIsNone( self.activationkey.search_host(activation_key['name'], client2.hostname)) self.assertIsNotNone( self.activationkey.search_host(another_ak['name'], client2.hostname)) self.assertIsNone( self.activationkey.search_host(another_ak['name'], client1.hostname))
def test_positive_end_to_end(self): """Perform end to end smoke tests using RH repos. 1. Create new organization and environment 2. Upload manifest 3. Sync a RedHat repository 4. Create content-view 5. Add repository to contet-view 6. Promote/publish content-view 7. Create an activation-key 8. Add product to activation-key 9. Create new virtualmachine 10. Pull rpm from Foreman server and install on client 11. Register client with foreman server using activation-key 12. Install rpm on client @Feature: Smoke test @Assert: All tests should succeed and Content should be successfully fetched by client """ # Product, RepoSet and repository variables rhel_product_name = PRDS['rhel'] rhel_repo_set = REPOSET['rhva6'] rhel_repo_name = REPOS['rhva6']['name'] org_name = random.choice(generate_strings_list()) # Create new org and environment new_org = make_org({u'name': org_name}) new_env = make_lifecycle_environment({ u'organization-id': new_org['id'], }) # Clone manifest and upload it with manifests.clone() as manifest: ssh.upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': new_org['id'], }) # Enable repo from Repository Set RepositorySet.enable({ u'basearch': 'x86_64', u'name': rhel_repo_set, u'organization-id': new_org['id'], u'product': rhel_product_name, u'releasever': '6Server', }) # Fetch repository info rhel_repo = Repository.info({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) # Synchronize the repository Repository.synchronize({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) # Create CV and associate repo to it new_cv = make_content_view({u'organization-id': new_org['id']}) ContentView.add_repository({ u'id': new_cv['id'], u'organization-id': new_org['id'], u'repository-id': rhel_repo['id'], }) # Publish a version1 of CV ContentView.publish({u'id': new_cv['id']}) # Get the CV info version1_id = ContentView.info({u'id': new_cv['id']})['versions'][0]['id'] # Store the version1 id # Promotion of version1 to next env ContentView.version_promote({ u'id': version1_id, u'to-lifecycle-environment-id': new_env['id'], }) # Create activation key activation_key = make_activation_key({ u'content-view': new_cv['name'], u'lifecycle-environment-id': new_env['id'], u'organization-id': new_org['id'], }) # List the subscriptions in given org result = Subscription.list({u'organization-id': new_org['id']}, per_page=False) self.assertGreater(len(result), 0) # Get the subscription ID from subscriptions list subscription_quantity = 0 for subscription in result: if subscription['name'] == DEFAULT_SUBSCRIPTION_NAME: subscription_id = subscription['id'] subscription_quantity = int(subscription['quantity']) self.assertGreater(subscription_quantity, 0) # Add the subscriptions to activation-key ActivationKey.add_subscription({ u'id': activation_key['id'], u'quantity': 1, u'subscription-id': subscription_id, }) # Enable product content ActivationKey.content_override({ u'content-label': 'rhel-6-server-rhev-agent-rpms', u'id': activation_key['id'], u'organization-id': new_org['id'], u'value': '1', }) # Create VM package_name = "python-kitchen" server_name = settings.server.hostname with VirtualMachine(distro='rhel66') as vm: # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(server_name)) self.assertEqual(result.return_code, 0) result = vm.run('rpm -i katello-ca-consumer*.noarch.rpm') self.assertEqual(result.return_code, 0) # Register client with foreman server using activation-key result = vm.run( u'subscription-manager register --activationkey {0} ' '--org {1} --force'.format(activation_key['name'], new_org['label'])) self.assertEqual(result.return_code, 0) # Install contents from sat6 server result = vm.run('yum install -y {0}'.format(package_name)) self.assertEqual(result.return_code, 0) # Verify if package is installed by query it result = vm.run('rpm -q {0}'.format(package_name)) self.assertEqual(result.return_code, 0)
def test_positive_restore_ak_and_content_hosts_subscriptions(self): """Restore activation key and content hosts subscriptions :id: a44fdeda-9c8c-4316-85b4-a9b6b9f1ffdb :customerscenario: true :steps: 1. Setup activation key , lifecycle environment and content view with RH repository 2. Add RH subscription to activation key 3. Setup hosts (minimum two) and subscribe them to activation key 4. Attach RH subscription to the created content hosts 5. export the activation key and content hosts subscriptions 6. Delete the subscription manifest 7. Ensure that the activation key and content hosts subscriptions does not exist 8. Upload the subscription manifest 9. Ensure the activation key and content hosts subscriptions does not exist 10. Restore the activation key and content hosts subscriptions :expectedresults: activation key and content hosts subscriptions restored :CaseImportance: Critical """ lce = make_lifecycle_environment({'organization-id': self.org['id']}) activation_key = make_activation_key({ 'organization-id': self.org['id'], 'lifecycle-environment-id': lce['id'], }) ActivationKey.update({ 'organization-id': self.org['id'], 'id': activation_key['id'], 'auto-attach': 'false', }) setup_org_for_a_rh_repo( { 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': self.org['id'], 'lifecycle-environment-id': lce['id'], 'activationkey-id': activation_key['id'], }, force_use_cdn=True) org_subs = Subscription.list({u'organization-id': self.org['id']}) default_subscription_id = None for sub in org_subs: if sub['name'] == DEFAULT_SUBSCRIPTION_NAME: default_subscription_id = sub['id'] break self.assertIsNotNone(default_subscription_id, msg='Default subscription not found') ak_subs = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in ak_subs]) with VirtualMachine() as client1, VirtualMachine() as client2: hosts = [] for client in [client1, client2]: client.install_katello_ca() client.register_contenthost( self.org['label'], activation_key=activation_key['name']) self.assertTrue(client.subscribed) host = Host.info({'name': client.hostname}) hosts.append(host) Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': default_subscription_id, }) host_subscriptions = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in host_subscriptions]) # export the current activations and content hosts subscriptions ak_file_path = '/tmp/ak_{0}.csv'.format(self.org['label']) ch_file_path = '/tmp/content_hosts_{0}.csv'.format( self.org['label']) CSV_.activation_keys({ 'export': True, 'file': ak_file_path, 'organization': self.org['name'], 'itemized-subscriptions': True, }) CSV_.content_hosts({ 'export': True, 'file': ch_file_path, 'organization': self.org['name'], 'itemized-subscriptions': True, }) # delete the manifest Subscription.delete_manifest({'organization-id': self.org['id']}) # ensure that the subscription does not exist any more ak_subs = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertNotIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in ak_subs]) for host in hosts: host_subscriptions = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertNotIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in host_subscriptions]) # upload the manifest again self._upload_manifest(self.org['id']) # ensure that the subscription was not auto attached ak_subs = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertNotIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in ak_subs]) for host in hosts: host_subscriptions = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertNotIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in host_subscriptions]) # restore from the saved activation key and content hosts # subscriptions CSV_.activation_keys({ 'file': ak_file_path, 'organization': self.org['name'], 'itemized-subscriptions': True, }) CSV_.content_hosts({ 'file': ch_file_path, 'organization': self.org['name'], 'itemized-subscriptions': True, }) # ensure that the subscriptions has been restored ak_subs = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in ak_subs]) for host in hosts: host_subscriptions = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertIn(DEFAULT_SUBSCRIPTION_NAME, [sub['name'] for sub in host_subscriptions])
def test_positive_restore_content_hosts_with_modified_subscription(self): """Restore content hosts subscription from an exported content host csv file with modified subscription. :id: d8ac08fe-24e0-41e7-b3d8-0ca13a702a64 :customerscenario: true :steps: 1. Setup activation key , lifecycle environment and content view with RH tools repository 2. Setup hosts (minimum two) and subscribe them to activation key 3. Attach RH subscription to the created content hosts 4. Export the organization content hosts to a csv file 5. Create a new csv file and modify the subscription with an other one (the new subscription must have other data than the default one) 6. Import the new csv file to organization content hosts :expectedresults: content hosts restored with the new subscription :BZ: 1296978 :CaseImportance: Critical """ lce = make_lifecycle_environment({'organization-id': self.org['id']}) activation_key = make_activation_key({ 'organization-id': self.org['id'], 'lifecycle-environment-id': lce['id'], }) ActivationKey.update({ 'organization-id': self.org['id'], 'id': activation_key['id'], 'auto-attach': 'false', }) # Create RH tools repository and contents, this step should upload # the default manifest setup_org_for_a_rh_repo( { 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': self.org['id'], 'lifecycle-environment-id': lce['id'], 'activationkey-id': activation_key['id'], }, force_use_cdn=True) # Export and download the organization subscriptions to prepare the new # subscription (The replacement of the default subscription) org_subs_csv_filename = 'subs_{0}.csv'.format(self.org['name']) org_subs_csv_remote_file_path = '/tmp/{0}'.format( org_subs_csv_filename) # export organization subscription to csv file CSV_.subscriptions({ 'export': True, 'file': org_subs_csv_remote_file_path, 'organization': self.org['name'], }) # download the organization subscriptions org_subs_csv_local_file_path = os.path.join(tempfile.gettempdir(), org_subs_csv_filename) download_file(org_subs_csv_remote_file_path, org_subs_csv_local_file_path) _, org_subscriptions = self._read_csv_file( org_subs_csv_local_file_path) new_subscription = None for sub in org_subscriptions: if sub['Subscription Name'] == SATELLITE_SUBSCRIPTION_NAME: new_subscription = sub break self.assertIsNotNone(new_subscription) # retrieve the default subscription id org_subs = Subscription.list({u'organization-id': self.org['id']}) default_subscription_id = None for sub in org_subs: if sub['name'] == DEFAULT_SUBSCRIPTION_NAME: default_subscription_id = sub['id'] break self.assertIsNotNone(default_subscription_id, msg='Default subscription not found') # create 2 Virtual machines with VirtualMachine() as client1, VirtualMachine() as client2: hosts = [] for client in [client1, client2]: client.install_katello_ca() client.register_contenthost( self.org['label'], activation_key=activation_key['name']) self.assertTrue(client.subscribed) host = Host.info({'name': client.hostname}) hosts.append(host) Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': default_subscription_id, }) host_subscriptions = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertEqual(len(host_subscriptions), 1) self.assertEqual(host_subscriptions[0]['name'], DEFAULT_SUBSCRIPTION_NAME) # export the content host data to csv file chs_export_file_name = 'chs_export_{0}.csv'.format( self.org['label']) chs_export_remote_file_path = ( '/tmp/{0}'.format(chs_export_file_name)) CSV_.content_hosts({ 'export': True, 'file': chs_export_remote_file_path, 'organization': self.org['name'], }) # download the csv file chs_export_local_file_path = os.path.join(tempfile.gettempdir(), chs_export_file_name) download_file(chs_export_remote_file_path, chs_export_local_file_path) # modify the content hosts subscription field_names, csv_data = self._read_csv_file( chs_export_local_file_path) # each client is represented by one row of data self.assertEqual(len(csv_data), 2) for row_data in csv_data: # The subscription is saved in the following format: # """<quantity>|<sku>|<name>|<contract>|<account>""" subscription_data = row_data['Subscriptions'].strip('"').split( '|') # change the subscription SKU (looks like RH00001) subscription_data[1] = new_subscription['Subscription SKU'] # change the name subscription_data[2] = new_subscription['Subscription Name'] # change the contract number subscription_data[3] = new_subscription[ 'Subscription Contract'] # change the subscription account subscription_data[4] = new_subscription['Subscription Account'] # modify the subscription data row_data['Subscriptions'] = '"{0}"'.format( '|'.join(subscription_data)) # generate a new csv file chs_import_file_name = 'chs_import_{0}.csv'.format( self.org['name']) chs_import_local_file_path = os.path.join(tempfile.gettempdir(), chs_import_file_name) self._write_csv_file(chs_import_local_file_path, field_names, csv_data) # upload the file chs_import_remote_file_path = ( '/tmp/{0}'.format(chs_import_file_name)) upload_file(chs_import_local_file_path, chs_import_remote_file_path) # import content hosts data from csv file CSV_.content_hosts({ 'file': chs_import_remote_file_path, 'organization': self.org['name'], }) for host in hosts: host_subscriptions = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertEqual(len(host_subscriptions), 1) self.assertEqual(host_subscriptions[0]['name'], SATELLITE_SUBSCRIPTION_NAME) self.assertEqual(host_subscriptions[0]['contract'], new_subscription['Subscription Contract']) self.assertEqual(host_subscriptions[0]['account'], new_subscription['Subscription Account'])
def test_positive_restore_ak_with_modified_subscription(self): """Restore activation key subscription from an exported activation key csv file with modified subscription. :id: 40b86d1c-88f8-451c-bf19-c5bf11223cb6 :steps: 1. Upload a manifest 2. Create an activation key 3. Attach RH subscription to the created activation key 4. Export the organization activation keys to a csv file 5. Create a new csv file and modify the subscription with an other one (the new subscription must have other data than the default one) 6. Import the new csv file to organization activation keys :expectedresults: activation key restored with the new subscription :BZ: 1296978 :CaseImportance: Critical """ # upload the organization default manifest self._upload_manifest(self.org['id']) # Export and download the organization subscriptions to prepare the new # subscription (The replacement of the default subscription) org_subs_csv_filename = 'subs_{0}.csv'.format(self.org['name']) org_subs_csv_remote_file_path = '/tmp/{0}'.format( org_subs_csv_filename) # export organization subscription to csv file CSV_.subscriptions({ 'export': True, 'file': org_subs_csv_remote_file_path, 'organization': self.org['name'], }) # download the organization subscriptions org_subs_csv_local_file_path = os.path.join(tempfile.gettempdir(), org_subs_csv_filename) download_file(org_subs_csv_remote_file_path, org_subs_csv_local_file_path) _, org_subscriptions = self._read_csv_file( org_subs_csv_local_file_path) new_subscription = None for sub in org_subscriptions: if sub['Subscription Name'] == SATELLITE_SUBSCRIPTION_NAME: new_subscription = sub break self.assertIsNotNone(new_subscription) # Create an activation key and add the default subscription activation_key = make_activation_key({ 'organization-id': self.org['id'], }) activationkey_add_subscription_to_repo({ 'organization-id': self.org['id'], 'activationkey-id': activation_key['id'], 'subscription': DEFAULT_SUBSCRIPTION_NAME, }) org_subs = Subscription.list({u'organization-id': self.org['id']}) default_subscription_id = None for sub in org_subs: if sub['name'] == DEFAULT_SUBSCRIPTION_NAME: default_subscription_id = sub['id'] break self.assertIsNotNone(default_subscription_id, msg='Default subscription not found') ak_subs = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertEqual(len(ak_subs), 1) self.assertEqual(ak_subs[0]['name'], DEFAULT_SUBSCRIPTION_NAME) # export activation key data to csv file ak_export_file_name = 'ak_{0}_{1}_export.csv'.format( self.org['name'], activation_key['name']) ak_remote_export_file_path = '/tmp/{0}'.format(ak_export_file_name) CSV_.activation_keys({ 'export': True, 'file': ak_remote_export_file_path, 'organization': self.org['name'], }) # download the file to local temp dir ak_local_export_file_path = os.path.join(tempfile.gettempdir(), ak_export_file_name) download_file(ak_remote_export_file_path, local_file=ak_local_export_file_path) # modify the file with new subscription data and upload it field_names, csv_ak_data = self._read_csv_file( ak_local_export_file_path) self.assertEqual(len(csv_ak_data), 1) csv_ak_data = csv_ak_data[0] field_names = csv_ak_data.keys() self.assertIn('Subscriptions', field_names) self.assertIn('Subscriptions', csv_ak_data) # The subscription is saved in the following format: # """<quantity>|<sku>|<name>|<contract>|<account>""" subscription_data = csv_ak_data['Subscriptions'].strip('"').split('|') # change the subscription SKU (looks like RH00001) subscription_data[1] = new_subscription['Subscription SKU'] # change the name subscription_data[2] = new_subscription['Subscription Name'] # change the contract number subscription_data[3] = new_subscription['Subscription Contract'] # change the subscription account subscription_data[4] = new_subscription['Subscription Account'] # modify the subscription data and generate a new csv file csv_ak_data['Subscriptions'] = '"{0}"'.format( '|'.join(subscription_data)) ak_import_file_name = 'ak_{0}_{1}_import.csv'.format( self.org['name'], activation_key['name']) ak_local_import_file_path = os.path.join(tempfile.gettempdir(), ak_import_file_name) self._write_csv_file(ak_local_import_file_path, field_names, [csv_ak_data]) # upload the generated file ak_remote_import_file_path = '/tmp/{0}'.format(ak_import_file_name) upload_file(ak_local_import_file_path, ak_remote_import_file_path) # import the generated csv file CSV_.activation_keys({ 'file': ak_remote_import_file_path, 'organization': self.org['name'], }) ak_subs = ActivationKey.subscriptions( { 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertEqual(len(ak_subs), 1) self.assertEqual(ak_subs[0]['name'], SATELLITE_SUBSCRIPTION_NAME) self.assertEqual(ak_subs[0]['contract'], new_subscription['Subscription Contract']) self.assertEqual(ak_subs[0]['account'], new_subscription['Subscription Account'])
def test_positive_restore_content_hosts_with_modified_subscription(self): """Restore content hosts subscription from an exported content host csv file with modified subscription. :id: d8ac08fe-24e0-41e7-b3d8-0ca13a702a64 :customerscenario: true :steps: 1. Setup activation key , lifecycle environment and content view with RH tools repository 2. Setup hosts (minimum two) and subscribe them to activation key 3. Attach RH subscription to the created content hosts 4. Export the organization content hosts to a csv file 5. Create a new csv file and modify the subscription with an other one (the new subscription must have other data than the default one) 6. Import the new csv file to organization content hosts :expectedresults: content hosts restored with the new subscription :BZ: 1296978 :CaseImportance: Critical """ lce = make_lifecycle_environment({'organization-id': self.org['id']}) activation_key = make_activation_key({ 'organization-id': self.org['id'], 'lifecycle-environment-id': lce['id'], }) ActivationKey.update({ 'organization-id': self.org['id'], 'id': activation_key['id'], 'auto-attach': 'false', }) # Create RH tools repository and contents, this step should upload # the default manifest setup_org_for_a_rh_repo({ 'product': PRDS['rhel'], 'repository-set': REPOSET['rhst7'], 'repository': REPOS['rhst7']['name'], 'organization-id': self.org['id'], 'lifecycle-environment-id': lce['id'], 'activationkey-id': activation_key['id'], }, force_use_cdn=True) # Export and download the organization subscriptions to prepare the new # subscription (The replacement of the default subscription) org_subs_csv_filename = 'subs_{0}.csv'.format(self.org['name']) org_subs_csv_remote_file_path = '/tmp/{0}'.format( org_subs_csv_filename) # export organization subscription to csv file CSV_.subscriptions({ 'export': True, 'file': org_subs_csv_remote_file_path, 'organization': self.org['name'], }) # download the organization subscriptions org_subs_csv_local_file_path = os.path.join( tempfile.gettempdir(), org_subs_csv_filename) download_file( org_subs_csv_remote_file_path, org_subs_csv_local_file_path) _, org_subscriptions = self._read_csv_file( org_subs_csv_local_file_path) new_subscription = None for sub in org_subscriptions: if sub['Subscription Name'] == SATELLITE_SUBSCRIPTION_NAME: new_subscription = sub break self.assertIsNotNone(new_subscription) # retrieve the default subscription id org_subs = Subscription.list({u'organization-id': self.org['id']}) default_subscription_id = None for sub in org_subs: if sub['name'] == DEFAULT_SUBSCRIPTION_NAME: default_subscription_id = sub['id'] break self.assertIsNotNone( default_subscription_id, msg='Default subscription not found') # create 2 Virtual machines with VirtualMachine() as client1, VirtualMachine() as client2: hosts = [] for client in [client1, client2]: client.install_katello_ca() client.register_contenthost( self.org['label'], activation_key=activation_key['name']) self.assertTrue(client.subscribed) host = Host.info({'name': client.hostname}) hosts.append(host) Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': default_subscription_id, }) host_subscriptions = ActivationKey.subscriptions({ 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertEqual(len(host_subscriptions), 1) self.assertEqual( host_subscriptions[0]['name'], DEFAULT_SUBSCRIPTION_NAME) # export the content host data to csv file chs_export_file_name = 'chs_export_{0}.csv'.format( self.org['label']) chs_export_remote_file_path = ( '/tmp/{0}'.format(chs_export_file_name) ) CSV_.content_hosts({ 'export': True, 'file': chs_export_remote_file_path, 'organization': self.org['name'], }) # download the csv file chs_export_local_file_path = os.path.join( tempfile.gettempdir(), chs_export_file_name) download_file( chs_export_remote_file_path, chs_export_local_file_path) # modify the content hosts subscription field_names, csv_data = self._read_csv_file( chs_export_local_file_path) # each client is represented by one row of data self.assertEqual(len(csv_data), 2) for row_data in csv_data: # The subscription is saved in the following format: # """<quantity>|<sku>|<name>|<contract>|<account>""" subscription_data = row_data['Subscriptions'].strip( '"').split('|') # change the subscription SKU (looks like RH00001) subscription_data[1] = new_subscription['Subscription SKU'] # change the name subscription_data[2] = new_subscription['Subscription Name'] # change the contract number subscription_data[3] = new_subscription[ 'Subscription Contract'] # change the subscription account subscription_data[4] = new_subscription[ 'Subscription Account'] # modify the subscription data row_data['Subscriptions'] = '"{0}"'.format( '|'.join(subscription_data)) # generate a new csv file chs_import_file_name = 'chs_import_{0}.csv'.format( self.org['name']) chs_import_local_file_path = os.path.join( tempfile.gettempdir(), chs_import_file_name) self._write_csv_file( chs_import_local_file_path, field_names, csv_data) # upload the file chs_import_remote_file_path = ( '/tmp/{0}'.format(chs_import_file_name) ) upload_file( chs_import_local_file_path, chs_import_remote_file_path) # import content hosts data from csv file CSV_.content_hosts({ 'file': chs_import_remote_file_path, 'organization': self.org['name'], }) for host in hosts: host_subscriptions = ActivationKey.subscriptions({ 'organization-id': self.org['id'], 'id': activation_key['id'], 'host-id': host['id'], }, output_format='json') self.assertEqual(len(host_subscriptions), 1) self.assertEqual( host_subscriptions[0]['name'], SATELLITE_SUBSCRIPTION_NAME) self.assertEqual( host_subscriptions[0]['contract'], new_subscription['Subscription Contract']) self.assertEqual( host_subscriptions[0]['account'], new_subscription['Subscription Account'])
def test_positive_restore_ak_with_modified_subscription(self): """Restore activation key subscription from an exported activation key csv file with modified subscription. :id: 40b86d1c-88f8-451c-bf19-c5bf11223cb6 :steps: 1. Upload a manifest 2. Create an activation key 3. Attach RH subscription to the created activation key 4. Export the organization activation keys to a csv file 5. Create a new csv file and modify the subscription with an other one (the new subscription must have other data than the default one) 6. Import the new csv file to organization activation keys :expectedresults: activation key restored with the new subscription :BZ: 1296978 :CaseImportance: Critical """ # upload the organization default manifest self._upload_manifest(self.org['id']) # Export and download the organization subscriptions to prepare the new # subscription (The replacement of the default subscription) org_subs_csv_filename = 'subs_{0}.csv'.format(self.org['name']) org_subs_csv_remote_file_path = '/tmp/{0}'.format( org_subs_csv_filename) # export organization subscription to csv file CSV_.subscriptions({ 'export': True, 'file': org_subs_csv_remote_file_path, 'organization': self.org['name'], }) # download the organization subscriptions org_subs_csv_local_file_path = os.path.join( tempfile.gettempdir(), org_subs_csv_filename) download_file( org_subs_csv_remote_file_path, org_subs_csv_local_file_path) _, org_subscriptions = self._read_csv_file( org_subs_csv_local_file_path) new_subscription = None for sub in org_subscriptions: if sub['Subscription Name'] == SATELLITE_SUBSCRIPTION_NAME: new_subscription = sub break self.assertIsNotNone(new_subscription) # Create an activation key and add the default subscription activation_key = make_activation_key({ 'organization-id': self.org['id'], }) activationkey_add_subscription_to_repo({ 'organization-id': self.org['id'], 'activationkey-id': activation_key['id'], 'subscription': DEFAULT_SUBSCRIPTION_NAME, }) org_subs = Subscription.list({u'organization-id': self.org['id']}) default_subscription_id = None for sub in org_subs: if sub['name'] == DEFAULT_SUBSCRIPTION_NAME: default_subscription_id = sub['id'] break self.assertIsNotNone( default_subscription_id, msg='Default subscription not found') ak_subs = ActivationKey.subscriptions({ 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertEqual(len(ak_subs), 1) self.assertEqual( ak_subs[0]['name'], DEFAULT_SUBSCRIPTION_NAME) # export activation key data to csv file ak_export_file_name = 'ak_{0}_{1}_export.csv'.format( self.org['name'], activation_key['name']) ak_remote_export_file_path = '/tmp/{0}'.format(ak_export_file_name) CSV_.activation_keys({ 'export': True, 'file': ak_remote_export_file_path, 'organization': self.org['name'], }) # download the file to local temp dir ak_local_export_file_path = os.path.join( tempfile.gettempdir(), ak_export_file_name) download_file( ak_remote_export_file_path, local_file=ak_local_export_file_path) # modify the file with new subscription data and upload it field_names, csv_ak_data = self._read_csv_file( ak_local_export_file_path) self.assertEqual(len(csv_ak_data), 1) csv_ak_data = csv_ak_data[0] field_names = csv_ak_data.keys() self.assertIn('Subscriptions', field_names) self.assertIn('Subscriptions', csv_ak_data) # The subscription is saved in the following format: # """<quantity>|<sku>|<name>|<contract>|<account>""" subscription_data = csv_ak_data['Subscriptions'].strip('"').split('|') # change the subscription SKU (looks like RH00001) subscription_data[1] = new_subscription['Subscription SKU'] # change the name subscription_data[2] = new_subscription['Subscription Name'] # change the contract number subscription_data[3] = new_subscription['Subscription Contract'] # change the subscription account subscription_data[4] = new_subscription['Subscription Account'] # modify the subscription data and generate a new csv file csv_ak_data['Subscriptions'] = '"{0}"'.format( '|'.join(subscription_data)) ak_import_file_name = 'ak_{0}_{1}_import.csv'.format( self.org['name'], activation_key['name']) ak_local_import_file_path = os.path.join( tempfile.gettempdir(), ak_import_file_name) self._write_csv_file( ak_local_import_file_path, field_names, [csv_ak_data]) # upload the generated file ak_remote_import_file_path = '/tmp/{0}'.format(ak_import_file_name) upload_file(ak_local_import_file_path, ak_remote_import_file_path) # import the generated csv file CSV_.activation_keys({ 'file': ak_remote_import_file_path, 'organization': self.org['name'], }) ak_subs = ActivationKey.subscriptions({ 'organization-id': self.org['id'], 'id': activation_key['id'], }, output_format='json') self.assertEqual(len(ak_subs), 1) self.assertEqual( ak_subs[0]['name'], SATELLITE_SUBSCRIPTION_NAME) self.assertEqual( ak_subs[0]['contract'], new_subscription['Subscription Contract']) self.assertEqual( ak_subs[0]['account'], new_subscription['Subscription Account'])