def enable_rhrepo_and_fetchid(basearch, org_id, product, repo, reposet, releasever): """Enable a RedHat Repository and fetches it's Id. :param str org_id: The organization Id. :param str product: The product name in which repository exists. :param str reposet: The reposet name in which repository exists. :param str repo: The repository name who's Id is to be fetched. :param str basearch: The architecture of the repository. :param str releasever: The releasever of the repository. :return: Returns the repository Id. :rtype: str """ prd_id = entities.Product().fetch_rhproduct_id(name=product, org_id=org_id) reposet_id = entities.Product(id=prd_id).fetch_reposet_id(name=reposet) task = entities.Product(id=prd_id).enable_rhrepo( base_arch=basearch, release_ver=releasever, reposet_id=reposet_id, ) if task['result'] != "success": raise entities.APIResponseError( 'Enabling the RedHat Repository {0} failed. Error: {1}'.format( repo, task['humanized']['errors'])) return entities.Repository().fetch_repoid(name=repo, org_id=org_id)
def test_positive_create_2(self): """@Test: Create a product and provide a GPG key. @Assert: A product is created with the specified GPG key. @Feature: Product """ # Create an organization, GPG key and product. # # * GPG key points to organization # * Product points to organization and GPG key # # Re-using an organization speeds up the test. org_attrs = entities.Organization().create() gpgkey_attrs = entities.GPGKey( content=read_data_file(VALID_GPG_KEY_FILE), organization=org_attrs['id'] ).create() product_attrs = entities.Product( gpg_key=gpgkey_attrs['id'], organization=org_attrs['id'] ).create() # GET the product and verify it's GPG key ID. attrs = entities.Product(id=product_attrs['id']).read_json() self.assertEqual(attrs['gpg_key_id'], gpgkey_attrs['id'])
def setUpClass(cls): """Create an organization and products which can be re-used in tests.""" cls.org_id = entities.Organization().create_json()['id'] cls.prod1_id = entities.Product( organization=cls.org_id).create_json()['id'] cls.prod2_id = entities.Product( organization=cls.org_id).create_json()['id'] super(SyncPlanSynchronizeTestCase, cls).setUpClass()
def test_positive_create_1(self, attrs): """@Test: Create a product and provide a name or description. @Assert: A product is created with the provided attributes. @Feature: Product """ prod_id = entities.Product(**attrs).create()['id'] prod_attrs = entities.Product(id=prod_id).read_json() for name, value in attrs.items(): self.assertIn(name, prod_attrs.keys()) self.assertEqual(value, prod_attrs[name])
def test_update_docker_repo_url(self, name): """@Test: Create a Docker-type repository and update its URL. @Assert: A repository is created with a Docker image and that its URL can be updated. @Feature: Docker """ new_url = gen_url(scheme='https') prod_id = entities.Product( organization=self.org_id).create_json()['id'] repo_id = _create_repository(prod_id, name)['id'] real_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(real_attrs['url'], DOCKER_REGISTRY_HUB) # Update the repository URL real_attrs['url'] = new_url client.put( entities.Repository(id=repo_id).path(), real_attrs, auth=get_server_credentials(), verify=False, ).raise_for_status() new_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(new_attrs['url'], new_url) self.assertNotEqual(new_attrs['url'], DOCKER_REGISTRY_HUB)
def test_positive_update_3(self, plan_name): """@Test: Update Sync plan and associate products @Feature: Content Sync Plan - Positive Update add products @Assert: Sync Plan has the associated product """ strategy, value = locators["sp.prd_select"] product_name = entities.Product( organization=self.org_id ).create()['name'] entities.Organization(id=self.org_id).sync_plan( name=plan_name, interval=SYNC_INTERVAL['week'] ) with Session(self.browser) as session: session.nav.go_to_select_org(self.org_name) session.nav.go_to_sync_plans() self.syncplan.update(plan_name, add_products=[product_name]) self.syncplan.search(plan_name).click() self.syncplan.wait_for_ajax() # Assert product is associated with sync plan self.syncplan.wait_until_element( tab_locators["sp.tab_products"]).click() self.syncplan.wait_for_ajax() element = self.syncplan.wait_until_element( (strategy, value % product_name)) self.assertIsNotNone(element)
def test_update_docker_repo_upstream_name(self, name): """@Test: Create a Docker-type repository and update its upstream name. @Assert: A repository is created with a Docker image and that its upstream name can be updated. @Feature: Docker @BZ: 1193669 """ upstream_name = u'busybox' new_upstream_name = u'fedora/ssh' content_type = u'docker' prod_id = entities.Product( organization=self.org_id).create_json()['id'] repo_id = _create_repository(prod_id, name, upstream_name)['id'] real_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(real_attrs['name'], name) self.assertEqual(real_attrs['docker_upstream_name'], upstream_name) self.assertEqual(real_attrs['content_type'], content_type) # Update the repository upstream name real_attrs['docker_upstream_name'] = new_upstream_name client.put( entities.Repository(id=repo_id).path(), real_attrs, auth=get_server_credentials(), verify=False, ).raise_for_status() new_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(new_attrs['docker_upstream_name'], new_upstream_name) self.assertNotEqual(new_attrs['name'], upstream_name)
def test_add_docker_repo_to_content_view(self, name): """@Test: Add one Docker-type repository to a non-composite content view @Assert: A repository is created with a Docker repository and the product is added to a non-composite content view @Feature: Docker """ upstream_name = u'busybox' prod_id = entities.Product( organization=self.org_id).create_json()['id'] repo_id = _create_repository(prod_id, name, upstream_name)['id'] real_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(real_attrs['name'], name) self.assertEqual(real_attrs['docker_upstream_name'], upstream_name) self.assertEqual(real_attrs['content_type'], u'docker') # Create content view and associate docker repo content_view = entities.ContentView(organization=self.org_id, composite=False).create_json() _add_repo_to_content_view(repo_id, content_view['id']) new_attrs = entities.ContentView(id=content_view['id']).read_json() self.assertIn(repo_id, new_attrs['repository_ids'])
def test_positive_update_3(self, repo_name): """@Test: Update content repository with new checksum type @Feature: Content Repo - Positive Update of checksum type. @Assert: Repo is updated with new checksum type. """ locator = locators["repo.fetch_checksum"] checksum_default = CHECKSUM_TYPE['default'] checksum_update = CHECKSUM_TYPE['sha1'] # Creates new product product_name = entities.Product(organization=self.org_id, location=self.loc_id).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, url=FAKE_1_YUM_REPO) self.assertIsNotNone(self.repository.search(repo_name)) self.repository.search(repo_name).click() self.repository.wait_for_ajax() checksum_text = self.repository.wait_until_element(locator).text self.assertEqual(checksum_text, checksum_default) self.navigator.go_to_products() self.products.search(product_name).click() self.repository.update(repo_name, new_repo_checksum=checksum_update) checksum_text = self.repository.wait_until_element(locator).text self.assertEqual(checksum_text, checksum_update)
def test_positive_update_1(self, repo_name): """@Test: Update content repository with new URL @Feature: Content Repo - Positive Update @Assert: Repo is updated with new url """ locator = locators["repo.fetch_url"] # Creates new product product_name = entities.Product(organization=self.org_id, location=self.loc_id).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, url=FAKE_1_YUM_REPO) self.assertIsNotNone(self.repository.search(repo_name)) self.repository.search(repo_name).click() self.repository.wait_for_ajax() url_text = self.repository.wait_until_element(locator).text self.assertEqual(url_text, FAKE_1_YUM_REPO) self.navigator.go_to_products() self.products.search(product_name).click() self.repository.update(repo_name, new_url=FAKE_2_YUM_REPO) url_text = self.repository.wait_until_element(locator).text self.assertEqual(url_text, FAKE_2_YUM_REPO)
def test_negative_create_2(self, repo_name): """@Test: Create repository with same name @Feature: Content Repos - Negative Create with same name @Assert: Repos is not created """ # Creates new product product_name = entities.Product(organization=self.org_id, location=self.loc_id).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, url=FAKE_1_YUM_REPO) self.assertIsNotNone(self.repository.search(repo_name)) make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, url=FAKE_1_YUM_REPO) invalid = self.products.wait_until_element( common_locators["common_invalid"]) self.assertTrue(invalid)
def test_create_repo_5(self, repo_name): """@Test: Create repository with checksum type as sha256. @Feature: Content Repos - Positive Create @Assert: Repos is created with checksum type as sha256. """ locator = locators['repo.fetch_checksum'] checksum = CHECKSUM_TYPE[u'sha256'] # Creates new product product_name = entities.Product( organization=self.org_id, location=self.loc_id, ).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, url=FAKE_1_YUM_REPO, repo_checksum=checksum) self.repository.search(repo_name).click() self.repository.wait_for_ajax() checksum_text = session.nav.wait_until_element(locator).text self.assertEqual(checksum_text, checksum)
def test_create_repo_4(self): """@Test: Create and sync a Docker-based repository @Feature: Content Repos - Positive Create @Assert: Docker-based repo is created and synchronized. """ # Creates new product repo_name = u'busybox' product_name = entities.Product( organization=self.org_id, location=self.loc_id, ).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, repo_type=REPO_TYPE['docker'], url=DOCKER_REGISTRY_HUB) self.assertIsNotNone(self.repository.search(repo_name)) # Synchronize it self.navigator.go_to_sync_status() synced = self.sync.sync_custom_repos(product_name, [repo_name]) self.assertTrue(synced)
def test_publish_once_docker_repo_content_view(self): """@Test: Add Docker-type repository to content view and publish it once. @Assert: One repository is created with a Docker image and the product is added to a content view which is then published only once. @Feature: Docker """ prod_id = entities.Product( organization=self.org_id).create_json()['id'] repo_id = _create_repository(prod_id)['id'] content_view = entities.ContentView(organization=self.org_id, composite=False).create_json() _add_repo_to_content_view(repo_id, content_view['id']) new_attrs = entities.ContentView(id=content_view['id']).read_json() self.assertIn(repo_id, new_attrs['repository_ids']) # Not published yet? self.assertIsNone(new_attrs['last_published']) self.assertEqual(new_attrs['next_version'], 1) # Publish it... self.assertTrue(_publish_content_view(content_view['id'])) # ... and check that it was indeed published new_attrs = entities.ContentView(id=content_view['id']).read_json() self.assertIsNotNone(new_attrs['last_published']) self.assertGreater(new_attrs['next_version'], 1)
def test_create_multiple_docker_repo_multiple_products(self): """@Test: Create multiple Docker-type repositories on multiple products. @Assert: Multiple docker repositories are created with a Docker image and they all belong to their respective products. @Feature: Docker """ for _ in range(randint(1, 5)): prod_id = entities.Product( organization=self.org_id).create_json()['id'] for _ in range(randint(1, 3)): repo_id = _create_repository(prod_id)['id'] prod_attrs = entities.Product(id=prod_id).read_json() self.assertIn( repo_id, [repo['id'] for repo in prod_attrs['repositories']], )
def test_create_repo_2(self, repo_name): """@Test: Create repository in two different orgs with same name @Assert: Repos is created @Feature: Content Repos - Positive Create """ org_2_name = gen_string("alpha", 10) # Creates new product_1 product_1_name = entities.Product( organization=self.org_id, location=self.loc_id, ).create()['name'] # Create new product_2 under new organization_2 org_2_id = entities.Organization(name=org_2_name).create()['id'] product_2_name = entities.Product( organization=org_2_id, location=self.loc_id, ).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_1_name, url=FAKE_1_YUM_REPO) self.assertIsNotNone(self.repository.search(repo_name)) make_repository(session, org=org_2_name, loc=self.loc_name, name=repo_name, product=product_2_name, url=FAKE_1_YUM_REPO, force_context=True) self.assertIsNotNone(self.repository.search(repo_name))
def test_create_one_docker_repo(self, name): """@Test: Create one Docker-type repository @Assert: A repository is created with a Docker image. @Feature: Docker """ prod_id = entities.Product( organization=self.org_id).create_json()['id'] repo_id = _create_repository(prod_id, name)['id'] real_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(real_attrs['name'], name) self.assertEqual(real_attrs['docker_upstream_name'], u'busybox') self.assertEqual(real_attrs['content_type'], u'docker')
def test_add_multiple_docker_repos_to_composite_content_view(self): """@Test: Add multiple Docker-type repositories to a composite content view. @Assert: One repository is created with a Docker image and the product is added to a random number of content views which are then added to a composite content view. @Feature: Docker """ prod_ids = [] cv_version_ids = [] for _ in range(randint(1, 5)): prod_ids.append( entities.Product(organization=self.org_id).create_json()['id']) for prod_id in prod_ids: repo_id = _create_repository(prod_id)['id'] # Create content view and associate docker repo content_view = entities.ContentView(organization=self.org_id, composite=False).create_json() _add_repo_to_content_view(repo_id, content_view['id']) new_attrs = entities.ContentView(id=content_view['id']).read_json() self.assertIn(repo_id, new_attrs['repository_ids']) # Publish it... self.assertTrue(_publish_content_view(content_view['id'])) # ... and grab its version ID (there should only be one version) new_attrs = entities.ContentView(id=content_view['id']).read_json() cv_version_ids.append(new_attrs['versions'][0]['id']) # Create composite content view and associate content view to # it comp_content_view_id = entities.ContentView( organization=self.org_id, composite=True).create_json()['id'] for version_id in cv_version_ids: _add_content_view_to_composite_view(comp_content_view_id, version_id) new_attrs = entities.ContentView( id=comp_content_view_id).read_json() self.assertIn(version_id, new_attrs['component_ids'])
def test_sync_docker_repo(self): """@Test: Create and sync a Docker-type repository @Assert: A repository is created with a Docker repository and it is synchronized. @Feature: Docker """ prod_id = entities.Product( organization=self.org_id).create_json()['id'] repo_id = _create_repository(prod_id)['id'] task = entities.Repository(id=repo_id).sync() self.assertEqual(u'success', task['result'], task) attrs = entities.Repository(id=repo_id).read_json() self.assertGreaterEqual(attrs[u'content_counts'][u'docker_image'], 1)
def setup_to_create_cv(self, repo_name=None, repo_url=None, repo_type=None, rh_repo=None, org_id=None): """Create product/repo and sync it""" if not rh_repo: repo_name = repo_name or gen_string("alpha", 8) # Creates new custom product via API's product_attrs = entities.Product( organization=org_id or self.org_id).create() # Creates new custom repository via API's repo_attrs = entities.Repository( name=repo_name, url=(repo_url or FAKE_1_YUM_REPO), content_type=(repo_type or REPO_TYPE['yum']), product=product_attrs['id'], ).create() repo_id = repo_attrs['id'] elif rh_repo: # Clone the manifest and fetch it's path. manifest_path = manifests.clone() # Uploads the manifest and returns the result. task = entities.Organization(id=org_id).upload_manifest( path=manifest_path) self.assertEqual(u'success', task['result'], task['humanized']['errors']) # Enables the RedHat repo and fetches it's Id. repo_id = utils.enable_rhrepo_and_fetchid( rh_repo['basearch'], str(org_id), # Org Id is passed as data in API hence str rh_repo['product'], rh_repo['name'], rh_repo['reposet'], rh_repo['releasever']) repo_name = rh_repo['name'] # Sync repository task_result = entities.Repository(id=repo_id).sync()['result'] self.assertEqual(task_result, u'success', u"Sync for repository {0} failed.".format(repo_name))
def test_discover_repo_1(self): """@Test: Create repository via repo-discovery under existing product @Feature: Content Repos - Discover repo via http URL @Assert: Repos is discovered and created """ discovered_urls = "fakerepo01/" product_name = entities.Product(organization=self.org_id, location=self.loc_id).create()['name'] with Session(self.browser) as session: session.nav.go_to_select_org(self.org_name) session.nav.go_to_products() self.repository.discover_repo(url_to_discover=REPO_DISCOVERY_URL, discovered_urls=[discovered_urls], product=product_name)
def test_syncnow_custom_repos_1(self, repository_name): """@Test: Create Custom yum repos and sync it via the repos page. @Feature: Custom yum Repos - Sync via repos page @Assert: Whether Sync is successful """ # Creates new product product_attrs = entities.Product(organization=self.org_id).create() # Creates new repository entities.Repository(name=repository_name, url=FAKE_1_YUM_REPO, product=product_attrs['id']).create() with Session(self.browser) as session: self.setup_navigate_syncnow(session, product_attrs['name'], repository_name) # prd_sync_is_ok returns boolean values and not objects self.assertTrue(self.prd_sync_is_ok(repository_name))
def test_positive_update_4(self, plan_name): """@Test: Update Sync plan and disassociate products @Feature: Content Sync Plan - Positive Update remove products @Assert: Sync Plan does not have the associated product """ strategy, value = locators["sp.prd_select"] product_name = entities.Product( organization=self.org_id ).create()['name'] entities.Organization(id=self.org_id).sync_plan( name=plan_name, interval=SYNC_INTERVAL['week'] ) with Session(self.browser) as session: session.nav.go_to_select_org(self.org_name) session.nav.go_to_sync_plans() self.syncplan.update(plan_name, add_products=[product_name]) self.syncplan.search(plan_name).click() self.syncplan.wait_for_ajax() self.syncplan.wait_until_element( tab_locators["sp.tab_products"]).click() self.syncplan.wait_for_ajax() element = self.syncplan.wait_until_element( (strategy, value % product_name)) self.assertIsNotNone(element) # Dis-associate the product from sync plan and the selected product # should automatically move from 'List/Remove` tab to 'Add' tab self.syncplan.update(plan_name, rm_products=[product_name]) self.syncplan.search(plan_name).click() self.syncplan.wait_for_ajax() self.syncplan.wait_until_element( tab_locators["sp.tab_products"]).click() self.syncplan.wait_for_ajax() self.syncplan.wait_until_element( tab_locators["sp.add_prd"]).click() self.syncplan.wait_for_ajax() element = self.syncplan.wait_until_element( (strategy, value % product_name)) self.assertIsNotNone(element)
def setUpClass(cls): # noqa """Set up organization, product and repositories for tests.""" super(CVPublishPromoteTestCase, cls).setUpClass() cls.org = entities.Organization() cls.org.id = cls.org.create_json()['id'] cls.product = entities.Product(organization=cls.org.id) cls.product.id = cls.product.create_json()['id'] cls.yum_repo = entities.Repository(product=cls.product.id) cls.yum_repo.id = cls.yum_repo.create_json()['id'] cls.yum_repo.sync() cls.puppet_repo = entities.Repository( content_type='puppet', product=cls.product.id, ) cls.puppet_repo.id = cls.puppet_repo.create_json()['id'] cls.puppet_repo.upload(PUPPET_MODULE_NTP_PUPPETLABS)
def test_sync_docker_repo(self): """@Test: Create and sync a Docker-type repository @Assert: A repository is created with a Docker repository and it is synchronized. @Feature: Repository """ prod_id = entities.Product(organization=self.org_id).create()['id'] repo_id = entities.Repository(product=prod_id, content_type=u'docker', name=u'busybox', docker_upstream_name=u'busybox', url=DOCKER_REGISTRY_HUB).create()['id'] task_result = entities.Repository(id=repo_id).sync()['result'] self.assertEqual(u'success', task_result) attrs = entities.Repository(id=repo_id).read_json() self.assertGreaterEqual(attrs[u'content_counts'][u'docker_image'], 1)
def test_positive_update_2(self, repo_name): """@Test: Update content repository with new gpg-key @Feature: Content Repo - Positive Update @Assert: Repo is updated with new gpg key """ key_1_content = read_data_file(VALID_GPG_KEY_FILE) key_2_content = read_data_file(VALID_GPG_KEY_BETA_FILE) locator = locators["repo.fetch_gpgkey"] # Create two new GPGKey's gpgkey_1_name = entities.GPGKey(content=key_1_content, organization=self.org_id, location=self.loc_id).create()['name'] gpgkey_2_name = entities.GPGKey(content=key_2_content, organization=self.org_id, location=self.loc_id).create()['name'] # Creates new product product_name = entities.Product(organization=self.org_id, location=self.loc_id).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, url=FAKE_1_YUM_REPO, gpg_key=gpgkey_1_name) self.assertIsNotNone(self.repository.search(repo_name)) self.repository.search(repo_name).click() self.repository.wait_for_ajax() gpgkey_1_text = self.repository.wait_until_element(locator).text self.assertEqual(gpgkey_1_text, gpgkey_1_name) self.navigator.go_to_products() self.products.search(product_name).click() self.repository.update(repo_name, new_gpg_key=gpgkey_2_name) gpgkey_2_text = self.repository.wait_until_element(locator).text self.assertEqual(gpgkey_2_text, gpgkey_2_name)
def test_create_repo_1(self, repo_name): """@Test: Create repository with minimal input parameters @Feature: Content Repos - Positive Create @Assert: Repos is created """ # Creates new product product_name = entities.Product( organization=self.org_id, location=self.loc_id, ).create()['name'] with Session(self.browser) as session: make_repository(session, org=self.org_name, loc=self.loc_name, name=repo_name, product=product_name, url=FAKE_1_YUM_REPO) self.assertIsNotNone(self.repository.search(repo_name))
def test_create_docker_repo(self, name): """@Test: Create a Docker-type repository @Assert: A repository is created with a Docker repository. @Feature: Repository """ upstream_name = u'busybox' content_type = u'docker' prod_id = entities.Product(organization=self.org_id).create()['id'] repo_id = entities.Repository(product=prod_id, content_type=content_type, name=name, docker_upstream_name=upstream_name, url=DOCKER_REGISTRY_HUB).create()['id'] real_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(real_attrs['name'], name) self.assertEqual(real_attrs['docker_upstream_name'], upstream_name) self.assertEqual(real_attrs['content_type'], content_type)
def test_delete_docker_repo(self, name): """@Test: Create and delete a Docker-type repository @Assert: A repository is created with a Docker image and then deleted. @Feature: Docker """ upstream_name = u'busybox' prod_id = entities.Product( organization=self.org_id).create_json()['id'] repo_id = _create_repository(prod_id, name, upstream_name)['id'] real_attrs = entities.Repository(id=repo_id).read_json() self.assertEqual(real_attrs['name'], name) self.assertEqual(real_attrs['docker_upstream_name'], upstream_name) self.assertEqual(real_attrs['content_type'], u'docker') # Delete it entities.Repository(id=repo_id).delete() with self.assertRaises(HTTPError): entities.Repository(id=repo_id).read_json()
def test_sync_custom_repos(self, repository_name): """@Test: Create Content Custom Sync with minimal input parameters @Feature: Content Custom Sync - Positive Create @Assert: Whether Sync is successful """ # Creates new product product_attrs = entities.Product(organization=self.org_id).create() # Creates new repository entities.Repository(name=repository_name, url=FAKE_1_YUM_REPO, product=product_attrs['id']).create() with Session(self.browser) as session: session.nav.go_to_select_org(Sync.org_name) session.nav.go_to_sync_status() sync = self.sync.sync_custom_repos(product_attrs['name'], [repository_name]) # syn.sync_custom_repos returns boolean values and not objects self.assertTrue(sync)