def setup_activation_key(org_id, content_view_id, lce_id, subscription_names=None): # type: (int, int, int, Optional[List[str]], Optional[str]) -> Dict """Create activation and associate content-view, lifecycle environment and subscriptions""" if subscription_names is None: subscription_names = [] activation_key = make_activation_key({ 'organization-id': org_id, 'lifecycle-environment-id': lce_id, 'content-view-id': content_view_id, }) # Add subscriptions to activation-key # Get organization subscriptions subscriptions = Subscription.list({'organization-id': org_id}, per_page=False) added_subscription_names = [] for subscription in subscriptions: if (subscription['name'] in subscription_names and subscription['name'] not in added_subscription_names): ActivationKey.add_subscription({ 'id': activation_key['id'], 'subscription-id': subscription['id'], 'quantity': 1, }) added_subscription_names.append(subscription['name']) if len(added_subscription_names) == len(subscription_names): break missing_subscription_names = set(subscription_names).difference( set(added_subscription_names)) if missing_subscription_names: raise ValueError('Missing subscriptions: {0}'.format(missing_subscription_names)) return activation_key
def test_positive_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 _add_ak_to_subscription(self, ak_id, sub_id): """Add activation key to subscription""" try: ActivationKey.add_subscription({ 'id': ak_id, 'quantity': self.add_ak_subscription_qty, 'subscription-id': sub_id, }) except CLIReturnCodeError: self.logger.error('Fail to add activation-key to subscription') return self.logger.info('Subscription added to this activation key.')
def test_positive_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_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_add_subscription_by_id(self): """Test that subscription can be added to activation key :id: b884be1c-b35d-440a-9a9d-c854c83e10a7 :Steps: 1. Create Activation key 2. Upload manifest and add subscription 3. Associate the activation key to subscription :expectedresults: Subscription successfully added to activation key :CaseLevel: Integration """ with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) org_id = make_org()['id'] ackey_id = self._make_activation_key()['id'] Subscription.upload({ 'file': manifest.filename, 'organization-id': org_id, }) subs_id = Subscription.list( {'organization-id': org_id}, per_page=False ) result = ActivationKey.add_subscription({ u'id': ackey_id, u'subscription-id': subs_id[0]['id'], }) self.assertIn('Subscription added to activation key', result)
def test_positive_add_subscription_by_id(self): """Test that subscription can be added to activation key :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 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 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 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 _add_ak_to_subscription(self, ak_id, sub_id): """Add activation key to subscription""" result = ActivationKey.add_subscription({ 'id': ak_id, 'subscription-id': sub_id, 'quantity': self.add_ak_subscription_qty }) if result.return_code != 0: self.logger.error('Fail to add activation-key to subscription') return self.logger.info('Subscription added to this activation key.')
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 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_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) try: org = make_org(cached=True) activation_key = self._make_activation_key({ u'organization-id': org['id'], }) result = Subscription.upload({ 'file': manifest, 'organization-id': self.org['id'], }) except CLIFactoryError as err: self.fail(err) subs_id = Subscription.list( {'organization-id': self.org['id']}, per_page=False) result = ActivationKey.add_subscription({ u'id': activation_key['id'], u'subscription-id': subs_id.stdout[0]['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 error here') self.assertIn("Subscription added to activation key", result.stdout)
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_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 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 test_end_to_end(self): """@Test: Perform end to end smoke tests using RH repos. 1. Create new organization and environment 2. Upload manifest 3. Sync a RedHat repository 4. Create content-view 5. Add repository to contet-view 6. Promote/publish content-view 7. Create an activation-key 8. Add product to activation-key 9. Create new virtualmachine 10. Pull rpm from Foreman server and install on client 11. Register client with foreman server using activation-key 12. Install rpm on client @Feature: Smoke test @Assert: All tests should succeed and Content should be successfully fetched by client """ # Product, RepoSet and repository variables rhel_product_name = "Red Hat Enterprise Linux Server" rhel_repo_set = "Red Hat Enterprise Virtualization Agents " "for RHEL 6 Server (RPMs)" rhel_repo_name = "Red Hat Enterprise Virtualization Agents " "for RHEL 6 Server " "RPMs x86_64 6Server" org_name = random.choice(generate_strings_list()) # Create new org and environment new_org = make_org({u"name": org_name}) new_env = make_lifecycle_environment({u"organization-id": new_org["id"], u"name": gen_alphanumeric()}) # Clone manifest and upload it manifest = manifests.clone() ssh.upload_file(manifest, remote_file=manifest) result = Subscription.upload({u"file": manifest, u"organization-id": new_org["id"]}) self.assertEqual(result.return_code, 0) # Enable repo from Repository Set result = RepositorySet.enable( { u"name": rhel_repo_set, u"organization-id": new_org["id"], u"product": rhel_product_name, u"releasever": "6Server", u"basearch": "x86_64", } ) self.assertEqual(result.return_code, 0) # Fetch repository info result = Repository.info( {u"name": rhel_repo_name, u"product": rhel_product_name, u"organization-id": new_org["id"]} ) rhel_repo = result.stdout # Synchronize the repository result = Repository.synchronize( {u"name": rhel_repo_name, u"organization-id": new_org["id"], u"product": rhel_product_name} ) self.assertEqual(result.return_code, 0) # Create CV and associate repo to it new_cv = make_content_view({u"organization-id": new_org["id"]}) result = ContentView.add_repository( {u"id": new_cv["id"], u"repository-id": rhel_repo["id"], u"organization-id": new_org["id"]} ) self.assertEqual(result.return_code, 0) # Publish a version1 of CV result = ContentView.publish({u"id": new_cv["id"]}) self.assertEqual(result.return_code, 0) # Get the CV info result = ContentView.info({u"id": new_cv["id"]}) self.assertEqual(result.return_code, 0) # Store the version1 id version1_id = result.stdout["versions"][0]["id"] # Promotion of version1 to next env result = ContentView.version_promote({u"id": version1_id, u"to-lifecycle-environment-id": new_env["id"]}) self.assertEqual(result.return_code, 0) # Create activation key activation_key = make_activation_key( { u"name": gen_alphanumeric(), u"lifecycle-environment-id": new_env["id"], u"organization-id": new_org["id"], u"content-view": new_cv["name"], } ) # List the subscriptions in given org result = Subscription.list({u"organization-id": new_org["id"]}, per_page=False) self.assertEqual(result.return_code, 0) # Get the subscription ID from subscriptions list for subscription in result.stdout: if subscription["name"] == DEFAULT_SUBSCRIPTION_NAME: subscription_id = subscription["id"] subscription_quantity = int(subscription["quantity"]) self.assertGreater(int(subscription_quantity), 0) # Add the subscriptions to activation-key result = ActivationKey.add_subscription( {u"id": activation_key["id"], u"subscription-id": subscription_id, u"quantity": 1} ) self.assertEqual(result.return_code, 0) # Enable product content ActivationKey.content_override( { u"id": activation_key["id"], u"organization-id": new_org["id"], u"content-label": "rhel-6-server-rhev-agent-rpms", u"value": "1", } ) # Create VM package_name = "python-kitchen" server_name = conf.properties["main.server.hostname"] with VirtualMachine(distro="rhel66") as vm: # Download and Install rpm result = vm.run("wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/".format(server_name)) self.assertEqual(result.return_code, 0) result = vm.run("rpm -i katello-ca-consumer*.noarch.rpm") self.assertEqual(result.return_code, 0) # Register client with foreman server using activation-key result = vm.run( u"subscription-manager register --activationkey {0} " "--org {1} --force".format(activation_key["name"], new_org["label"]) ) self.assertEqual(result.return_code, 0) # Install contents from sat6 server result = vm.run("yum install -y {0}".format(package_name)) self.assertEqual(result.return_code, 0) # Verify if package is installed by query it result = vm.run("rpm -q {0}".format(package_name)) self.assertEqual(result.return_code, 0)
def test_end_to_end(self): """@Test: Perform end to end smoke tests using RH repos. 1. Create new organization and environment 2. Upload manifest 3. Sync a RedHat repository 4. Create content-view 5. Add repository to contet-view 6. Promote/publish content-view 7. Create an activation-key 8. Add product to activation-key 9. Create new virtualmachine 10. Pull rpm from Foreman server and install on client 11. Register client with foreman server using activation-key 12. Install rpm on client @Feature: Smoke test @Assert: All tests should succeed and Content should be successfully fetched by client """ # Product, RepoSet and repository variables rhel_product_name = 'Red Hat Enterprise Linux Server' rhel_repo_set = ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Server (RPMs)' ) rhel_repo_name = ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Server ' 'RPMs x86_64 6Server' ) org_name = random.choice(generate_strings_list()) # Create new org and environment new_org = make_org({u'name': org_name}) new_env = make_lifecycle_environment({ u'organization-id': new_org['id'], u'name': gen_alphanumeric(), }) # Clone manifest and upload it manifest = manifests.clone() upload_file(manifest, remote_file=manifest) result = Subscription.upload({ u'file': manifest, u'organization-id': new_org['id'], }) self.assertEqual( result.return_code, 0, "Failed to upload manifest: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Enable repo from Repository Set result = RepositorySet.enable({ u'name': rhel_repo_set, u'organization-id': new_org['id'], u'product': rhel_product_name, u'releasever': '6Server', u'basearch': 'x86_64', }) self.assertEqual( result.return_code, 0, "Repo was not enabled: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Fetch repository info result = Repository.info({ u'name': rhel_repo_name, u'product': rhel_product_name, u'organization-id': new_org['id'], }) rhel_repo = result.stdout # Synchronize the repository result = Repository.synchronize({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) self.assertEqual( result.return_code, 0, "Repo was not synchronized: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create CV and associate repo to it new_cv = make_content_view({u'organization-id': new_org['id']}) result = ContentView.add_repository({ u'id': new_cv['id'], u'repository-id': rhel_repo['id'], u'organization-id': new_org['id'], }) self.assertEqual( result.return_code, 0, "Failed repository association: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Publish a version1 of CV result = ContentView.publish({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, "Version1 publishing failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Get the CV info result = ContentView.info({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, "ContentView was not found: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Store the version1 id version1_id = result.stdout['versions'][0]['id'] # Promotion of version1 to next env result = ContentView.version_promote({ u'id': version1_id, u'to-lifecycle-environment-id': new_env['id'], }) self.assertEqual( result.return_code, 0, "version1 promotion failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create activation key activation_key = make_activation_key({ u'name': gen_alphanumeric(), u'lifecycle-environment-id': new_env['id'], u'organization-id': new_org['id'], u'content-view': new_cv['name'], }) # List the subscriptions in given org result = Subscription.list( {u'organization-id': new_org['id']}, per_page=False ) self.assertEqual( result.return_code, 0, "Failed to list subscriptions: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Get the subscription ID from subscriptions list for subscription in result.stdout: if subscription['name'] == "Red Hat Employee Subscription": subscription_id = subscription['id'] subscription_quantity = int(subscription['quantity']) self.assertGreater( int(subscription_quantity), 0, 'Unexpected subscription quantity {0}' .format(subscription_quantity) ) # Add the subscriptions to activation-key result = ActivationKey.add_subscription({ u'id': activation_key['id'], u'subscription-id': subscription_id, u'quantity': 1, }) self.assertEqual( result.return_code, 0, "Failed to add subscription: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create VM package_name = "python-kitchen" server_name = conf.properties['main.server.hostname'] with VirtualMachine(distro='rhel66') as vm: # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(server_name) ) self.assertEqual( result.return_code, 0, "failed to fetch katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) result = vm.run( 'rpm -i katello-ca-consumer*.noarch.rpm' ) self.assertEqual( result.return_code, 0, "failed to install katello-ca rpm: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Register client with foreman server using activation-key result = vm.run( u'subscription-manager register --activationkey {0} ' '--org {1} --force' .format(activation_key['name'], new_org['label']) ) self.assertEqual( result.return_code, 0, "failed to register client:: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Enable Red Hat Enterprise Virtualization Agents repo via cli # As the below repo is disabled by default under ak's prd-content result = vm.run( 'subscription-manager repos --enable ' 'rhel-6-server-rhev-agent-rpms' ) self.assertEqual( result.return_code, 0, "Enabling repo failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Install contents from sat6 server result = vm.run('yum install -y {0}'.format(package_name)) self.assertEqual( result.return_code, 0, "Package install failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Verify if package is installed by query it result = vm.run('rpm -q {0}'.format(package_name)) self.assertIn(package_name, result.stdout[0])
def test_end_to_end(self): """@Test: Perform end to end smoke tests using RH repos. 1. Create new organization and environment 2. Upload manifest 3. Sync a RedHat repository 4. Create content-view 5. Add repository to contet-view 6. Promote/publish content-view 7. Create an activation-key 8. Add product to activation-key 9. Create new virtualmachine 10. Pull rpm from Foreman server and install on client 11. Register client with foreman server using activation-key 12. Install rpm on client @Feature: Smoke test @Assert: All tests should succeed and Content should be successfully fetched by client """ # Product, RepoSet and repository variables rhel_product_name = 'Red Hat Enterprise Linux Server' rhel_repo_set = ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Server (RPMs)' ) rhel_repo_name = ( 'Red Hat Enterprise Virtualization Agents ' 'for RHEL 6 Server ' 'RPMs x86_64 6Server' ) org_name = random.choice(generate_strings_list()) # Create new org and environment new_org = make_org({u'name': org_name}) new_env = make_lifecycle_environment({ u'organization-id': new_org['id'], u'name': gen_alphanumeric(), }) # Clone manifest and upload it manifest = manifests.clone() upload_file(manifest, remote_file=manifest) result = Subscription.upload({ u'file': manifest, u'organization-id': new_org['id'], }) self.assertEqual( result.return_code, 0, "Failed to upload manifest: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Enable repo from Repository Set result = RepositorySet.enable({ u'name': rhel_repo_set, u'organization-id': new_org['id'], u'product': rhel_product_name, u'releasever': '6Server', u'basearch': 'x86_64', }) self.assertEqual( result.return_code, 0, "Repo was not enabled: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Fetch repository info result = Repository.info({ u'name': rhel_repo_name, u'product': rhel_product_name, u'organization-id': new_org['id'], }) rhel_repo = result.stdout # Synchronize the repository result = Repository.synchronize({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) self.assertEqual( result.return_code, 0, "Repo was not synchronized: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create CV and associate repo to it new_cv = make_content_view({u'organization-id': new_org['id']}) result = ContentView.add_repository({ u'id': new_cv['id'], u'repository-id': rhel_repo['id'], u'organization-id': new_org['id'], }) self.assertEqual( result.return_code, 0, "Failed repository association: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Publish a version1 of CV result = ContentView.publish({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, "Version1 publishing failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Get the CV info result = ContentView.info({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, "ContentView was not found: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Store the version1 id version1_id = result.stdout['versions'][0]['id'] # Promotion of version1 to next env result = ContentView.version_promote({ u'id': version1_id, u'to-lifecycle-environment-id': new_env['id'], }) self.assertEqual( result.return_code, 0, "version1 promotion failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create activation key activation_key = make_activation_key({ u'name': gen_alphanumeric(), u'lifecycle-environment-id': new_env['id'], u'organization-id': new_org['id'], u'content-view': new_cv['name'], }) # List the subscriptions in given org result = Subscription.list( {u'organization-id': new_org['id']}, per_page=False ) self.assertEqual( result.return_code, 0, "Failed to list subscriptions: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Get the subscription ID from subscriptions list for subscription in result.stdout: if subscription['name'] == "Red Hat Employee Subscription": subscription_id = subscription['id'] subscription_quantity = int(subscription['quantity']) self.assertGreater( int(subscription_quantity), 0, 'Unexpected subscription quantity {0}' .format(subscription_quantity) ) # Add the subscriptions to activation-key result = ActivationKey.add_subscription({ u'id': activation_key['id'], u'subscription-id': subscription_id, u'quantity': 1, }) self.assertEqual( result.return_code, 0, "Failed to add subscription: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Create VM package_name = "python-kitchen" server_name = conf.properties['main.server.hostname'] with VirtualMachine(distro='rhel65') as vm: # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(server_name) ) self.assertEqual( result.return_code, 0, "failed to fetch katello-ca rpm: {0}, return code: {1}" .format(result.stderr, result.return_code) ) result = vm.run( 'rpm -i katello-ca-consumer*.noarch.rpm' ) self.assertEqual( result.return_code, 0, "failed to install katello-ca rpm: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Register client with foreman server using activation-key result = vm.run( u'subscription-manager register --activationkey {0} ' '--org {1} --force' .format(activation_key['name'], new_org['label']) ) self.assertEqual( result.return_code, 0, "failed to register client:: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Install contents from sat6 server result = vm.run('yum install -y {0}'.format(package_name)) self.assertEqual( result.return_code, 0, "Package install failed: {0} and return code: {1}" .format(result.stderr, result.return_code) ) # Verify if package is installed by query it result = vm.run('rpm -q {0}'.format(package_name)) self.assertIn(package_name, result.stdout[0])
def test_end_to_end(self): """@Test: Perform end to end smoke tests using RH repos. 1. Create new organization and environment 2. Upload manifest 3. Sync a RedHat repository 4. Create content-view 5. Add repository to contet-view 6. Promote/publish content-view 7. Create an activation-key 8. Add product to activation-key 9. Create new virtualmachine 10. Pull rpm from Foreman server and install on client 11. Register client with foreman server using activation-key 12. Install rpm on client @Feature: Smoke test @Assert: All tests should succeed and Content should be successfully fetched by client """ # Product, RepoSet and repository variables rhel_product_name = PRDS['rhel'] rhel_repo_set = REPOSET['rhva6'] rhel_repo_name = REPOS['rhva6']['name'] org_name = random.choice(generate_strings_list()) # Create new org and environment new_org = make_org({u'name': org_name}) new_env = make_lifecycle_environment({ u'organization-id': new_org['id'], }) # Clone manifest and upload it manifest = manifests.clone() ssh.upload_file(manifest, remote_file=manifest) Subscription.upload({ u'file': manifest, u'organization-id': new_org['id'], }) # Enable repo from Repository Set RepositorySet.enable({ u'basearch': 'x86_64', u'name': rhel_repo_set, u'organization-id': new_org['id'], u'product': rhel_product_name, u'releasever': '6Server', }) # Fetch repository info rhel_repo = Repository.info({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) # Synchronize the repository Repository.synchronize({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) # Create CV and associate repo to it new_cv = make_content_view({u'organization-id': new_org['id']}) ContentView.add_repository({ u'id': new_cv['id'], u'organization-id': new_org['id'], u'repository-id': rhel_repo['id'], }) # Publish a version1 of CV ContentView.publish({u'id': new_cv['id']}) # Get the CV info version1_id = ContentView.info({ u'id': new_cv['id']})['versions'][0]['id'] # Store the version1 id # Promotion of version1 to next env ContentView.version_promote({ u'id': version1_id, u'to-lifecycle-environment-id': new_env['id'], }) # Create activation key activation_key = make_activation_key({ u'content-view': new_cv['name'], u'lifecycle-environment-id': new_env['id'], u'organization-id': new_org['id'], }) # List the subscriptions in given org result = Subscription.list( {u'organization-id': new_org['id']}, per_page=False ) # Get the subscription ID from subscriptions list for subscription in result: if subscription['name'] == DEFAULT_SUBSCRIPTION_NAME: subscription_id = subscription['id'] subscription_quantity = int(subscription['quantity']) self.assertGreater(int(subscription_quantity), 0) # Add the subscriptions to activation-key ActivationKey.add_subscription({ u'id': activation_key['id'], u'quantity': 1, u'subscription-id': subscription_id, }) # Enable product content ActivationKey.content_override({ u'content-label': 'rhel-6-server-rhev-agent-rpms', u'id': activation_key['id'], u'organization-id': new_org['id'], u'value': '1', }) # Create VM package_name = "python-kitchen" server_name = conf.properties['main.server.hostname'] with VirtualMachine(distro='rhel66') as vm: # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(server_name) ) self.assertEqual(result.return_code, 0) result = vm.run( 'rpm -i katello-ca-consumer*.noarch.rpm' ) self.assertEqual(result.return_code, 0) # Register client with foreman server using activation-key result = vm.run( u'subscription-manager register --activationkey {0} ' '--org {1} --force' .format(activation_key['name'], new_org['label']) ) self.assertEqual(result.return_code, 0) # Install contents from sat6 server result = vm.run('yum install -y {0}'.format(package_name)) self.assertEqual(result.return_code, 0) # Verify if package is installed by query it result = vm.run('rpm -q {0}'.format(package_name)) self.assertEqual(result.return_code, 0)
def _make_public_key(self): """Perform all the steps needed to populate an Activation Key""" if TestActivationKey.pub_key is None: TestActivationKey.pub_key = {} try: organization_id = make_org()['id'] TestActivationKey.pub_key['org_id'] = organization_id TestActivationKey.pub_key['prod_id'] = make_product({ 'organization-id': organization_id, })['id'] TestActivationKey.pub_key['manifest'] = manifests.clone() upload_file(TestActivationKey.pub_key['manifest']) Subscription.upload({ 'file': TestActivationKey.pub_key['manifest'], 'organization-id': TestActivationKey.pub_key['org_id'], }) # create content view TestActivationKey.pub_key['content_view_id'] = ( make_content_view({ u'organization-id': ( TestActivationKey.pub_key['org_id']), u'name': gen_string('alpha'), })['id'] ) TestActivationKey.pub_key['repo_id'] = make_repository({ u'product-id': TestActivationKey.pub_key['prod_id'], })['id'] Repository.synchronize({ 'id': TestActivationKey.pub_key['repo_id'], 'organization-id': TestActivationKey.pub_key['org_id'], }) ContentView.add_repository({ u'id': TestActivationKey.pub_key['content_view_id'], u'repository-id': TestActivationKey.pub_key['repo_id'], }) ContentView.publish({ u'id': TestActivationKey.pub_key['content_view_id'], }) TestActivationKey.pub_key['key_id'] = make_activation_key({ u'organization-id': TestActivationKey.pub_key['org_id'] })['id'] subscription_result = Subscription.list({ 'organization-id': TestActivationKey.pub_key['org_id'], 'order': 'id desc' }, per_page=False) ActivationKey.add_subscription({ u'id': TestActivationKey.pub_key['key_id'], u'subscription-id': subscription_result[-1]['id'], }) except CLIFactoryError as err: TestActivationKey.pub_key = None self.fail(err)
def test_positive_end_to_end(self): """Perform end to end smoke tests using RH repos. 1. Create new organization and environment 2. Upload manifest 3. Sync a RedHat repository 4. Create content-view 5. Add repository to contet-view 6. Promote/publish content-view 7. Create an activation-key 8. Add product to activation-key 9. Create new virtualmachine 10. Pull rpm from Foreman server and install on client 11. Register client with foreman server using activation-key 12. Install rpm on client @Feature: Smoke test @Assert: All tests should succeed and Content should be successfully fetched by client """ # Product, RepoSet and repository variables rhel_product_name = PRDS['rhel'] rhel_repo_set = REPOSET['rhva6'] rhel_repo_name = REPOS['rhva6']['name'] org_name = random.choice(generate_strings_list()) # Create new org and environment new_org = make_org({u'name': org_name}) new_env = make_lifecycle_environment({ u'organization-id': new_org['id'], }) # Clone manifest and upload it with manifests.clone() as manifest: ssh.upload_file(manifest.content, manifest.filename) Subscription.upload({ u'file': manifest.filename, u'organization-id': new_org['id'], }) # Enable repo from Repository Set RepositorySet.enable({ u'basearch': 'x86_64', u'name': rhel_repo_set, u'organization-id': new_org['id'], u'product': rhel_product_name, u'releasever': '6Server', }) # Fetch repository info rhel_repo = Repository.info({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) # Synchronize the repository Repository.synchronize({ u'name': rhel_repo_name, u'organization-id': new_org['id'], u'product': rhel_product_name, }) # Create CV and associate repo to it new_cv = make_content_view({u'organization-id': new_org['id']}) ContentView.add_repository({ u'id': new_cv['id'], u'organization-id': new_org['id'], u'repository-id': rhel_repo['id'], }) # Publish a version1 of CV ContentView.publish({u'id': new_cv['id']}) # Get the CV info version1_id = ContentView.info({u'id': new_cv['id']})['versions'][0]['id'] # Store the version1 id # Promotion of version1 to next env ContentView.version_promote({ u'id': version1_id, u'to-lifecycle-environment-id': new_env['id'], }) # Create activation key activation_key = make_activation_key({ u'content-view': new_cv['name'], u'lifecycle-environment-id': new_env['id'], u'organization-id': new_org['id'], }) # List the subscriptions in given org result = Subscription.list({u'organization-id': new_org['id']}, per_page=False) self.assertGreater(len(result), 0) # Get the subscription ID from subscriptions list subscription_quantity = 0 for subscription in result: if subscription['name'] == DEFAULT_SUBSCRIPTION_NAME: subscription_id = subscription['id'] subscription_quantity = int(subscription['quantity']) self.assertGreater(subscription_quantity, 0) # Add the subscriptions to activation-key ActivationKey.add_subscription({ u'id': activation_key['id'], u'quantity': 1, u'subscription-id': subscription_id, }) # Enable product content ActivationKey.content_override({ u'content-label': 'rhel-6-server-rhev-agent-rpms', u'id': activation_key['id'], u'organization-id': new_org['id'], u'value': '1', }) # Create VM package_name = "python-kitchen" server_name = settings.server.hostname with VirtualMachine(distro='rhel66') as vm: # Download and Install rpm result = vm.run( "wget -nd -r -l1 --no-parent -A '*.noarch.rpm' http://{0}/pub/" .format(server_name)) self.assertEqual(result.return_code, 0) result = vm.run('rpm -i katello-ca-consumer*.noarch.rpm') self.assertEqual(result.return_code, 0) # Register client with foreman server using activation-key result = vm.run( u'subscription-manager register --activationkey {0} ' '--org {1} --force'.format(activation_key['name'], new_org['label'])) self.assertEqual(result.return_code, 0) # Install contents from sat6 server result = vm.run('yum install -y {0}'.format(package_name)) self.assertEqual(result.return_code, 0) # Verify if package is installed by query it result = vm.run('rpm -q {0}'.format(package_name)) self.assertEqual(result.return_code, 0)