def test_positive_remove_cv_version_from_multi_env(self):
        """Remove promoted content view version from multiple environment

        :id: 18b86a68-8e6a-43ea-b95e-188fba125a26

        :Steps:

            1. Create a content view
            2. Add a yum repo and a puppet module to the content view
            3. Publish the content view
            4. Promote the content view version to multiple environments
               Library -> DEV -> QE -> STAGE -> PROD
            5. Remove content view version from QE, STAGE and PROD

        :expectedresults: Content view version exists only in Library, DEV

        :CaseLevel: Integration

        :CaseImportance: Low
        """
        org = entities.Organization().create()
        lce_dev = entities.LifecycleEnvironment(organization=org).create()
        lce_qe = entities.LifecycleEnvironment(organization=org, prior=lce_dev).create()
        lce_stage = entities.LifecycleEnvironment(organization=org, prior=lce_qe).create()
        lce_prod = entities.LifecycleEnvironment(organization=org, prior=lce_stage).create()
        product = entities.Product(organization=org).create()
        yum_repo = entities.Repository(url=FAKE_1_YUM_REPO, product=product).create()
        yum_repo.sync()
        puppet_repo = entities.Repository(
            url=FAKE_0_PUPPET_REPO, content_type='puppet', product=product
        ).create()
        puppet_repo.sync()
        # create a content view and add to it the yum repo
        content_view = entities.ContentView(organization=org).create()
        content_view.repository = [yum_repo]
        content_view = content_view.update(['repository'])
        # get a random puppet module and add it to content view
        puppet_module = random.choice(content_view.available_puppet_modules()['results'])
        entities.ContentViewPuppetModule(
            author=puppet_module['author'], name=puppet_module['name'], content_view=content_view
        ).create()
        # publish the content view
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        content_view_version = content_view.version[0].read()
        self.assertEqual(len(content_view_version.environment), 1)
        lce_library = entities.LifecycleEnvironment(
            id=content_view_version.environment[0].id
        ).read()
        self.assertEqual(lce_library.name, ENVIRONMENT)
        # promote content view version to DEV QE STAGE PROD lifecycle
        # environments
        for lce in [lce_dev, lce_qe, lce_stage, lce_prod]:
            promote(content_view_version, lce.id)
        self.assertEqual(
            {lce_library.id, lce_dev.id, lce_qe.id, lce_stage.id, lce_prod.id},
            {lce.id for lce in content_view_version.read().environment},
        )
        # remove the content view version from QE STAGE and PROD environments
        for lce in [lce_qe, lce_stage, lce_prod]:
            content_view.delete_from_environment(lce.id)
        # assert that the content view version exists only in Library and DEV
        # environments
        self.assertEqual(
            {lce_library.id, lce_dev.id},
            {lce.id for lce in content_view_version.read().environment},
        )
Esempio n. 2
0
    def test_positive_sync_puppet_module_with_versions(self, capsule_vm):
        """Ensure it's possible to sync multiple versions of the same puppet
        module to the capsule

        :id: 83a0ddd6-8a6a-43a0-b169-094a2556dd28

        :customerscenario: true

        :BZ: 1365952, 1655243

        :Steps:

            1. Register a capsule
            2. Associate LCE with the capsule
            3. Sync a puppet module with multiple versions
            4. Publish a CV with one version of puppet module and promote it to
               capsule's LCE
            5. Wait for capsule synchronization to finish
            6. Publish another CV with different version of puppet module and
               promote it to capsule's LCE
            7. Wait for capsule synchronization to finish once more

        :expectedresults: Capsule was successfully synchronized, new version of
            puppet module is present on capsule

        :CaseLevel: System

        :CaseImportance: Medium
        """
        module_name = 'versioned'
        module_versions = ['2.2.2', '3.3.3']
        org = entities.Organization().create()
        lce = entities.LifecycleEnvironment(organization=org).create()
        content_view = entities.ContentView(organization=org).create()
        prod = entities.Product(organization=org).create()
        puppet_repository = entities.Repository(
            content_type=REPO_TYPE['puppet'], product=prod, url=CUSTOM_PUPPET_REPO
        ).create()
        capsule = entities.Capsule(id=capsule_vm._capsule.id).read()
        capsule.content_add_lifecycle_environment(data={'environment_id': lce.id})
        result = capsule.content_lifecycle_environments()

        assert len(result['results']) >= 1
        assert lce.id in [capsule_lce['id'] for capsule_lce in result['results']]

        puppet_repository.sync()
        puppet_module_old = entities.PuppetModule().search(
            query={'search': f'name={module_name} and version={module_versions[0]}'}
        )[0]
        # Add puppet module to the CV
        entities.ContentViewPuppetModule(
            content_view=content_view, id=puppet_module_old.id
        ).create()
        content_view = content_view.read()

        assert len(content_view.puppet_module) > 0

        # Publish and promote CVV
        content_view.publish()
        content_view = content_view.read()

        assert len(content_view.version) == 1

        cvv = content_view.version[-1].read()
        promote(cvv, lce.id)
        cvv = cvv.read()

        assert len(cvv.environment) == 2

        # Wait till capsule sync finishes
        sync_status = capsule.content_get_sync()

        assert len(sync_status['active_sync_tasks']) >= 1 or sync_status['last_sync_time']

        for task in sync_status['active_sync_tasks']:
            entities.ForemanTask(id=task['id']).poll()
        sync_status = capsule.content_get_sync()
        last_sync_time = sync_status['last_sync_time']
        # Unassign old puppet module version from CV
        entities.ContentViewPuppetModule(
            content_view=content_view, id=content_view.puppet_module[0].id
        ).delete()
        # Assign new puppet module version
        puppet_module_new = entities.PuppetModule().search(
            query={'search': f'name={module_name} and version={module_versions[1]}'}
        )[0]
        entities.ContentViewPuppetModule(
            content_view=content_view, id=puppet_module_new.id
        ).create()

        assert len(content_view.puppet_module) > 0

        # Publish and promote CVV
        content_view.publish()
        content_view = content_view.read()

        assert len(content_view.version) == 2

        cvv = content_view.version[-1].read()
        promote(cvv, lce.id)
        cvv = cvv.read()

        assert len(cvv.environment) == 2

        # Wait till capsule sync finishes
        sync_status = capsule.content_get_sync()
        if sync_status['active_sync_tasks']:
            for task in sync_status['active_sync_tasks']:
                entities.ForemanTask(id=task['id']).poll()
        else:
            assert sync_status['last_sync_time'] != last_sync_time

        stored_modules = get_repo_files(PULP_PUBLISHED_PUPPET_REPOS_PATH, 'gz', capsule_vm.ip_addr)
        matching_filenames = filter(
            lambda filename: f'{module_name}-{module_versions[1]}' in filename, stored_modules
        )
        assert next(matching_filenames, None)
    def test_positive_remove_prod_promoted_cv_version_from_default_env(self):
        """Remove PROD promoted content view version from Library environment

        :id: 24911876-7c2a-4a12-a3aa-98051dfda29d

        :Steps:

            1. Create a content view
            2. Add yum repositories, puppet modules, docker repositories to CV
            3. Publish content view
            4. Promote the content view version to multiple environments
                Library -> DEV -> QE -> PROD
            5. remove the content view version from Library environment

        :expectedresults: Content view version exist only in DEV, QE, PROD and
            not in Library

        :CaseLevel: Integration
        """
        org = entities.Organization().create()
        lce_dev = entities.LifecycleEnvironment(organization=org).create()
        lce_qe = entities.LifecycleEnvironment(organization=org, prior=lce_dev).create()
        lce_prod = entities.LifecycleEnvironment(organization=org, prior=lce_qe).create()
        product = entities.Product(organization=org).create()
        yum_repo = entities.Repository(url=FAKE_1_YUM_REPO, product=product).create()
        yum_repo.sync()
        docker_repo = entities.Repository(
            content_type='docker',
            docker_upstream_name='busybox',
            product=product,
            url=DOCKER_REGISTRY_HUB,
        ).create()
        docker_repo.sync()
        puppet_repo = entities.Repository(
            url=FAKE_0_PUPPET_REPO, content_type='puppet', product=product
        ).create()
        puppet_repo.sync()
        # create a content view and add to it the yum and docker repos
        content_view = entities.ContentView(organization=org).create()
        content_view.repository = [yum_repo, docker_repo]
        content_view = content_view.update(['repository'])
        # get a random puppet module and add it to content view
        puppet_module = random.choice(content_view.available_puppet_modules()['results'])
        entities.ContentViewPuppetModule(
            author=puppet_module['author'], name=puppet_module['name'], content_view=content_view
        ).create()
        # publish the content view
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        content_view_version = content_view.version[0].read()
        self.assertEqual(len(content_view_version.environment), 1)
        lce_library = entities.LifecycleEnvironment(
            id=content_view_version.environment[0].id
        ).read()
        self.assertEqual(lce_library.name, ENVIRONMENT)
        # promote content view version to DEV QE PROD lifecycle environments
        for lce in [lce_dev, lce_qe, lce_prod]:
            promote(content_view_version, lce.id)
        self.assertEqual(
            {lce_library.id, lce_dev.id, lce_qe.id, lce_prod.id},
            {lce.id for lce in content_view_version.read().environment},
        )
        # remove the content view version from Library environment
        content_view.delete_from_environment(lce_library.id)
        # assert that the content view version exists only in DEV QE PROD and
        # not in Library environment
        self.assertEqual(
            {lce_dev.id, lce_qe.id, lce_prod.id},
            {lce.id for lce in content_view_version.read().environment},
        )
Esempio n. 4
0
    def test_positive_sync_puppet_module_with_versions(self):
        """Ensure it's possible to sync multiple versions of the same puppet
        module to the capsule

        :id: 83a0ddd6-8a6a-43a0-b169-094a2556dd28

        :customerscenario: true

        :BZ: 1365952

        :Steps:

            1. Register a capsule
            2. Associate LCE with the capsule
            3. Sync a puppet module with multiple versions
            4. Publish a CV with one version of puppet module and promote it to
               capsule's LCE
            5. Wait for capsule synchronization to finish
            6. Publish another CV with different version of puppet module and
               promote it to capsule's LCE
            7. Wait for capsule synchronization to finish once more

        :expectedresults: Capsule was successfully synchronized, new version of
            puppet module is present on capsule

        :CaseLevel: System
        """
        module_name = 'versioned'
        module_versions = ['2.2.2', '3.3.3']
        org = entities.Organization().create()
        lce = entities.LifecycleEnvironment(organization=org).create()
        content_view = entities.ContentView(organization=org).create()
        prod = entities.Product(organization=org).create()
        puppet_repository = entities.Repository(
            content_type=REPO_TYPE['puppet'],
            product=prod,
            url=CUSTOM_PUPPET_REPO,
        ).create()
        capsule = entities.Capsule(id=self.capsule_id).read()
        capsule.content_add_lifecycle_environment(data={
            'environment_id': lce.id,
        })
        result = capsule.content_lifecycle_environments()
        self.assertGreaterEqual(len(result['results']), 1)
        self.assertIn(lce.id,
                      [capsule_lce['id'] for capsule_lce in result['results']])
        puppet_repository.sync()
        puppet_module_old = entities.PuppetModule().search(
            query={
                'search':
                'name={} and version={}'.format(module_name,
                                                module_versions[0])
            })[0]
        # Add puppet module to the CV
        entities.ContentViewPuppetModule(
            content_view=content_view,
            id=puppet_module_old.id,
        ).create()
        content_view = content_view.read()
        self.assertGreater(len(content_view.puppet_module), 0)
        # Publish and promote CVV
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cvv = content_view.version[-1].read()
        promote(cvv, lce.id)
        cvv = cvv.read()
        self.assertEqual(len(cvv.environment), 2)
        # Wait till capsule sync finishes
        sync_status = capsule.content_get_sync()
        self.assertTrue(
            len(sync_status['active_sync_tasks']) >= 1
            or sync_status['last_sync_time'])
        for task in sync_status['active_sync_tasks']:
            entities.ForemanTask(id=task['id']).poll()
        sync_status = capsule.content_get_sync()
        last_sync_time = sync_status['last_sync_time']
        # Unassign old puppet module version from CV
        entities.ContentViewPuppetModule(
            content_view=content_view,
            id=content_view.puppet_module[0].id,
        ).delete()
        # Assign new puppet module version
        puppet_module_new = entities.PuppetModule().search(
            query={
                'search':
                'name={} and version={}'.format(module_name,
                                                module_versions[1])
            })[0]
        entities.ContentViewPuppetModule(
            content_view=content_view,
            id=puppet_module_new.id,
        ).create()
        self.assertGreater(len(content_view.puppet_module), 0)
        # Publish and promote CVV
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 2)
        cvv = content_view.version[-1].read()
        promote(cvv, lce.id)
        cvv = cvv.read()
        self.assertEqual(len(cvv.environment), 2)
        # Wait till capsule sync finishes
        sync_status = capsule.content_get_sync()
        if sync_status['active_sync_tasks']:
            for task in sync_status['active_sync_tasks']:
                entities.ForemanTask(id=task['id']).poll()
        else:
            self.assertNotEqual(sync_status['last_sync_time'], last_sync_time)
        stored_modules = get_repo_files(PULP_PUBLISHED_PUPPET_REPOS_PATH, 'gz',
                                        self.capsule_hostname)
        with self.assertNotRaises(StopIteration):
            next(
                filename for filename in stored_modules
                if '{}-{}'.format(module_name, module_versions[1]) in filename)
Esempio n. 5
0
    def test_inherit_puppetclass(self):
        """Host that created from HostGroup entity with PuppetClass
        assigned to it should inherit such puppet class information under
        'all_puppetclasses' field

        :id: 7b840f3d-413c-40bb-9a7d-cd9dad3c0737

        :expectedresults: Host inherited 'all_puppetclasses' details from
            HostGroup that was used for such Host create procedure

        :BZ: 1107708, 1222118, 1487586

        :CaseLevel: System
        """
        # Creating entities like organization, content view and lifecycle_env
        # with not utf-8 names for easier interaction with puppet environment
        # further in test
        org = entities.Organization(name=gen_string('alpha')).create()
        location = entities.Location(organization=[org]).create()
        # Creating puppet repository with puppet module assigned to it
        product = entities.Product(organization=org).create()
        puppet_repo = entities.Repository(content_type='puppet',
                                          product=product).create()
        # Working with 'ntp' module as we know for sure that it contains at
        # least few puppet classes
        with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
            puppet_repo.upload_content(files={'content': handle})

        content_view = entities.ContentView(name=gen_string('alpha'),
                                            organization=org).create()

        result = content_view.available_puppet_modules()['results']
        assert len(result) == 1
        entities.ContentViewPuppetModule(author=result[0]['author'],
                                         name=result[0]['name'],
                                         content_view=content_view).create()
        content_view.publish()
        content_view = content_view.read()
        lc_env = entities.LifecycleEnvironment(name=gen_string('alpha'),
                                               organization=org).create()
        promote(content_view.version[0], lc_env.id)
        content_view = content_view.read()
        assert len(content_view.version) == 1
        assert len(content_view.puppet_module) == 1

        # Form environment name variable for our test
        env_name = f'KT_{org.name}_{lc_env.name}_{content_view.name}_{content_view.id}'

        # Get all environments for current organization.
        # We have two environments (one created after publishing and one more
        # was created after promotion), so we need to select promoted one
        environments = entities.Environment().search(
            query={'organization_id': org.id})
        assert len(environments) == 2
        environments = [
            environment for environment in environments
            if environment.name == env_name
        ]
        assert len(environments) == 1
        environment = environments[0].read()
        environment.location = [location]
        environment.update()

        # Create a host group and it dependencies.
        mac = entity_fields.MACAddressField().gen_value()
        root_pass = entity_fields.StringField(length=(8, 30)).gen_value()
        domain = entities.Domain().create()
        architecture = entities.Architecture().create()
        ptable = entities.PartitionTable().create()
        operatingsystem = entities.OperatingSystem(architecture=[architecture],
                                                   ptable=[ptable]).create()
        medium = entities.Media(operatingsystem=[operatingsystem]).create()
        hostgroup = entities.HostGroup(
            architecture=architecture,
            domain=domain,
            environment=environment,
            location=[location.id],
            medium=medium,
            name=gen_string('alpha'),
            operatingsystem=operatingsystem,
            organization=[org.id],
            ptable=ptable,
        ).create()
        assert len(hostgroup.read_json()['all_puppetclasses']) == 0

        # Get puppet class id for ntp module
        response = client.get(
            environment.path('self') + '/puppetclasses',
            auth=get_credentials(),
            verify=False,
        )
        response.raise_for_status()
        results = response.json()['results']
        puppet_class_id = results['ntp'][0]['id']

        # Assign puppet class
        client.post(
            hostgroup.path('self') + '/puppetclass_ids',
            data={
                'puppetclass_id': puppet_class_id
            },
            auth=get_credentials(),
            verify=False,
        ).raise_for_status()
        hostgroup_attrs = hostgroup.read_json()
        assert len(hostgroup_attrs['all_puppetclasses']) == 1
        assert hostgroup_attrs['all_puppetclasses'][0]['name'] == 'ntp'

        # Create Host entity using HostGroup
        host = entities.Host(
            hostgroup=hostgroup,
            mac=mac,
            root_pass=root_pass,
            environment=environment,
            location=location,
            organization=org,
            content_facet_attributes={
                'content_view_id': content_view.id,
                'lifecycle_environment_id': lc_env.id,
            },
            name=gen_string('alpha'),
        ).create(False)
        host_attrs = host.read_json()
        assert len(host_attrs['all_puppetclasses']) == 1
        assert host_attrs['all_puppetclasses'][0]['name'] == 'ntp'
Esempio n. 6
0
    def test_positive_delete_cv_promoted_to_multi_env(self):
        """Delete published content view with version promoted to multiple
         environments

        :id: c164bd97-e710-4a5a-9c9f-657e6bed804b

        :Steps:

            1. Create a content view
            2. Add a yum repo and a puppet module to the content view
            3. Publish the content view
            4. Promote the content view to multiple environment
               Library -> DEV -> QE -> STAGE -> PROD
            5. Delete the content view, this should delete the content with all
               it's published/promoted versions from all environments

        :expectedresults: The content view doesn't exists

        :CaseLevel: Integration

        :CaseImportance: Critical
        """
        org = entities.Organization().create()
        lce_dev = entities.LifecycleEnvironment(organization=org).create()
        lce_qe = entities.LifecycleEnvironment(organization=org,
                                               prior=lce_dev).create()
        lce_stage = entities.LifecycleEnvironment(organization=org,
                                                  prior=lce_qe).create()
        lce_prod = entities.LifecycleEnvironment(organization=org,
                                                 prior=lce_stage).create()
        product = entities.Product(organization=org).create()
        yum_repo = entities.Repository(url=FAKE_1_YUM_REPO,
                                       product=product).create()
        yum_repo.sync()
        puppet_repo = entities.Repository(url=FAKE_0_PUPPET_REPO,
                                          content_type='puppet',
                                          product=product).create()
        puppet_repo.sync()
        # create a content view and add to it the yum repo
        content_view = entities.ContentView(organization=org).create()
        content_view.repository = [yum_repo]
        content_view = content_view.update(['repository'])
        # get a random puppet module and add it to content view
        puppet_module = random.choice(
            content_view.available_puppet_modules()['results'])
        entities.ContentViewPuppetModule(author=puppet_module['author'],
                                         name=puppet_module['name'],
                                         content_view=content_view).create()
        # publish the content view
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        content_view_version = content_view.version[0].read()
        self.assertEqual(len(content_view_version.environment), 1)
        lce_library = entities.LifecycleEnvironment(
            id=content_view_version.environment[0].id).read()
        self.assertEqual(lce_library.name, ENVIRONMENT)
        # promote content view version to DEV QE STAGE PROD lifecycle
        # environments
        for lce in [lce_dev, lce_qe, lce_stage, lce_prod]:
            promote(content_view_version, lce.id)
        content_view_version = content_view_version.read()
        self.assertEqual(
            {lce_library.id, lce_dev.id, lce_qe.id, lce_stage.id, lce_prod.id},
            {lce.id
             for lce in content_view_version.environment},
        )
        # remove content view version from all lifecycle environments
        for lce in content_view_version.environment:
            content_view.delete_from_environment(lce.id)
        # delete the content view
        content_view.delete()
        with self.assertRaises(HTTPError):
            content_view.read()
Esempio n. 7
0
    def test_positive_end_to_end(self):
        """Perform end to end smoke tests using RH and custom repos.

        1. Create a new user with admin permissions
        2. Using the new user from above
            1. Create a new organization
            2. Clone and upload manifest
            3. Create a new lifecycle environment
            4. Create a custom product
            5. Create a custom YUM repository
            6. Create a custom PUPPET repository
            7. Enable a Red Hat repository
            8. Synchronize the three repositories
            9. Create a new content view
            10. Associate the YUM and Red Hat repositories to new content view
            11. Add a PUPPET module to new content view
            12. Publish content view
            13. Promote content view to the lifecycle environment
            14. Create a new activation key
            15. Add the products to the activation key
            16. Create a new libvirt compute resource
            17. Create a new subnet
            18. Create a new domain
            19. Create a new hostgroup and associate previous entities to it
            20. Provision a client

        :id: b2f73740-d3ce-4e6e-abc7-b23e5562bac1

        :expectedresults: All tests should succeed and Content should be
            successfully fetched by client.
        """
        # step 1: Create a new user with admin permissions
        login = gen_string('alphanumeric')
        password = gen_string('alphanumeric')
        entities.User(admin=True, login=login, password=password).create()

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

        # step 2.2: Clone and upload manifest
        if self.fake_manifest_is_set:
            with manifests.clone() as manifest:
                upload_manifest(org.id, manifest.content)

        # step 2.3: Create a new lifecycle environment
        le1 = entities.LifecycleEnvironment(server_config,
                                            organization=org).create()

        # step 2.4: Create a custom product
        prod = entities.Product(server_config, organization=org).create()
        repositories = []

        # step 2.5: Create custom YUM repository
        repo1 = entities.Repository(server_config,
                                    product=prod,
                                    content_type=u'yum',
                                    url=CUSTOM_RPM_REPO).create()
        repositories.append(repo1)

        # step 2.6: Create custom PUPPET repository
        repo2 = entities.Repository(server_config,
                                    product=prod,
                                    content_type=u'puppet',
                                    url=FAKE_0_PUPPET_REPO).create()
        repositories.append(repo2)

        # step 2.7: Enable a Red Hat repository
        if self.fake_manifest_is_set:
            repo3 = entities.Repository(id=enable_rhrepo_and_fetchid(
                basearch='x86_64',
                org_id=org.id,
                product=PRDS['rhel'],
                repo=REPOS['rhva6']['name'],
                reposet=REPOSET['rhva6'],
                releasever='6Server',
            ))
            repositories.append(repo3)

        # step 2.8: Synchronize the three repositories
        for repo in repositories:
            repo.sync()

        # step 2.9: Create content view
        content_view = entities.ContentView(server_config,
                                            organization=org).create()

        # step 2.10: Associate the YUM and Red Hat repositories to new content
        # view
        repositories.remove(repo2)
        content_view.repository = repositories
        content_view = content_view.update(['repository'])

        # step 2.11: Add a PUPPET module to new content view
        puppet_mods = content_view.available_puppet_modules()
        self.assertGreater(len(puppet_mods['results']), 0)
        puppet_module = random.choice(puppet_mods['results'])
        puppet = entities.ContentViewPuppetModule(
            author=puppet_module['author'],
            content_view=content_view,
            name=puppet_module['name'],
        ).create()
        self.assertEqual(
            puppet.name,
            puppet_module['name'],
        )

        # step 2.12: Publish content view
        content_view.publish()

        # step 2.13: Promote content view to the lifecycle environment
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = content_view.version[0].read()
        self.assertEqual(len(cv_version.environment), 1)
        promote(cv_version, le1.id)
        # check that content view exists in lifecycle
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = cv_version.read()

        # step 2.14: Create a new activation key
        activation_key_name = gen_string('alpha')
        activation_key = entities.ActivationKey(
            name=activation_key_name,
            environment=le1,
            organization=org,
            content_view=content_view,
        ).create()

        # step 2.15: Add the products to the activation key
        for sub in entities.Subscription(organization=org).search():
            if sub.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME:
                activation_key.add_subscriptions(data={
                    'quantity': 1,
                    'subscription_id': sub.id,
                })
                break
        # step 2.15.1: Enable product content
        if self.fake_manifest_is_set:
            activation_key.content_override(
                data={
                    'content_override': {
                        u'content_label': AK_CONTENT_LABEL,
                        u'value': u'1',
                    }
                })

        # BONUS: Create a content host and associate it with promoted
        # content view and last lifecycle where it exists
        content_host = entities.Host(
            content_facet_attributes={
                'content_view_id': content_view.id,
                'lifecycle_environment_id': le1.id,
            },
            organization=org,
        ).create()
        # check that content view matches what we passed
        self.assertEqual(
            content_host.content_facet_attributes['content_view_id'],
            content_view.id)
        # check that lifecycle environment matches
        self.assertEqual(
            content_host.content_facet_attributes['lifecycle_environment_id'],
            le1.id)

        # step 2.16: Create a new libvirt compute resource
        entities.LibvirtComputeResource(
            server_config,
            url=u'qemu+ssh://root@{0}/system'.format(
                settings.compute_resources.libvirt_hostname),
        ).create()

        # step 2.17: Create a new subnet
        subnet = entities.Subnet(server_config).create()

        # step 2.18: Create a new domain
        domain = entities.Domain(server_config).create()

        # step 2.19: Create a new hostgroup and associate previous entities to
        # it
        entities.HostGroup(server_config, domain=domain,
                           subnet=subnet).create()

        # step 2.20: Provision a client
        self.client_provisioning(activation_key_name, org.label)
Esempio n. 8
0
    def test_positive_smoke(self):
        """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
        server_config = get_nailgun_config()
        server_config.auth = (login, password)
        org = entities.Organization(server_config).create()

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

        # step 2.3: Create a custom product
        prod = entities.Product(server_config, organization=org).create()

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

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

        # step 2.6: Synchronize both repositories
        for repo in [repo1, repo2]:
            repo.sync()

        # step 2.7: Create content view
        content_view = entities.ContentView(server_config,
                                            organization=org).create()

        # step 2.8: Associate YUM repository to new content view
        content_view.repository = [repo1]
        content_view = content_view.update(['repository'])

        # Fetch all available puppet modules
        puppet_mods = content_view.available_puppet_modules()
        self.assertGreater(puppet_mods['results'], 0)

        # Select a random puppet module from the results
        puppet_module = random.choice(puppet_mods['results'])
        # ... and associate it to the content view
        puppet = entities.ContentViewPuppetModule(
            author=puppet_module['author'],
            name=puppet_module['name'],
            content_view=content_view,
        ).create()
        self.assertEqual(
            puppet.name,
            puppet_module['name'],
        )

        # step 2.9: Publish content view
        content_view.publish()

        # step 2.10: Promote content view to both lifecycles
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = content_view.version[0].read()
        self.assertEqual(len(cv_version.environment), 1)
        promote(cv_version, le1.id)
        # Check that content view exists in 2 lifecycles
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = cv_version.read()
        self.assertEqual(len(cv_version.environment), 2)
        promote(cv_version, le2.id)
        # Check that content view exists in 2 lifecycles
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        cv_version = cv_version.read()
        self.assertEqual(len(cv_version.environment), 3)

        # BONUS: Create a content host and associate it with promoted
        # content view and last lifecycle where it exists
        content_host = entities.System(server_config,
                                       content_view=content_view,
                                       environment=le2).create()
        # Check that content view matches what we passed
        self.assertEqual(content_host.content_view.id, content_view.id)
        # Check that lifecycle environment matches
        self.assertEqual(content_host.environment.id, le2.id)

        # step 2.11: Create a new libvirt compute resource
        entities.LibvirtComputeResource(
            server_config,
            url=u'qemu+tcp://{0}:16509/system'.format(
                settings.server.hostname),
        ).create()

        # step 2.12: Create a new subnet
        subnet = entities.Subnet(server_config).create()

        # step 2.13: Create a new domain
        domain = entities.Domain(server_config).create()

        # step 2.14: Create a new hostgroup and associate previous entities to
        # it
        entities.HostGroup(server_config, domain=domain,
                           subnet=subnet).create()
Esempio n. 9
0
    def test_positive_delete_with_puppet_content(self):
        """Delete content view version with puppet module content

        :id: cae1164c-6608-4e19-923c-936e75ed807b

        :steps:
            1. Create a lifecycle environment
            2. Create a content view
            3. Add a puppet module to content view
            4. Publish the content view
            5. Promote the content view to lifecycle environment
            6. Remove the content view versions from all lifecycle environments
            7. Delete the content view version

        :expectedresults: Content view version deleted successfully

        :CaseLevel: Integration
        """
        org = entities.Organization().create()
        lce_library = entities.LifecycleEnvironment(
            organization=org, name=ENVIRONMENT).search()[0].read()
        lce = entities.LifecycleEnvironment(organization=org,
                                            prior=lce_library).create()
        product = entities.Product(organization=org).create()
        puppet_repo = entities.Repository(
            url=FAKE_0_PUPPET_REPO,
            content_type=REPO_TYPE['puppet'],
            product=product,
        ).create()
        puppet_repo.sync()
        # create a content view and add the yum repo to it
        content_view = entities.ContentView(organization=org).create()
        # get a random puppet module
        puppet_module = random.choice(
            content_view.available_puppet_modules()['results'])
        # add the puppet module to content view
        entities.ContentViewPuppetModule(
            author=puppet_module['author'],
            name=puppet_module['name'],
            content_view=content_view,
        ).create()
        # publish the content view
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        content_view_version = content_view.version[0].read()
        self.assertEqual(len(content_view_version.environment), 1)
        lce_library = entities.LifecycleEnvironment(
            id=content_view_version.environment[0].id).read()
        self.assertEqual(lce_library.name, ENVIRONMENT)
        # promote content view version to the created lifecycle environment
        promote(content_view_version, lce.id)
        content_view_version = content_view_version.read()
        self.assertEqual({lce_library.id, lce.id},
                         {lce.id
                          for lce in content_view_version.environment})
        # remove the content view versions from all lifecycle environments
        for env in (lce_library, lce):
            content_view.delete_from_environment(env.id)
        content_view_version = content_view_version.read()
        self.assertEqual(len(content_view_version.environment), 0)
        # delete the content view version
        content_view_version.delete()
        self.assertEqual(len(content_view.read().version), 0)
Esempio n. 10
0
def test_positive_remove_cv_version_from_env(module_org):
    """Remove promoted content view version from environment

    :id: 17cf18bf-09d5-4641-b0e0-c50e628fa6c8

    :Steps:

        1. Create a content view
        2. Add a yum repo and a puppet module to the content view
        3. Publish the content view
        4. Promote the content view version to multiple environments
           Library -> DEV -> QE -> STAGE -> PROD
        5. remove the content view version from PROD environment
        6. Assert: content view version exists only in Library, DEV, QE,
           STAGE and not in PROD
        7. Promote again from STAGE -> PROD

    :expectedresults: Content view version exist in Library, DEV, QE,
        STAGE, PROD

    :CaseLevel: Integration
    """
    lce_dev = entities.LifecycleEnvironment(organization=module_org).create()
    lce_qe = entities.LifecycleEnvironment(organization=module_org,
                                           prior=lce_dev).create()
    lce_stage = entities.LifecycleEnvironment(organization=module_org,
                                              prior=lce_qe).create()
    lce_prod = entities.LifecycleEnvironment(organization=module_org,
                                             prior=lce_stage).create()
    product = entities.Product(organization=module_org).create()
    yum_repo = entities.Repository(url=FAKE_1_YUM_REPO,
                                   product=product).create()
    yum_repo.sync()
    puppet_repo = entities.Repository(url=FAKE_0_PUPPET_REPO,
                                      content_type='puppet',
                                      product=product).create()
    puppet_repo.sync()
    # create a content view and add the yum repo to it
    content_view = entities.ContentView(organization=module_org).create()
    content_view.repository = [yum_repo]
    content_view = content_view.update(['repository'])
    # get a random puppet module and add it to content view
    puppet_module = random.choice(
        content_view.available_puppet_modules()['results'])
    entities.ContentViewPuppetModule(author=puppet_module['author'],
                                     name=puppet_module['name'],
                                     content_view=content_view).create()
    # publish the content view
    content_view.publish()
    content_view = content_view.read()
    assert len(content_view.version) == 1
    content_view_version = content_view.version[0].read()
    assert len(content_view_version.environment) == 1
    lce_library = entities.LifecycleEnvironment(
        id=content_view_version.environment[0].id).read()
    assert lce_library.name == ENVIRONMENT
    # promote content view version to DEV QE STAGE PROD lifecycle
    # environments
    for lce in [lce_dev, lce_qe, lce_stage, lce_prod]:
        promote(content_view_version, lce.id)
    assert {lce_library.id, lce_dev.id, lce_qe.id, lce_stage.id, lce_prod.id
            } == {lce.id
                  for lce in content_view_version.read().environment}
    # remove the content view version from Library environment
    content_view.delete_from_environment(lce_prod.id)
    # assert that the content view version exists only in Library DEV QE
    # STAGE and not in PROD environment
    assert {lce_library.id, lce_dev.id, lce_qe.id, lce_stage.id
            } == {lce.id
                  for lce in content_view_version.read().environment}
    # promote content view version to PROD environment again
    promote(content_view_version, lce_prod.id)
    assert {lce_library.id, lce_dev.id, lce_qe.id, lce_stage.id, lce_prod.id
            } == {lce.id
                  for lce in content_view_version.read().environment}