Пример #1
0
    def test_subscribe_system_to_cv(self):
        """@Test: Subscribe a system to a content view.

        @Feature: ContentView

        @Assert: It is possible to create a system and set its
        'content_view_id' attribute.

        """
        # organization
        # ├── lifecycle environment
        # └── content view
        org = entities.Organization()
        org.id = org.create()['id']
        lifecycle_env = entities.LifecycleEnvironment(organization=org.id)
        lifecycle_env.id = lifecycle_env.create()['id']
        content_view = entities.ContentView(organization=org.id)
        content_view.id = content_view.create()['id']

        # Publish the content view.
        response = content_view.publish()
        humanized_errors = response['humanized']['errors']
        _check_bz_1186432(humanized_errors)
        self.assertEqual(response['result'], 'success', humanized_errors)

        # 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.
        response = cv_version.promote(environment_id=lifecycle_env.id)
        humanized_errors = response['humanized']['errors']
        _check_bz_1186432(humanized_errors)
        self.assertEqual('success', response['result'], humanized_errors)

        # Create a system that is subscribed to the published and promoted
        # content view. Associating this system with the organization and
        # environment created above is not particularly important, but doing so
        # means a shorter test where fewer entities are created, as
        # System.organization and System.environment are required attributes.
        system_attrs = entities.System(
            content_view=content_view.id,
            environment=lifecycle_env.id,
            organization=org.id,
        ).create()

        # See BZ #1151240
        self.assertEqual(system_attrs['content_view_id'], content_view.id)
        self.assertEqual(system_attrs['environment']['id'], lifecycle_env.id)
        self.assertEqual(system_attrs['organization_id'], org.id)
Пример #2
0
    def test_positive_promote_1(self):
        """@Test: Promote a content view version ``REPEAT`` times.

        @Assert: The content view version points to ``REPEAT + 1`` lifecycle
        environments after the promotions.

        @Feature: ContentView

        """
        content_view = entities.ContentView(organization=self.org.id)
        content_view.id = content_view.create_json()['id']
        response = content_view.publish()
        humanized_errors = response['humanized']['errors']
        _check_bz_1186432(humanized_errors)
        self.assertEqual(response['result'], 'success', humanized_errors)

        # Promote the content view version several times.
        cvv = entities.ContentViewVersion(
            id=content_view.read_json()['versions'][0]['id']  # only one ver
        )
        for _ in range(REPEAT):
            lc_env_id = entities.LifecycleEnvironment(
                organization=self.org.id).create_json()['id']
            response = cvv.promote(lc_env_id)
            humanized_errors = response['humanized']['errors']
            _check_bz_1186432(humanized_errors)
            self.assertEqual(response['result'], 'success', humanized_errors)

        # Does it show up in the correct number of lifecycle environments?
        self.assertEqual(
            len(content_view.read_json()['versions'][0]['environment_ids']),
            REPEAT + 1)
Пример #3
0
    def test_positive_publish_3(self):
        """@Test: Publish a content view that has puppet modules several times.

        @Assert: The puppet module is referenced fromt he content view, the
        content view can be published several times, and each version
        references the puppet module.

        @Feature: ContentView

        """
        content_view = entities.ContentView(organization=self.org.id)
        content_view.id = content_view.create_json()['id']
        puppet_module = content_view.available_puppet_modules()['results'][0]
        content_view.add_puppet_module(puppet_module['author'],
                                       puppet_module['name'])

        # Check that the puppet module is referenced.
        self.assertEqual(len(content_view.read_json()['puppet_modules']), 1)

        # Publish the content view several times and check that each version
        # has the puppet module added above.
        for _ in range(REPEAT):
            response = content_view.publish()
            humanized_errors = response['humanized']['errors']
            _check_bz_1186432(humanized_errors)
            self.assertEqual(response['result'], 'success', humanized_errors)
        for cvv_id in (  # content view version ID
                version['id']
                for version in content_view.read_json()['versions']):
            cvv = entities.ContentViewVersion(id=cvv_id)
            self.assertEqual(len(cvv.read_json()['puppet_modules']), 1)
Пример #4
0
    def test_positive_publish_2(self):
        """@Test: Give a content view yum packages and publish it repeatedly.

        @Assert: The yum repo is referenced from the content view, the content
        view can be published several times, and each content view version has
        at least one package.

        @Feature: ContentView

        """
        content_view = entities.ContentView(organization=self.org.id)
        content_view.id = content_view.create_json()['id']
        content_view.set_repository_ids([self.yum_repo.id])

        # Check that the yum repo is referenced.
        self.assertEqual(len(content_view.read_json()['repositories']), 1)

        # Publish the content view several times and check that each version
        # has some software packages.
        for _ in range(REPEAT):
            response = content_view.publish()
            humanized_errors = response['humanized']['errors']
            _check_bz_1186432(humanized_errors)
            self.assertEqual(response['result'], 'success', humanized_errors)
        for cvv_id in (  # content view version ID
                version['id']
                for version in content_view.read_json()['versions']):
            cvv = entities.ContentViewVersion(id=cvv_id)
            self.assertGreater(cvv.read_json()['package_count'], 0)
Пример #5
0
    def test_negative_promote_2(self):
        """@Test: Promote a content view version using an invalid environment.

        @Assert: The promotion fails.

        @Feature: ContentViewVersion

        """
        with self.assertRaises(HTTPError):
            entities.ContentViewVersion(id=1).promote(-1)
Пример #6
0
    def test_positive_promote_3(self):
        """@Test: Give a content view a puppet module, publish it once and
        promote the content view version ``REPEAT + 1`` times.

        @Assert: The content view has one puppet module, the content view
        version is in ``REPEAT + 1`` lifecycle environments and it has one
        puppet module.

        @Feature: ContentView

        """
        content_view = entities.ContentView(organization=self.org.id)
        content_view.id = content_view.create_json()['id']
        puppet_module = content_view.available_puppet_modules()['results'][0]
        content_view.add_puppet_module(puppet_module['author'],
                                       puppet_module['name'])
        response = content_view.publish()
        humanized_errors = response['humanized']['errors']
        _check_bz_1186432(humanized_errors)
        self.assertEqual(response['result'], 'success', humanized_errors)

        # Promote the content view version.
        cvv = entities.ContentViewVersion(
            id=content_view.read_json()['versions'][0]['id']  # only one ver
        )
        for _ in range(REPEAT):
            lc_env_id = entities.LifecycleEnvironment(
                organization=self.org.id).create_json()['id']
            response = cvv.promote(lc_env_id)
            humanized_errors = response['humanized']['errors']
            _check_bz_1186432(humanized_errors)
            self.assertEqual(response['result'], 'success', humanized_errors)

        # Everything's done. Check some content view attributes...
        cv_attrs = content_view.read_json()
        self.assertEqual(len(cv_attrs['versions']), 1)
        self.assertEqual(len(cv_attrs['puppet_modules']), 1)

        # ...and some content view version attributes.
        cvv_attrs = entities.ContentViewVersion(
            id=cv_attrs['versions'][0]['id']).read_json()
        self.assertEqual(len(cvv_attrs['environments']), REPEAT + 1)
        self.assertEqual(len(cvv_attrs['puppet_modules']), 1)
Пример #7
0
    def test_negative_promote_1(self):
        """@Test: Promote the default content view version.

        @Assert: The promotion fails.

        @Feature: ContentViewVersion

        """
        env_id = entities.Environment().create()['id']
        with self.assertRaises(HTTPError):
            entities.ContentViewVersion(id=1).promote(env_id)
Пример #8
0
    def test_positive_promote_2(self):
        """@Test: Give a content view a yum repo, publish it once and promote
        the content view version ``REPEAT + 1`` times.

        @Assert: The content view has one repository, the content view version
        is in ``REPEAT + 1`` lifecycle environments and it has at least one
        package.

        @Feature: ContentView

        """
        content_view = entities.ContentView(organization=self.org.id)
        content_view.id = content_view.create_json()['id']
        content_view.set_repository_ids([self.yum_repo.id])
        response = content_view.publish()
        humanized_errors = response['humanized']['errors']
        _check_bz_1186432(humanized_errors)
        self.assertEqual(response['result'], 'success', humanized_errors)

        # Promote the content view version.
        cvv = entities.ContentViewVersion(
            id=content_view.read_json()['versions'][0]['id']  # only one ver
        )
        for _ in range(REPEAT):
            lc_env_id = entities.LifecycleEnvironment(
                organization=self.org.id).create_json()['id']
            response = cvv.promote(lc_env_id)
            humanized_errors = response['humanized']['errors']
            _check_bz_1186432(humanized_errors)
            self.assertEqual(response['result'], 'success', humanized_errors)

        # Everything's done - check some content view attributes...
        cv_attrs = content_view.read_json()
        self.assertEqual(len(cv_attrs['repositories']), 1)
        self.assertEqual(len(cv_attrs['versions']), 1)

        # ...and some content view version attributes.
        cvv_attrs = entities.ContentViewVersion(
            id=cv_attrs['versions'][0]['id']).read_json()
        self.assertEqual(len(cvv_attrs['environments']), REPEAT + 1)
        self.assertGreater(cvv_attrs['package_count'], 0)
Пример #9
0
    def test_smoke(self):
        """@Test: Check that basic content can be created

        1. Create a new user with admin permissions
        2. Using the new user from above:
            1. Create a new organization
            2. Create two new lifecycle environments
            3. Create a custom product
            4. Create a custom YUM repository
            5. Create a custom PUPPET repository
            6. Synchronize both custom repositories
            7. Create a new content view
            8. Associate both repositories to new content view
            9. Publish content view
            10. Promote content view to both lifecycles
            11. Create a new libvirt compute resource
            12. Create a new subnet
            13. Create a new domain
            14. Create a new hostgroup and associate previous entities to it

        @Feature: Smoke Test

        @Assert: All entities are created and associated.

        """
        # prep work
        #
        # FIXME: Use a larger charset when authenticating users.
        #
        # It is possible to create a user with a wide range of characters. (see
        # the "User" entity). However, Foreman supports only HTTP Basic
        # authentication, and the requests lib enforces the latin1 charset in
        # this auth mode. We then further restrict ourselves to the
        # alphanumeric charset, because Foreman complains about incomplete
        # multi-byte chars when latin1 chars are used.
        #
        login = gen_string('alphanumeric')
        password = gen_string('alphanumeric')

        # step 1: Create a new user with admin permissions
        entities.User(admin=True, login=login, password=password).create()

        # step 2.1: Create a new organization
        org = entities.Organization().create(auth=(login, password))

        # step 2.2: Create 2 new lifecycle environments
        le1 = entities.LifecycleEnvironment(organization=org['id']).create()
        le2 = entities.LifecycleEnvironment(
            organization=org['id'], prior=le1['id']).create()

        # step 2.3: Create a custom product
        prod = entities.Product(organization=org['id']).create()

        # step 2.4: Create custom YUM repository
        repo1 = entities.Repository(
            product=prod['id'],
            content_type=u'yum',
            url=GOOGLE_CHROME_REPO
        ).create()

        # step 2.5: Create custom PUPPET repository
        repo2 = entities.Repository(
            product=prod['id'],
            content_type=u'puppet',
            url=FAKE_0_PUPPET_REPO
        ).create()

        # step 2.6: Synchronize both repositories
        for repo in [repo1, repo2]:
            response = client.post(
                entities.Repository(id=repo['id']).path('sync'),
                {
                    u'ids': [repo['id']],
                    u'organization_id': org['id']
                },
                auth=get_server_credentials(),
                verify=False,
            ).json()
            self.assertGreater(
                len(response['id']),
                1,
                u"Was not able to fetch a task ID.")
            task_status = entities.ForemanTask(id=response['id']).poll()
            self.assertEqual(
                task_status['result'],
                u'success',
                u"Sync for repository {0} failed.".format(repo['name']))

        # step 2.7: Create content view
        content_view = entities.ContentView(organization=org['id']).create()

        # step 2.8: Associate YUM repository to new content view
        response = client.put(
            entities.ContentView(id=content_view['id']).path(),
            auth=get_server_credentials(),
            verify=False,
            data={u'repository_ids': [repo1['id']]})

        # Fetch all available puppet modules
        puppet_mods = client.get(
            entities.ContentView(id=content_view['id']).path(
                'available_puppet_module_names'),
            auth=get_server_credentials(),
            verify=False).json()
        self.assertGreater(
            puppet_mods['results'],
            0,
            u"No puppet modules were found")

        # Select a random puppet module from the results
        puppet_mod = random.choice(puppet_mods['results'])
        # ... and associate it to the content view
        path = entities.ContentView(id=content_view['id']).path(
            'content_view_puppet_modules')
        response = client.post(
            path,
            auth=get_server_credentials(),
            verify=False,
            data={u'name': puppet_mod['module_name']})
        self.assertEqual(
            response.status_code,
            httplib.OK,
            status_code_error(path, httplib.OK, response)
        )
        self.assertEqual(
            response.json()['name'],
            puppet_mod['module_name'],
        )

        # step 2.9: Publish content view
        task_status = entities.ContentView(id=content_view['id']).publish()
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Publishing {0} failed.".format(content_view['name']))

        # step 2.10: Promote content view to both lifecycles
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(
            len(content_view['versions']),
            1,
            u'There should only be 1 version published.')
        self.assertEqual(
            len(content_view['versions'][0]['environment_ids']),
            1,
            u"Content view should be present on 1 lifecycle only")
        task_status = entities.ContentViewVersion(
            id=content_view['versions'][0]['id']
        ).promote(le1['id'])
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Promoting {0} to {1} failed.".format(
                content_view['name'], le1['name']))
        # Check that content view exists in 2 lifecycles
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(
            len(content_view['versions']),
            1,
            u'There should only be 1 version published.')
        self.assertEqual(
            len(content_view['versions'][0]['environment_ids']),
            2,
            u"Content view should be present on 2 lifecycles only")
        task_status = entities.ContentViewVersion(
            id=content_view['versions'][0]['id']
        ).promote(le2['id'])
        self.assertEqual(
            task_status['result'],
            u'success',
            u"Promoting {0} to {1} failed.".format(
                content_view['name'], le2['name']))
        # Check that content view exists in 2 lifecycles
        content_view = entities.ContentView(id=content_view['id']).read_json()
        self.assertEqual(
            len(content_view['versions']),
            1,
            u'There should only be 1 version published.')
        self.assertEqual(
            len(content_view['versions'][0]['environment_ids']),
            3,
            u"Content view should be present on 3 lifecycle only")

        # BONUS: Create a content host and associate it with promoted
        # content view and last lifecycle where it exists
        content_host = entities.System(
            content_view=content_view['id'],
            environment=le2['id']
        ).create()
        # Check that content view matches what we passed
        self.assertEqual(
            content_host['content_view_id'],
            content_view['id'],
            u"Content views do not match."
        )
        # Check that lifecycle environment matches
        self.assertEqual(
            content_host['environment']['id'],
            le2['id'],
            u"Environments do not match."
        )
Пример #10
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])