Example #1
0
    def test_redhat_sync_1(self):
        """@Test: Sync RedHat Repository.

        @Feature: Repositories

        @Assert: Repository synced should fetch the data successfully.

        """
        cloned_manifest_path = manifests.clone()
        org_id = entities.Organization().create()['id']
        repo = "Red Hat Enterprise Linux 6 Server - RH Common RPMs x86_64 6.3"
        task = entities.Organization(
            id=org_id).upload_manifest(path=cloned_manifest_path)
        self.assertEqual(
            u'success', task['result'], task['humanized']['errors']
        )
        repo_id = utils.enable_rhrepo_and_fetchid(
            "x86_64",
            org_id,
            "Red Hat Enterprise Linux Server",
            repo,
            "Red Hat Enterprise Linux 6 Server - RH Common (RPMs)",
            "6.3",
        )
        task_result = entities.Repository(id=repo_id).sync()['result']
        self.assertEqual(
            task_result,
            u'success',
            u"Sync for repository '{0}' failed.".format(repo))
Example #2
0
    def test_positive_delete_bz1225588(self, org_name):
        """@test: Create Organization with valid values and upload manifest.
        Then try to delete that organization.

        @feature: Organization Positive Delete Test.

        @assert: Organization is deleted successfully.

        """
        org = entities.Organization(name=org_name).create()
        with open(manifests.clone(), 'rb') as manifest:
            upload_manifest(org.id, manifest)
        with Session(self.browser) as session:
            make_lifecycle_environment(session, org_name, name='DEV')
            make_lifecycle_environment(
                session, org_name, name='QE', prior='DEV'
            )
            # Org cannot be deleted when selected,
            # So switching to Default Org and then deleting.
            session.nav.go_to_select_org('Default Organization')
            self.org.remove(org_name)
            status = self.org.search(org_name)
            if bz_bug_is_open(1251926):
                # Check for at max Five times, the org is deleted
                for _ in range(5):
                    status = self.org.search(org_name)
                    if status is None:
                        break
            self.assertIsNone(status)
Example #3
0
    def test_sync_rhrepos(self):
        """@Test: Create Content RedHat Sync with two repos.

        @Feature: Content RedHat Sync - Positive Create

        @Assert: Whether Syncing RedHat Repos is successful

        """

        repos = self.sync.create_repos_tree(RHCT)
        alert_loc = common_locators['alert.success']
        path = clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(path, remote_file=path)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            session.nav.go_to_red_hat_subscriptions()
            self.subscriptions.upload(path)
            success_ele = session.nav.wait_until_element(alert_loc)
            self.assertTrue(success_ele)
            session.nav.go_to_red_hat_repositories()
            self.sync.enable_rh_repos(repos)
            session.nav.go_to_sync_status()
            sync = self.sync.sync_rh_repos(repos)
            # syn.sync_rh_repos returns boolean values and not objects
            self.assertTrue(sync)
Example #4
0
    def test_redhat_sync_1(self):
        """@Test: Sync RedHat Repository.

        @Feature: Repositories

        @Assert: Repository synced should fetch the data successfully.

        """
        cloned_manifest_path = manifests.clone()
        org_id = entities.Organization().create()['id']
        repo = "Red Hat Enterprise Linux 6 Server - RH Common RPMs x86_64 6.3"
        task = entities.Organization(id=org_id).upload_manifest(
            path=cloned_manifest_path)
        self.assertEqual(u'success', task['result'],
                         task['humanized']['errors'])
        repo_id = utils.enable_rhrepo_and_fetchid(
            "x86_64",
            org_id,
            "Red Hat Enterprise Linux Server",
            repo,
            "Red Hat Enterprise Linux 6 Server - RH Common (RPMs)",
            "6.3",
        )
        task_result = entities.Repository(id=repo_id).sync()['result']
        self.assertEqual(task_result, u'success',
                         u"Sync for repository '{0}' failed.".format(repo))
Example #5
0
    def test_repositoryset_disable_by_id(self):
        """@Test: Disable repo from reposet by IDs of reposet, org and product

        @Feature: Repository-set

        @Assert: Repository was disabled

        """
        org = make_org()
        manifest = manifests.clone()
        upload_file(manifest, remote_file=manifest)
        result = Subscription.upload({
            u'file': manifest,
            u'organization-id': org['id'],
        })
        self.assertEqual(result.return_code, 0)
        product_id = Product.info({
            u'name': PRDS['rhel'],
            u'organization-id': org['id'],
        }).stdout['id']
        reposet_id = RepositorySet.info({
            u'name': REPOSET['rhva6'],
            u'organization-id': org['id'],
            u'product-id': product_id,
        }).stdout['id']
        result = RepositorySet.enable({
            u'id': reposet_id,
            u'organization-id': org['id'],
            u'product-id': product_id,
            u'releasever': '6Server',
            u'basearch': 'x86_64',
        })
        self.assertEqual(result.return_code, 0)
        result = RepositorySet.disable({
            u'id': reposet_id,
            u'organization-id': org['id'],
            u'product-id': product_id,
            u'releasever': '6Server',
            u'basearch': 'x86_64',
        })
        self.assertEqual(result.return_code, 0)
        result = RepositorySet.available_repositories({
            u'id': reposet_id,
            u'organization-id': org['id'],
            u'product-id': product_id,
        })
        self.assertEqual(result.return_code, 0)
        enabled = [
            repo['enabled']
            for repo
            in result.stdout
            if repo['arch'] == 'x86_64' and repo['release'] == '6Server'
        ][0]
        self.assertEqual(enabled, 'false')
Example #6
0
    def test_positive_create_1(self):
        """@Test: Upload a manifest.

        @Assert: Manifest is uploaded successfully

        @Feature: Subscriptions

        """
        org = entities.Organization().create()
        with open(manifests.clone(), 'rb') as manifest:
            upload_manifest(org.id, manifest)
Example #7
0
    def test_positive_create_1(self):
        """@Test: Upload a manifest.

        @Assert: Manifest is uploaded successfully

        @Feature: Subscriptions

        """
        cloned_manifest_path = manifests.clone()
        org_id = entities.Organization().create_json()['id']
        entities.Organization(id=org_id).upload_manifest(
            path=cloned_manifest_path
        )
    def test_positive_create_1(self):
        """@Test: Upload a manifest.

        @Assert: Manifest is uploaded successfully

        @Feature: Subscriptions

        """
        cloned_manifest_path = manifests.clone()
        org_id = entities.Organization().create()['id']
        task_result = entities.Organization(id=org_id).upload_manifest(
            path=cloned_manifest_path
        )['result']
        self.assertEqual(u'success', task_result)
Example #9
0
    def test_positive_create_1(self):
        """@Test: Upload a manifest.

        @Assert: Manifest is uploaded successfully

        @Feature: Subscriptions

        """
        cloned_manifest_path = manifests.clone()
        org_id = entities.Organization().create()['id']
        task = entities.Organization(id=org_id).upload_manifest(
            path=cloned_manifest_path)
        self.assertEqual(u'success', task['result'],
                         task['humanized']['errors'])
Example #10
0
    def test_negative_create_1(self):
        """@Test: Upload the same manifest to two organizations.

        @Assert: The manifest is not uploaded to the second organization.

        @Feature: Subscriptions

        """
        orgs = [entities.Organization().create() for _ in range(2)]
        with open(manifests.clone(), 'rb') as manifest:
            upload_manifest(orgs[0].id, manifest)
            with self.assertRaises(TaskFailedError):
                upload_manifest(orgs[1].id, manifest)
        self.assertEqual(
            len(entities.Subscription(organization=orgs[1]).search()), 0)
Example #11
0
    def test_positive_delete_1(self):
        """@Test: Delete an Uploaded manifest.

        @Assert: Manifest is Deleted successfully

        @Feature: Subscriptions

        """
        org = entities.Organization().create()
        sub = entities.Subscription(organization=org)
        with open(manifests.clone(), 'rb') as manifest:
            upload_manifest(org.id, manifest)
        self.assertGreater(len(sub.search()), 0)
        sub.delete_manifest(data={'organization_id': org.id})
        self.assertEqual(len(sub.search()), 0)
    def setup_to_create_cv(self, session, cv_name, repo_name=None,
                           repo_url=None, repo_type=None, rh_repo=None):
        """Create product/repo and sync it and create CV"""
        cv_name = cv_name or gen_string("alpha", 8)

        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=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_result = entities.Organization(
                id=self.org_id
            ).upload_manifest(path=manifest_path)['result']
            self.assertEqual(u'success', task_result)

            # Enables the RedHat repo and fetches it's Id.
            repo_id = utils.enable_rhrepo_and_fetchid(
                rh_repo['basearch'],
                str(self.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))
        make_contentview(session, org=self.org_name, name=cv_name)
        self.assertIsNotNone(self.content_views.search(cv_name))
Example #13
0
    def setUpClass(cls):  # noqa
        """Set up organization, product and repositories for tests."""
        super(CVRedHatContent, cls).setUpClass()

        cls.org = entities.Organization().create()
        with open(manifests.clone(), "rb") as manifest:
            entities.Subscription().upload(data={"organization_id": cls.org.id}, files={"content": manifest})
        repo_id = enable_rhrepo_and_fetchid(
            basearch="x86_64",
            org_id=cls.org.id,
            product=PRDS["rhel"],
            repo=REPOS["rhst7"]["name"],
            reposet=REPOSET["rhst7"],
            releasever=None,
        )
        cls.repo = entities.Repository(id=repo_id)
        cls.repo.sync()
Example #14
0
    def test_import_orgs_manifests(self, test_data):
        """@test: Import all organizations from the default data set
        (predefined source) and upload manifests for each of them

        @feature: Import Organizations including Manifests

        @assert: 3 Organizations are created with 3 manifests uploaded

        """
        files = dict(self.default_dataset[1])
        files['users'] = update_csv_values(
            files['users'],
            u'organization_id',
            test_data,
            self.default_dataset[0]
        )
        csv_records = csv_to_dataset([files['users']])
        # create number of manifests corresponding to the number of orgs
        manifest_list = []
        man_dir = ssh.command(
            u'mktemp -d -p {}'.format(self.default_dataset[0])
        ).stdout[0]
        for org in set([rec['organization'] for rec in csv_records]):
            for char in [' ', '.', '#']:
                org = org.replace(char, '_')
            man_file = manifests.clone()
            ssh.upload_file(man_file, u'{0}/{1}.zip'.format(man_dir, org))
            manifest_list.append(u'{0}/{1}.zip'.format(man_dir, org))
            os.remove(man_file)
        ssh_import = Import.organization({
            'csv-file': files['users'],
            'upload-manifests-from': man_dir,
        })
        # now to check whether the orgs from csv appeared in satellite
        orgs = set(org['name'] for org in Org.list().stdout)
        imp_orgs = set(
            org['organization'] for
            org in csv_to_dataset([files['users']])
        )
        self.assertEqual(ssh_import.return_code, 0)
        self.assertTrue(imp_orgs.issubset(orgs))
        for org in imp_orgs:
            manifest_history = Subscription.manifest_history(
                {'organization': org}
            ).stdout[3]
            self.assertIn('SUCCESS', manifest_history)
Example #15
0
    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))
Example #16
0
    def test_positive_delete_1(self):
        """@Test: Delete an Uploaded manifest.

        @Assert: Manifest is Deleted successfully

        @Feature: Subscriptions

        """
        cloned_manifest_path = clone()
        org_id = entities.Organization().create()['id']
        task_id = entities.Organization(id=org_id).upload_manifest(
            path=cloned_manifest_path
        )
        task_result = entities.ForemanTask(id=task_id).poll()['result']
        self.assertEqual(u'success', task_result)
        task_id = entities.Organization(id=org_id).delete_manifest()
        task_result = entities.ForemanTask(id=task_id).poll()['result']
        self.assertEqual(u'success', task_result)
    def test_positive_upload_1(self):
        """@Test: Upload a manifest with minimal input parameters

        @Feature: Manifest/Subscription - Positive Create

        @Assert: Manifest is uploaded

        """

        alert_loc = common_locators['alert.success']
        manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(manifest_path, remote_file=manifest_path)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            session.nav.go_to_red_hat_subscriptions()
            self.subscriptions.upload(manifest_path)
            success_ele = self.subscriptions.wait_until_element(alert_loc)
            self.assertTrue(success_ele)
Example #18
0
    def test_positive_upload_1(self):
        """@Test: Upload a manifest with minimal input parameters

        @Feature: Manifest/Subscription - Positive Create

        @Assert: Manifest is uploaded

        """

        alert_loc = common_locators['alert.success']
        manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(manifest_path, remote_file=manifest_path)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            session.nav.go_to_red_hat_subscriptions()
            self.subscriptions.upload(manifest_path)
            success_ele = self.subscriptions.wait_until_element(alert_loc)
            self.assertTrue(success_ele)
Example #19
0
    def test_sync_rh_repos(self):
        """@Test: Create Content RedHat Sync with two repos.

        @Feature: Content RedHat Sync - Positive Create

        @Assert: Whether Syncing RedHat Repos is successful

        """
        repos = self.sync.create_repos_tree(RHCT)
        with open(manifests.clone(), "rb") as manifest:
            upload_manifest(self.organization.id, manifest)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.organization.name)
            session.nav.go_to_red_hat_repositories()
            self.sync.enable_rh_repos(repos)
            session.nav.go_to_sync_status()
            sync = self.sync.sync_rh_repos(repos)
            # syn.sync_rh_repos returns boolean values and not objects
            self.assertTrue(sync)
    def test_negative_create_1(self):
        """@Test: Upload same manifest to 2 different Organizations.

        @Assert: Manifest is not uploaded in the second Organization.

        @Feature: Subscriptions

        """
        cloned_manifest_path = manifests.clone()
        orgid_one = entities.Organization().create()['id']
        orgid_two = entities.Organization().create()['id']
        task_result1 = entities.Organization(
            id=orgid_one
        ).upload_manifest(path=cloned_manifest_path)['result']
        self.assertEqual(u'success', task_result1)
        task_result2 = entities.Organization(
            id=orgid_two
        ).upload_manifest(path=cloned_manifest_path)['result']
        self.assertNotEqual(u'success', task_result2)
Example #21
0
    def test_negative_create_1(self):
        """@Test: Upload the same manifest to two organizations.

        @Assert: The manifest is not uploaded to the second organization.

        @Feature: Subscriptions

        """
        manifest_path = manifests.clone()

        # Upload the manifest to one organization.
        org_id = entities.Organization().create_json()['id']
        entities.Organization(id=org_id).upload_manifest(manifest_path)

        # Upload the manifest to a second organization.
        org = entities.Organization()
        org.id = org.create_json()['id']
        org.upload_manifest(manifest_path)
        self.assertEqual([], org.subscriptions())
    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)
Example #23
0
    def test_positive_delete_1(self):
        """@Test: Upload a manifest and delete the manifest.

        @Feature: Manifest/Subscription - Positive Delete

        @Assert: Manifest is Deleted successfully

        """

        alert_loc = common_locators["alert.success"]
        manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(manifest_path, remote_file=manifest_path)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            session.nav.go_to_red_hat_subscriptions()
            self.subscriptions.upload(manifest_path)
            self.subscriptions.delete()
            success_ele = self.subscriptions.wait_until_element(alert_loc)
            self.assertTrue(success_ele)
Example #24
0
    def test_negative_create_1(self):
        """@Test: Upload the same manifest to two organizations.

        @Assert: The manifest is not uploaded to the second organization.

        @Feature: Subscriptions

        """
        manifest_path = manifests.clone()

        # Upload the manifest to one organization.
        org_id = entities.Organization().create_json()['id']
        task = entities.Organization(id=org_id).upload_manifest(manifest_path)
        self.assertEqual('success', task['result'],
                         task['humanized']['errors'])

        # Upload the manifest to a second organization.
        org = entities.Organization()
        org.id = org.create_json()['id']
        self.assertNotEqual('success',
                            org.upload_manifest(manifest_path)['result'])
        self.assertEqual([], org.subscriptions())
Example #25
0
    def test_assert_delete_button(self):
        """@Test: Upload and delete a manifest

        @Feature: Manifest/Subscription - Positive Delete

        @Assert: Manifest is Deleted. Delete button is asserted . Subscriptions
        is asserted

        """
        alert_loc = common_locators["alert.success"]
        del_mf = locators["subs.delete_manifest"]
        manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(manifest_path, remote_file=manifest_path)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            session.nav.go_to_red_hat_subscriptions()
            self.subscriptions.upload(manifest_path)
            self.subscriptions.delete()
            self.assertTrue(self.subscriptions.wait_until_element(alert_loc))
            self.assertTrue(self.subscriptions.wait_until_element(del_mf))
            self.assertIsNone(self.subscriptions.search(DEFAULT_SUBSCRIPTION_NAME))
Example #26
0
    def test_repositoryset_enable(self):
        """@Test: Enable repo from reposet

        @Feature: Repository-set

        @Assert: Repository was enabled

        """
        org = entities.Organization().create()
        with open(manifests.clone(), "rb") as manifest:
            upload_manifest(org.id, manifest)
        product = entities.Product(name=PRDS["rhel"], organization=org).search()[0]
        reposet = entities.RepositorySet(name=REPOSET["rhva6"], product=product).search()[0]
        reposet.enable(data={"basearch": "x86_64", "releasever": "6Server"})
        repositories = reposet.available_repositories()["results"]
        self.assertTrue(
            [
                repo["enabled"]
                for repo in repositories
                if (repo["substitutions"]["basearch"] == "x86_64" and repo["substitutions"]["releasever"] == "6Server")
            ][0]
        )
Example #27
0
    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_json()

            # 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_json()
            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.
            entities.Organization(id=org_id).upload_manifest(
                path=manifest_path
            )
            # 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
        entities.Repository(id=repo_id).sync()
Example #28
0
    def test_repositoryset_enable_by_label(self):
        """@Test: Enable repo from reposet by org label, reposet and product
        names

        @Feature: Repository-set

        @Assert: Repository was enabled

        """
        org = make_org()
        manifest = manifests.clone()
        upload_file(manifest, remote_file=manifest)
        result = Subscription.upload({
            u'file': manifest,
            u'organization-id': org['id'],
        })
        self.assertEqual(result.return_code, 0)
        result = RepositorySet.enable({
            u'name': REPOSET['rhva6'],
            u'organization-label': org['label'],
            u'product': PRDS['rhel'],
            u'releasever': '6Server',
            u'basearch': 'x86_64',
        })
        self.assertEqual(result.return_code, 0)
        result = RepositorySet.available_repositories({
            u'name': REPOSET['rhva6'],
            u'organization-label': org['label'],
            u'product': PRDS['rhel'],
        })
        self.assertEqual(result.return_code, 0)
        enabled = [
            repo['enabled']
            for repo
            in result.stdout
            if repo['arch'] == 'x86_64' and repo['release'] == '6Server'
        ][0]
        self.assertEqual(enabled, 'true')
Example #29
0
    def test_assert_delete_button(self):
        """@Test: Upload and delete a manifest

        @Feature: Manifest/Subscription - Positive Delete

        @Assert: Manifest is Deleted. Delete button is asserted . Subscriptions
        is asserted

        """
        alert_loc = common_locators['alert.success']
        del_mf = locators['subs.delete_manifest']
        manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(manifest_path, remote_file=manifest_path)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            session.nav.go_to_red_hat_subscriptions()
            self.subscriptions.upload(manifest_path)
            self.subscriptions.delete()
            self.assertTrue(self.subscriptions.wait_until_element(alert_loc))
            self.assertTrue(self.subscriptions.wait_until_element(del_mf))
            self.assertIsNone(
                self.subscriptions.search("Red Hat Employee Subscription"))
Example #30
0
    def test_sync_rh_repos(self):
        """@Test: Create Content RedHat Sync with two repos.

        @Feature: Content RedHat Sync - Positive Create

        @Assert: Whether Syncing RedHat Repos is successful

        """

        repos = self.sync.create_repos_tree(RHCT)
        manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(manifest_path, remote_file=manifest_path)
        with Session(self.browser) as session:
            session.nav.go_to_select_org(self.org_name)
            session.nav.go_to_red_hat_subscriptions()
            self.subscriptions.upload(manifest_path)
            session.nav.go_to_red_hat_repositories()
            self.sync.enable_rh_repos(repos)
            session.nav.go_to_sync_status()
            sync = self.sync.sync_rh_repos(repos)
            # syn.sync_rh_repos returns boolean values and not objects
            self.assertTrue(sync)
Example #31
0
    def test_redhat_sync_1(self):
        """@Test: Sync RedHat Repository.

        @Feature: Repositories

        @Assert: Repository synced should fetch the data successfully.

        """
        cloned_manifest_path = manifests.clone()
        org_id = entities.Organization().create_json()['id']
        repo = "Red Hat Enterprise Linux 6 Server - RH Common RPMs x86_64 6.3"
        entities.Organization(id=org_id).upload_manifest(
            path=cloned_manifest_path
        )
        repo_id = utils.enable_rhrepo_and_fetchid(
            "x86_64",
            org_id,
            "Red Hat Enterprise Linux Server",
            repo,
            "Red Hat Enterprise Linux 6 Server - RH Common (RPMs)",
            "6.3",
        )
        entities.Repository(id=repo_id).sync()
Example #32
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])
Example #33
0
    def test_puppet_install(self):
        """@Test: Perform puppet end to end smoke tests using RH repos.

        @Feature: Smoke test puppet install and configure on client

        @Assert: Client should get configured by puppet-module.

        """
        activation_key_name = gen_string('alpha')
        cloned_manifest_path = manifests.clone()
        cv_name = gen_string('alpha')
        env_name = gen_string('alpha')
        org_name = gen_string('alpha')
        product_name = gen_string('alpha')
        puppet_module = 'motd'
        puppet_repository_name = gen_string('alpha')
        repos = self.sync.create_repos_tree(SAT6_TOOLS_TREE)
        rhel_prd = DEFAULT_SUBSCRIPTION_NAME
        rhel6_repo = conf.properties['clients.rhel6_repo']
        upload_file(cloned_manifest_path)
        with Session(self.browser) as session:
            # Create New organization
            make_org(session, org_name=org_name)
            self.assertIsNotNone(self.org.search(org_name))
            # Create New Lifecycle environment
            make_lifecycle_environment(session, org=org_name, name=env_name)
            strategy, value = locators['content_env.select_name']
            self.assertIsNotNone(self.contentenv.wait_until_element(
                (strategy, value % env_name)
            ))
            session.nav.go_to_red_hat_subscriptions()
            # Upload manifest from webui
            self.subscriptions.upload(cloned_manifest_path)
            self.assertTrue(session.nav.wait_until_element(
                common_locators['alert.success']
            ))
            session.nav.go_to_red_hat_repositories()
            # List of dictionary passed to enable the redhat repos
            # It selects Product->Reposet-> Repo
            self.sync.enable_rh_repos(repos)
            session.nav.go_to_sync_status()
            # Sync the repos
            # syn.sync_rh_repos returns boolean values and not objects
            self.assertTrue(self.sync.sync_noversion_rh_repos(
                PRDS['rhel'], [REPOS['rhst6']['name']]
            ))
            # Create custom product
            make_product(session, org=org_name, name=product_name)
            self.assertIsNotNone(self.products.search(product_name))
            # Create a puppet Repository
            make_repository(
                session,
                org=org_name,
                name=puppet_repository_name,
                product=product_name,
                url=FAKE_6_PUPPET_REPO,
                repo_type=REPO_TYPE['puppet']
            )
            self.assertIsNotNone(self.repository.search(
                puppet_repository_name
            ))
            # Sync the repos
            # syn.sync_rh_repos returns boolean values and not objects
            session.nav.go_to_sync_status()
            self.assertIsNotNone(self.sync.sync_custom_repos(
                product_name,
                [puppet_repository_name]
            ))
            # Create new content-view
            make_contentview(session, org=org_name, name=cv_name)
            self.assertIsNotNone(self.content_views.search(cv_name))
            # Add YUM repository to content-view
            self.content_views.add_remove_repos(
                cv_name,
                [REPOS['rhst6']['name']],
            )
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(self.content_views.wait_until_element(
                    common_locators['alert.success']
                ))
            # Add puppet-module to content-view
            self.content_views.add_puppet_module(
                cv_name, puppet_module, filter_term='Latest')
            # Publish content-view
            self.content_views.publish(cv_name)
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(self.content_views.wait_until_element(
                    common_locators['alert.success']
                ))
            # Promote content-view to life-cycle environment.
            self.content_views.promote(
                cv_name, version='Version 1', env=env_name)
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(self.content_views.wait_until_element(
                    common_locators['alert.success']
                ))
            # Create Activation-Key
            make_activationkey(
                session,
                org=org_name,
                name=activation_key_name,
                env=env_name,
                content_view=cv_name
            )
            self.activationkey.associate_product(
                activation_key_name, [product_name, rhel_prd])
            self.activationkey.enable_repos(
                activation_key_name, [REPOSET['rhst6']]
            )
            if not bz_bug_is_open(1191541):
                self.assertIsNotNone(self.activationkey.wait_until_element(
                    common_locators['alert.success']
                ))
            # Create VM
            with VirtualMachine(distro='rhel67') as vm:
                vm.install_katello_cert()
                vm.register_contenthost(activation_key_name, org_name)
                vm.configure_puppet(rhel6_repo)
                host = vm.fetch_hostname()
                session.nav.go_to_hosts()
                set_context(session, org=ANY_CONTEXT['org'])
                self.hosts.update_host_bulkactions(host=host, org=org_name)
                self.hosts.update(
                    name=host,
                    lifecycle_env=env_name,
                    cv=cv_name,
                    reset_puppetenv=True,
                )
                session.nav.go_to_hosts()
                self.hosts.update(
                    name=host,
                    reset_puppetenv=False,
                    puppet_module=puppet_module
                )
                vm.run(u'puppet agent -t')
                result = vm.run(u'cat /etc/motd | grep FQDN')
                self.assertEqual(result.return_code, 0)
Example #34
0
    def test_end_to_end(self):
        """@Test: Perform end to end smoke tests using RH repos.

        @Feature: Smoke test

        @Assert: All tests should succeed and Content should be successfully
        fetched by client

        """
        org_name = gen_string('alpha', 6)
        cv_name = gen_string('alpha', 6)
        activation_key_name = gen_string('alpha', 6)
        env_name = gen_string('alpha', 6)
        repos = self.sync.create_repos_tree(RHVA_REPO_TREE)
        cloned_manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(cloned_manifest_path)
        with Session(self.browser) as session:
            # Create New organization
            make_org(session, org_name=org_name)
            self.assertIsNotNone(self.org.search(org_name))
            # Create New Lifecycle environment
            make_lifecycle_environment(session, org=org_name, name=env_name)
            strategy, value = locators['content_env.select_name']
            self.assertIsNotNone(self.contentenv.wait_until_element(
                (strategy, value % env_name)
            ))
            # Navigate UI to select org and redhat subscription page
            session.nav.go_to_select_org(org_name)
            session.nav.go_to_red_hat_subscriptions()
            # Upload manifest from webui
            self.subscriptions.upload(cloned_manifest_path)
            self.assertTrue(session.nav.wait_until_element(
                common_locators['alert.success']
            ))
            session.nav.go_to_red_hat_repositories()
            # List of dictionary passed to enable the redhat repos
            # It selects Product->Reposet-> Repo
            self.sync.enable_rh_repos(repos)
            session.nav.go_to_sync_status()
            # Sync the repos
            # syn.sync_rh_repos returns boolean values and not objects
            self.assertTrue(self.sync.sync_rh_repos(repos))
            # Create new content-view
            make_contentview(session, org=org_name, name=cv_name)
            self.assertIsNotNone(self.content_views.search(cv_name))
            # Add YUM repository to content-view
            self.content_views.add_remove_repos(
                cv_name,
                [REPOS['rhva65']['name'], REPOS['rhva6']['name']]
            )
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(self.content_views.wait_until_element(
                    common_locators['alert.success']
                ))
            # Publish content-view
            self.content_views.publish(cv_name)
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(self.content_views.wait_until_element(
                    common_locators['alert.success']
                ))

            # Promote content-view to life-cycle environment 1
            self.content_views.promote(
                cv_name, version='Version 1', env=env_name)
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(self.content_views.wait_until_element(
                    common_locators['alert.success']
                ))
            # Create Activation-Key
            make_activationkey(
                session,
                org=org_name,
                name=activation_key_name,
                env=env_name,
                content_view=cv_name
            )
            self.activationkey.associate_product(
                activation_key_name, [DEFAULT_SUBSCRIPTION_NAME])
            self.activationkey.enable_repos(
                activation_key_name, [REPOSET['rhva6']])
            if not bz_bug_is_open(1191541):
                self.assertIsNotNone(self.activationkey.wait_until_element(
                    common_locators['alert.success']
                ))
            # Create VM
            with VirtualMachine(distro='rhel66') as vm:
                vm.install_katello_cert()
                result = vm.register_contenthost(activation_key_name, org_name)
                self.assertEqual(result.return_code, 0)

                # Install contents from sat6 server
                package_name = 'python-kitchen'
                result = vm.run(u'yum install -y {0}'.format(package_name))
                self.assertEqual(result.return_code, 0)
                # Verify if package is installed by query it
                result = vm.run(u'rpm -q {0}'.format(package_name))
                self.assertEqual(result.return_code, 0)
Example #35
0
    def setUp(self):  # noqa
        """Tests for content-view via Hammer CLI"""

        super(TestSubscription, self).setUp()
        self.org = make_org(cached=True)
        self.manifest = manifests.clone()
Example #36
0
    def test_end_to_end(self):
        """@Test: Perform end to end smoke tests using RH repos.

        @Feature: Smoke test

        @Assert: All tests should succeed and Content should be successfully
        fetched by client

        """
        org_name = gen_string("alpha", 6)
        cv_name = gen_string("alpha", 6)
        activation_key_name = gen_string("alpha", 6)
        env_name = gen_string("alpha", 6)
        product_name = "Red Hat Employee Subscription"
        repo_names = [
            "Red Hat Enterprise Virtualization Agents for RHEL 6 Server "
            "RPMs x86_64 6.5",
            "Red Hat Enterprise Virtualization Agents for RHEL 6 Server "
            "RPMs x86_64 6Server",
        ]
        repos = self.sync.create_repos_tree(RHVA_REPO_TREE)
        package_name = "python-kitchen"
        cloned_manifest_path = manifests.clone()
        # upload_file function should take care of uploading to sauce labs.
        upload_file(cloned_manifest_path, remote_file=cloned_manifest_path)
        with Session(self.browser) as session:
            # Create New organization
            make_org(session, org_name=org_name)
            self.assertIsNotNone(self.org.search(org_name))
            # Create New Lifecycle environment
            make_lifecycle_environment(session, org=org_name, name=env_name)
            strategy, value = locators["content_env.select_name"]
            self.assertIsNotNone(
                self.contentenv.wait_until_element(
                    (strategy, value % env_name)))
            # Navigate UI to select org and redhat subscription page
            session.nav.go_to_select_org(org_name)
            session.nav.go_to_red_hat_subscriptions()
            # Upload manifest from webui
            self.subscriptions.upload(cloned_manifest_path)
            self.assertTrue(
                session.nav.wait_until_element(
                    common_locators['alert.success']))
            session.nav.go_to_red_hat_repositories()
            # List of dictionary passed to enable the redhat repos
            # It selects Product->Reposet-> Repo
            self.sync.enable_rh_repos(repos)
            session.nav.go_to_sync_status()
            # Sync the repos
            sync = self.sync.sync_rh_repos(repos)
            # syn.sync_rh_repos returns boolean values and not objects
            self.assertTrue(sync)
            # Create new content-view
            make_contentview(session, org=org_name, name=cv_name)
            self.assertIsNotNone(self.content_views.search(cv_name))
            # Add YUM repository to content-view
            self.content_views.add_remove_repos(cv_name, repo_names)
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(
                    self.content_views.wait_until_element(
                        common_locators["alert.success"]))
            # Publish content-view
            self.content_views.publish(cv_name)
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(
                    self.content_views.wait_until_element(
                        common_locators["alert.success"]))

            # Promote content-view to life-cycle environment 1
            self.content_views.promote(cv_name,
                                       version="Version 1",
                                       env=env_name)
            if not bz_bug_is_open(1191422):
                self.assertIsNotNone(
                    self.content_views.wait_until_element(
                        common_locators["alert.success"]))
            # Create Activation-Key
            make_activationkey(session,
                               org=org_name,
                               name=activation_key_name,
                               env=env_name,
                               content_view=cv_name)
            self.activationkey.associate_product(activation_key_name,
                                                 [product_name])
            self.activationkey.enable_repos(activation_key_name,
                                            [REPOSET['rhva6']])
            if not bz_bug_is_open(1191541):
                self.assertIsNotNone(
                    self.activationkey.wait_until_element(
                        common_locators["alert.success"]))
            # Create VM
            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(self.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}, return code: {1}".
                    format(result.stderr, result.return_code))
                # Register client with foreman server using activation-key
                result = vm.run(
                    'subscription-manager register --activationkey {0} '
                    '--org {1} --force'.format(activation_key_name, org_name))
                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])
Example #37
0
    def test_end_to_end(self):
        """@Test: Perform end to end smoke tests using RH repos.

        1. Create new organization and environment
        2. Clone and 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 = "Red Hat Enterprise Linux Server"
        reposet = ("Red Hat Enterprise Virtualization Agents "
                   "for RHEL 6 Server (RPMs)")
        repo = ("Red Hat Enterprise Virtualization Agents for RHEL 6 Server "
                "RPMs x86_64 6Server")
        activation_key_name = gen_string('alpha')

        # step 1.1: Create a new organization
        org = entities.Organization().create()

        # step 1.2: Create new lifecycle environments
        lifecycle_env = entities.LifecycleEnvironment(
            organization=org['id']
        ).create()

        # step 2: Upload manifest
        manifest_path = manifests.clone()
        task = entities.Organization(
            id=org['id']
        ).upload_manifest(path=manifest_path)
        self.assertEqual(
            u'success', task['result'], task['humanized']['errors']
        )
        # step 3.1: Enable RH repo and fetch repository_id
        repo_id = utils.enable_rhrepo_and_fetchid(
            basearch="x86_64",
            org_id=org['id'],
            product=product,
            repo=repo,
            reposet=reposet,
            releasever="6Server",
        )
        # step 3.2: sync repository
        task_result = entities.Repository(id=repo_id).sync()['result']
        self.assertEqual(
            task_result,
            u'success',
            u" Error while syncing repository '{0}' and state is {1}."
            .format(repo, task_result))

        # step 4: Create content view
        content_view = entities.ContentView(organization=org['id']).create()
        # step 5: Associate repository to new content view
        response = client.put(
            entities.ContentView(id=content_view['id']).path(),
            {u'repository_ids': [repo_id]},
            auth=get_server_credentials(),
            verify=False,
        )
        response.raise_for_status()

        # step 6.1: Publish content view
        task_status = entities.ContentView(id=content_view['id']).publish()
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Error publishing content-view {0} and state is {1}."
            .format(content_view['name'], task_status['result']))

        # step 6.2: Promote content view to lifecycle_env
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(len(content_view['versions']), 1)
        task_status = entities.ContentViewVersion(
            id=content_view['versions'][0]['id']
        ).promote(lifecycle_env['id'])
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Error promoting {0} to {1} and state is {2}."
            .format(content_view['name'],
                    lifecycle_env['name'],
                    task_status['result']))

        # step 7: Create activation key
        ak_id = entities.ActivationKey(
            name=activation_key_name,
            environment=lifecycle_env['id'],
            organization=org['id'],
            content_view=content_view['id'],
        ).create_json()['id']

        # Walk through the list of subscriptions. Find the "Red Hat Employee
        # Subscription" and attach it to the just-created activation key.
        for subscription in entities.Organization(id=org['id']).subscriptions():
            if subscription['product_name'] == "Red Hat Employee Subscription":
                # 'quantity' must be 1, not subscription['quantity']. Greater
                # values produce this error: "RuntimeError: Error: Only pools
                # with multi-entitlement product subscriptions can be added to
                # the activation key with a quantity greater than one."
                entities.ActivationKey(id=ak_id).add_subscriptions({
                    'quantity': 1,
                    'subscription_id': subscription['id'],
                })
                break

        # Create VM
        package_name = "python-kitchen"
        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(conf.properties['main.server.hostname'])
            )
            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, 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])
Example #38
0
    def test_end_to_end(self):
        """@Test: Perform end to end smoke tests using RH repos.

        1. Create new organization and environment
        2. Clone and 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 = "Red Hat Enterprise Linux Server"
        reposet = ("Red Hat Enterprise Virtualization Agents "
                   "for RHEL 6 Server (RPMs)")
        repo = ("Red Hat Enterprise Virtualization Agents for RHEL 6 Server "
                "RPMs x86_64 6Server")
        activation_key_name = gen_string('alpha')

        # step 1.1: Create a new organization
        org = entities.Organization().create()

        # step 1.2: Create new lifecycle environments
        lifecycle_env = entities.LifecycleEnvironment(
            organization=org['id']
        ).create()

        # step 2: Upload manifest
        manifest_path = manifests.clone()
        task = entities.Organization(
            id=org['id']
        ).upload_manifest(path=manifest_path)
        self.assertEqual(
            u'success', task['result'], task['humanized']['errors']
        )
        # step 3.1: Enable RH repo and fetch repository_id
        repo_id = utils.enable_rhrepo_and_fetchid(
            basearch="x86_64",
            org_id=org['id'],
            product=product,
            repo=repo,
            reposet=reposet,
            releasever="6Server",
        )
        # step 3.2: sync repository
        task_result = entities.Repository(id=repo_id).sync()['result']
        self.assertEqual(
            task_result,
            u'success',
            u" Error while syncing repository '{0}' and state is {1}."
            .format(repo, task_result))

        # step 4: Create content view
        content_view = entities.ContentView(organization=org['id']).create()
        # step 5: Associate repository to new content view
        response = client.put(
            entities.ContentView(id=content_view['id']).path(),
            {u'repository_ids': [repo_id]},
            auth=get_server_credentials(),
            verify=False,
        )
        response.raise_for_status()

        # step 6.1: Publish content view
        task_status = entities.ContentView(id=content_view['id']).publish()
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Error publishing content-view {0} and state is {1}."
            .format(content_view['name'], task_status['result']))

        # step 6.2: Promote content view to lifecycle_env
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(len(content_view['versions']), 1)
        task_status = entities.ContentViewVersion(
            id=content_view['versions'][0]['id']
        ).promote(lifecycle_env['id'])
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Error promoting {0} to {1} and state is {2}."
            .format(content_view['name'],
                    lifecycle_env['name'],
                    task_status['result']))

        # step 7: Create activation key
        ak_id = entities.ActivationKey(
            name=activation_key_name,
            environment=lifecycle_env['id'],
            organization=org['id'],
            content_view=content_view['id'],
        ).create_json()['id']

        # Walk through the list of subscriptions. Find the "Red Hat Employee
        # Subscription" and attach it to the just-created activation key.
        for subscription in entities.Organization(id=org['id']).subscriptions():
            if subscription['product_name'] == "Red Hat Employee Subscription":
                # 'quantity' must be 1, not subscription['quantity']. Greater
                # values produce this error: "RuntimeError: Error: Only pools
                # with multi-entitlement product subscriptions can be added to
                # the activation key with a quantity greater than one."
                entities.ActivationKey(id=ak_id).add_subscriptions({
                    'quantity': 1,
                    'subscription_id': subscription['id'],
                })
                break

        # Create VM
        package_name = "python-kitchen"
        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(conf.properties['main.server.hostname'])
            )
            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, 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 create_cv(self, name, env_name, product_name=None, repo_name=None,
                  repo_url=None, repo_type=None, rh_repo=None):
        """Create product/repo and sync it and promote to given env"""
        if not rh_repo:
            product_name = product_name or gen_string("alpha", 8)
            repo_name = repo_name or gen_string("alpha", 8)
            # Creates new product and repository via API's
            product_attrs = entities.Product(
                name=product_name,
                organization=self.org_id
            ).create()
            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']
        else:
            # Upload manifest
            manifest_path = manifests.clone()
            task_result = entities.Organization(
                id=self.org_id
            ).upload_manifest(path=manifest_path)['result']
            self.assertEqual(u'success', task_result)
            # Enable RH repo and fetch repository_id
            repo_id = utils.enable_rhrepo_and_fetchid(
                rh_repo['basearch'],
                self.org_id,
                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))

        # Create Life-Cycle content environment
        env_attrs = entities.LifecycleEnvironment(
            name=env_name,
            organization=self.org_id
        ).create()

        # Create content view(CV)
        content_view = entities.ContentView(
            name=name,
            organization=self.org_id
        )
        content_view.id = content_view.create()['id']

        # Associate YUM repo to created CV
        response = client.put(
            entities.ContentView(id=content_view.id).path(),
            auth=get_server_credentials(),
            verify=False,
            data={u'repository_ids': [repo_id]})
        response.raise_for_status()

        # Publish content view
        self.assertEqual(u'success', content_view.publish()['result'])

        # Get the content view version's ID.
        response = client.get(
            entities.ContentViewVersion().path(),
            auth=get_server_credentials(),
            data={u'content_view_id': content_view.id},
            verify=False,
        )
        response.raise_for_status()
        results = response.json()['results']
        self.assertEqual(len(results), 1)
        cv_version = entities.ContentViewVersion(id=results[0]['id'])

        # Promote the content view version.
        self.assertEqual(
            'success',
            cv_version.promote(environment_id=env_attrs['id'])['result']
        )
    def test_associate_product_3(self):
        """@Test: Test that RH/Custom product can be associated to Activation
        keys

        @Feature: Activation key - Product

        @Steps:
        1. Create Activation key
        2. Associate RH product(s) to Activation Key
        3. Associate custom product(s) to Activation Key

        @Assert: RH/Custom product is successfully associated to Activation key

        """
        name = gen_string("alpha", 8)
        rh_repo = {
            'name': ("Red Hat Enterprise Virtualization Agents for RHEL 6 "
                     "Server RPMs x86_64 6Server"),
            'product': "Red Hat Enterprise Linux Server",
            'reposet': ("Red Hat Enterprise Virtualization Agents "
                        "for RHEL 6 Server (RPMs)"),
            'basearch': "x86_64",
            'releasever': "6Server",
        }
        product_subscription = "Red Hat Employee Subscription"
        custom_product_name = gen_string("alpha", 8)
        repo_name = gen_string("alpha", 8)
        # Creates new product and repository via API's
        product_attrs = entities.Product(
            name=custom_product_name,
            organization=self.org_id
        ).create()
        repo_attrs = entities.Repository(
            name=repo_name,
            url=FAKE_1_YUM_REPO,
            content_type=REPO_TYPE['yum'],
            product=product_attrs['id'],
        ).create()
        custom_repo_id = repo_attrs['id']
        # Upload manifest
        manifest_path = manifests.clone()
        task_result = entities.Organization(
            id=self.org_id
        ).upload_manifest(path=manifest_path)['result']
        self.assertEqual(u'success', task_result)
        # Enable RH repo and fetch repository_id
        rhel_repo_id = utils.enable_rhrepo_and_fetchid(
            rh_repo['basearch'],
            self.org_id,
            rh_repo['product'],
            rh_repo['name'],
            rh_repo['reposet'],
            rh_repo['releasever']
        )
        # Sync repository
        for repo_id in [rhel_repo_id, custom_repo_id]:
            task_result = entities.Repository(id=repo_id).sync()['result']
            self.assertEqual(
                task_result,
                u'success',
                u"Sync for repository {0} failed.".format(repo_name))
        with Session(self.browser) as session:
            make_activationkey(
                session, org=self.org_name, name=name, env=ENVIRONMENT,
                content_view=DEFAULT_CV
            )
            self.assertIsNotNone(self.activationkey.search_key(name))
            self.activationkey.associate_product(
                name, [product_subscription, custom_product_name])
            self.assertIsNotNone(self.activationkey.wait_until_element
                                 (common_locators["alert.success"]))
Example #41
0
    def test_repositoryset_available_repositories(self):
        """@Test: List available repositories for repository-set

        @Feature: Repository-set

        @Assert: List of available repositories is displayed, with
        valid amount of enabled repositories

        """
        rhel_product_name = 'Red Hat Enterprise Linux Server'
        rhel_repo_set = (
            'Red Hat Enterprise Virtualization Agents '
            'for RHEL 6 Server (RPMs)'
        )

        # Clone manifest and upload it
        org = make_org()
        manifest = manifests.clone()
        upload_file(manifest, remote_file=manifest)
        result = Subscription.upload({
            u'file': manifest,
            u'organization-id': org['id'],
        })
        self.assertEqual(result.return_code, 0)

        # No repos should be enabled by default
        result = RepositorySet.available_repositories({
            u'name': rhel_repo_set,
            u'organization-id': org['id'],
            u'product': rhel_product_name,
        })
        self.assertEqual(result.return_code, 0)
        self.assertEqual(
            sum(int(repo['enabled'] == u'true') for repo in result.stdout),
            0
        )

        # Enable repo from Repository Set
        result = RepositorySet.enable({
            u'name': rhel_repo_set,
            u'organization-id': org['id'],
            u'product': rhel_product_name,
            u'releasever': '6Server',
            u'basearch': 'x86_64',
        })
        self.assertEqual(result.return_code, 0)

        # Only 1 repo should be enabled
        result = RepositorySet.available_repositories({
            u'name': rhel_repo_set,
            u'organization': org['name'],
            u'product': rhel_product_name,
        })
        self.assertEqual(result.return_code, 0)
        self.assertEqual(
            sum(int(repo['enabled'] == u'true') for repo in result.stdout),
            1
        )

        # Enable one more repo
        result = RepositorySet.enable({
            u'name': rhel_repo_set,
            u'organization-id': org['id'],
            u'product': rhel_product_name,
            u'releasever': '6Server',
            u'basearch': 'i386',
        })
        self.assertEqual(result.return_code, 0)

        # 2 repos should be enabled
        result = RepositorySet.available_repositories({
            u'name': rhel_repo_set,
            u'organization-label': org['label'],
            u'product': rhel_product_name,
        })
        self.assertEqual(result.return_code, 0)
        self.assertEqual(
            sum(int(repo['enabled'] == u'true') for repo in result.stdout),
            2
        )

        # Disable one repo
        result = RepositorySet.disable({
            u'name': rhel_repo_set,
            u'organization-id': org['id'],
            u'product': rhel_product_name,
            u'releasever': '6Server',
            u'basearch': 'i386',
        })
        self.assertEqual(result.return_code, 0)

        # There should remain only 1 enabled repo
        result = RepositorySet.available_repositories({
            u'name': rhel_repo_set,
            u'organization-id': org['id'],
            u'product': rhel_product_name,
        })
        self.assertEqual(result.return_code, 0)
        self.assertEqual(
            sum(int(repo['enabled'] == u'true') for repo in result.stdout),
            1
        )

        # Disable the last enabled repo
        result = RepositorySet.disable({
            u'name': rhel_repo_set,
            u'organization-id': org['id'],
            u'product': rhel_product_name,
            u'releasever': '6Server',
            u'basearch': 'x86_64',
        })
        self.assertEqual(result.return_code, 0)

        # There should be no enabled repos
        result = RepositorySet.available_repositories({
            u'name': rhel_repo_set,
            u'organization-id': org['id'],
            u'product': rhel_product_name,
        })
        self.assertEqual(result.return_code, 0)
        self.assertEqual(
            sum(int(repo['enabled'] == u'true') for repo in result.stdout),
            0
        )