def test_positive_add_subscription_by_id(self): """Test that subscription can be added to activation key @Feature: Activation key - Subscription @Steps: 1. Create Activation key 2. Upload manifest and add subscription 3. Associate the activation key to subscription @Assert: Subscription successfully added to activation key """ with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) org_id = make_org()['id'] ackey_id = self._make_activation_key()['id'] Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }) subs_id = Subscription.list( {'organization-id': org_id}, per_page=False ) result = ActivationKey.add_subscription({ u'id': ackey_id, u'subscription-id': subs_id[0]['id'], }) self.assertIn('Subscription added to activation key', result)
def test_positive_add_subscription_by_id(self): """Test that subscription can be added to activation key :id: b884be1c-b35d-440a-9a9d-c854c83e10a7 :Steps: 1. Create Activation key 2. Upload manifest and add subscription 3. Associate the activation key to subscription :expectedresults: Subscription successfully added to activation key :CaseLevel: Integration """ with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) org_id = make_org()['id'] ackey_id = self._make_activation_key()['id'] Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }) subs_id = Subscription.list( {'organization-id': org_id}, per_page=False ) result = ActivationKey.add_subscription({ u'id': ackey_id, u'subscription-id': subs_id[0]['id'], }) self.assertIn('Subscription added to activation key', result)
def test_positive_enable_by_name(self): """Enable repo from reposet by names of reposet, org and product @Feature: Repository-set @Assert: Repository was enabled """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
def test_repositoryset_enable_by_label(self): """@Test: Enable repo from reposet by org label, reposet and product names @Feature: Repository-set @Assert: Repository was enabled """ org = make_org() manifest = manifests.clone() upload_file(manifest, remote_file=manifest) Subscription.upload({ u'file': manifest, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
def test_positive_export_rh_product(self): """Export a repository from the Red Hat product @Feature: Repository - Export @Assert: Repository was successfully exported, rpm files are present on satellite machine """ # Enable RH repository with manifests.clone() as manifest: ssh.upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': self.org['id'], }) RepositorySet.enable({ 'basearch': 'x86_64', 'name': REPOSET['rhva6'], 'organization-id': self.org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'organization-id': self.org['id'], 'product': PRDS['rhel'], }) repo_export_dir = ( '/mnt/{0}/{1}-{2}-{3}/{1}/{4}/content/dist/rhel/server/6/6Server/' 'x86_64/rhev-agent/3/os'.format( self.export_dir, self.org['label'], PRDS['rhel'].replace(' ', '_'), repo['label'], ENVIRONMENT, )) # Update the download policy to 'immediate' Repository.update({ 'download-policy': 'immediate', 'id': repo['id'], }) # Export the repository Repository.export({'id': repo['id']}) # Verify export directory is empty result = ssh.command('ls -l {0} | grep .rpm'.format(repo_export_dir)) self.assertEqual(len(result.stdout), 0) # Synchronize the repository Repository.synchronize({'id': repo['id']}) # Export the repository once again Repository.export({'id': repo['id']}) # Verify RPMs were successfully exported result = ssh.command('ls -l {0} | grep .rpm'.format(repo_export_dir)) self.assertEqual(result.return_code, 0) self.assertGreaterEqual(len(result.stdout), 1)
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_enable_by_name(self): """Enable repo from reposet by names of reposet, org and product @id: a78537bd-b88d-4f00-8901-e7944e5de729 @Assert: Repository was enabled """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
def test_positive_enable_by_label(self): """Enable repo from reposet by org label, reposet and product names @id: 5230c1cd-fed7-40ac-8445-bac4f9c5ee68 @Assert: Repository was enabled """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
def test_positive_synchronize_rh_product_future_sync_date(self): """Create a sync plan with sync date in a future and sync one RH product with it automatically. :id: 6ce2f777-f230-4bb8-9822-2cf3580c21aa :expectedresults: Product is synchronized successfully. :CaseLevel: System """ delay = 10 * 60 # delay for sync date in seconds org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'organization-id': org['id'], 'sync-date': (datetime.utcnow() + timedelta(seconds=delay)).strftime("%Y-%m-%d %H:%M:%S"), }) RepositorySet.enable({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', 'basearch': 'x86_64', }) product = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'], }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'product': product['name'], 'organization-id': org['id'], }) # Verify product is not synced and doesn't have any content self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time sleep(delay / 2) # Verify product has not been synced yet self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(delay / 2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
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 _upload_manifest(self, manifest, org_id): """Uploads a manifest file and import it into an organization""" upload_file(manifest, remote_file=manifest) Subscription.upload({ 'file': manifest, 'organization-id': org_id, })
def test_positive_enable_by_label(self): """Enable repo from reposet by org label, reposet and product names @id: 5230c1cd-fed7-40ac-8445-bac4f9c5ee68 @Assert: Repository was enabled """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
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_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_positive_enable_by_name(self): """Enable repo from reposet by names of reposet, org and product :id: a78537bd-b88d-4f00-8901-e7944e5de729 :expectedresults: Repository was enabled :CaseImportance: Critical """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
def test_positive_synchronize_rh_product_past_sync_date(self): """Create a sync plan with past datetime as a sync date, add a RH product and verify the product gets synchronized on the next sync occurrence :id: 47280ef4-3936-4dbc-8ed0-1076aa8d40df :expectedresults: Product is synchronized successfully. :BZ: 1279539 :CaseLevel: System """ interval = 60 * 60 # 'hourly' sync interval in seconds delay = 80 org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': org['id'], 'sync-date': ( datetime.utcnow() - timedelta(interval - delay/2) ).strftime("%Y-%m-%d %H:%M:%S"), }) RepositorySet.enable({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', 'basearch': 'x86_64', }) product = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'], }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'product': product['name'], 'organization-id': org['id'], }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Verify product has not been synced yet sleep(delay/4) self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(delay) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
def test_positive_synchronize_rh_product_current_sync_date(self): """Create a sync plan with current datetime as a sync date, add a RH product and verify the product gets synchronized on the next sync occurrence @Assert: Product is synchronized successfully. @Feature: SyncPlan @BZ: 1279539 """ interval = 60 * 60 # 'hourly' sync interval in seconds org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) RepositorySet.enable({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', 'basearch': 'x86_64', }) product = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'], }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'product': product['name'], 'organization-id': org['id'], }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time sleep(interval / 2) # Verify product has not been synced yet self.validate_repo_content(repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(interval / 2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
def manifest_org(org, target_sat): """Upload a manifest to the organization.""" with manifests.clone() as manifest: target_sat.put(manifest, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'] }) return org
def manifest_org(org): """Upload a manifest to the organization.""" with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'] }) return org
def test_positive_synchronize_rh_product_future_sync_date(self): """Create a sync plan with sync date in a future and sync one RH product with it automatically. :id: 6ce2f777-f230-4bb8-9822-2cf3580c21aa :expectedresults: Product is synchronized successfully. :CaseLevel: System """ delay = 10 * 60 # delay for sync date in seconds org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'organization-id': org['id'], 'sync-date': (datetime.utcnow() + timedelta(seconds=delay)) .strftime("%Y-%m-%d %H:%M:%S"), }) RepositorySet.enable({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', 'basearch': 'x86_64', }) product = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'], }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'product': product['name'], 'organization-id': org['id'], }) # Verify product is not synced and doesn't have any content self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time sleep(delay/2) # Verify product has not been synced yet self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(delay/2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
def test_positive_synchronize_rh_product_current_sync_date(self): """Create a sync plan with current datetime as a sync date, add a RH product and verify the product gets synchronized on the next sync occurrence @Assert: Product is synchronized successfully. @Feature: SyncPlan @BZ: 1279539 """ interval = 60 * 60 # 'hourly' sync interval in seconds org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'], }) sync_plan = self._make_sync_plan({ 'enabled': 'true', 'interval': 'hourly', 'organization-id': org['id'], 'sync-date': datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"), }) RepositorySet.enable({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product': PRDS['rhel'], 'releasever': '6Server', 'basearch': 'x86_64', }) product = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'], }) repo = Repository.info({ 'name': REPOS['rhva6']['name'], 'product': product['name'], 'organization-id': org['id'], }) # Associate sync plan with product Product.set_sync_plan({ 'id': product['id'], 'sync-plan-id': sync_plan['id'], }) # Wait half of expected time sleep(interval / 2) # Verify product has not been synced yet self.validate_repo_content( repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time sleep(interval / 2) # Verify product was synced successfully self.validate_repo_content(repo, ['errata', 'packages'])
def test_positive_disable_by_id(self): """Disable repo from reposet by IDs of reposet, org and product :id: 0d6102ba-3fb9-4eb8-972e-d537e252a8e6 :expectedresults: Repository was disabled :CaseImportance: Critical """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) product_id = Product.info({ u'name': PRDS['rhel'], u'organization-id': org['id'], })['id'] reposet_id = RepositorySet.info({ u'name': REPOSET['rhva6'], u'organization-id': org['id'], u'product-id': product_id, })['id'] RepositorySet.enable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) RepositorySet.disable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'false')
def _upload_manifest(self, org_id, manifest=None): """Uploads a manifest into an organization. A cloned manifest will be used if ``manifest`` is None. """ if manifest is None: manifest = manifests.clone() upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, 'organization-id': org_id, }) manifest.content.close()
def _upload_manifest(self, org_id, manifest=None): """Uploads a manifest into an organization. A cloned manifest will be used if ``manifest`` is None. """ if manifest is None: manifest = manifests.clone() upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, 'organization-id': org_id, }) manifest.content.close()
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_disable_by_id(self): """Disable repo from reposet by IDs of reposet, org and product :id: 0d6102ba-3fb9-4eb8-972e-d537e252a8e6 :expectedresults: Repository was disabled :CaseImportance: Critical """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) product_id = Product.info({ u'name': PRDS['rhel'], u'organization-id': org['id'], })['id'] reposet_id = RepositorySet.info({ u'name': REPOSET['rhva6'], u'organization-id': org['id'], u'product-id': product_id, })['id'] RepositorySet.enable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) RepositorySet.disable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'false')
def test_repositoryset_disable_by_id(self): """@Test: Disable repo from reposet by IDs of reposet, org and product @Feature: Repository-set @Assert: Repository was disabled """ org = make_org() manifest = manifests.clone() upload_file(manifest, remote_file=manifest) Subscription.upload({ u'file': manifest, u'organization-id': org['id'], }) product_id = Product.info({ u'name': PRDS['rhel'], u'organization-id': org['id'], })['id'] reposet_id = RepositorySet.info({ u'name': REPOSET['rhva6'], u'organization-id': org['id'], u'product-id': product_id, })['id'] RepositorySet.enable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) RepositorySet.disable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'false')
def test_positive_copy_subscription(self): """Copy Activation key and verify contents :id: f4ee8096-4120-4d06-8c9a-57ac1eaa8f68 :Steps: 1. Create parent key and add content 2. Copy Activation key by passing id of parent 3. Verify content was successfully copied :expectedresults: Activation key is successfully copied :CaseLevel: Integration """ # Begin test setup parent_ak = self._make_activation_key() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': self.org['id'], }) subscription_result = Subscription.list( {'organization-id': self.org['id']}, per_page=False) ActivationKey.add_subscription({ u'id': parent_ak['id'], u'subscription-id': subscription_result[0]['id'], }) # End test setup new_name = gen_string('utf8') result = ActivationKey.copy({ u'id': parent_ak['id'], u'new-name': new_name, u'organization-id': self.org['id'], }) self.assertEqual(result[0], u'Activation key copied') result = ActivationKey.subscriptions({ u'name': new_name, u'organization-id': self.org['id'], }) # Verify that the subscription copied over self.assertIn( subscription_result[0]['name'], # subscription name result[3] # subscription list )
def test_positive_logging_from_candlepin(module_org, default_sat): """Check logging after manifest upload. :id: 8c06e501-52d7-4baf-903e-7de9caffb066 :expectedresults: line of logs with POST has request ID :CaseImportance: Medium """ POST_line_found = False source_log = '/var/log/candlepin/candlepin.log' test_logfile = '/var/tmp/logfile_from_candlepin' # regex for a version 4 UUID (8-4-4-12 format) regex = r"\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b" # get the number of lines in the source log before the test line_count_start = line_count(source_log, default_sat) # command for this test with manifests.clone() as manifest: with NamedTemporaryFile(dir=robottelo_tmp_dir) as content_file: content_file.write(manifest.content.read()) content_file.seek(0) default_sat.put(local_path=content_file.name, remote_path=manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': module_org.id }) # get the number of lines in the source log after the test line_count_end = line_count(source_log, default_sat) # get the log lines of interest, put them in test_logfile cut_lines(line_count_start, line_count_end, source_log, test_logfile, default_sat) # use same location on remote and local for log file extract default_sat.get(remote_path=test_logfile) # search the log file extract for the line with POST to candlepin API with open(test_logfile) as logfile: for line in logfile: if re.search(r'verb=POST, uri=/candlepin/owners/{0}', line.format(module_org.name)): logger.info('Found the line with POST to candlepin API') POST_line_found = True # Confirm the request ID was logged in the line with POST match = re.search(regex, line) assert match, "Request ID not found" logger.info("Request ID found for logging from candlepin") break assert POST_line_found, "The POST command to candlepin was not found in logs."
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 upload_manifest_locked(org_id, manifest=None, interface=INTERFACE_API, timeout=None): """Upload a manifest with locking, using the requested interface. :type org_id: int :type manifest: robottelo.manifests.Manifest :type interface: str :type timeout: int :returns: the upload result Note: The manifest uploading is strictly locked only when using this function Usage:: # for API interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_API) # for CLI interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_CLI) # or in one line with default interface result = upload_manifest_locked(org_id, manifests.clone()) subscription_id = result[id'] """ if interface not in [INTERFACE_API, INTERFACE_CLI]: raise ValueError( f'upload manifest with interface "{interface}" not supported') if manifest is None: manifest = clone() if timeout is None: # Set the timeout to 1500 seconds to align with the API timeout. # And as we are in locked state, other functions/tests can try to upload the manifest in # other processes and we do not want to be interrupted by the default configuration # ssh_client timeout. timeout = 1500 if interface == INTERFACE_API: with manifest: result = entities.Subscription().upload( data={'organization_id': org_id}, files={'content': manifest.content}) else: # interface is INTERFACE_CLI with manifest: upload_file(manifest.content, manifest.filename) result = Subscription.upload( { 'file': manifest.filename, 'organization-id': org_id }, timeout=timeout) return result
def test_manifest_upload(self): """@Test: upload manifest (positive) @Feature: Subscriptions/Manifest Upload @Assert: Manifest are uploaded 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, "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.")
def test_manifest_upload(self): """@Test: upload manifest (positive) @Feature: Subscriptions/Manifest Upload @Assert: Manifest are uploaded 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, "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.")
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_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_logging_from_candlepin(self): """Check logging after manifest upload. :id: 8c06e501-52d7-4baf-903e-7de9caffb066 :expectedresults: line of logs with POST has request ID :CaseImportance: Medium """ POST_line_found = False source_log = '/var/log/candlepin/candlepin.log' test_logfile = '/var/tmp/logfile_from_candlepin' # regex for a version 4 UUID (8-4-4-12 format) regex = r"\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b" with ssh.get_connection() as connection: # get the number of lines in the source log before the test line_count_start = line_count(source_log, connection) # command for this test with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': self.org['id'] }) # get the number of lines in the source log after the test line_count_end = line_count(source_log, connection) # get the log lines of interest, put them in test_logfile cut_lines(line_count_start, line_count_end, source_log, test_logfile, connection) # use same location on remote and local for log file extract ssh.download_file(test_logfile) # search the log file extract for the line with POST to candlepin API with open(test_logfile) as logfile: for line in logfile: if re.search(r'verb=POST, uri=/candlepin/owners/{0}', line.format(self.org['name'])): self.logger.info( 'Found the line with POST to candlepin API') POST_line_found = True # Confirm the request ID was logged in the line with POST match = re.search(regex, line) assert match, "Request ID not found" self.logger.info( "Request ID found for logging from candlepin") break assert POST_line_found, "The POST command to candlepin was not found in logs."
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 upload_manifest_locked(org_id, manifest=None, interface=INTERFACE_API, timeout=None): """Upload a manifest with locking, using the requested interface. :type org_id: int :type manifest: robottelo.manifests.Manifest :type interface: str :type timeout: int :returns: the upload result Note: The manifest uploading is strictly locked only when using this function Usage:: # for API interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_API) # for CLI interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_CLI) # or in one line with default interface result = upload_manifest_locked(org_id, manifests.clone()) subscription_id = result[id'] """ if interface not in [INTERFACE_API, INTERFACE_CLI]: raise ValueError( 'upload manifest with interface "{0}" not supported' .format(interface) ) if manifest is None: manifest = clone() if timeout is None: # Set the timeout to 1500 seconds to align with the API timeout. # And as we are in locked state, other functions/tests can try to upload the manifest in # other processes and we do not want to be interrupted by the default configuration # ssh_client timeout. timeout = 1500 if interface == INTERFACE_API: with manifest: result = entities.Subscription().upload( data={'organization_id': org_id}, files={'content': manifest.content}, ) else: # interface is INTERFACE_CLI with manifest: upload_file(manifest.content, manifest.filename) result = Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }, timeout=timeout) return result
def test_positive_enable_by_id(self): """Enable repo from reposet by IDs of reposet, org and product :id: f7c88534-1d45-45d9-9b87-c50c4e268e8d :expectedresults: Repository was enabled :CaseImportance: Critical """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ 'file': manifest.filename, 'organization-id': org['id'] }) product_id = Product.info({ 'name': PRDS['rhel'], 'organization-id': org['id'] })['id'] reposet_id = RepositorySet.info({ 'name': REPOSET['rhva6'], 'organization-id': org['id'], 'product-id': product_id })['id'] RepositorySet.enable({ 'basearch': 'x86_64', 'id': reposet_id, 'organization-id': org['id'], 'product-id': product_id, 'releasever': '6Server', }) result = RepositorySet.available_repositories({ 'id': reposet_id, 'organization-id': org['id'], 'product-id': product_id }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
def _upload_manifest(self): """Utility function to upload manifest""" self.logger.debug('org-id is {0}'.format(self.org_id)) try: Subscription.upload({ 'file': '/root/{0}'.format(MANIFEST_FILE_NAME), 'organization-id': self.org_id, }) except CLIReturnCodeError: self.logger.error('Fail to upload manifest!') raise RuntimeError('Invalid manifest. Stop!') self.logger.info('Upload successful!') # after uploading manifest, get all default parameters self.pid = self._get_production_id() (self.sub_id, self.sub_name) = self._get_subscription_id() self.logger.debug('product id is {0}'.format(self.pid))
def _upload_manifest(self): """Utility function to upload manifest""" self.logger.debug('org-id is {0}'.format(self.org_id)) try: Subscription.upload({ 'file': '/root/{0}'.format(MANIFEST_FILE_NAME), 'organization-id': self.org_id, }) except CLIReturnCodeError: self.logger.error('Fail to upload manifest!') raise RuntimeError('Invalid manifest. Stop!') self.logger.info('Upload successful!') # after uploading manifest, get all default parameters self.pid = self._get_production_id() (self.sub_id, self.sub_name) = self._get_subscription_id() self.logger.debug('product id is {0}'.format(self.pid))
def _upload_manifest(self, manifest, org_id): """Uploads a manifest file and import it into an organization""" upload_file(manifest, remote_file=manifest) result = Subscription.upload({ 'file': manifest, 'organization-id': org_id, }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0)
def test_positive_disable_by_name(self): """Disable repo from reposet by names of reposet, org and product :id: 1690a701-ae41-4724-bbc6-b0adba5a5319 :expectedresults: Repository was disabled :CaseImportance: Critical """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], u'releasever': '6Server', }) RepositorySet.disable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization': org['name'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'false')
def test_positive_disable_by_label(self): """Disable repo from reposet by org label, reposet and product names :id: a87a5df6-f8ab-469e-94e5-ca79378f8dbe :expectedresults: Repository was disabled :CaseImportance: Critical """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], u'releasever': '6Server', }) RepositorySet.disable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'false')
def test_positive_disable_by_label(self): """Disable repo from reposet by org label, reposet and product names :id: a87a5df6-f8ab-469e-94e5-ca79378f8dbe :expectedresults: Repository was disabled :CaseImportance: Critical """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], u'releasever': '6Server', }) RepositorySet.disable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'name': REPOSET['rhva6'], u'organization-label': org['label'], u'product': PRDS['rhel'], }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'false')
def test_positive_enable_by_id(self): """Enable repo from reposet by IDs of reposet, org and product @Feature: Repository-set @Assert: Repository was enabled """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) product_id = Product.info({ u'name': PRDS['rhel'], u'organization-id': org['id'], })['id'] reposet_id = RepositorySet.info({ u'name': REPOSET['rhva6'], u'organization-id': org['id'], u'product-id': product_id, })['id'] RepositorySet.enable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
def test_positive_enable_by_id(self): """Enable repo from reposet by IDs of reposet, org and product @id: f7c88534-1d45-45d9-9b87-c50c4e268e8d @Assert: Repository was enabled """ org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) product_id = Product.info({ u'name': PRDS['rhel'], u'organization-id': org['id'], })['id'] reposet_id = RepositorySet.info({ u'name': REPOSET['rhva6'], u'organization-id': org['id'], u'product-id': product_id, })['id'] RepositorySet.enable({ u'basearch': 'x86_64', u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, u'releasever': '6Server', }) result = RepositorySet.available_repositories({ u'id': reposet_id, u'organization-id': org['id'], u'product-id': product_id, }) enabled = [ repo['enabled'] for repo in result if repo['arch'] == 'x86_64' and repo['release'] == '6Server' ][0] self.assertEqual(enabled, 'true')
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_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_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_delete_subscription(self): """@Test: 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)
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)
def upload_manifest_locked(org_id, manifest=None, interface=INTERFACE_API): """Upload a manifest with locking, using the requested interface. :type org_id: int :type manifest: robottelo.manifests.Manifest :type interface: str :returns: the upload result Note: The manifest uploading is strictly locked only when using this function Usage:: # for API interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_API) # for CLI interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_CLI) # or in one line with default interface result = upload_manifest_locked(org_id, manifests.clone()) subscription_id = result[id'] """ if interface not in [INTERFACE_API, INTERFACE_CLI]: raise ValueError( 'upload manifest with interface "{0}" not supported'.format( interface)) if manifest is None: manifest = clone() if interface == INTERFACE_API: with manifest: result = entities.Subscription().upload( data={'organization_id': org_id}, files={'content': manifest.content}, ) else: # interface is INTERFACE_CLI with manifest: upload_file(manifest.content, manifest.filename) result = Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }) return result
def upload_manifest_locked(org_id, manifest, interface=INTERFACE_API): """Upload a manifest with locking, using the requested interface. :type org_id: int :type manifest: robottelo.manifests.Manifest :type interface: str :returns: the upload result Note: The manifest uploading is strictly locked only when using this function Usage:: # for API interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_API) # for CLI interface manifest = manifests.clone() upload_manifest_locked(org_id, manifest, interface=INTERFACE_CLI) # or in one line with default interface result = upload_manifest_locked(org_id, manifests.clone()) subscription_id = result[id'] """ if interface not in [INTERFACE_API, INTERFACE_CLI]: raise ValueError( 'upload manifest with interface "{0}" not supported' .format(interface) ) if interface == INTERFACE_API: with manifest: result = entities.Subscription().upload( data={'organization_id': org_id}, files={'content': manifest.content}, ) else: # interface is INTERFACE_CLI with manifest: upload_file(manifest.content, manifest.filename) result = Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }) return result
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)
def _upload_manifest(self): self.logger.debug('org-id is {}'.format(self.org_id)) result = Subscription.upload({ 'file': '/root/{}'.format(MANIFEST_FILE_NAME), 'organization-id': self.org_id }) if result.return_code != 0: self.logger.error('Fail to upload manifest!') raise RuntimeError('Invalid manifest. Stop!') self.logger.info('Upload successful!') # after uploading manifest, get all default parameters self.pid = self._get_production_id() (self.sub_id, self.sub_name) = self._get_subscription_id() self.logger.debug('product id is {}'.format(self.pid))
def _upload_manifest(self): self.logger.debug('org-id is {}'.format(self.org_id)) result = Subscription.upload({ 'file': '/root/{}'.format(MANIFEST_FILE_NAME), 'organization-id': self.org_id }) if result.return_code != 0: self.logger.error('Fail to upload manifest!') raise RuntimeError('Invalid manifest. Stop!') self.logger.info('Upload successful!') # after uploading manifest, get all default parameters self.pid = self._get_production_id() (self.sub_id, self.sub_name) = self._get_subscription_id() self.logger.debug('product id is {}'.format(self.pid))
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 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_end_to_end(self): """Perform end to end smoke tests using RH and custom repos. 1. Create a new user with admin permissions 2. Using the new user from above 1. Create a new organization 2. Clone and upload manifest 3. Create a new lifecycle environment 4. Create a custom product 5. Create a custom YUM repository 6. Create a custom PUPPET repository 7. Enable a Red Hat repository 8. Synchronize the three repositories 9. Create a new content view 10. Associate the YUM and Red Hat repositories to new content view 11. Add a PUPPET module to new content view 12. Publish content view 13. Promote content view to the lifecycle environment 14. Create a new activation key 15. Add the products to the activation key 16. Create a new libvirt compute resource 17. Create a new subnet 18. Create a new domain 19. Create a new hostgroup and associate previous entities to it 20. Provision a client @id: 8c8b3ffa-0d54-436b-8eeb-1a3542e100a8 @Assert: All tests should succeed and Content should be successfully fetched by client. """ # step 1: Create a new user with admin permissions password = gen_alphanumeric() user = make_user({u'admin': u'true', u'password': password}) user['password'] = password # step 2.1: Create a new organization org = self._create(user, Org, {u'name': gen_alphanumeric()}) # step 2.2: Clone and upload manifest if self.fake_manifest_is_set: with manifests.clone() as manifest: ssh.upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': org['id'], }) # step 2.3: Create a new lifecycle environment lifecycle_environment = self._create( user, LifecycleEnvironment, { u'name': gen_alphanumeric(), u'organization-id': org['id'], u'prior': u'Library', }) # step 2.4: Create a custom product product = self._create(user, Product, { u'name': gen_alphanumeric(), u'organization-id': org['id'], }) repositories = [] # step 2.5: Create custom YUM repository yum_repo = self._create( user, Repository, { u'content-type': u'yum', u'name': gen_alphanumeric(), u'product-id': product['id'], u'publish-via-http': u'true', u'url': GOOGLE_CHROME_REPO, }) repositories.append(yum_repo) # step 2.6: Create custom PUPPET repository puppet_repo = self._create( user, Repository, { u'content-type': u'puppet', u'name': gen_alphanumeric(), u'product-id': product['id'], u'publish-via-http': u'true', u'url': FAKE_0_PUPPET_REPO, }) repositories.append(puppet_repo) # step 2.7: Enable a Red Hat repository if self.fake_manifest_is_set: RepositorySet.enable({ u'basearch': 'x86_64', u'name': REPOSET['rhva6'], u'organization-id': org['id'], u'product': PRDS['rhel'], u'releasever': '6Server', }) rhel_repo = Repository.info({ u'name': REPOS['rhva6']['name'], u'organization-id': org['id'], u'product': PRDS['rhel'], }) repositories.append(rhel_repo) # step 2.8: Synchronize the three repositories for repo in repositories: Repository.with_user(user['login'], user['password']).synchronize( {u'id': repo['id']}) # step 2.9: Create content view content_view = self._create(user, ContentView, { u'name': gen_alphanumeric(), u'organization-id': org['id'], }) # step 2.10: Associate the YUM and Red Hat repositories to new content # view repositories.remove(puppet_repo) for repo in repositories: ContentView.add_repository({ u'id': content_view['id'], u'organization-id': org['id'], u'repository-id': repo['id'], }) # step 2.11: Add a PUPPET module to new content view result = PuppetModule.with_user(user['login'], user['password']).list({ u'repository-id': puppet_repo['id'], u'per-page': False, }) ContentView.with_user(user['login'], user['password']).puppet_module_add({ u'content-view-id': content_view['id'], u'id': random.choice(result)['id'], }) # step 2.12: Publish content view ContentView.with_user(user['login'], user['password']).publish( {u'id': content_view['id']}) # step 2.13: Promote content view to the lifecycle environment content_view = ContentView.with_user( user['login'], user['password']).info({u'id': content_view['id']}) self.assertEqual(len(content_view['versions']), 1) cv_version = ContentView.with_user( user['login'], user['password']).version_info({ 'id': content_view['versions'][0]['id'], }) self.assertEqual(len(cv_version['lifecycle-environments']), 1) ContentView.with_user(user['login'], user['password']).version_promote({ u'id': cv_version['id'], u'to-lifecycle-environment-id': lifecycle_environment['id'], }) # check that content view exists in lifecycle content_view = ContentView.with_user( user['login'], user['password']).info({u'id': content_view['id']}) self.assertEqual(len(content_view['versions']), 1) cv_version = ContentView.with_user( user['login'], user['password']).version_info({ 'id': content_view['versions'][0]['id'], }) self.assertEqual(len(cv_version['lifecycle-environments']), 2) self.assertEqual(cv_version['lifecycle-environments'][-1]['id'], lifecycle_environment['id']) # step 2.14: Create a new activation key activation_key = self._create( user, ActivationKey, { u'content-view-id': content_view['id'], u'lifecycle-environment-id': lifecycle_environment['id'], u'name': gen_alphanumeric(), u'organization-id': org['id'], }) # step 2.15: Add the products to the activation key subscription_list = Subscription.with_user( user['login'], user['password']).list({u'organization-id': org['id']}, per_page=False) for subscription in subscription_list: if subscription['name'] == DEFAULT_SUBSCRIPTION_NAME: ActivationKey.with_user(user['login'], user['password']).add_subscription({ u'id': activation_key['id'], u'quantity': 1, u'subscription-id': subscription['id'], }) # step 2.15.1: Enable product content if self.fake_manifest_is_set: ActivationKey.with_user(user['login'], user['password']).content_override({ u'content-label': AK_CONTENT_LABEL, u'id': activation_key['id'], u'organization-id': org['id'], u'value': '1', }) # BONUS: Create a content host and associate it with promoted # content view and last lifecycle where it exists content_host_name = gen_alphanumeric() content_host = Host.with_user(user['login'], user['password']).subscription_register({ u'content-view-id': content_view['id'], u'lifecycle-environment-id': lifecycle_environment['id'], u'name': content_host_name, u'organization-id': org['id'], }) if bz_bug_is_open(1328202): results = ContentHost.with_user(user['login'], user['password']).list( {'organization-id': org['id']}) # Content host registration converts the name to lowercase, make # sure to use the same format while matching against the result content_host_name = content_host_name.lower() for result in results: if result['name'] == content_host_name: content_host = result content_host = ContentHost.with_user( user['login'], user['password']).info({'id': content_host['id']}) # check that content view matches what we passed self.assertEqual(content_host['content-view'], content_view['name']) # check that lifecycle environment matches self.assertEqual(content_host['lifecycle-environment'], lifecycle_environment['name']) # step 2.16: Create a new libvirt compute resource self._create( user, ComputeResource, { u'name': gen_alphanumeric(), u'provider': u'Libvirt', u'url': u'qemu+ssh://root@{0}/system'.format( settings.compute_resources.libvirt_hostname), }) # step 2.17: Create a new subnet subnet = self._create( user, Subnet, { u'name': gen_alphanumeric(), u'network': gen_ipaddr(ip3=True), u'mask': u'255.255.255.0', }) # step 2.18: Create a new domain domain = self._create(user, Domain, {u'name': gen_alphanumeric()}) # step 2.19: Create a new hostgroup and associate previous entities to # it host_group = self._create( user, HostGroup, { u'domain-id': domain['id'], u'name': gen_alphanumeric(), u'subnet-id': subnet['id'], }) if not bz_bug_is_open('1326101'): Org.with_user(user['login'], user['password']).add_hostgroup({ u'hostgroup-id': host_group['id'], u'id': org['id'], }) # step 2.20: Provision a client self.client_provisioning(activation_key['name'], org['label'])