def setUp(self): """ Tests for activation keys via Hammer CLI """ super(TestActivationKey, self).setUp() if TestActivationKey.org is None: TestActivationKey.org = make_org() if TestActivationKey.env1 is None: TestActivationKey.env1 = make_lifecycle_environment( {u'organization-id': TestActivationKey.org['id']}) if TestActivationKey.env2 is None: TestActivationKey.env2 = make_lifecycle_environment({ u'organization-id': TestActivationKey.org['id'], u'prior': TestActivationKey.env1['label'] }) if TestActivationKey.product is None: TestActivationKey.product = make_product( {u'organization-id': TestActivationKey.org['id']}) if TestActivationKey.library is None: TestActivationKey.library = LifecycleEnvironment.info({ 'organization-id': TestActivationKey.org['id'], 'name': 'Library' }).stdout
def test_positive_list_all_with_per_page(self): """Attempt to list more than 20 lifecycle environment with per-page option. :id: 6e10fb0e-5e2c-45e6-85a8-0c853450257b :BZ: 1420503 :expectedresults: all the Lifecycle environments are listed """ org = make_org() lifecycle_environments_count = 25 per_page_count = lifecycle_environments_count + 5 env_base_name = gen_string('alpha') last_env_name = ENVIRONMENT env_names = [last_env_name] for env_index in range(lifecycle_environments_count): env_name = '{0}-{1}'.format(env_base_name, env_index) make_lifecycle_environment({ 'name': env_name, 'organization-id': org['id'], 'prior': last_env_name }) last_env_name = env_name env_names.append(env_name) lifecycle_environments = LifecycleEnvironment.list({ 'organization-id': org['id'], 'per_page': per_page_count }) self.assertEqual(len(lifecycle_environments), lifecycle_environments_count + 1) env_name_set = {env['name'] for env in lifecycle_environments} self.assertEqual(env_name_set, set(env_names))
def test_positive_remove_lce(self): """Remove a lifecycle environment from organization @id: bfa9198e-6078-4f10-b79a-3d7f51b835fd @Assert: Lifecycle environment is removed from the org @CaseLevel: Integration """ # Create a lifecycle environment. org_id = make_org()['id'] lc_env_name = make_lifecycle_environment( {'organization-id': org_id})['name'] lc_env_attrs = { 'name': lc_env_name, 'organization-id': org_id, } # Read back information about the lifecycle environment. Verify the # sanity of that information. response = LifecycleEnvironment.list(lc_env_attrs) self.assertEqual(response[0]['name'], lc_env_name) # Delete it. LifecycleEnvironment.delete(lc_env_attrs) # We should get a zero-length response when searching for the LC env. response = LifecycleEnvironment.list(lc_env_attrs) self.assertEqual(len(response), 0)
def test_environment_paths(self): """@Test: List the environment paths under a given organization @Feature: Lifecycle Environment @Assert: Lifecycle environment paths listed """ try: org = make_org() test_env = make_lifecycle_environment({ 'organization-id': org['id'], }) except CLIFactoryError as err: self.fail(err) # Add paths to lifecycle environments result = LifecycleEnvironment.paths({ 'organization-id': org['id'], 'permission-type': 'readable', }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertIn( u'Library >> {0}'.format(test_env['name']), u''.join(result.stdout) )
def test_positive_delete_1(self, test_data): """@Test: Create lifecycle environment with valid name, prior to Library @Feature: Lifecycle Environment @Assert: Lifecycle environment is deleted """ new_obj = make_lifecycle_environment({ 'organization-id': self.org['id'], 'name': test_data['name'], }) # Delete the lifecycle environment result = LifecycleEnvironment.delete({'id': new_obj['id']}) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) # Can we find the object result = LifecycleEnvironment.info({ 'organization-id': self.org['id'], 'id': new_obj['id'], }) self.assertGreater(result.return_code, 0) self.assertGreater(len(result.stderr), 0)
def test_positive_update_1(self, test_data): """@Test: Create lifecycle environment then update its name @Feature: Lifecycle Environment @Assert: Lifecycle environment name is updated """ payload = { 'organization-id': self.org['id'], } new_obj = make_lifecycle_environment(payload) # Update its name result = LifecycleEnvironment.update({ 'organization-id': self.org['id'], 'id': new_obj['id'], 'new-name': test_data['name'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) # Fetch the object result = LifecycleEnvironment.info({ 'organization-id': self.org['id'], 'id': new_obj['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertGreater(len(result.stdout), 0) self.assertEqual(test_data['name'], result.stdout['name']) self.assertNotEqual(new_obj['name'], result.stdout['name'])
def test_positive_update_2(self, test_data): """@Test: Create lifecycle environment then update its description @Feature: Lifecycle Environment @Assert: Lifecycle environment description is updated """ new_obj = make_lifecycle_environment({ 'organization-id': self.org['id'], }) # Update its description result = LifecycleEnvironment.update({ 'description': test_data['description'], 'id': new_obj['id'], 'organization-id': self.org['id'], 'prior': new_obj['prior-lifecycle-environment'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) # Fetch the object result = LifecycleEnvironment.info({ 'id': new_obj['id'], 'organization-id': self.org['id'], }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertGreater(len(result.stdout), 0) self.assertEqual( test_data['description'], result.stdout['description']) self.assertNotEqual( new_obj['description'], result.stdout['description'])
def test_environment_paths(self): """@Test: List the environment paths under a given organization @Feature: Lifecycle Environment @Assert: Lifecycle environment paths listed """ try: org = make_org(cached=True) payload = { 'organization-id': org['id'], } test_env = make_lifecycle_environment(payload) except CLIFactoryError as err: self.fail(err) # Add paths to lifecycle environments result = LifecycleEnvironment.paths({'organization-id': org['id'], 'permission-type': 'readable'}) 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(u'Library >> {0}'.format(test_env['name']), result.stdout)
def test_promote_multiple_docker_repo_content_view(self): """@Test: Add Docker-type repository to content view and publish it. Then promote it to multiple available lifecycle-environments. @Assert: Docker-type repository is promoted to content view found in the specific lifecycle-environments. @Feature: Docker """ self._create_and_associate_repo_with_cv() ContentView.publish({'id': self.content_view['id']}) self.content_view = ContentView.info({ 'id': self.content_view['id']}) self.assertEqual(len(self.content_view['versions']), 1) cvv = ContentView.version_info({ 'id': self.content_view['versions'][0]['id'], }) self.assertEqual(len(cvv['lifecycle-environments']), 1) for i in range(1, randint(3, 6)): lce = make_lifecycle_environment({'organization-id': self.org_id}) ContentView.version_promote({ 'id': cvv['id'], 'lifecycle-environment-id': lce['id'], }) cvv = ContentView.version_info({ 'id': self.content_view['versions'][0]['id'], }) self.assertEqual(len(cvv['lifecycle-environments']), i+1)
def setUpClass(cls): """Create necessary objects which can be re-used in tests.""" super(DockerActivationKeyTestCase, cls).setUpClass() cls.org = make_org() cls.lce = make_lifecycle_environment({ 'organization-id': cls.org['id'], }) cls.product = make_product({ 'organization-id': cls.org['id'], }) cls.repo = _make_docker_repo(cls.product['id']) cls.content_view = make_content_view({ 'composite': False, 'organization-id': cls.org['id'], }) ContentView.add_repository({ 'id': cls.content_view['id'], 'repository-id': cls.repo['id'], }) cls.content_view = ContentView.info({ 'id': cls.content_view['id'] }) ContentView.publish({'id': cls.content_view['id']}) cls.content_view = ContentView.info({ 'id': cls.content_view['id']}) cls.cvv = ContentView.version_info({ 'id': cls.content_view['versions'][0]['id'], }) ContentView.version_promote({ 'id': cls.content_view['versions'][0]['id'], 'lifecycle-environment-id': cls.lce['id'], }) cls.cvv = ContentView.version_info({ 'id': cls.content_view['versions'][0]['id'], })
def test_positive_create_1(self, test_data): """@Test: Create lifecycle environment with valid name, prior to Library @Feature: Lifecycle Environment @Assert: Lifecycle environment is created with Library as prior """ payload = { 'organization-id': self.org['id'], 'name': test_data['name'], } new_obj = make_lifecycle_environment(payload) self.assertIsNotNone(new_obj, "Could not create lifecycle environment.") # Can we find the new object result = LifecycleEnvironment.info({ 'organization-id': self.org['id'], 'id': new_obj['id'], }) self.assertEqual(result.return_code, 0, "Could find the lifecycle environment") self.assertEqual(len(result.stderr), 0, "There should not be an error here.") self.assertGreater(len(result.stdout), 0, "No output was returned") self.assertEqual( new_obj['name'], result.stdout['name'], "Could not find lifecycle environment \'%s\'" % new_obj['name'])
def test_bugzilla_1077333(self): """@Test: Search lifecycle environment via its name containing UTF-8 chars @Feature: Lifecycle Environment @Assert: Can get info for lifecycle by its name """ payload = { 'organization-id': self.org['id'], 'name': gen_string('utf8', 15), } new_obj = make_lifecycle_environment(payload) self.assertIsNotNone(new_obj, "Could not create lifecycle environment.") # Can we find the new object result = LifecycleEnvironment.info({ 'organization-id': self.org['id'], 'name': new_obj['name'], }) self.assertEqual(result.return_code, 0, "Could find the lifecycle environment") self.assertEqual(len(result.stderr), 0, "There should not be an error here.") self.assertGreater(len(result.stdout), 0, "No output was returned") self.assertEqual( new_obj['name'], result.stdout['name'], "Could not find lifecycle environment \'%s\'" % new_obj['name'])
def test_environment_paths(self): """@Test: List the environment paths under a given organization @Feature: Lifecycle Environment @Assert: Lifecycle environment paths listed """ try: org = make_org() test_env = make_lifecycle_environment({ 'organization-id': org['id'], }) except CLIFactoryError as err: self.fail(err) # Add paths to lifecycle environments result = LifecycleEnvironment.paths({ 'organization-id': org['id'], 'permission-type': 'readable', }) self.assertEqual(result.return_code, 0) self.assertEqual(len(result.stderr), 0) self.assertIn(u'Library >> {0}'.format(test_env['name']), u''.join(result.stdout))
def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(KatelloAgentTestCase, cls).setUpClass() # Create new org, environment, CV and activation key KatelloAgentTestCase.org = make_org() KatelloAgentTestCase.env = make_lifecycle_environment({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.content_view = make_content_view({ u'organization-id': KatelloAgentTestCase.org['id'], }) KatelloAgentTestCase.activation_key = make_activation_key({ u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'organization-id': KatelloAgentTestCase.org['id'], }) # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo({ u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], }) # Create custom repo, add subscription to activation key setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': KatelloAgentTestCase.org['id'], u'content-view-id': KatelloAgentTestCase.content_view['id'], u'lifecycle-environment-id': KatelloAgentTestCase.env['id'], u'activationkey-id': KatelloAgentTestCase.activation_key['id'], })
def setup_content_view(self, org_id, lce_id=None): # type: (int, int) -> Tuple[Dict, Dict] """Setup organization content view by adding all the repositories, publishing and promoting to lce if needed. """ if lce_id is None: lce = make_lifecycle_environment({'organization-id': org_id}) else: lce = LifecycleEnvironment.info({ 'id': lce_id, 'organization-id': org_id, }) content_view = make_content_view({'organization-id': org_id}) # Add repositories to content view for repo in self: repo.add_to_content_view(org_id, content_view['id']) # Publish the content view ContentView.publish({'id': content_view['id']}) if lce['name'] != ENVIRONMENT: # Get the latest content view version id content_view_version = ContentView.info({'id': content_view['id'] })['versions'][-1] # Promote content view version to lifecycle environment ContentView.version_promote({ 'id': content_view_version['id'], 'organization-id': org_id, 'to-lifecycle-environment-id': lce['id'], }) content_view = ContentView.info({'id': content_view['id']}) return content_view, lce
def test_positive_update_lce(self): """Update Environment in an Activation key @Feature: Activation key - Positive Update @Assert: Activation key is updated """ ak_env = self._make_activation_key({ u'lifecycle-environment-id': self.get_default_env()['id'], }) env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) ActivationKey.update({ u'id': ak_env['id'], u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': ak_env['id']}) self.assertEqual(updated_ak['lifecycle-environment'], env['name'])
def test_positive_update_registry_name_pattern(self): """Create lifecycle environment and then update registry name pattern :id: 131aaed7-d74f-4c9a-be7e-04226d48e64a :expectedresults: Lifecycle environment registry name pattern is updated :CaseImportance: Critical """ lce = make_lifecycle_environment({'organization-id': self.org['id']}) registry_name_pattern = ( "{}-<%= organization.label %>/<%= repository.docker_upstream_name %>" ).format(gen_string('alpha', 5)) LifecycleEnvironment.update({ 'registry-name-pattern': registry_name_pattern, 'id': lce['id'], 'organization-id': self.org['id'], }) result = LifecycleEnvironment.info({ 'id': lce['id'], 'organization-id': self.org['id'] }) self.assertGreater(len(result), 0) self.assertEqual(result['registry-name-pattern'], registry_name_pattern)
def test_vm_install_package(value): """Install a package with all supported distros and cdn not cdn variants :id: b2a6065a-69f6-4805-a28b-eaaa812e0f4b :expectedresults: Package is install is installed """ # the value is support distro DISTRO_RH6 or DISTRO_RH7 # this will create 4 tests: # - one test with disto rhel6 cdn False # - one test with distro rhel7 cdn False # - one test with disto rhel6 cdn True # - one test with distro rhel7 cdn True distro, cdn = value org = make_org() lce = make_lifecycle_environment({'organization-id': org['id']}) repos_collection = RepositoryCollection( distro=distro, repositories=[ SatelliteToolsRepository(cdn=cdn), YumRepository(url=FAKE_0_YUM_REPO) ]) # this will create repositories , content view and activation key repos_collection.setup_content(org['id'], lce['id'], upload_manifest=True) with VirtualMachine(distro=distro) as vm: # this will install katello ca, register vm host, enable rh repos, # install katello-agent repos_collection.setup_virtual_machine(vm) # install a package result = vm.run('yum -y install {0}'.format(FAKE_0_CUSTOM_PACKAGE)) assert result.return_code == 0
def test_positive_update_description(self): """Create lifecycle environment then update its description @Feature: Lifecycle Environment @Assert: Lifecycle environment description is updated """ new_lce = make_lifecycle_environment({ 'organization-id': self.org['id'], }) for new_desc in valid_data_list(): with self.subTest(new_desc): LifecycleEnvironment.update({ 'description': new_desc, 'id': new_lce['id'], 'organization-id': self.org['id'], 'prior': new_lce['prior-lifecycle-environment'], }) result = LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'], }) self.assertGreater(len(result), 0) self.assertEqual(result['description'], new_desc)
def test_positive_update_1(self): """@Test: Create lifecycle environment then update its name @Feature: Lifecycle Environment @Assert: Lifecycle environment name is updated """ new_lce = make_lifecycle_environment({ 'organization-id': self.org['id'], }) for new_name in valid_data_list(): with self.subTest(new_name): LifecycleEnvironment.update({ 'id': new_lce['id'], 'new-name': new_name, 'organization-id': self.org['id'], 'prior': new_lce['prior-lifecycle-environment'], }) result = LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'], }) self.assertGreater(len(result), 0) self.assertEqual(result['name'], new_name)
def test_positive_delete_by_id(self): """Create lifecycle environment with valid name, prior to Library :id: 76989039-5389-4136-9f7c-220eb38f157b :expectedresults: Lifecycle environment is deleted :CaseImportance: Critical """ for name in valid_data_list(): with self.subTest(name): new_lce = make_lifecycle_environment({ 'name': name, 'organization-id': self.org['id'] }) LifecycleEnvironment.delete({'id': new_lce['id']}) with self.assertRaises(CLIReturnCodeError): LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'] })
def test_positive_update_aks_to_chost(self): """Check if multiple Activation keys can be attached to a Content host :id: 24fddd9c-03ae-41a7-8649-72296cbbafdf :expectedresults: Multiple Activation keys are attached to a Content host :CaseLevel: System """ env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) new_aks = [ make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) for _ in range(2) ] with VirtualMachine(distro=DISTRO_RHEL6) as vm: vm.install_katello_ca() for i in range(2): vm.register_contenthost( self.org['label'], new_aks[i]['name']) self.assertTrue(vm.subscribed)
def test_positive_add_and_remove_lce(module_org): """Remove a lifecycle environment from organization :id: bfa9198e-6078-4f10-b79a-3d7f51b835fd :expectedresults: Lifecycle environment is handled as expected :steps: 1. create and add lce to org 2. remove lce from org :CaseLevel: Integration """ # Create a lifecycle environment. lc_env_name = make_lifecycle_environment({'organization-id': module_org.id})['name'] lc_env_attrs = {'name': lc_env_name, 'organization-id': module_org.id} # Read back information about the lifecycle environment. Verify the # sanity of that information. response = LifecycleEnvironment.list(lc_env_attrs) assert response[0]['name'] == lc_env_name # Delete it. LifecycleEnvironment.delete(lc_env_attrs) # We should get a zero-length response when searching for the LC env. response = LifecycleEnvironment.list(lc_env_attrs) assert len(response) == 0
def test_delete_ak_with_env(self): """@Test: Create activation key with lifecycle environment assigned to it and delete it using activation key id @Feature: Activation key - Positive Delete @Steps: 1. Create Activation key with lifecycle environment assigned to it 2. Delete Activation key using activation key id @Assert: Activation key is deleted """ self.update_env() env = make_lifecycle_environment({ u'organization-id': self.org['id'], }) activation_key = self._make_activation_key({ u'lifecycle-environment': env['name'], u'name': gen_string('alpha'), }) ActivationKey.delete({'id': activation_key['id']}) with self.assertRaises(CLIReturnCodeError): ActivationKey.info({'id': activation_key['id']})
def test_positive_sync_publish_promote_cv(self): """Synchronize repository with DRPMs, add repository to content view, publish and promote content view to lifecycle environment @id: a01cb12b-d388-4902-8532-714f4e28ec56 @Assert: drpms can be listed in content view in proper lifecycle environment """ lce = make_lifecycle_environment({"organization-id": self.org["id"]}) repo = make_repository({"product-id": self.product["id"], "url": FAKE_YUM_DRPM_REPO}) Repository.synchronize({"id": repo["id"]}) cv = make_content_view({"organization-id": self.org["id"]}) ContentView.add_repository({"id": cv["id"], "repository-id": repo["id"]}) ContentView.publish({"id": cv["id"]}) content_view = ContentView.info({"id": cv["id"]}) cvv = content_view["versions"][0] ContentView.version_promote({"id": cvv["id"], "to-lifecycle-environment-id": lce["id"]}) result = ssh.command( "ls /var/lib/pulp/published/yum/https/repos/{}/{}/{}/custom/{}/{}" "/drpms/ | grep .drpm".format( self.org["label"], lce["label"], cv["label"], self.product["label"], repo["label"] ) ) self.assertEqual(result.return_code, 0) self.assertGreaterEqual(len(result.stdout), 1)
def test_vm_install_package(value): """Install a package with all supported distros and cdn not cdn variants :id: b2a6065a-69f6-4805-a28b-eaaa812e0f4b :expectedresults: Package is install is installed """ # the value is support distro DISTRO_RH6 or DISTRO_RH7 # this will create 4 tests: # - one test with disto rhel6 cdn False # - one test with distro rhel7 cdn False # - one test with disto rhel6 cdn True # - one test with distro rhel7 cdn True distro, cdn = value org = make_org() lce = make_lifecycle_environment({'organization-id': org['id']}) repos_collection = RepositoryCollection( distro=distro, repositories=[ SatelliteToolsRepository(cdn=cdn), YumRepository(url=FAKE_0_YUM_REPO) ] ) # this will create repositories , content view and activation key repos_collection.setup_content(org['id'], lce['id'], upload_manifest=True) with VirtualMachine(distro=distro) as vm: # this will install katello ca, register vm host, enable rh repos, # install katello-agent repos_collection.setup_virtual_machine(vm) # install a package result = vm.run('yum -y install {0}'.format(FAKE_0_CUSTOM_PACKAGE)) assert result.return_code == 0
def setUpClass(cls): """Create Org, Lifecycle Environment, Content View, Activation key """ super(RemoteExecutionTestCase, cls).setUpClass() cls.org = make_org() ssh.command( '''echo 'getenforce' > {0}'''.format(TEMPLATE_FILE) ) cls.env = make_lifecycle_environment({ u'organization-id': cls.org['id'], }) cls.content_view = make_content_view({ u'organization-id': cls.org['id'], }) cls.activation_key = make_activation_key({ u'lifecycle-environment-id': cls.env['id'], u'organization-id': cls.org['id'], }) # Add subscription to Satellite Tools repo to activation key setup_org_for_a_rh_repo({ u'product': PRDS['rhel'], u'repository-set': REPOSET['rhst7'], u'repository': REPOS['rhst7']['name'], u'organization-id': cls.org['id'], u'content-view-id': cls.content_view['id'], u'lifecycle-environment-id': cls.env['id'], u'activationkey-id': cls.activation_key['id'], })
def setUpClass(cls): """Tests for Content Host via Hammer CLI""" super(ContentHostTestCase, cls).setUpClass() ContentHostTestCase.NEW_ORG = make_org(cached=True) ContentHostTestCase.NEW_LIFECYCLE = make_lifecycle_environment( {u"organization-id": ContentHostTestCase.NEW_ORG["id"]}, cached=True ) ContentHostTestCase.LIBRARY = LifecycleEnvironment.info( {u"organization-id": ContentHostTestCase.NEW_ORG["id"], u"name": u"Library"} ) ContentHostTestCase.DEFAULT_CV = ContentView.info( {u"organization-id": ContentHostTestCase.NEW_ORG["id"], u"name": u"Default Organization View"} ) ContentHostTestCase.NEW_CV = make_content_view({u"organization-id": ContentHostTestCase.NEW_ORG["id"]}) cv_id = ContentHostTestCase.NEW_CV["id"] ContentView.publish({u"id": cv_id}) version_id = ContentView.version_list({u"content-view-id": cv_id})[0]["id"] ContentView.version_promote( { u"id": version_id, u"to-lifecycle-environment-id": ContentHostTestCase.NEW_LIFECYCLE["id"], u"organization-id": ContentHostTestCase.NEW_ORG["id"], } ) ContentHostTestCase.PROMOTED_CV = ContentHostTestCase.NEW_CV
def test_positive_update_aks_to_chost(self): """@Test: Check if multiple Activation keys can be attached to a Content host @Feature: Activation key - Content host @Assert: Multiple Activation keys are attached to a Content host """ env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) new_aks = [ make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) for _ in range(2) ] with VirtualMachine(distro='rhel65') as vm: vm.install_katello_ca() for i in range(2): result = vm.register_contenthost( new_aks[i]['name'], self.org['label']) self.assertEqual(result.return_code, 0)
def test_positive_update_name(self): """Create lifecycle environment then update its name :id: de67a44e-6c6a-430e-927b-4fa43c7c2771 :expectedresults: Lifecycle environment name is updated :CaseImportance: Critical """ new_lce = make_lifecycle_environment({ 'organization-id': self.org['id'], }) for new_name in valid_data_list(): with self.subTest(new_name): LifecycleEnvironment.update({ 'id': new_lce['id'], 'new-name': new_name, 'organization-id': self.org['id'], }) result = LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'], }) self.assertGreater(len(result), 0) self.assertEqual(result['name'], new_name)
def setUpClass(cls): """Tests for Content Host via Hammer CLI""" super(ContentHostTestCase, cls).setUpClass() ContentHostTestCase.NEW_ORG = make_org(cached=True) ContentHostTestCase.NEW_LIFECYCLE = make_lifecycle_environment( {u'organization-id': ContentHostTestCase.NEW_ORG['id']}, cached=True ) ContentHostTestCase.LIBRARY = LifecycleEnvironment.info({ u'organization-id': ContentHostTestCase.NEW_ORG['id'], u'name': u'Library', }) ContentHostTestCase.DEFAULT_CV = ContentView.info({ u'organization-id': ContentHostTestCase.NEW_ORG['id'], u'name': u'Default Organization View', }) ContentHostTestCase.NEW_CV = make_content_view({ u'organization-id': ContentHostTestCase.NEW_ORG['id'], }) cv_id = ContentHostTestCase.NEW_CV['id'] ContentView.publish({u'id': cv_id}) version_id = ContentView.version_list({ u'content-view-id': cv_id, })[0]['id'] ContentView.version_promote({ u'id': version_id, u'to-lifecycle-environment-id': ContentHostTestCase.NEW_LIFECYCLE[ 'id' ], u'organization-id': ContentHostTestCase.NEW_ORG['id'] }) ContentHostTestCase.PROMOTED_CV = ContentHostTestCase.NEW_CV
def test_positive_update_description(self): """Create lifecycle environment then update its description :id: 15b82949-3c3a-4942-b42b-db1de34cf5be :expectedresults: Lifecycle environment description is updated :CaseImportance: Critical """ new_lce = make_lifecycle_environment({ 'organization-id': self.org['id'], }) for new_desc in valid_data_list(): with self.subTest(new_desc): LifecycleEnvironment.update({ 'description': new_desc, 'id': new_lce['id'], 'organization-id': self.org['id'], }) result = LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'], }) self.assertGreater(len(result), 0) self.assertEqual(result['description'], new_desc)
def test_positive_update_description(self): """Create lifecycle environment then update its description :id: 15b82949-3c3a-4942-b42b-db1de34cf5be :expectedresults: Lifecycle environment description is updated :CaseImportance: Critical """ new_lce = make_lifecycle_environment( {'organization-id': self.org['id']}) for new_desc in valid_data_list(): with self.subTest(new_desc): LifecycleEnvironment.update({ 'description': new_desc, 'id': new_lce['id'], 'organization-id': self.org['id'], }) result = LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'] }) self.assertGreater(len(result), 0) self.assertEqual(result['description'], new_desc)
def test_positive_delete_1(self, test_data): """ @Test: Create lifecycle environment with valid name, prior to Library @Feature: Lifecycle Environment @Assert: Lifecycle environment is deleted """ payload = {"organization-id": self.org["label"], "name": test_data["name"]} new_obj = make_lifecycle_environment(payload) self.assertIsNotNone(new_obj, "Could not create lifecycle environment.") # Can we find the new object result = LifecycleEnvironment.info({"organization-id": self.org["label"], "id": new_obj["id"]}) self.assertEqual(result.return_code, 0, "Could find the lifecycle environment") self.assertEqual(len(result.stderr), 0, "There should not be an error here.") self.assertGreater(len(result.stdout), 0, "No output was returned") self.assertEqual( new_obj["name"], result.stdout["name"], "Could not find lifecycle environment '%s'" % new_obj["name"] ) # Delete the lifecycle environment result = LifecycleEnvironment.delete({"id": new_obj["id"]}) self.assertEqual(result.return_code, 0, "Could find the lifecycle environment") self.assertEqual(len(result.stderr), 0, "There should not be an error here.") # Can we find the object result = LifecycleEnvironment.info({"organization-id": self.org["label"], "id": new_obj["id"]}) self.assertGreater(result.return_code, 0, "Should not find the lifecycle environment") self.assertGreater(len(result.stderr), 0, "There should be an error here")
def test_positive_update_lce(self): """@Test: Update Environment in an Activation key @Feature: Activation key - Positive Update @Assert: Activation key is updated """ ak_env = self._make_activation_key({ u'lifecycle-environment-id': self.get_default_env()['id'], }) env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) ActivationKey.update({ u'id': ak_env['id'], u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': ak_env['id']}) self.assertEqual(updated_ak['lifecycle-environment'], env['name'])
def test_positive_update_2(self, test_data): """ @Test: Create lifecycle environment then update its description @Feature: Lifecycle Environment @Assert: Lifecycle environment description is updated """ payload = {"organization-id": self.org["label"]} new_obj = make_lifecycle_environment(payload) self.assertIsNotNone(new_obj, "Could not create lifecycle environment.") # Update its description result = LifecycleEnvironment.update( {"organization-id": self.org["label"], "id": new_obj["id"], "description": test_data["description"]} ) self.assertEqual(result.return_code, 0, "Could find the lifecycle environment") self.assertEqual(len(result.stderr), 0, "There should not be an error here.") # Fetch the object result = LifecycleEnvironment.info({"organization-id": self.org["label"], "id": new_obj["id"]}) self.assertEqual(result.return_code, 0, "Could find the lifecycle environment") self.assertEqual(len(result.stderr), 0, "There should not be an error here.") self.assertGreater(len(result.stdout), 0, "No output was returned") self.assertEqual(test_data["description"], result.stdout["description"], "Description was not updated") self.assertNotEqual( new_obj["description"], result.stdout["description"], "Description should have been updated" )
def setup_content(request): """Pytest fixture for setting up an organization, manifest, content-view, lifecycle environment, and activation key with subscriptions""" org = make_org() with manifests.clone() as manifest: upload_file(manifest.content, manifest.filename) new_product = make_product({'organization-id': org['id']}) new_repo = make_repository({'product-id': new_product['id']}) Repository.synchronize({'id': new_repo['id']}) content_view = make_content_view({'organization-id': org['id']}) ContentView.add_repository( {'id': content_view['id'], 'organization-id': org['id'], 'repository-id': new_repo['id']} ) ContentView.publish({'id': content_view['id']}) env = make_lifecycle_environment({'organization-id': org['id']}) cvv = ContentView.info({'id': content_view['id']})['versions'][0] ContentView.version_promote({'id': cvv['id'], 'to-lifecycle-environment-id': env['id']}) new_ak = make_activation_key( { 'lifecycle-environment-id': env['id'], 'content-view': content_view['name'], 'organization-id': org['id'], 'auto-attach': False, } ) subs_id = Subscription.list({'organization-id': org['id']}, per_page=False) ActivationKey.add_subscription({'id': new_ak['id'], 'subscription-id': subs_id[0]['id']}) request.cls.setup_org = org request.cls.setup_new_ak = new_ak request.cls.setup_subs_id = subs_id request.cls.setup_env = env request.cls.setup_content_view = content_view
def test_positive_update_aks_to_chost(self): """Check if multiple Activation keys can be attached to a Content host @Feature: Activation key - Content host @Assert: Multiple Activation keys are attached to a Content host """ env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) new_aks = [ make_activation_key({ u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) for _ in range(2) ] with VirtualMachine(distro='rhel65') as vm: vm.install_katello_ca() for i in range(2): result = vm.register_contenthost( new_aks[i]['name'], self.org['label']) self.assertEqual(result.return_code, 0)
def test_positive_update_aks_to_chost(self): """Check if multiple Activation keys can be attached to a Content host @Feature: Activation key - Content host @Assert: Multiple Activation keys are attached to a Content host """ env = make_lifecycle_environment({u"organization-id": self.org["id"]}) new_cv = make_content_view({u"organization-id": self.org["id"]}) ContentView.publish({u"id": new_cv["id"]}) cvv = ContentView.info({u"id": new_cv["id"]})["versions"][0] ContentView.version_promote({u"id": cvv["id"], u"to-lifecycle-environment-id": env["id"]}) new_aks = [ make_activation_key( { u"lifecycle-environment-id": env["id"], u"content-view": new_cv["name"], u"organization-id": self.org["id"], } ) for _ in range(2) ] with VirtualMachine(distro="rhel65") as vm: vm.install_katello_ca() for i in range(2): result = vm.register_contenthost(new_aks[i]["name"], self.org["label"]) self.assertEqual(result.return_code, 0)
def test_positive_update_lce(self): """Update Environment in an Activation key :id: 55aaee60-b8c8-49f0-995a-6c526b9b653b :expectedresults: Activation key is updated :CaseLevel: Integration """ ak_env = self._make_activation_key({ u'lifecycle-environment-id': self.get_default_env()['id'], }) env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_cv = make_content_view({u'organization-id': self.org['id']}) ContentView.publish({u'id': new_cv['id']}) cvv = ContentView.info({u'id': new_cv['id']})['versions'][0] ContentView.version_promote({ u'id': cvv['id'], u'to-lifecycle-environment-id': env['id'], }) ActivationKey.update({ u'id': ak_env['id'], u'lifecycle-environment-id': env['id'], u'content-view': new_cv['name'], u'organization-id': self.org['id'], }) updated_ak = ActivationKey.info({'id': ak_env['id']}) self.assertEqual(updated_ak['lifecycle-environment'], env['name'])
def setUp(self): """Tests for Host Collections via Hammer CLI""" super(HostCollectionTestCase, self).setUp() if HostCollectionTestCase.org is None: HostCollectionTestCase.org = make_org(cached=True) if HostCollectionTestCase.new_lifecycle is None: HostCollectionTestCase.new_lifecycle = make_lifecycle_environment( {u"organization-id": HostCollectionTestCase.org["id"]}, cached=True ) if HostCollectionTestCase.library is None: HostCollectionTestCase.library = LifecycleEnvironment.info( {u"organization-id": HostCollectionTestCase.org["id"], u"name": ENVIRONMENT} ) if HostCollectionTestCase.default_cv is None: HostCollectionTestCase.default_cv = ContentView.info( {u"organization-id": HostCollectionTestCase.org["id"], u"name": DEFAULT_CV} ) if HostCollectionTestCase.new_cv is None: HostCollectionTestCase.new_cv = make_content_view({u"organization-id": HostCollectionTestCase.org["id"]}) HostCollectionTestCase.promoted_cv = None cv_id = HostCollectionTestCase.new_cv["id"] ContentView.publish({u"id": cv_id}) result = ContentView.version_list({u"content-view-id": cv_id}) version_id = result[0]["id"] ContentView.version_promote( { u"id": version_id, u"organization-id": HostCollectionTestCase.org["id"], u"to-lifecycle-environment-id": (HostCollectionTestCase.new_lifecycle["id"]), } ) HostCollectionTestCase.promoted_cv = HostCollectionTestCase.new_cv
def setUp(self): """ Tests for Content Host via Hammer CLI """ super(TestContentHost, self).setUp() if TestContentHost.NEW_ORG is None: TestContentHost.NEW_ORG = make_org() if TestContentHost.NEW_LIFECYCLE is None: TestContentHost.NEW_LIFECYCLE = make_lifecycle_environment( {u'organization-id': TestContentHost.NEW_ORG['id']} ) if TestContentHost.LIBRARY is None: library_result = LifecycleEnvironment.info( {u'organization-id': TestContentHost.NEW_ORG['id'], u'name': u'Library'} ) TestContentHost.LIBRARY = library_result.stdout if TestContentHost.DEFAULT_CV is None: cv_result = ContentView.info( {u'organization-id': TestContentHost.NEW_ORG['id'], u'name': u'Default Organization View'} ) TestContentHost.DEFAULT_CV = cv_result.stdout
def test_positive_delete_by_id(self): """Create lifecycle environment with valid name, prior to Library @Feature: Lifecycle Environment @Assert: Lifecycle environment is deleted """ for name in valid_data_list(): with self.subTest(name): new_lce = make_lifecycle_environment({ 'name': name, 'organization-id': self.org['id'], }) LifecycleEnvironment.delete({'id': new_lce['id']}) with self.assertRaises(CLIReturnCodeError): LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'], })
def setUp(self): """ Tests for content-view via Hammer CLI """ super(TestSubscription, self).setUp() if TestSubscription.org is None: TestSubscription.org = make_org() if TestSubscription.env1 is None: TestSubscription.env1 = make_lifecycle_environment( {u'organization-id': TestSubscription.org['id']}) if TestSubscription.env2 is None: TestSubscription.env2 = make_lifecycle_environment( {u'organization-id': TestSubscription.org['id'], u'prior': TestSubscription.env1['label']})
def test_positive_update_unauthenticated_pull(self): """Create lifecycle environment and then update registry's unauthenticated pull :id: 8b73e0b7-30c9-4211-87a4-53dc0b0f3e21 :expectedresults: Lifecycle environment registry's unauthenticated pull is updated :CaseImportance: Critical """ lce = make_lifecycle_environment({'organization-id': self.org['id']}) LifecycleEnvironment.update({ 'registry-unauthenticated-pull': 'true', 'id': lce['id'], 'organization-id': self.org['id'], }) result = LifecycleEnvironment.info({ 'id': lce['id'], 'organization-id': self.org['id'] }) self.assertGreater(len(result), 0) self.assertEqual(result['unauthenticated-pull'], 'true')
def test_positive_create_with_description(self): """Create lifecycle environment with valid description prior to Library :id: 714c42f8-d09e-4e48-9f35-bbc25fe9e229 :expectedresults: Lifecycle environment is created with Library as prior """ for desc in valid_data_list(): name = gen_alphanumeric() with self.subTest(desc): lc_env = make_lifecycle_environment({ 'description': desc, 'name': name, 'organization-id': self.org['id'] }) self.assertEqual(lc_env['name'], name) self.assertEqual(lc_env['description'], desc) self.assertEqual(lc_env['prior-lifecycle-environment'], ENVIRONMENT)
def test_positive_update_name(self): """Create lifecycle environment then update its name :id: de67a44e-6c6a-430e-927b-4fa43c7c2771 :expectedresults: Lifecycle environment name is updated :CaseImportance: Critical """ new_lce = make_lifecycle_environment( {'organization-id': self.org['id']}) for new_name in valid_data_list(): with self.subTest(new_name): LifecycleEnvironment.update({ 'id': new_lce['id'], 'new-name': new_name, 'organization-id': self.org['id'] }) result = LifecycleEnvironment.info({ 'id': new_lce['id'], 'organization-id': self.org['id'] }) self.assertGreater(len(result), 0) self.assertEqual(result['name'], new_name)
def setup_content_view(self, org_id, lce_id=None): # type: (int, int) -> Tuple[Dict, Dict] """Setup organization content view by adding all the repositories, publishing and promoting to lce if needed. """ if lce_id is None: lce = make_lifecycle_environment({'organization-id': org_id}) else: lce = LifecycleEnvironment.info({ 'id': lce_id, 'organization-id': org_id, }) content_view = make_content_view({'organization-id': org_id}) # Add repositories to content view for repo in self: repo.add_to_content_view(org_id, content_view['id']) # Publish the content view ContentView.publish({'id': content_view['id']}) if lce['name'] != ENVIRONMENT: # Get the latest content view version id content_view_version = ContentView.info({ 'id': content_view['id'] })['versions'][-1] # Promote content view version to lifecycle environment ContentView.version_promote({ 'id': content_view_version['id'], 'organization-id': org_id, 'to-lifecycle-environment-id': lce['id'], }) content_view = ContentView.info({'id': content_view['id']}) return content_view, lce
def test_positive_lce_crud(module_org): """CRUD test case for lifecycle environment for name, description, label, registry name pattern, and unauthenticated pull :id: 6b0fbf4f-528c-4983-bc3f-e81ccb7438fd :expectedresults: Lifecycle environment is created, read, updated, and deleted successfull :CaseImportance: High """ name = gen_string('alpha') new_name = gen_string('alpha') desc = gen_string('alpha') new_desc = gen_string('alpha') label = gen_string('alpha') org_name = module_org.name registry_name_pattern = ( "{}-<%= organization.label %>/<%= repository.docker_upstream_name %>" ).format(gen_string('alpha', 5)) # create lce = make_lifecycle_environment({ 'organization': org_name, 'organization-id': module_org.id, 'name': name, 'label': label, 'description': desc, }) assert lce['prior-lifecycle-environment'] == ENVIRONMENT assert lce['name'] == name assert lce['description'] == desc assert lce['label'] == label assert lce['organization'] == org_name # update LifecycleEnvironment.update({ 'id': lce['id'], 'new-name': new_name, 'description': new_desc, 'registry-unauthenticated-pull': 'true', 'registry-name-pattern': registry_name_pattern, }) lce = LifecycleEnvironment.info({ 'id': lce['id'], 'organization-id': module_org.id }) assert lce['name'] == new_name assert lce['registry-name-pattern'] == registry_name_pattern assert lce['unauthenticated-pull'] == 'true' # delete LifecycleEnvironment.delete({'id': lce['id']}) with pytest.raises(CLIReturnCodeError): LifecycleEnvironment.info({ 'id': lce['id'], 'organization-id': module_org.id })
def setUp(self): """ Tests for content-view via Hammer CLI """ super(TestSubscription, self).setUp() if TestSubscription.org is None: TestSubscription.org = make_org() if TestSubscription.env1 is None: TestSubscription.env1 = make_lifecycle_environment( {u'organization-id': TestSubscription.org['id']}) if TestSubscription.env2 is None: TestSubscription.env2 = make_lifecycle_environment({ u'organization-id': TestSubscription.org['id'], u'prior': TestSubscription.env1['label'] })
def setUpClass(cls): """Create organization and lifecycle environments to reuse in tests""" super().setUpClass() cls.lces_count = 25 cls.org = make_org() env_base_name = gen_string('alpha') last_env_name = ENVIRONMENT cls.env_names = [last_env_name] for env_index in range(cls.lces_count): env_name = f'{env_base_name}-{env_index}' make_lifecycle_environment({ 'name': env_name, 'organization-id': cls.org['id'], 'prior': last_env_name }) last_env_name = env_name cls.env_names.append(env_name) cls.lces_count += 1 # include default 'Library' lce
def test_positive_create_with_non_default_lce(self): """Create Activation key with associated custom environment @id: ad4d4611-3fb5-4449-ae47-305f9931350e @Assert: Activation key is created and associated to expected environment """ env = make_lifecycle_environment({u'organization-id': self.org['id']}) new_ak_env = self._make_activation_key({ u'lifecycle-environment-id': env['id'], }) self.assertEqual(new_ak_env['lifecycle-environment'], env['name'])
def test_positive_create_with_organization_name(self): """Create lifecycle environment, specifying organization name @Feature: Lifecycle Environment @Assert: Lifecycle environment is created for correct organization """ new_lce = make_lifecycle_environment({ 'name': gen_string('alpha'), 'organization': self.org['name'], }) self.assertEqual(new_lce['organization'], self.org['name'])