def test_positive_enable_manifest_reposet(self): """enable repository set @Feature: Subscriptions/Repository Sets @Assert: you are able to enable and synchronize repository contained in a manifest """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) RepositorySet.enable({ 'basearch': 'x86_64', 'name': REPOSET['rhva6'], 'organization-id': self.org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', }) Repository.synchronize({ 'name': REPOS['rhva6']['name'], 'organization-id': self.org['id'], 'product': PRDS['rhel'], })
def test_positive_enable_manifest_reposet(self): """enable repository set :id: cc0f8f40-5ea6-4fa7-8154-acdc2cb56b45 :expectedresults: you are able to enable and synchronize repository contained in a manifest :CaseLevel: Integration :CaseImportance: Critical """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) RepositorySet.enable({ 'basearch': 'x86_64', 'name': REPOSET['rhva6'], 'organization-id': self.org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', }) Repository.synchronize({ 'name': REPOS['rhva6']['name'], 'organization-id': self.org['id'], 'product': PRDS['rhel'], })
def test_enable_manifest_reposet(self): """@Test: enable repository set (positive) @Feature: Subscriptions/Repository Sets @Assert: you are able to enable and synchronize repository contained in a manifest """ self._upload_manifest(self.manifest, self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) RepositorySet.enable({ 'basearch': 'x86_64', 'name': ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Workstation (RPMs)' ), 'organization-id': self.org['id'], 'product': 'Red Hat Enterprise Linux Workstation', 'releasever': '6Workstation', }) Repository.synchronize({ 'name': ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Workstation ' 'RPMs x86_64 6Workstation' ), 'organization-id': self.org['id'], 'product': 'Red Hat Enterprise Linux Workstation', })
def test_manifest_delete(self): """@Test: Delete uploaded manifest (positive) @Feature: Subscriptions/Manifest Delete @Assert: Manifest are deleted properly @BZ: 1207501 """ self._upload_manifest(self.manifest, self.org['id']) result = Subscription.list( {'organization-id': self.org['id']}, per_page=False ) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) result = Subscription.delete_manifest({ 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) result = Subscription.list( {'organization-id': self.org['id']}, per_page=False ) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stdout), 0)
def test_positive_manifest_upload(self): """upload manifest @id: e5a0e4f8-fed9-4896-87a0-ac33f6baa227 @Assert: Manifest are uploaded properly """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, )
def test_positive_manifest_upload(self): """upload manifest @Feature: Subscriptions/Manifest Upload @Assert: Manifest are uploaded properly """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, )
def test_positive_manifest_upload(self): """upload manifest :id: e5a0e4f8-fed9-4896-87a0-ac33f6baa227 :expectedresults: Manifest are uploaded properly :CaseImportance: Critical """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, )
def test_manifest_delete(self): """@Test: Delete uploaded manifest (positive) @Feature: Subscriptions/Manifest Delete @Assert: Manifest are deleted properly @BZ: 1207501 """ upload_file(self.manifest, remote_file=self.manifest) result = Subscription.upload({ 'file': self.manifest, 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "Failed to upload manifest") self.assertEqual( len(result.stderr), 0, "There should not be an exception while uploading manifest.") result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) self.assertEqual(result.return_code, 0, "Failed to list manifests in this org.") self.assertEqual( len(result.stderr), 0, "There should not be an exception while listing the manifest.") result = Subscription.delete_manifest({ 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "Failed to delete manifest") self.assertEqual( len(result.stderr), 0, "There should not be an exception while deleting manifest.") result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) self.assertEqual(result.return_code, 0, "Failed to list manifests in this org.") self.assertEqual( len(result.stdout), 0, "There should not be any subscriptions in this org.")
def test_add_subscription(self): """@Test: Test that subscription can be added to activation key @Feature: Activation key - Host @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 """ manifest = manifests.clone() upload_file(manifest, remote_file=manifest) org_id = make_org()['id'] ackey_id = self._make_activation_key()['id'] Subscription.upload({ 'file': manifest, '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_manifest_history(self): """@Test: upload manifest (positive) and check history @Feature: Subscriptions/Manifest History @Assert: Manifest history is shown properly """ self._upload_manifest(self.manifest, self.org['id']) result = Subscription.list( {'organization-id': self.org['id']}, per_page=None ) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) result = Subscription.manifest_history({ 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertIn( '{0} file imported successfully.'.format(self.org['name']), ''.join(result.stdout) )
def test_manifest_refresh(self): """@Test: upload manifest (positive) and refresh @Feature: Subscriptions/Manifest refresh @Assert: Manifests can be refreshed """ self._upload_manifest( manifests.download_manifest_template(), self.org['id']) result = Subscription.list( {'organization-id': self.org['id']}, per_page=False ) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) result = Subscription.refresh_manifest({ 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) result = Subscription.delete_manifest({ 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0)
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_manifest_upload(self): """ @test: upload manifest (positive) @feature: Subscriptions/Manifest Upload @assert: Manifest are uploaded properly """ mdetails = manifest.fetch_manifest() try: upload_file(mdetails['path'], remote_file=mdetails['path']) result = Subscription.upload( {'file': mdetails['path'], 'organization-id': self.org['id']}) self.assertEqual(result.return_code, 0, "Failed to upload manifest") self.assertEqual( len(result.stderr), 0, "There should not be an exception while uploading manifest.") result = Subscription.list({'organization-id': self.org['id']}, per_page=False) self.assertEqual(result.return_code, 0, "Failed to list manifests in this org.") self.assertEqual( len(result.stdout), 8, "There should not be an exception while listing the manifest.") finally: manifest.delete_distributor(ds_uuid=mdetails['uuid'])
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 :BZ: 1463685 :CaseLevel: Integration """ with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) org_id = make_org()['id'] ackey_id = self._make_activation_key({'organization-id': org_id})['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 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_negative_manifest_refresh(self): """manifest refresh must fail with a cloned manifest @Feature: Subscriptions/Manifest refresh @Assert: the refresh command returns a non-zero return code @BZ: 1226425 """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) with self.assertRaises(CLIReturnCodeError): Subscription.refresh_manifest({ 'organization-id': self.org['id'], })
def test_positive_manifest_refresh(self): """upload manifest and refresh @Feature: Subscriptions/Manifest refresh @Assert: Manifests can be refreshed """ self._upload_manifest( self.org['id'], manifests.original_manifest()) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.refresh_manifest({ 'organization-id': self.org['id'], }) Subscription.delete_manifest({ 'organization-id': self.org['id'], })
def test_manifest_refresh(self): """@Test: upload manifest (positive) and refresh @Feature: Subscriptions/Manifest refresh @Assert: Manifests can be refreshed """ self._upload_manifest( manifests.download_manifest_template(), self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.refresh_manifest({ 'organization-id': self.org['id'], }) Subscription.delete_manifest({ 'organization-id': self.org['id'], })
def test_positive_manifest_history(self): """upload manifest and check history @id: 000ab0a0-ec1b-497a-84ff-3969a965b52c @Assert: Manifest history is shown properly """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=None, ) history = Subscription.manifest_history({ 'organization-id': self.org['id'], }) self.assertIn( '{0} file imported successfully.'.format(self.org['name']), ''.join(history), )
def test_positive_manifest_delete(self): """Delete uploaded manifest @Feature: Subscriptions/Manifest Delete @Assert: Manifest are deleted properly """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.delete_manifest({ 'organization-id': self.org['id'], }) Subscription.list( {'organization-id': self.org['id']}, per_page=False, )
def test_positive_manifest_refresh(self): """upload manifest and refresh @id: 579bbbf7-11cf-4d78-a3b1-16d73bd4ca57 @Assert: Manifests can be refreshed """ self._upload_manifest( self.org['id'], manifests.original_manifest()) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.refresh_manifest({ 'organization-id': self.org['id'], }) Subscription.delete_manifest({ 'organization-id': self.org['id'], })
def test_positive_manifest_history(self): """upload manifest and check history @Feature: Subscriptions/Manifest History @Assert: Manifest history is shown properly """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=None, ) history = Subscription.manifest_history({ 'organization-id': self.org['id'], }) self.assertIn( '{0} file imported successfully.'.format(self.org['name']), ''.join(history), )
def test_positive_manifest_delete(self): """Delete uploaded manifest @id: 01539c07-00d5-47e2-95eb-c0fd4f39090f @Assert: Manifest are deleted properly """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.delete_manifest({ 'organization-id': self.org['id'], }) Subscription.list( {'organization-id': self.org['id']}, per_page=False, )
def test_negative_manifest_refresh(self): """manifest refresh must fail with a cloned manifest :id: 7f40795f-7841-4063-8a43-de0325c92b1f :expectedresults: the refresh command returns a non-zero return code :BZ: 1226425 :CaseImportance: Critical """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) with self.assertRaises(CLIReturnCodeError): Subscription.refresh_manifest({ 'organization-id': self.org['id'], })
def test_enable_manifest_repository_set(self): """@Test: enable repository set (positive) @Feature: Subscriptions/Repository Sets @Assert: you are able to enable and synchronize repository contained in a manifest """ upload_file(self.manifest, remote_file=self.manifest) result = Subscription.upload({ 'file': self.manifest, 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "Failed to upload manifest") self.assertEqual( len(result.stderr), 0, "There should not be an exception while uploading manifest.") result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) self.assertEqual( len(result.stderr), 0, "There should not be an exception while listing the manifest.") result = RepositorySet.enable({ 'name': ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Workstation (RPMs)' ), 'organization-id': self.org['id'], 'product': 'Red Hat Enterprise Linux Workstation', 'releasever': '6Workstation', 'basearch': 'x86_64', }) self.assertEqual(result.return_code, 0, "Repo was not enabled") self.assertEqual(len(result.stderr), 0, "No error was expected") result = Repository.synchronize({ 'name': ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Workstation ' 'RPMs x86_64 6Workstation' ), 'organization-id': self.org['id'], 'product': 'Red Hat Enterprise Linux Workstation', }) self.assertEqual(result.return_code, 0, "Repo was not synchronized") self.assertEqual(len(result.stderr), 0, "No error was expected")
def test_positive_manifest_refresh(self): """upload manifest and refresh :id: 579bbbf7-11cf-4d78-a3b1-16d73bd4ca57 :expectedresults: Manifests can be refreshed :CaseImportance: Critical """ self._upload_manifest( self.org['id'], manifests.original_manifest()) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.refresh_manifest({ 'organization-id': self.org['id'], }) Subscription.delete_manifest({ 'organization-id': self.org['id'], })
def test_positive_manifest_history(self): """upload manifest and check history :id: 000ab0a0-ec1b-497a-84ff-3969a965b52c :expectedresults: Manifest history is shown properly :CaseImportance: Medium """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=None, ) history = Subscription.manifest_history({ 'organization-id': self.org['id'], }) self.assertIn( '{0} file imported successfully.'.format(self.org['name']), ''.join(history), )
def test_positive_manifest_delete(self): """Delete uploaded manifest :id: 01539c07-00d5-47e2-95eb-c0fd4f39090f :expectedresults: Manifest are deleted properly :CaseImportance: Critical """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.delete_manifest({ 'organization-id': self.org['id'], }) Subscription.list( {'organization-id': self.org['id']}, per_page=False, )
def test_positive_deploy_configure_by_script(self, default_org, form_data, virtwho_config): """Verify " hammer virt-who-config fetch" :id: 6aaffaeb-aaf2-42cf-b0dc-ca41a53d42a6 :expectedresults: Config can be created, fetch and deploy :CaseLevel: Integration :CaseImportance: High """ assert virtwho_config['status'] == 'No Report Yet' script = VirtWhoConfig.fetch({'id': virtwho_config['id']}, output_format='base') hypervisor_name, guest_name = deploy_configure_by_script( script, form_data['hypervisor-type'], debug=True, org=default_org.label) virt_who_instance = VirtWhoConfig.info( {'id': virtwho_config['id']})['general-information']['status'] assert virt_who_instance == 'OK' hosts = [ ( hypervisor_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL', ), ( guest_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED', ), ] for hostname, sku in hosts: host = Host.list({'search': hostname})[0] subscriptions = Subscription.list({ 'organization': default_org.name, 'search': sku }) vdc_id = subscriptions[0]['id'] if 'type=STACK_DERIVED' in sku: for item in subscriptions: if hypervisor_name.lower() in item['type']: vdc_id = item['id'] break result = Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': vdc_id }) assert result.strip( ) == 'Subscription attached to the host successfully.' VirtWhoConfig.delete({'name': virtwho_config['name']}) assert not VirtWhoConfig.exists(search=('name', form_data['name']))
def test_positive_manifest_delete(self): """Delete uploaded manifest :id: 01539c07-00d5-47e2-95eb-c0fd4f39090f :expectedresults: Manifest are deleted properly :CaseImportance: Critical """ self._upload_manifest(self.org['id']) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.delete_manifest({ 'organization-id': self.org['id'], }) Subscription.list( {'organization-id': self.org['id']}, per_page=False, )
def test_enable_manifest_repository_set(self): """@Test: enable repository set (positive) @Feature: Subscriptions/Repository Sets @Assert: you are able to enable and synchronize repository contained in a manifest """ upload_file(self.manifest, remote_file=self.manifest) result = Subscription.upload({ 'file': self.manifest, 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "Failed to upload manifest") self.assertEqual( len(result.stderr), 0, "There should not be an exception while uploading manifest.") result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) self.assertEqual( len(result.stderr), 0, "There should not be an exception while listing the manifest.") result = RepositorySet.enable({ 'name': ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Workstation (RPMs)' ), 'organization-id': self.org['id'], 'product': 'Red Hat Enterprise Linux Workstation', 'releasever': '6Workstation', 'basearch': 'x86_64', }) self.assertEqual(result.return_code, 0, "Repo was not enabled") self.assertEqual(len(result.stderr), 0, "No error was expected") result = Repository.synchronize({ 'name': ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Workstation ' 'RPMs x86_64 6Workstation' ), 'organization-id': self.org['id'], 'product': 'Red Hat Enterprise Linux Workstation', }) self.assertEqual(result.return_code, 0, "Repo was not synchronized") self.assertEqual(len(result.stderr), 0, "No error was expected")
def test_positive_manifest_refresh(self): """upload manifest and refresh :id: 579bbbf7-11cf-4d78-a3b1-16d73bd4ca57 :expectedresults: Manifests can be refreshed :CaseImportance: Critical """ self._upload_manifest( self.org['id'], manifests.original_manifest()) Subscription.list( {'organization-id': self.org['id']}, per_page=False, ) Subscription.refresh_manifest({ 'organization-id': self.org['id'], }) Subscription.delete_manifest({ 'organization-id': self.org['id'], })
def _get_subscription_id(self): """Get subscription id""" try: result = Subscription.list({'organization-id': self.org_id}, per_page=False) except CLIReturnCodeError: self.logger.error('Fail to get subscription id!') raise RuntimeError('Invalid subscription id. Stop!') subscription_id = result[0]['id'] subscription_name = result[0]['name'] self.logger.info('Subscribed to {0} with subscription id {1}'.format( subscription_name, subscription_id)) return subscription_id, subscription_name
def test_positive_deploy_configure_by_id(self, form_data, virtwho_config): """Verify "POST /foreman_virt_who_configure/api/v2/configs" :id: 72d74c05-2580-4f38-b6c0-999ff470d4d6 :expectedresults: Config can be created and deployed :CaseLevel: Integration :CaseImportance: High """ assert virtwho_config.status == 'unknown' command = get_configure_command(virtwho_config.id) hypervisor_name, guest_name = deploy_configure_by_command( command, form_data['hypervisor_type'], debug=True) virt_who_instance = (entities.VirtWhoConfig().search( query={'search': f'name={virtwho_config.name}'})[0].status) assert virt_who_instance == 'ok' hosts = [ ( hypervisor_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL', ), ( guest_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED', ), ] for hostname, sku in hosts: host = Host.list({'search': hostname})[0] subscriptions = Subscription.list({ 'organization': DEFAULT_ORG, 'search': sku }) vdc_id = subscriptions[0]['id'] if 'type=STACK_DERIVED' in sku: for item in subscriptions: if hypervisor_name.lower() in item['type']: vdc_id = item['id'] break entities.HostSubscription(host=host['id']).add_subscriptions( data={'subscriptions': [{ 'id': vdc_id, 'quantity': 1 }]}) result = entities.Host().search( query={'search': hostname})[0].read_json() assert result['subscription_status_label'] == 'Fully entitled' virtwho_config.delete() assert not entities.VirtWhoConfig().search( query={'search': f"name={form_data['name']}"})
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_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_manifest_upload(self): """@Test: upload manifest (positive) @Feature: Subscriptions/Manifest Upload @Assert: Manifest are uploaded properly """ self._upload_manifest(self.manifest, self.org['id']) result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0)
def test_positive_subscription_list(function_org, manifest_clone_upload): """Verify that subscription list contains start and end date :id: 4861bcbc-785a-436d-98ce-14cfef7d6907 :expectedresults: subscription list contains the start and end date :BZ: 1686916 :CaseImportance: Medium """ subscription_list = Subscription.list({'organization-id': function_org.id}, per_page=False) for column in ['start-date', 'end-date']: assert column in subscription_list[0].keys()
def test_positive_deploy_configure_by_id(self, default_org, form_data, virtwho_config): """Verify " hammer virt-who-config deploy" :id: e66bf88a-bd4e-409a-91a8-bc5e005d95dd :expectedresults: Config can be created and deployed :CaseLevel: Integration :CaseImportance: High """ assert virtwho_config['status'] == 'No Report Yet' command = get_configure_command(virtwho_config['id'], default_org.name) hypervisor_name, guest_name = deploy_configure_by_command( command, form_data['hypervisor-type'], debug=True, org=default_org.label) virt_who_instance = VirtWhoConfig.info( {'id': virtwho_config['id']})['general-information']['status'] assert virt_who_instance == 'OK' hosts = [ (hypervisor_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL' ), (guest_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED' ), ] for hostname, sku in hosts: host = Host.list({'search': hostname})[0] subscriptions = Subscription.list({ 'organization': default_org.name, 'search': sku }) vdc_id = subscriptions[0]['id'] if 'type=STACK_DERIVED' in sku: for item in subscriptions: if hypervisor_name.lower() in item['type']: vdc_id = item['id'] break result = Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': vdc_id }) assert result.strip( ) == 'Subscription attached to the host successfully.' VirtWhoConfig.delete({'name': virtwho_config['name']}) assert not VirtWhoConfig.exists(search=('name', form_data['name']))
def test_positive_deploy_configure_by_id(self): """ Verify " hammer virt-who-config deploy" :id: 19ffe76e-7e3d-48c7-b846-10a83afe0f3e :expectedresults: Config can be created and deployed :CaseLevel: Integration :CaseImportance: High """ name = gen_string('alpha') args = self._make_virtwho_configure() args.update({'name': name}) vhd = VirtWhoConfig.create(args)['general-information'] self.assertEqual(vhd['status'], 'No Report Yet') command = get_configure_command(vhd['id']) hypervisor_name, guest_name = deploy_configure_by_command(command, debug=True) self.assertEqual( VirtWhoConfig.info({'id': vhd['id']})['general-information']['status'], 'OK') hosts = [ (hypervisor_name, 'product_id={} and type=NORMAL'.format(self.vdc_physical)), (guest_name, 'product_id={} and type=STACK_DERIVED'.format(self.vdc_physical)) ] for hostname, sku in hosts: host = Host.list({'search': hostname})[0] subscriptions = Subscription.list({ 'organization': DEFAULT_ORG, 'search': sku, }) vdc_id = subscriptions[0]['id'] if 'type=STACK_DERIVED' in sku: for item in subscriptions: if hypervisor_name.lower() in item['type']: vdc_id = item['id'] break result = Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': vdc_id }) self.assertTrue( 'attached to the host successfully' in '\n'.join(result)) VirtWhoConfig.delete({'name': name}) self.assertFalse(VirtWhoConfig.exists(search=('name', name)))
def _get_subscription_id(self): result = Subscription.list({'organization-id': self.org_id}, per_page=False) if result.return_code != 0: self.logger.error('Fail to list subscriptions!') raise RuntimeError('Invalid subscription id. Stop!') if not result.stdout: self.logger.error('Fail to get subscription id!') raise RuntimeError('Manifest has no subscription!') subscription_id = result.stdout[0]['id'] subscription_name = result.stdout[0]['name'] self.logger.info('Subscribe to {0} with subscription id: {1}'.format( subscription_name, subscription_id)) return (subscription_id, subscription_name)
def test_positive_subscription_list(self): """Verify that subscription list contains start and end date :id: 4861bcbc-785a-436d-98ce-14cfef7d6907 :expectedresults: subscription list contains the start and end date :BZ: 1686916 :CaseImportance: Medium """ self._upload_manifest(self.org['id']) subscription_list = Subscription.list({'organization-id': self.org['id']}, per_page=False) for column in ['start-date', 'end-date']: self.assertIn(column, subscription_list[0].keys())
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_positive_delete_manifest_as_another_user(function_org, default_sat): """Verify that uploaded manifest if visible and deletable by a different user than the one who uploaded it :id: 4861bdbc-785a-436d-98cf-13cfef7d6907 :expectedresults: manifest is refreshed :customerscenario: true :BZ: 1669241 :CaseImportance: Medium """ user1_password = gen_string('alphanumeric') user1 = default_sat.api.User( admin=True, password=user1_password, organization=[function_org], default_organization=function_org, ).create() sc1 = ServerConfig( auth=(user1.login, user1_password), url=default_sat.url, verify=False, ) user2_password = gen_string('alphanumeric') user2 = default_sat.api.User( admin=True, password=user2_password, organization=[function_org], default_organization=function_org, ).create() sc2 = ServerConfig( auth=(user2.login, user2_password), url=default_sat.url, verify=False, ) # use the first admin to upload a manifest with manifests.clone() as manifest: entities.Subscription(sc1, organization=function_org).upload( data={'organization_id': function_org.id}, files={'content': manifest.content} ) # try to search and delete the manifest with another admin entities.Subscription(sc2, organization=function_org).delete_manifest( data={'organization_id': function_org.id} ) assert len(Subscription.list({'organization-id': function_org.id})) == 0
def _get_subscription_id(self): """Utility function to get subscription id after uploading manifest""" try: result = Subscription.list({'organization-id': self.org_id}, per_page=False) except CLIReturnCodeError: self.logger.error('Fail to list subscriptions!') raise RuntimeError('Invalid subscription id. Stop!') if not result: self.logger.error('Fail to get subscription id!') raise RuntimeError('Manifest has no subscription!') subscription_id = result[0]['id'] subscription_name = result[0]['name'] self.logger.info('Subscribe to {0} with subscription id: {1}'.format( subscription_name, subscription_id)) return (subscription_id, subscription_name)
def test_positive_deploy_configure_by_script(self, form_data, virtwho_config): """Verify " hammer virt-who-config fetch" :id: 4c7c3159-8bd3-4fe8-a330-2211bfbcfa11 :expectedresults: Config can be created, fetch and deploy :CaseLevel: Integration :CaseImportance: High """ assert virtwho_config['status'] == 'No Report Yet' script = VirtWhoConfig.fetch({'id': virtwho_config['id']}, output_format='base') hypervisor_name, guest_name = deploy_configure_by_script( script, form_data['hypervisor-type'], debug=True) virt_who_instance = VirtWhoConfig.info( {'id': virtwho_config['id']})['general-information']['status'] assert virt_who_instance == 'OK' hosts = [ (hypervisor_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL' ), (guest_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED' ), ] for hostname, sku in hosts: host = Host.list({'search': hostname})[0] subscriptions = Subscription.list({ 'organization': DEFAULT_ORG, 'search': sku }) vdc_id = subscriptions[0]['id'] if 'type=STACK_DERIVED' in sku: for item in subscriptions: if hypervisor_name.lower() in item['type']: vdc_id = item['id'] break result = Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': vdc_id }) assert 'attached to the host successfully' in '\n'.join(result) VirtWhoConfig.delete({'name': virtwho_config['name']}) assert not VirtWhoConfig.exists(search=('name', form_data['name']))
def test_positive_deploy_configure_by_id(self, form_data, virtwho_config): """ Verify " hammer virt-who-config deploy" :id: 1885dd56-e3f9-43a7-af27-e496967b6256 :expectedresults: Config can be created and deployed :CaseLevel: Integration :CaseImportance: High """ assert virtwho_config['status'] == 'No Report Yet' command = get_configure_command(virtwho_config['id']) hypervisor_name, guest_name = deploy_configure_by_command( command, form_data['hypervisor-type'], debug=True) virt_who_instance = VirtWhoConfig.info( {'id': virtwho_config['id']})['general-information']['status'] assert virt_who_instance == 'OK' hosts = [ ( hypervisor_name, f'product_id={virtwho.sku.vdc_physical} and type=NORMAL', ), ( guest_name, f'product_id={virtwho.sku.vdc_physical} and type=STACK_DERIVED', ), ] for hostname, sku in hosts: host = Host.list({'search': hostname})[0] subscriptions = Subscription.list({ 'organization': DEFAULT_ORG, 'search': sku }) vdc_id = subscriptions[0]['id'] if 'type=STACK_DERIVED' in sku: for item in subscriptions: if hypervisor_name.lower() in item['type']: vdc_id = item['id'] break result = Host.subscription_attach({ 'host-id': host['id'], 'subscription-id': vdc_id }) assert 'attached to the host successfully' in '\n'.join(result) VirtWhoConfig.delete({'name': virtwho_config['name']}) assert not VirtWhoConfig.exists(search=('name', form_data['name']))
def test_positive_delete_manifest_as_another_user(self): """Verify that uploaded manifest if visible and deletable by a different user than the one who uploaded it :id: 4861bdbc-785a-436d-98cf-13cfef7d6907 :expectedresults: manifest is refreshed :BZ: 1669241 :CaseImportance: Medium """ org = entities.Organization().create() user1_password = gen_string('alphanumeric') user1 = entities.User(admin=True, password=user1_password, organization=[org], default_organization=org).create() sc1 = ServerConfig( auth=(user1.login, user1_password), url='https://{}'.format(settings.server.hostname), verify=False, ) user2_password = gen_string('alphanumeric') user2 = entities.User(admin=True, password=user2_password, organization=[org], default_organization=org).create() sc2 = ServerConfig( auth=(user2.login, user2_password), url='https://{}'.format(settings.server.hostname), verify=False, ) # use the first admin to upload a manifest with manifests.clone() as manifest: entities.Subscription(sc1, organization=org).upload( data={'organization_id': org.id}, files={'content': manifest.content}) # try to search and delete the manifest with another admin entities.Subscription( sc2, organization=org).delete_manifest(data={'organization_id': org.id}) self.assertEquals(0, len(Subscription.list({'organization-id': org.id})))
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_manifest_history(self): """@Test: upload manifest (positive) and check history @Feature: Subscriptions/Manifest History @Assert: Manifest history is shown properly """ upload_file(self.manifest, remote_file=self.manifest) result = Subscription.upload({ 'file': self.manifest, 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "return code must be 0, instead got {0}" ''.format(result.return_code)) self.assertEqual( len(result.stderr), 0, "There should not be an exception while uploading manifest.") result = Subscription.list( {'organization-id': self.org['id']}, per_page=None) self.assertEqual(result.return_code, 0, "return code must be 0, instead got {0}" ''.format(result.return_code)) self.assertEqual( len(result.stderr), 0, "There should not be an exception while listing the manifest.") self.assertGreater(len(result.stdout), 0) result = Subscription.manifest_history({ 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "return code must be 0, instead got {0}" ''.format(result.return_code)) self.assertEqual( len(result.stderr), 0, "There should not be an exception for manifest history.") self.assertIn('{0} file imported successfully.' ''.format(self.org['name']), ''.join(result.stdout))
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_manifest_refresh(self): """@Test: upload manifest (positive) and refresh @Feature: Subscriptions/Manifest refresh @Assert: Manifests can be refreshed """ upload_file(self.manifest, remote_file=self.manifest) result = Subscription.upload({ 'file': self.manifest, 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "return code must be 0, instead got {0}" ''.format(result.return_code)) self.assertEqual( len(result.stderr), 0, "There should not be an exception while uploading manifest.") result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) self.assertEqual(result.return_code, 0, "return code must be 0, instead got {0}" ''.format(result.return_code)) self.assertEqual( len(result.stderr), 0, "There should not be an exception while listing the manifest.") self.assertGreater(len(result.stdout), 0) result = Subscription.refresh_manifest({ 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0, "return code must be 0, instead got {0}" ''.format(result.return_code)) self.assertEqual( len(result.stderr), 0, "There should not be an exception while refreshing the manifest .")
def test_positive_delete_manifest_as_another_user(): """Verify that uploaded manifest if visible and deletable by a different user than the one who uploaded it :id: 4861bcbc-785a-436d-98cf-13cfef7d6907 :expectedresults: manifest is refreshed :customerscenario: true :BZ: 1669241 :CaseImportance: Medium """ org = entities.Organization().create() user1_password = gen_string('alphanumeric') user1 = entities.User(admin=True, password=user1_password, organization=[org], default_organization=org).create() user2_password = gen_string('alphanumeric') user2 = entities.User(admin=True, password=user2_password, organization=[org], default_organization=org).create() # use the first admin to upload a manifest with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.with_user(username=user1.login, password=user1_password).upload({ 'file': manifest.filename, 'organization-id': org.id }) # try to search and delete the manifest with another admin Subscription.with_user(username=user2.login, password=user2_password).delete_manifest( {'organization-id': org.id}) assert len(Subscription.list({'organization-id': org.id})) == 0
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_delete_subscription(self): """Check if deleting a subscription removes it from Activation key @Feature: Activation key - Subscription @Assert: Deleting subscription removes it from the Activation key """ 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)
print r.stdout[0] ssh.command('rm test_manifest.zip') ssh.upload_file('/home/chozhang/Documents/satellite6/20150526-10k-RHEL-Manifest.zip','test_manifest.zip') start = time.time() result = Subscription.upload({ 'file':'./test_manifest.zip', 'organization-id':'1' }) if result.return_code != 0: print "Failed to upload manifest: {0} and return code: {1}" \ .format(result.stderr, result.return_code) else: # print subscription list result = Subscription.list({'organization-id':'1'}, per_page=False) if result.return_code == 0: print "Subscription name: ",result.stdout[0]['name'] print "Subscription id: ",result.stdout[0]['id'] print "Upload successful!" else: print "Failed to list subscriptions: {0} and return code: {1}".format(result.stderr, result.return_code) end = time.time() print 'real',' ',end-start,'s' from robottelo.cli.org import Org # update organization id Org.update({'id':'1', 'redhat-repository-url':'http://172.16.20.12/pub'}) result = Org.info({'id':'1'})
def virt_who_hypervisor_config( self, config_id, org_id=None, lce_id=None, hypervisor_hostname=None, configure_ssh=False, hypervisor_user=None, subscription_name=None, exec_one_shot=False, upload_manifest=True, extra_repos=None, ): """ Configure virtual machine as hypervisor virt-who service :param int config_id: virt-who config id :param int org_id: the organization id :param int lce_id: the lifecycle environment id to use :param str hypervisor_hostname: the hypervisor hostname :param str hypervisor_user: hypervisor user that connect with the ssh key :param bool configure_ssh: configure the ssh key to allow host to connect to hypervisor :param str subscription_name: the subscription name to assign to virt-who hypervisor guests :param bool exec_one_shot: whether to run the virt-who one-shot command after startup :param bool upload_manifest: whether to upload the organization manifest :param list extra_repos: (Optional) repositories dict options to setup additionally. """ from robottelo.cli.org import Org from robottelo.cli import factory as cli_factory from robottelo.cli.lifecycleenvironment import LifecycleEnvironment from robottelo.cli.subscription import Subscription from robottelo.cli.virt_who_config import VirtWhoConfig org = cli_factory.make_org() if org_id is None else Org.info( {'id': org_id}) if lce_id is None: lce = cli_factory.make_lifecycle_environment( {'organization-id': org['id']}) else: lce = LifecycleEnvironment.info({ 'id': lce_id, 'organization-id': org['id'] }) extra_repos = extra_repos or [] repos = [ # Red Hat Satellite Tools { 'product': constants.PRDS['rhel'], 'repository-set': constants.REPOSET['rhst7'], 'repository': constants.REPOS['rhst7']['name'], 'repository-id': constants.REPOS['rhst7']['id'], 'url': settings.sattools_repo['rhel7'], 'cdn': bool(settings.cdn or not settings.sattools_repo['rhel7']), } ] repos.extend(extra_repos) content_setup_data = cli_factory.setup_cdn_and_custom_repos_content( org['id'], lce['id'], repos, upload_manifest=upload_manifest, rh_subscriptions=[constants.DEFAULT_SUBSCRIPTION_NAME], ) activation_key = content_setup_data['activation_key'] content_view = content_setup_data['content_view'] self.contenthost_setup( org_label=org['label'], activation_key=activation_key['name'], patch_os_release_distro=constants.DISTRO_RHEL7, rh_repo_ids=[ repo['repository-id'] for repo in repos if repo['cdn'] ], install_katello_agent=False, ) # configure manually RHEL custom repo url as sync time is very big # (more than 2 hours for RHEL 7Server) and not critical in this context. rhel_repo_option_name = ( f'rhel{constants.DISTROS_MAJOR_VERSION[constants.DISTRO_RHEL7]}_repo' ) rhel_repo_url = getattr(settings.repos, rhel_repo_option_name, None) if not rhel_repo_url: raise ValueError( f'Settings option "{rhel_repo_option_name}" is whether not set or does not exist' ) self.configure_rhel_repo(rhel_repo_url) if hypervisor_hostname and configure_ssh: # configure ssh access of hypervisor from self hypervisor_ssh_key_name = f'hypervisor-{gen_alpha().lower()}.key' # upload the ssh key self.put_ssh_key(settings.server.ssh_key, hypervisor_ssh_key_name) # setup the ssh config and known_hosts files self.update_known_hosts(self, hypervisor_ssh_key_name, hypervisor_hostname, user=hypervisor_user) # upload the virt-who config deployment script virt_who_deploy_directory = '/root/virt_who_deploy_output' virt_who_deploy_filename = f'{gen_alpha(length=5)}-virt-who-deploy-{config_id}' virt_who_deploy_file = f'{virt_who_deploy_directory}/{virt_who_deploy_filename}' VirtWhoConfig.fetch({'id': config_id, 'output': virt_who_deploy_file}) # remote_copy from satellite to self satellite = Satellite(settings.server.hostname) satellite.session.remote_copy(virt_who_deploy_file, self) # ensure the virt-who config deploy script is executable result = self.run(f'chmod +x {virt_who_deploy_file}') if result.status != 0: raise CLIFactoryError( f'Failed to set deployment script as executable:\n{result.stderr}' ) # execute the deployment script result = self.run(f'{virt_who_deploy_file}') if result.status != 0: raise CLIFactoryError( f'Deployment script failure:\n{result.stderr}') # after this step, we should have virt-who service installed and started if exec_one_shot: # usually to be sure that the virt-who generated the report we need # to force a one shot report, for this we have to stop the virt-who # service result = self.run('service virt-who stop') if result.status != 0: raise CLIFactoryError( f'Failed to stop the virt-who service:\n{result.stderr}') result = self.run('virt-who --one-shot', timeout=900) if result.status != 0: raise CLIFactoryError( f'Failed when executing virt-who --one-shot:\n{result.stderr}' ) result = self.run('service virt-who start') if result.status != 0: raise CLIFactoryError( f'Failed to start the virt-who service:\n{result.stderr}') # after this step the hypervisor as a content host should be created # do not confuse virt-who host with hypervisor host as they can be # diffrent hosts and as per this setup we have only registered the virt-who # host, the hypervisor host should registered after virt-who send the # first report when started or with one shot command # the virt-who hypervisor will be registered to satellite with host name # like "virt-who-{hypervisor_hostname}-{organization_id}" virt_who_hypervisor_hostname = f'virt-who-{hypervisor_hostname}-{org["id"]}' # find the registered virt-who hypervisor host org_hosts = Host.list({ 'organization-id': org['id'], 'search': f'name={virt_who_hypervisor_hostname}' }) # Note: if one shot command was executed the report is immediately # generated, and the server must have already registered the virt-who # hypervisor host if not org_hosts and not exec_one_shot: # we have to wait until the first report was sent. # the report is generated after the virt-who service startup, but some # small delay can occur. max_time = time.time() + 60 while time.time() <= max_time: time.sleep(5) org_hosts = Host.list({ 'organization-id': org['id'], 'search': f'name={virt_who_hypervisor_hostname}', }) if org_hosts: break if len(org_hosts) == 0: raise CLIFactoryError( f'Failed to find hypervisor host:\n{result.stderr}') virt_who_hypervisor_host = org_hosts[0] subscription_id = None if hypervisor_hostname and subscription_name: subscriptions = Subscription.list({'organization-id': org_id}, per_page=False) for subscription in subscriptions: if subscription['name'] == subscription_name: subscription_id = subscription['id'] Host.subscription_attach({ 'host': virt_who_hypervisor_hostname, 'subscription-id': subscription_id }) break return { 'subscription_id': subscription_id, 'subscription_name': subscription_name, 'activation_key_id': activation_key['id'], 'organization_id': org['id'], 'content_view_id': content_view['id'], 'lifecycle_environment_id': lce['id'], 'virt_who_hypervisor_host': virt_who_hypervisor_host, }
def organization_has_manifest(organization_id): """Check if an organization has a manifest, an organization has manifest if one of it's subscriptions have the account defined. """ subscriptions = Subscription.list({'organization-id': organization_id}, per_page=False) return any(bool(sub['account']) for sub in subscriptions)
def test_pre_create_virt_who_configuration(self, form_data): """Create and deploy virt-who configuration. :id: preupgrade-a36cbe89-47a2-422f-9881-0f86bea0e24e :steps: In Preupgrade Satellite, Create and deploy virt-who configuration. :expectedresults: 1. Config can be created and deployed by command. 2. No error msg in /var/log/rhsm/rhsm.log. 3. Report is sent to satellite. 4. Virtual sku can be generated and attached. """ default_loc_id = entities.Location().search( query={'search': f'name="{DEFAULT_LOC}"'})[0].id default_loc = entities.Location(id=default_loc_id).read() org = entities.Organization(name=ORG_DATA['name']).create() default_loc.organization.append(entities.Organization(id=org.id)) default_loc.update(['organization']) with manifests.clone() as manifest: upload_manifest(org.id, manifest.content) form_data.update({'organization_id': org.id}) vhd = entities.VirtWhoConfig(**form_data).create() assert vhd.status == 'unknown' command = get_configure_command(vhd.id, org=org.name) hypervisor_name, guest_name = deploy_configure_by_command( command, form_data['hypervisor_type'], debug=True, org=org.label) virt_who_instance = (entities.VirtWhoConfig( organization_id=org.id).search( query={'search': f'name={form_data["name"]}'})[0].status) assert virt_who_instance == 'ok' hosts = [ (hypervisor_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL' ), (guest_name, f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED' ), ] for hostname, sku in hosts: host = Host.list({'search': hostname})[0] subscriptions = Subscription.list({ 'organization-id': org.id, 'search': sku }) vdc_id = subscriptions[0]['id'] if 'type=STACK_DERIVED' in sku: for item in subscriptions: if hypervisor_name.lower() in item['type']: vdc_id = item['id'] break entities.HostSubscription(host=host['id']).add_subscriptions( data={'subscriptions': [{ 'id': vdc_id, 'quantity': 1 }]}) result = (entities.Host(organization=org.id).search( query={'search': hostname})[0].read_json()) assert result['subscription_status_label'] == 'Fully entitled' scenario_dict = { self.__class__.__name__: { 'hypervisor_name': hypervisor_name, 'guest_name': guest_name, } } create_dict(scenario_dict)