コード例 #1
0
    def test_bugzilla_1127382(self):
        """
        @Test: hammer puppet-module <info,list> --help
        @Feature: puppet-module info/list
        @Assert: Assert product option are present
        """
        # puppet-module list --help:
        result = PuppetModule.list({'help': True})
        # get list of lines and check they all are unique
        lines = [line['message'] for line in result.stdout]
        self.assertEqual(len(set(lines)), len(lines),
                         'The help should not have repeat options')
        product_options = [line for line in lines
                           if line.startswith('--product')]
        self.assertGreater(len(product_options), 0,
                           'At least one --product option should be present')

        # puppet-module info --help:info, ignore exception
        result = PuppetModule.info({'help': True})
        # get list of lines and check they all are unique
        lines = [line for line in result.stdout['options']]
        self.assertEqual(len(set(lines)), len(lines),
                         'The help should not have repeat options')
        product_options = [line for line in lines
                           if line.startswith('--product')]
        self.assertGreater(len(product_options), 0,
                           'At least one --product option should be present')
コード例 #2
0
ファイル: test_puppetmodule.py プロジェクト: cswiii/robottelo
    def test_bugzilla_1127382(self):
        """@Test: hammer puppet-module <info,list> --help

        @Feature: puppet-module info/list

        @Assert: Assert product option are present

        """
        # puppet-module list --help:
        result = PuppetModule.list({'help': True})
        # get list of lines and check they all are unique
        lines = [line['message'] for line in result.stdout]
        self.assertEqual(len(set(lines)), len(lines),
                         'The help should not have repeat options')
        product_options = [line for line in lines
                           if line.startswith('--product')]
        self.assertGreater(len(product_options), 0,
                           'At least one --product option should be present')

        # puppet-module info --help:info, ignore exception
        result = PuppetModule.info({'help': True})
        # get list of lines and check they all are unique
        lines = [line for line in result.stdout['options']]
        self.assertEqual(len(set(lines)), len(lines),
                         'The help should not have repeat options')
        product_options = [line for line in lines
                           if line.startswith('--product')]
        self.assertGreater(len(product_options), 0,
                           'At least one --product option should be present')
コード例 #3
0
    def test_positive_list_multiple_repos(self):
        """Verify that puppet-modules list for specific repo is correct
        and does not affected by other repositories.

        :id: f36d25b3-2495-4e89-a1cf-e39d52762d95

        :expectedresults: Number of modules has no changed after a second repo
            was synced.

        :CaseImportance: Critical
        """
        # Verify that number of synced modules is correct
        repo1 = Repository.info({'id': self.repo['id']})
        repo_content_count = repo1['content-counts']['puppet-modules']
        modules_num = len(PuppetModule.list({'repository-id': repo1['id']}))
        self.assertEqual(repo_content_count, str(modules_num))
        # Create and sync second repo
        repo2 = make_repository({
            u'organization-id': self.org['id'],
            u'product-id': self.product['id'],
            u'content-type': u'puppet',
            u'url': FAKE_1_PUPPET_REPO,
        })
        Repository.synchronize({'id': repo2['id']})
        # Verify that number of modules from the first repo has not changed
        self.assertEqual(
            modules_num, len(PuppetModule.list({'repository-id':
                                                repo1['id']})))
コード例 #4
0
    def test_positive_list_multiple_repos(self):
        """Verify that puppet-modules list for specific repo is correct
        and does not affected by other repositories.

        @id: f36d25b3-2495-4e89-a1cf-e39d52762d95

        @Assert: Number of modules has no changed after a second repo
        was synced.
        """
        # Verify that number of synced modules is correct
        repo1 = Repository.info({'id': self.repo['id']})
        repo_content_count = repo1['content-counts']['puppet-modules']
        modules_num = len(
            PuppetModule.list({'repository-id': repo1['id']}))
        self.assertEqual(repo_content_count, str(modules_num))
        # Create and sync second repo
        repo2 = make_repository({
            u'organization-id': self.org['id'],
            u'product-id': self.product['id'],
            u'content-type': u'puppet',
            u'url': FAKE_1_PUPPET_REPO,
        })
        Repository.synchronize({'id': repo2['id']})
        # Verify that number of modules from the first repo has not changed
        self.assertEqual(
            modules_num,
            len(PuppetModule.list({'repository-id': repo1['id']}))
        )
コード例 #5
0
    def test_positive_info(self):
        """Check if puppet-module info retrieves info for the given
        puppet-module id

        @id: 8aaa9243-5e20-49d6-95ce-620cc1ba18dc

        @Assert: The puppet-module info is retrieved
        """
        return_value = PuppetModule.list({
            'organization-id': self.org['id'],
        })
        for i in range(len(return_value)):
            result = PuppetModule.info({'id': return_value[i]['id']},
                                       output_format='json')
            self.assertEqual(result['id'], return_value[i]['id'])
コード例 #6
0
 def setupScenario(self):
     """ Create yum, puppet repositories and synchronize them.
     """
     self.org = make_org({'name': self.org_name})
     self.product = make_product({
         'name': self.product_name,
         'organization-id': self.org['id']
     })
     self.yum_repo1 = make_repository({
         'name': self.yum_repo1_name,
         'product-id': self.product['id'],
         'content-type': 'yum',
         'url': FAKE_1_YUM_REPO
     })
     Repository.synchronize({'id': self.yum_repo1['id']})
     self.module = {'name': self.puppet_module_name, 'version': '3.3.3'}
     self.puppet_repo = make_repository({
         'name': self.puppet_repo_name,
         'content-type': 'puppet',
         'product-id': self.product['id'],
         'url': CUSTOM_PUPPET_REPO,
     })
     Repository.synchronize({'id': self.puppet_repo['id']})
     self.puppet_module = PuppetModule.list({
         'search':
         'name={name} and version={version}'.format(**self.module)
     })[0]
コード例 #7
0
def test_positive_info(module_setup):
    """Check if puppet-module info retrieves info for the given
    puppet-module id

    :id: 8aaa9243-5e20-49d6-95ce-620cc1ba18dc

    :expectedresults: The puppet-module info is retrieved

    :CaseImportance: Critical
    """
    return_value = PuppetModule.list(
        {'organization-id': module_setup['org'].id})
    for i in range(len(return_value)):
        result = PuppetModule.info({'id': return_value[i]['id']},
                                   output_format='json')
        assert result['id'] == return_value[i]['id']
コード例 #8
0
    def test_puppet_module_info(self):
        """@Test: Check if puppet-module info retrieves info for the given
        puppet-module id

        @Feature: Puppet-module

        @Assert: The puppet-module info is retrieved
        """
        return_value = PuppetModule.list({
            'organization-id': self.org['id'],
        })
        for i in range(len(return_value)):
            result = PuppetModule.info(
                {'id': return_value[i]['id']},
                output_format='json'
            )
            self.assertEqual(result['ID'], return_value[i]['id'])
コード例 #9
0
    def test_positive_info(self):
        """Check if puppet-module info retrieves info for the given
        puppet-module id

        @id: 8aaa9243-5e20-49d6-95ce-620cc1ba18dc

        @Assert: The puppet-module info is retrieved
        """
        return_value = PuppetModule.list({
            'organization-id': self.org['id'],
        })
        for i in range(len(return_value)):
            result = PuppetModule.info(
                {'id': return_value[i]['id']},
                output_format='json'
            )
            self.assertEqual(result['id'], return_value[i]['id'])
コード例 #10
0
ファイル: test_contentview.py プロジェクト: tstrych/robottelo
    def test_cv_preupgrade_scenario(self, request):
        """Pre-upgrade scenario that creates content-view with various repositories.

        :id: a4ebbfa1-106a-4962-9c7c-082833879ae8

        :steps:
          1. Create custom repositories of yum, puppet and file type.
          2. Create content-view.
          3. Add yum, file repositories and puppet module in the content view.
          4. Publish the content-view.

        :expectedresults: Content-view created with various repositories.
        """
        test_name = request.node.name
        puppet_module = {'name': 'versioned', 'version': '3.3.3'}
        org = entities.Organization(name=f'{request.node.name}_org').create()
        product = entities.Product(organization=org,
                                   name=f'{request.node.name}_prod').create()
        yum_repository = entities.Repository(product=product,
                                             name=f'{test_name}_yum_repo',
                                             url=FAKE_1_YUM_REPO).create()
        entities.Repository.sync(yum_repository)
        puppet_repository = entities.Repository(
            product=product,
            name=f'{request.node.name}_puppet_repo',
            content_type="puppet",
            url=CUSTOM_PUPPET_REPO,
        ).create()
        entities.Repository.sync(puppet_repository)
        puppet_module_list = PuppetModule.list({
            'search':
            'name={name} and version={version}'.format(**puppet_module)
        })[0]

        file_repository = entities.Repository(product=product,
                                              name=f'{test_name}_file_repo',
                                              content_type="file").create()

        remote_file_path = f"/tmp/{RPM_TO_UPLOAD}"

        ssh.upload_file(local_file=get_data_file(RPM_TO_UPLOAD),
                        remote_file=remote_file_path)
        with open(f'{get_data_file(RPM_TO_UPLOAD)}', "rb") as content:
            file_repository.upload_content(files={'content': content})
        assert RPM_TO_UPLOAD in file_repository.files()["results"][0]['name']
        cv = entities.ContentView(name=f"{test_name}_cv",
                                  organization=org).create()
        cv.repository = [yum_repository, file_repository]
        cv.update(['repository'])
        ContentView.puppet_module_add({
            'content-view-id': cv.id,
            'name': puppet_module_list['name'],
            'author': puppet_module_list['author'],
        })
        cv.publish()
        assert len(cv.puppet_module) == 0
        assert len(cv.read_json()['versions']) == 1
コード例 #11
0
    def test_puppet_module_list(self):
        """@Test: Check if puppet-module list retrieves puppet-modules of
        the given org

        @Feature: Puppet-module

        @Assert: Puppet-modules are retrieved for the given org
        """
        result = PuppetModule.list({'organization-id': self.org['id']})
        # There are 4 puppet modules in the test puppet-module url
        self.assertEqual(len(result), 4)
コード例 #12
0
    def test_positive_list(self):
        """Check if puppet-module list retrieves puppet-modules of
        the given org

        @id: 77635e70-19e7-424d-9c89-ec5dbe91de75

        @Assert: Puppet-modules are retrieved for the given org
        """
        result = PuppetModule.list({'organization-id': self.org['id']})
        # There are 4 puppet modules in the test puppet-module url
        self.assertEqual(len(result), 4)
コード例 #13
0
    def test_positive_list(self):
        """Check if puppet-module list retrieves puppet-modules of
        the given org

        @id: 77635e70-19e7-424d-9c89-ec5dbe91de75

        @Assert: Puppet-modules are retrieved for the given org
        """
        result = PuppetModule.list({'organization-id': self.org['id']})
        # There are 4 puppet modules in the test puppet-module url
        self.assertEqual(len(result), 4)
コード例 #14
0
    def test_positive_list(self):
        """Check if puppet-module list retrieves puppet-modules of
        the given org

        :id: 77635e70-19e7-424d-9c89-ec5dbe91de75

        :expectedresults: Puppet-modules are retrieved for the given org

        :bz: 1283173

        :CaseImportance: Critical
        """
        result = PuppetModule.list({'organization-id': self.org['id']})
        # There are 4 puppet modules in the test puppet-module url
        self.assertEqual(len(result), 4)
コード例 #15
0
def test_positive_list(module_setup):
    """Check if puppet-module list retrieves puppet-modules of
    the given org

    :id: 77635e70-19e7-424d-9c89-ec5dbe91de75

    :expectedresults: Puppet-modules are retrieved for the given org

    :BZ: 1283173

    :CaseImportance: Critical
    """
    result = PuppetModule.list({'organization-id': module_setup['org'].id})
    # There are 4 puppet modules in the test puppet-module url
    assert len(result) == 4
コード例 #16
0
ファイル: test_contentview.py プロジェクト: jhutar/robottelo
 def setupScenario(self):
     """ Create yum, puppet repositories and synchronize them.
     """
     self.org = make_org({'name': self.org_name})
     self.product = make_product({
         'name': self.product_name, 'organization-id': self.org['id']})
     self.yum_repo1 = make_repository({
         'name': self.yum_repo1_name,
         'product-id': self.product['id'],
         'content-type': 'yum',
         'url': FAKE_1_YUM_REPO})
     Repository.synchronize({'id': self.yum_repo1['id']})
     self.module = {'name': self.puppet_module_name, 'version': '3.3.3'}
     self.puppet_repo = make_repository({
         'name': self.puppet_repo_name,
         'content-type': 'puppet',
         'product-id': self.product['id'],
         'url': CUSTOM_PUPPET_REPO,
     })
     Repository.synchronize({'id': self.puppet_repo['id']})
     self.puppet_module = PuppetModule.list({
         'search': 'name={name} and version={version}'.format(**self.module)})[0]
コード例 #17
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: 8c8b3ffa-0d54-436b-8eeb-1a3542e100a8

        @Assert: All tests should succeed and Content should be successfully
        fetched by client.
        """
        # step 1: Create a new user with admin permissions
        password = gen_alphanumeric()
        user = make_user({u'admin': u'true', u'password': password})
        user['password'] = password

        # step 2.1: Create a new organization
        org = self._create(user, Org, {u'name': gen_alphanumeric()})

        # step 2.2: Clone and upload manifest
        if self.fake_manifest_is_set:
            with manifests.clone() as manifest:
                ssh.upload_file(manifest.content, manifest.filename)
            Subscription.upload({
                u'file': manifest.filename,
                u'organization-id': org['id'],
            })

        # step 2.3: Create a new lifecycle environment
        lifecycle_environment = self._create(
            user,
            LifecycleEnvironment,
            {
                u'name': gen_alphanumeric(),
                u'organization-id': org['id'],
                u'prior': u'Library',
            }
        )

        # step 2.4: Create a custom product
        product = self._create(
            user,
            Product,
            {
                u'name': gen_alphanumeric(),
                u'organization-id': org['id'],
            }
        )
        repositories = []

        # step 2.5: Create custom YUM repository
        yum_repo = self._create(
            user,
            Repository,
            {
                u'content-type': u'yum',
                u'name': gen_alphanumeric(),
                u'product-id': product['id'],
                u'publish-via-http': u'true',
                u'url': GOOGLE_CHROME_REPO,
            }
        )
        repositories.append(yum_repo)

        # step 2.6: Create custom PUPPET repository
        puppet_repo = self._create(
            user,
            Repository,
            {
                u'content-type': u'puppet',
                u'name': gen_alphanumeric(),
                u'product-id': product['id'],
                u'publish-via-http': u'true',
                u'url': FAKE_0_PUPPET_REPO,
            }
        )
        repositories.append(puppet_repo)

        # step 2.7: Enable a Red Hat repository
        if self.fake_manifest_is_set:
            RepositorySet.enable({
                u'basearch': 'x86_64',
                u'name': REPOSET['rhva6'],
                u'organization-id': org['id'],
                u'product': PRDS['rhel'],
                u'releasever': '6Server',
            })
            rhel_repo = Repository.info({
                u'name': REPOS['rhva6']['name'],
                u'organization-id': org['id'],
                u'product': PRDS['rhel'],
            })
            repositories.append(rhel_repo)

        # step 2.8: Synchronize the three repositories
        for repo in repositories:
            Repository.with_user(
                user['login'],
                user['password']
            ).synchronize({u'id': repo['id']})

        # step 2.9: Create content view
        content_view = self._create(
            user,
            ContentView,
            {
                u'name': gen_alphanumeric(),
                u'organization-id': org['id'],
            }
        )

        # step 2.10: Associate the YUM and Red Hat repositories to new content
        # view
        repositories.remove(puppet_repo)
        for repo in repositories:
            ContentView.add_repository({
                u'id': content_view['id'],
                u'organization-id': org['id'],
                u'repository-id': repo['id'],
            })

        # step 2.11: Add a PUPPET module to new content view
        result = PuppetModule.with_user(
            user['login'],
            user['password']
        ).list({
            u'repository-id': puppet_repo['id'],
            u'per-page': False,
        })
        ContentView.with_user(
            user['login'],
            user['password']
        ).puppet_module_add({
            u'content-view-id': content_view['id'],
            u'id': random.choice(result)['id'],
        })

        # step 2.12: Publish content view
        ContentView.with_user(
            user['login'],
            user['password']
        ).publish({u'id': content_view['id']})

        # step 2.13: Promote content view to the lifecycle environment
        content_view = ContentView.with_user(
            user['login'],
            user['password']
        ).info({u'id': content_view['id']})
        self.assertEqual(len(content_view['versions']), 1)
        cv_version = ContentView.with_user(
            user['login'],
            user['password']
        ).version_info({
            'id': content_view['versions'][0]['id'],
        })
        self.assertEqual(len(cv_version['lifecycle-environments']), 1)
        ContentView.with_user(
            user['login'],
            user['password']
        ).version_promote({
            u'id': cv_version['id'],
            u'to-lifecycle-environment-id': lifecycle_environment['id'],
        })
        # check that content view exists in lifecycle
        content_view = ContentView.with_user(
            user['login'],
            user['password']
        ).info({u'id': content_view['id']})
        self.assertEqual(len(content_view['versions']), 1)
        cv_version = ContentView.with_user(
            user['login'],
            user['password']
        ).version_info({
            'id': content_view['versions'][0]['id'],
        })
        self.assertEqual(len(cv_version['lifecycle-environments']), 2)
        self.assertEqual(
            cv_version['lifecycle-environments'][-1]['id'],
            lifecycle_environment['id']
        )

        # step 2.14: Create a new activation key
        activation_key = self._create(
            user,
            ActivationKey,
            {
                u'content-view-id': content_view['id'],
                u'lifecycle-environment-id': lifecycle_environment['id'],
                u'name': gen_alphanumeric(),
                u'organization-id': org['id'],
            }
        )

        # step 2.15: Add the products to the activation key
        subscription_list = Subscription.with_user(
            user['login'],
            user['password']
        ).list(
            {u'organization-id': org['id']},
            per_page=False
        )
        for subscription in subscription_list:
            if subscription['name'] == DEFAULT_SUBSCRIPTION_NAME:
                ActivationKey.with_user(
                    user['login'],
                    user['password']
                ).add_subscription({
                    u'id': activation_key['id'],
                    u'quantity': 1,
                    u'subscription-id': subscription['id'],
                })

        # step 2.15.1: Enable product content
        if self.fake_manifest_is_set:
            ActivationKey.with_user(
                user['login'],
                user['password']
            ).content_override({
                u'content-label': AK_CONTENT_LABEL,
                u'id': activation_key['id'],
                u'organization-id': org['id'],
                u'value': '1',
            })

        # BONUS: Create a content host and associate it with promoted
        # content view and last lifecycle where it exists
        content_host_name = gen_alphanumeric()
        content_host = Host.with_user(
            user['login'],
            user['password']
        ).subscription_register({
            u'content-view-id': content_view['id'],
            u'lifecycle-environment-id': lifecycle_environment['id'],
            u'name': content_host_name,
            u'organization-id': org['id'],
        })
        if bz_bug_is_open(1328202):
            results = ContentHost.with_user(
                user['login'],
                user['password']
            ).list({
                'organization-id': org['id']
            })
            # Content host registration converts the name to lowercase, make
            # sure to use the same format while matching against the result
            content_host_name = content_host_name.lower()
            for result in results:
                if result['name'] == content_host_name:
                    content_host = result
        content_host = ContentHost.with_user(
            user['login'],
            user['password']
        ).info({'id': content_host['id']})
        # check that content view matches what we passed
        self.assertEqual(
            content_host['content-view'],
            content_view['name']
        )
        # check that lifecycle environment matches
        self.assertEqual(
            content_host['lifecycle-environment'],
            lifecycle_environment['name']
        )

        # step 2.16: Create a new libvirt compute resource
        self._create(
            user,
            ComputeResource,
            {
                u'name': gen_alphanumeric(),
                u'provider': u'Libvirt',
                u'url': u'qemu+ssh://root@{0}/system'.format(
                    settings.compute_resources.libvirt_hostname
                ),
            }
        )

        # step 2.17: Create a new subnet
        subnet = self._create(
            user,
            Subnet,
            {
                u'name': gen_alphanumeric(),
                u'network': gen_ipaddr(ip3=True),
                u'mask': u'255.255.255.0',
            }
        )

        # step 2.18: Create a new domain
        domain = self._create(user, Domain, {u'name': gen_alphanumeric()})

        # step 2.19: Create a new hostgroup and associate previous entities to
        # it
        host_group = self._create(
            user,
            HostGroup,
            {
                u'domain-id': domain['id'],
                u'name': gen_alphanumeric(),
                u'subnet-id': subnet['id'],
            }
        )
        if not bz_bug_is_open('1326101'):
            Org.with_user(
                user['login'],
                user['password']
            ).add_hostgroup({
                u'hostgroup-id': host_group['id'],
                u'id': org['id'],
            })

        # step 2.20: Provision a client
        self.client_provisioning(activation_key['name'], org['label'])
コード例 #18
0
ファイル: test_cli_smoke.py プロジェクト: lpramuk/robottelo
    def test_smoke(self):
        """@Test: Check that basic content can be created

        * Create a new user with admin permissions
        * Using the new user from above:

            * Create a new organization
            * Create two new lifecycle environments
            * Create a custom product
            * Create a custom YUM repository
            * Create a custom PUPPET repository
            * Synchronize both custom repositories
            * Create a new content view
            * Associate both repositories to new content view
            * Publish content view
            * Promote content view to both lifecycles
            * Create a new libvirt compute resource
            * Create a new subnet
            * Create a new domain
            * Create a new hostgroup and associate previous entities to it

        @Feature: Smoke Test

        @Assert: All entities are created and associated.

        """
        # Create new user
        password = gen_alphanumeric()
        new_user = make_user({u'admin': u'true', u'password': password})

        # Append the password as the info command does not return it
        new_user[u'password'] = password

        # Create new org as new user
        new_org = self._create(
            new_user,
            Org,
            {u'name': gen_alphanumeric()}
        )

        # Create new lifecycle environment 1
        lifecycle1 = self._create(
            new_user,
            LifecycleEnvironment,
            {
                u'name': gen_alphanumeric(),
                u'organization-id': new_org['id'],
                u'prior': u'Library',
            }
        )

        # Create new lifecycle environment 2
        lifecycle2 = self._create(
            new_user,
            LifecycleEnvironment,
            {
                u'name': gen_alphanumeric(),
                u'organization-id': new_org['id'],
                u'prior': lifecycle1['name'],
            }
        )

        # Create a new product
        new_product = self._create(
            new_user,
            Product,
            {
                u'name': gen_alphanumeric(),
                u'organization-id': new_org['id'],
            }
        )

        # Create a YUM repository
        new_repo1 = self._create(
            new_user,
            Repository,
            {
                u'content-type': u'yum',
                u'name': gen_alphanumeric(),
                u'product-id': new_product['id'],
                u'publish-via-http': u'true',
                u'url': GOOGLE_CHROME_REPO,
            }
        )

        # Create a Puppet repository
        new_repo2 = self._create(
            new_user,
            Repository,
            {
                u'content-type': u'puppet',
                u'name': gen_alphanumeric(),
                u'product-id': new_product['id'],
                u'publish-via-http': u'true',
                u'url': FAKE_0_PUPPET_REPO,
            }
        )

        # Synchronize YUM repository
        Repository.with_user(
            new_user['login'],
            new_user['password']
        ).synchronize({u'id': new_repo1['id']})

        # Synchronize puppet repository
        Repository.with_user(
            new_user['login'],
            new_user['password']
        ).synchronize({u'id': new_repo2['id']})

        # Create a Content View
        new_cv = self._create(
            new_user,
            ContentView,
            {
                u'name': gen_alphanumeric(),
                u'organization-id': new_org['id'],
            }
        )

        # Associate yum repository to content view
        ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).add_repository({
            u'id': new_cv['id'],
            u'repository-id': new_repo1['id'],
        })

        # Fetch puppet module
        puppet_result = PuppetModule.with_user(
            new_user['login'],
            new_user['password']
        ).list({
            u'repository-id': new_repo2['id'],
            u'per-page': False,
        })

        # Associate puppet repository to content view
        ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).puppet_module_add({
            u'content-view-id': new_cv['id'],
            u'id': puppet_result[0]['id'],
        })

        # Publish content view
        ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).publish({u'id': new_cv['id']})

        # Only after we publish version1 the info is populated.
        result = ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).info({u'id': new_cv['id']})

        # Let us now store the version1 id
        version1_id = result['versions'][0]['id']

        # Promote content view to first lifecycle
        ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).version_promote({
            u'id': version1_id,
            u'to-lifecycle-environment-id': lifecycle1['id'],
        })

        # Promote content view to second lifecycle
        ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).version_promote({
            u'id': version1_id,
            u'to-lifecycle-environment-id': lifecycle2['id'],
        })

        # Create a new libvirt compute resource
        self._create(
            new_user,
            ComputeResource,
            {
                u'name': gen_alphanumeric(),
                u'provider': u'Libvirt',
                u'url': u'qemu+tcp://{0}:16509/system'.format(
                    conf.properties['main.server.hostname']),
            }
        )

        # Create a new subnet
        new_subnet = self._create(
            new_user,
            Subnet,
            {
                u'name': gen_alphanumeric(),
                u'network': gen_ipaddr(ip3=True),
                u'mask': u'255.255.255.0',
            }
        )

        # Create a domain
        new_domain = self._create(
            new_user,
            Domain,
            {
                u'name': gen_alphanumeric(),
            }
        )

        # Fetch Puppet environment for second lifecycle
        # (unfortunately it is not straight forward to extract this)

        # The puppet environment we want has a name like this...
        env_name = u'KT_{0}_{1}_'.format(
            #  Hyphens are replaced by underscores
            new_org['label'].replace('-', '_',),
            lifecycle2['label'].replace('-', '_')
        )
        # We fetch all the puppet environments for our organization...
        result = Environment.with_user(
            new_user['login'],
            new_user['password']
        ).list({
            u'search': u'organization="{0}"'.format(new_org['name']),
        })
        # Now look for the puppet environment that matches lifecycle2
        puppet_env = [
            env for env in result
            if env['name'].startswith(env_name)
        ]
        self.assertEqual(len(puppet_env), 1)

        # Create a hostgroup...
        new_hg = self._create(
            new_user,
            HostGroup,
            {
                u'domain-id': new_domain['id'],
                u'environment-id': puppet_env[0]['id'],
                u'name': gen_alphanumeric(),
                u'subnet-id': new_subnet['id'],
            }
        )
        # ...and add it to the organization
        Org.with_user(
            new_user['login'],
            new_user['password']
        ).add_hostgroup({
            u'hostgroup-id': new_hg['id'],
            u'id': new_org['id'],
        })
コード例 #19
0
    def test_smoke(self):
        """
        @Test: Check that basic content can be created
        * Create a new user with admin permissions
        * Using the new user from above:

            * Create a new organization
            * Create two new lifecycle environments
            * Create a custom product
            * Create a custom YUM repository
            * Create a custom PUPPET repository
            * Synchronize both custom repositories
            * Create a new content view
            * Associate both repositories to new content view
            * Publish content view
            * Promote content view to both lifecycles
            * Create a new libvirt compute resource
            * Create a new subnet
            * Create a new domain
            * Create a new capsule
            * Create a new hostgroup and associate previous entities to it

        @Feature: Smoke Test
        @Assert: All entities are created and associated.
        """

        # Create new user
        new_user = make_user({'admin': 'true'})

        # Create new org as new user
        new_org = self._create(
            new_user,
            Org,
            {u'name': self._generate_name()}
        )

        # Create new lifecycle environment 1
        lifecycle1 = self._create(
            new_user,
            LifecycleEnvironment,
            {u'organization-id': new_org['id'],
             u'name': self._generate_name(),
             u'prior': u'Library'}
        )

        # Create new lifecycle environment 2
        lifecycle2 = self._create(
            new_user,
            LifecycleEnvironment,
            {u'organization-id': new_org['id'],
             u'name': self._generate_name(),
             u'prior': lifecycle1['name']}
        )

        # Create a new product
        new_product = self._create(
            new_user,
            Product,
            {u'organization-id': new_org['id'],
             u'name': self._generate_name()}
        )

        # Create a YUM repository
        new_repo1 = self._create(
            new_user,
            Repository,
            {u'product-id': new_product['id'],
             u'name': self._generate_name(),
             u'content-type': u'yum',
             u'publish-via-http': u'true',
             u'url': GOOGLE_CHROME_REPO}
        )

        # Create a Puppet repository
        new_repo2 = self._create(
            new_user,
            Repository,
            {u'product-id': new_product['id'],
             u'name': self._generate_name(),
             u'content-type': u'puppet',
             u'publish-via-http': u'true',
             u'url': FAKE_PUPPET_REPO}
        )

        # Synchronize YUM repository
        result = Repository.with_user(
            new_user['login'],
            new_user['password']
        ).synchronize({'id': new_repo1['id']})
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to synchronize YUM repo: {0}".format(result.stderr))

        # Synchronize puppet repository
        result = Repository.with_user(
            new_user['login'],
            new_user['password']
        ).synchronize({'id': new_repo2['id']})
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to synchronize Puppet repo: {0}".format(result.stderr))

        # Create a Content View
        new_cv = self._create(
            new_user,
            ContentView,
            {u'organization-id': new_org['id'],
             u'name': self._generate_name()}
        )

        # Associate yum repository to content view
        result = ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).add_repository(
            {u'id': new_cv['id'],
             u'repository-id': new_repo1['id']})
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to add YUM repo to content view: {0}".format(
                result.stderr))

        # Fetch puppet module
        puppet_result = PuppetModule.with_user(
            new_user['login'],
            new_user['password']
        ).list(
            {u'repository-id': new_repo2['id'],
             u'per-page': False})
        self.assertEqual(
            puppet_result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(puppet_result.stderr),
            0,
            u"Puppet modules list was not generated: {0}".format(
                result.stderr))

        # Associate puppet repository to content view
        result = ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).puppet_module_add(
            {
                u'content-view-id': new_cv['id'],
                u'name': puppet_result.stdout[0]['name']
            }
        )
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to add YUM repo to content view: {0}".format(
                result.stderr))

        # Publish content view
        result = ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).publish({u'id': new_cv['id']})
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to publish content view: {0}".format(result.stderr))

        # Only after we publish version1 the info is populated.
        result = ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).info({u'id': new_cv['id']})
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Could not fetch content view info: {0}".format(result.stderr))

        # Let us now store the version1 id
        version1_id = result.stdout['versions'][0]['id']

        # Promote content view to first lifecycle
        result = ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).version_promote(
            {u'id': result.stdout['versions'][0]['id'],
             u'lifecycle-environment-id': lifecycle1['id']})
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to promote content view to lifecycle '{0}': {1}".format(
                lifecycle1['name'], result.stderr))

        # Promote content view to second lifecycle
        result = ContentView.with_user(
            new_user['login'],
            new_user['password']
        ).version_promote(
            {u'id': version1_id,
             u'lifecycle-environment-id': lifecycle2['id']})
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to promote content view to lifecycle '{0}': {1}".format(
                lifecycle2['name'], result.stderr))

        # Create a new libvirt compute resource
        result = self._create(
            new_user,
            ComputeResource,
            {
                u'name': self._generate_name(),
                u'provider': u'Libvirt',
                u'url': u'qemu+tcp://{0}:16509/system'.format(
                    conf.properties['main.server.hostname'])
            })

        # Create a new subnet
        new_subnet = self._create(
            new_user,
            Subnet,
            {
                u'name': self._generate_name(),
                u'network': FauxFactory.generate_ipaddr(ip3=True),
                u'mask': u'255.255.255.0'
            }
        )

        # Create a domain
        new_domain = self._create(
            new_user,
            Domain,
            {
                u'name': self._generate_name(),
            }
        )

        # Fetch Puppet environment for second lifecycle
        # (unfortunately it is not straight forward to extract this)

        # The puppet environment we want has a name like this...
        env_name = u'KT_{0}_{1}_'.format(
            #  Hyphens are replaced by underscores
            new_org['label'].replace('-', '_',),
            lifecycle2['label'].replace('-', '_')
        )
        # We fetch all the puppet environments for our organization...
        result = Environment.with_user(
            new_user['login'],
            new_user['password']
        ).list(
            {
                u'search': u'organization=\"{0}\"'.format(
                    new_org['name'])
            })
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to fetch puppet environments: {0}".format(
                result.stderr))
        # Now look for the puppet environment that matches lifecycle2
        puppet_env = [
            env for env in result.stdout if env['name'].startswith(
                env_name)]
        self.assertEqual(
            len(puppet_env),
            1,
            u'Could not find the puppet environment: {0}'.format(env_name))

        # Create new Capsule...
        new_capsule = self._create(
            new_user,
            Proxy,
            {
                u'name': self._generate_name(),
                u'url': u'https://{0}:9090/'.format(
                    conf.properties['main.server.hostname'])
            }
        )
        # ...and add it to the organization
        result = Org.with_user(
            new_user['login'],
            new_user['password']
        ).add_smart_proxy(
            {
                u'id': new_org['id'],
                u'smart-proxy-id': new_capsule['id']
            }
        )
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to add capsule '{0}' to org '{1}': {2}".format(
                new_capsule['name'], new_org['name'], result.stderr))

        # Create a hostgroup...
        new_hg = self._create(
            new_user,
            HostGroup,
            {
                u'name': self._generate_name(),
                u'domain-id': new_domain['id'],
                u'subnet-id': new_subnet['id'],
                u'environment-id': puppet_env[0]['id'],
                u'puppet-ca-proxy-id': new_capsule['id'],
                u'puppet-proxy-id': new_capsule['id'],
            }
        )
        # ...and add it to the organization
        result = Org.with_user(
            new_user['login'],
            new_user['password']
        ).add_hostgroup(
            {
                u'id': new_org['id'],
                u'hostgroup-id': new_hg['id']
            }
        )
        self.assertEqual(
            result.return_code,
            0,
            u"Return code is non-zero: {0}".format(result.return_code))
        self.assertEqual(
            len(result.stderr),
            0,
            u"Failed to add hostgroup '{0}' to org '{1}': {2}".format(
                new_hg['name'], new_org['name'], result.stderr))
コード例 #20
0
ファイル: test_contentview.py プロジェクト: tstrych/robottelo
    def test_cv_postupgrade_scenario(self, request, dependent_scenario_name):
        """After upgrade, the existing content-view(created before upgrade) should be updated.

        :id: a4ebbfa1-106a-4962-9c7c-082833879ae8

        :steps:
          1. Check yum, puppet and file repository which was added in CV before upgrade.
          2. Check the content view which was was created before upgrade.
          3. Remove yum repository from existing CV.
          4. Create new yum repository in existing CV.
          5. Remove puppet module which was added to content-view before upgrade.
          6. Add another puppet module to content-view
          7. Publish content-view

        :expectedresults: After upgrade,
          1. All the repositories should be intact.
          2. Content view created before upgrade should be intact.
          3. The new repository should be added/updated to the CV.
          4. Puppet module should be added/updated to the CV.

        """
        pre_test_name = dependent_scenario_name
        puppet_module = {'name': 'versioned', 'version': '3.3.3'}
        org = entities.Organization().search(
            query={'search': f'name="{pre_test_name}_org"'})[0]
        request.addfinalizer(org.delete)
        product = entities.Product(organization=org.id).search(
            query={'search': f'name="{pre_test_name}_prod"'})[0]
        request.addfinalizer(product.delete)
        cv = entities.ContentView(organization=org.id).search(
            query={'search': f'name="{pre_test_name}_cv"'})[0]
        yum_repo = entities.Repository(organization=org.id).search(
            query={'search': f'name="{pre_test_name}_yum_repo"'})[0]
        request.addfinalizer(yum_repo.delete)
        file_repo = entities.Repository(organization=org.id).search(
            query={'search': f'name="{pre_test_name}_file_repo"'})[0]
        request.addfinalizer(file_repo.delete)
        puppet_repo = entities.Repository(organization=org.id).search(
            query={'search': f'name="{pre_test_name}_puppet_repo"'})[0]
        request.addfinalizer(puppet_repo.delete)
        request.addfinalizer(cv.delete)
        puppet_module_list = PuppetModule.list({
            'search':
            'name={name} and version={version}'.format(**puppet_module)
        })[0]
        cv.repository = []
        cv.update(['repository'])
        assert len(cv.read_json()['repositories']) == 0

        yum_repository2 = entities.Repository(
            product=product,
            name=f'{pre_test_name}_yum_repos2',
            url=FAKE_2_YUM_REPO).create()
        yum_repository2.sync()
        cv.repository = [yum_repository2]
        cv.update(['repository'])
        assert cv.read_json(
        )['repositories'][0]['name'] == yum_repository2.name

        ContentView.puppet_module_remove({
            'organization':
            org.name,
            'content-view':
            cv.name,
            'name':
            puppet_module_list['name'],
            'author':
            puppet_module_list['author'],
        })
        assert len(cv.read_json()['puppet_modules']) == 0

        module = {'name': 'versioned', 'version': '2.2.2'}
        puppet_module_list = PuppetModule.list(
            {'search':
             'name={name} and version={version}'.format(**module)})[0]
        ContentView.puppet_module_add({
            'organization': org.name,
            'content-view': cv.name,
            'name': puppet_module_list['name'],
            'author': puppet_module_list['author'],
        })
        assert len(cv.read_json()['puppet_modules']) > 0
        cv.publish()
        assert len(cv.read_json()['versions']) == 2
        content_view_json = cv.read_json()['environments'][0]
        cv.delete_from_environment(content_view_json['id'])
        assert len(cv.read_json()['environments']) == 0
コード例 #21
0
    def test_cv_postupgrade_scenario(self):
        """This is post-upgrade scenario test to verify if we can update
         content-view created in pre-upgrade scenario with various repositories.

         :id: a4ebbfa1-106a-4962-9c7c-082833879ae8

         :steps:
           1. Remove yum repository which was added to content-view before upgrade.
           2. Create new yum repository and add it to content-view.
           3. Remove puppet module which was added to content-view before upgrade.
           4. Add another puppet module to content-view
           5. Publish content-view

         :expectedresults: content-view updated with various repositories.
        """
        product_id = Repository.info({
            'name': self.yum_repo1_name,
            'organization': self.org_name,
            'product': self.product_name
        })['product']['id']
        ContentView.remove_repository({
            'organization': self.org_name,
            'name': self.cv_name,
            'repository': self.yum_repo1_name
        })
        content_view = ContentView.info({
            'name': self.cv_name,
            'organization': self.org_name
        })
        self.assertNotIn(self.yum_repo1_name, content_view['yum-repositories'])
        yum_repo2 = make_repository({
            'name': self.yum_repo2_name,
            'organization': self.org_name,
            'content-type': 'yum',
            'product-id': product_id,
            'url': FAKE_2_YUM_REPO
        })
        Repository.synchronize({
            'id': yum_repo2['id'],
            'organization': self.org_name
        })
        ContentView.add_repository({
            'name': self.cv_name,
            'organization': self.org_name,
            'product': self.product_name,
            'repository-id': yum_repo2['id']
        })
        content_view = ContentView.info({
            'name': self.cv_name,
            'organization': self.org_name
        })
        self.assertEqual(
            content_view['yum-repositories'][0]['name'],
            self.yum_repo2_name,
            'Repo was not associated to CV',
        )
        ContentView.puppet_module_remove({
            'organization': self.org_name,
            'content-view': self.cv_name,
            'name': self.puppet_module_name,
            'author': self.puppet_module_author,
        })
        content_view = ContentView.info({
            'name': self.cv_name,
            'organization': self.org_name
        })
        self.assertEqual(len(content_view['puppet-modules']), 0)
        module = {'name': 'versioned', 'version': '2.2.2'}
        puppet_module = PuppetModule.list(
            {'search':
             'name={name} and version={version}'.format(**module)})[0]
        ContentView.puppet_module_add({
            'organization': self.org_name,
            'content-view': self.cv_name,
            'name': puppet_module['name'],
            'author': puppet_module['author'],
        })
        content_view = ContentView.info({'id': content_view['id']})
        self.assertGreater(len(content_view['puppet-modules']), 0)
        ContentView.publish({
            'name': self.cv_name,
            'organization': self.org_name
        })
        content_view = ContentView.info({
            'name': self.cv_name,
            'organization': self.org_name
        })
        self.assertEqual(len(content_view['versions']), 2)
コード例 #22
0
ファイル: test_contentview.py プロジェクト: jhutar/robottelo
    def test_cv_postupgrade_scenario(self):
        """This is post-upgrade scenario test to verify if we can update
         content-view created in pre-upgrade scenario with various repositories.

         :id: a4ebbfa1-106a-4962-9c7c-082833879ae8

         :steps:
           1. Remove yum repository which was added to content-view before upgrade.
           2. Create new yum repository and add it to content-view.
           3. Remove puppet module which was added to content-view before upgrade.
           4. Add another puppet module to content-view
           5. Publish content-view

         :expectedresults: content-view updated with various repositories.
        """
        product_id = Repository.info({
            'name': self.yum_repo1_name,
            'organization': self.org_name,
            'product': self.product_name
        })['product']['id']
        ContentView.remove_repository({
            'organization': self.org_name,
            'name': self.cv_name,
            'repository': self.yum_repo1_name
        })
        content_view = ContentView.info({'name': self.cv_name,
                                         'organization': self.org_name})
        self.assertNotIn(self.yum_repo1_name,
                         content_view['yum-repositories'])
        yum_repo2 = make_repository({
            'name': self.yum_repo2_name,
            'organization': self.org_name,
            'content-type': 'yum',
            'product-id': product_id,
            'url': FAKE_2_YUM_REPO})
        Repository.synchronize({'id': yum_repo2['id'],
                                'organization': self.org_name})
        ContentView.add_repository({
            'name': self.cv_name,
            'organization': self.org_name,
            'product': self.product_name,
            'repository-id': yum_repo2['id']})
        content_view = ContentView.info({'name': self.cv_name,
                                         'organization': self.org_name})
        self.assertEqual(
            content_view['yum-repositories'][0]['name'],
            self.yum_repo2_name,
            'Repo was not associated to CV',
        )
        ContentView.puppet_module_remove({
            'organization': self.org_name,
            'content-view': self.cv_name,
            'name': self.puppet_module_name,
            'author': self.puppet_module_author,
        })
        content_view = ContentView.info({'name': self.cv_name,
                                         'organization': self.org_name})
        self.assertEqual(len(content_view['puppet-modules']), 0)
        module = {'name': 'versioned', 'version': '2.2.2'}
        puppet_module = PuppetModule.list({
            'search': 'name={name} and version={version}'.format(**module)})[0]
        ContentView.puppet_module_add({
            'organization': self.org_name,
            'content-view': self.cv_name,
            'name': puppet_module['name'],
            'author': puppet_module['author'],
        })
        content_view = ContentView.info({'id': content_view['id']})
        self.assertGreater(len(content_view['puppet-modules']), 0)
        ContentView.publish({'name': self.cv_name,
                             'organization': self.org_name})
        content_view = ContentView.info({'name': self.cv_name,
                                         'organization': self.org_name})
        self.assertEqual(len(content_view['versions']), 2)
コード例 #23
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: 8c8b3ffa-0d54-436b-8eeb-1a3542e100a8

        @Assert: All tests should succeed and Content should be successfully
        fetched by client.
        """
        # step 1: Create a new user with admin permissions
        password = gen_alphanumeric()
        user = make_user({u'admin': u'true', u'password': password})
        user['password'] = password

        # step 2.1: Create a new organization
        org = self._create(user, Org, {u'name': gen_alphanumeric()})

        # step 2.2: Clone and upload manifest
        if self.fake_manifest_is_set:
            with manifests.clone() as manifest:
                ssh.upload_file(manifest.content, manifest.filename)
            Subscription.upload({
                u'file': manifest.filename,
                u'organization-id': org['id'],
            })

        # step 2.3: Create a new lifecycle environment
        lifecycle_environment = self._create(
            user, LifecycleEnvironment, {
                u'name': gen_alphanumeric(),
                u'organization-id': org['id'],
                u'prior': u'Library',
            })

        # step 2.4: Create a custom product
        product = self._create(user, Product, {
            u'name': gen_alphanumeric(),
            u'organization-id': org['id'],
        })
        repositories = []

        # step 2.5: Create custom YUM repository
        yum_repo = self._create(
            user, Repository, {
                u'content-type': u'yum',
                u'name': gen_alphanumeric(),
                u'product-id': product['id'],
                u'publish-via-http': u'true',
                u'url': GOOGLE_CHROME_REPO,
            })
        repositories.append(yum_repo)

        # step 2.6: Create custom PUPPET repository
        puppet_repo = self._create(
            user, Repository, {
                u'content-type': u'puppet',
                u'name': gen_alphanumeric(),
                u'product-id': product['id'],
                u'publish-via-http': u'true',
                u'url': FAKE_0_PUPPET_REPO,
            })
        repositories.append(puppet_repo)

        # step 2.7: Enable a Red Hat repository
        if self.fake_manifest_is_set:
            RepositorySet.enable({
                u'basearch': 'x86_64',
                u'name': REPOSET['rhva6'],
                u'organization-id': org['id'],
                u'product': PRDS['rhel'],
                u'releasever': '6Server',
            })
            rhel_repo = Repository.info({
                u'name': REPOS['rhva6']['name'],
                u'organization-id': org['id'],
                u'product': PRDS['rhel'],
            })
            repositories.append(rhel_repo)

        # step 2.8: Synchronize the three repositories
        for repo in repositories:
            Repository.with_user(user['login'], user['password']).synchronize(
                {u'id': repo['id']})

        # step 2.9: Create content view
        content_view = self._create(user, ContentView, {
            u'name': gen_alphanumeric(),
            u'organization-id': org['id'],
        })

        # step 2.10: Associate the YUM and Red Hat repositories to new content
        # view
        repositories.remove(puppet_repo)
        for repo in repositories:
            ContentView.add_repository({
                u'id': content_view['id'],
                u'organization-id': org['id'],
                u'repository-id': repo['id'],
            })

        # step 2.11: Add a PUPPET module to new content view
        result = PuppetModule.with_user(user['login'], user['password']).list({
            u'repository-id':
            puppet_repo['id'],
            u'per-page':
            False,
        })
        ContentView.with_user(user['login'],
                              user['password']).puppet_module_add({
                                  u'content-view-id':
                                  content_view['id'],
                                  u'id':
                                  random.choice(result)['id'],
                              })

        # step 2.12: Publish content view
        ContentView.with_user(user['login'], user['password']).publish(
            {u'id': content_view['id']})

        # step 2.13: Promote content view to the lifecycle environment
        content_view = ContentView.with_user(
            user['login'], user['password']).info({u'id': content_view['id']})
        self.assertEqual(len(content_view['versions']), 1)
        cv_version = ContentView.with_user(
            user['login'], user['password']).version_info({
                'id':
                content_view['versions'][0]['id'],
            })
        self.assertEqual(len(cv_version['lifecycle-environments']), 1)
        ContentView.with_user(user['login'],
                              user['password']).version_promote({
                                  u'id':
                                  cv_version['id'],
                                  u'to-lifecycle-environment-id':
                                  lifecycle_environment['id'],
                              })
        # check that content view exists in lifecycle
        content_view = ContentView.with_user(
            user['login'], user['password']).info({u'id': content_view['id']})
        self.assertEqual(len(content_view['versions']), 1)
        cv_version = ContentView.with_user(
            user['login'], user['password']).version_info({
                'id':
                content_view['versions'][0]['id'],
            })
        self.assertEqual(len(cv_version['lifecycle-environments']), 2)
        self.assertEqual(cv_version['lifecycle-environments'][-1]['id'],
                         lifecycle_environment['id'])

        # step 2.14: Create a new activation key
        activation_key = self._create(
            user, ActivationKey, {
                u'content-view-id': content_view['id'],
                u'lifecycle-environment-id': lifecycle_environment['id'],
                u'name': gen_alphanumeric(),
                u'organization-id': org['id'],
            })

        # step 2.15: Add the products to the activation key
        subscription_list = Subscription.with_user(
            user['login'],
            user['password']).list({u'organization-id': org['id']},
                                   per_page=False)
        for subscription in subscription_list:
            if subscription['name'] == DEFAULT_SUBSCRIPTION_NAME:
                ActivationKey.with_user(user['login'],
                                        user['password']).add_subscription({
                                            u'id':
                                            activation_key['id'],
                                            u'quantity':
                                            1,
                                            u'subscription-id':
                                            subscription['id'],
                                        })

        # step 2.15.1: Enable product content
        if self.fake_manifest_is_set:
            ActivationKey.with_user(user['login'],
                                    user['password']).content_override({
                                        u'content-label':
                                        AK_CONTENT_LABEL,
                                        u'id':
                                        activation_key['id'],
                                        u'organization-id':
                                        org['id'],
                                        u'value':
                                        '1',
                                    })

        # BONUS: Create a content host and associate it with promoted
        # content view and last lifecycle where it exists
        content_host_name = gen_alphanumeric()
        content_host = Host.with_user(user['login'],
                                      user['password']).subscription_register({
                                          u'content-view-id':
                                          content_view['id'],
                                          u'lifecycle-environment-id':
                                          lifecycle_environment['id'],
                                          u'name':
                                          content_host_name,
                                          u'organization-id':
                                          org['id'],
                                      })
        if bz_bug_is_open(1328202):
            results = ContentHost.with_user(user['login'],
                                            user['password']).list(
                                                {'organization-id': org['id']})
            # Content host registration converts the name to lowercase, make
            # sure to use the same format while matching against the result
            content_host_name = content_host_name.lower()
            for result in results:
                if result['name'] == content_host_name:
                    content_host = result
        content_host = ContentHost.with_user(
            user['login'], user['password']).info({'id': content_host['id']})
        # check that content view matches what we passed
        self.assertEqual(content_host['content-view'], content_view['name'])
        # check that lifecycle environment matches
        self.assertEqual(content_host['lifecycle-environment'],
                         lifecycle_environment['name'])

        # step 2.16: Create a new libvirt compute resource
        self._create(
            user, ComputeResource, {
                u'name':
                gen_alphanumeric(),
                u'provider':
                u'Libvirt',
                u'url':
                u'qemu+ssh://root@{0}/system'.format(
                    settings.compute_resources.libvirt_hostname),
            })

        # step 2.17: Create a new subnet
        subnet = self._create(
            user, Subnet, {
                u'name': gen_alphanumeric(),
                u'network': gen_ipaddr(ip3=True),
                u'mask': u'255.255.255.0',
            })

        # step 2.18: Create a new domain
        domain = self._create(user, Domain, {u'name': gen_alphanumeric()})

        # step 2.19: Create a new hostgroup and associate previous entities to
        # it
        host_group = self._create(
            user, HostGroup, {
                u'domain-id': domain['id'],
                u'name': gen_alphanumeric(),
                u'subnet-id': subnet['id'],
            })
        if not bz_bug_is_open('1326101'):
            Org.with_user(user['login'], user['password']).add_hostgroup({
                u'hostgroup-id':
                host_group['id'],
                u'id':
                org['id'],
            })

        # step 2.20: Provision a client
        self.client_provisioning(activation_key['name'], org['label'])
コード例 #24
0
ファイル: test_cli_smoke.py プロジェクト: ares/robottelo
    def test_smoke(self):
        """@Test: Check that basic content can be created

        * Create a new user with admin permissions
        * Using the new user from above:

            * Create a new organization
            * Create two new lifecycle environments
            * Create a custom product
            * Create a custom YUM repository
            * Create a custom PUPPET repository
            * Synchronize both custom repositories
            * Create a new content view
            * Associate both repositories to new content view
            * Publish content view
            * Promote content view to both lifecycles
            * Create a new libvirt compute resource
            * Create a new subnet
            * Create a new domain
            * Create a new hostgroup and associate previous entities to it

        @Feature: Smoke Test

        @Assert: All entities are created and associated.

        """
        # Create new user
        password = gen_alphanumeric()
        new_user = make_user({u"admin": u"true", u"password": password})

        # Append the password as the info command does not return it
        new_user[u"password"] = password

        # Create new org as new user
        new_org = self._create(new_user, Org, {u"name": gen_alphanumeric()})

        # Create new lifecycle environment 1
        lifecycle1 = self._create(
            new_user,
            LifecycleEnvironment,
            {u"organization-id": new_org["id"], u"name": gen_alphanumeric(), u"prior": u"Library"},
        )

        # Create new lifecycle environment 2
        lifecycle2 = self._create(
            new_user,
            LifecycleEnvironment,
            {u"organization-id": new_org["id"], u"name": gen_alphanumeric(), u"prior": lifecycle1["name"]},
        )

        # Create a new product
        new_product = self._create(new_user, Product, {u"organization-id": new_org["id"], u"name": gen_alphanumeric()})

        # Create a YUM repository
        new_repo1 = self._create(
            new_user,
            Repository,
            {
                u"product-id": new_product["id"],
                u"name": gen_alphanumeric(),
                u"content-type": u"yum",
                u"publish-via-http": u"true",
                u"url": GOOGLE_CHROME_REPO,
            },
        )

        # Create a Puppet repository
        new_repo2 = self._create(
            new_user,
            Repository,
            {
                u"product-id": new_product["id"],
                u"name": gen_alphanumeric(),
                u"content-type": u"puppet",
                u"publish-via-http": u"true",
                u"url": FAKE_0_PUPPET_REPO,
            },
        )

        # Synchronize YUM repository
        result = Repository.with_user(new_user["login"], new_user["password"]).synchronize({u"id": new_repo1["id"]})
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Synchronize puppet repository
        result = Repository.with_user(new_user["login"], new_user["password"]).synchronize({u"id": new_repo2["id"]})
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Create a Content View
        new_cv = self._create(new_user, ContentView, {u"organization-id": new_org["id"], u"name": gen_alphanumeric()})

        # Associate yum repository to content view
        result = ContentView.with_user(new_user["login"], new_user["password"]).add_repository(
            {u"id": new_cv["id"], u"repository-id": new_repo1["id"]}
        )
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Fetch puppet module
        puppet_result = PuppetModule.with_user(new_user["login"], new_user["password"]).list(
            {u"repository-id": new_repo2["id"], u"per-page": False}
        )
        self.assertEqual(puppet_result.return_code, 0)
        self.assertEqual(len(puppet_result.stderr), 0)

        # Associate puppet repository to content view
        result = ContentView.with_user(new_user["login"], new_user["password"]).puppet_module_add(
            {u"content-view-id": new_cv["id"], u"id": puppet_result.stdout[0]["id"]}
        )
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Publish content view
        result = ContentView.with_user(new_user["login"], new_user["password"]).publish({u"id": new_cv["id"]})
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Only after we publish version1 the info is populated.
        result = ContentView.with_user(new_user["login"], new_user["password"]).info({u"id": new_cv["id"]})
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Let us now store the version1 id
        version1_id = result.stdout["versions"][0]["id"]

        # Promote content view to first lifecycle
        result = ContentView.with_user(new_user["login"], new_user["password"]).version_promote(
            {u"id": result.stdout["versions"][0]["id"], u"to-lifecycle-environment-id": lifecycle1["id"]}
        )
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Promote content view to second lifecycle
        result = ContentView.with_user(new_user["login"], new_user["password"]).version_promote(
            {u"id": version1_id, u"to-lifecycle-environment-id": lifecycle2["id"]}
        )
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)

        # Create a new libvirt compute resource
        result = self._create(
            new_user,
            ComputeResource,
            {
                u"name": gen_alphanumeric(),
                u"provider": u"Libvirt",
                u"url": u"qemu+tcp://{0}:16509/system".format(conf.properties["main.server.hostname"]),
            },
        )

        # Create a new subnet
        new_subnet = self._create(
            new_user, Subnet, {u"name": gen_alphanumeric(), u"network": gen_ipaddr(ip3=True), u"mask": u"255.255.255.0"}
        )

        # Create a domain
        new_domain = self._create(new_user, Domain, {u"name": gen_alphanumeric()})

        # Fetch Puppet environment for second lifecycle
        # (unfortunately it is not straight forward to extract this)

        # The puppet environment we want has a name like this...
        env_name = u"KT_{0}_{1}_".format(
            #  Hyphens are replaced by underscores
            new_org["label"].replace("-", "_"),
            lifecycle2["label"].replace("-", "_"),
        )
        # We fetch all the puppet environments for our organization...
        result = Environment.with_user(new_user["login"], new_user["password"]).list(
            {u"search": u'organization="{0}"'.format(new_org["name"])}
        )
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)
        # Now look for the puppet environment that matches lifecycle2
        puppet_env = [env for env in result.stdout if env["name"].startswith(env_name)]
        self.assertEqual(len(puppet_env), 1)

        # Create a hostgroup...
        new_hg = self._create(
            new_user,
            HostGroup,
            {
                u"name": gen_alphanumeric(),
                u"domain-id": new_domain["id"],
                u"subnet-id": new_subnet["id"],
                u"environment-id": puppet_env[0]["id"],
            },
        )
        # ...and add it to the organization
        result = Org.with_user(new_user["login"], new_user["password"]).add_hostgroup(
            {u"id": new_org["id"], u"hostgroup-id": new_hg["id"]}
        )
        self.assertEqual(result.return_code, 0)
        self.assertEqual(len(result.stderr), 0)
コード例 #25
0
    def test_positive_smoke(self):
        """Check that basic content can be created

        * Create a new user with admin permissions
        * Using the new user from above.

            * Create a new organization
            * Create two new lifecycle environments
            * Create a custom product
            * Create a custom YUM repository
            * Create a custom PUPPET repository
            * Synchronize both custom repositories
            * Create a new content view
            * Associate both repositories to new content view
            * Publish content view
            * Promote content view to both lifecycles
            * Create a new libvirt compute resource
            * Create a new subnet
            * Create a new domain
            * Create a new hostgroup and associate previous entities to it

        @Feature: Smoke Test

        @Assert: All entities are created and associated.

        """
        # Create new user
        password = gen_alphanumeric()
        new_user = make_user({u'admin': u'true', u'password': password})

        # Append the password as the info command does not return it
        new_user[u'password'] = password

        # Create new org as new user
        new_org = self._create(new_user, Org, {u'name': gen_alphanumeric()})

        # Create new lifecycle environment 1
        lifecycle1 = self._create(
            new_user, LifecycleEnvironment, {
                u'name': gen_alphanumeric(),
                u'organization-id': new_org['id'],
                u'prior': u'Library',
            })

        # Create new lifecycle environment 2
        lifecycle2 = self._create(
            new_user, LifecycleEnvironment, {
                u'name': gen_alphanumeric(),
                u'organization-id': new_org['id'],
                u'prior': lifecycle1['name'],
            })

        # Create a new product
        new_product = self._create(new_user, Product, {
            u'name': gen_alphanumeric(),
            u'organization-id': new_org['id'],
        })

        # Create a YUM repository
        new_repo1 = self._create(
            new_user, Repository, {
                u'content-type': u'yum',
                u'name': gen_alphanumeric(),
                u'product-id': new_product['id'],
                u'publish-via-http': u'true',
                u'url': GOOGLE_CHROME_REPO,
            })

        # Create a Puppet repository
        new_repo2 = self._create(
            new_user, Repository, {
                u'content-type': u'puppet',
                u'name': gen_alphanumeric(),
                u'product-id': new_product['id'],
                u'publish-via-http': u'true',
                u'url': FAKE_0_PUPPET_REPO,
            })

        # Synchronize YUM repository
        Repository.with_user(new_user['login'],
                             new_user['password']).synchronize(
                                 {u'id': new_repo1['id']})

        # Synchronize puppet repository
        Repository.with_user(new_user['login'],
                             new_user['password']).synchronize(
                                 {u'id': new_repo2['id']})

        # Create a Content View
        new_cv = self._create(new_user, ContentView, {
            u'name': gen_alphanumeric(),
            u'organization-id': new_org['id'],
        })

        # Associate yum repository to content view
        ContentView.with_user(new_user['login'],
                              new_user['password']).add_repository({
                                  u'id':
                                  new_cv['id'],
                                  u'repository-id':
                                  new_repo1['id'],
                              })

        # Fetch puppet module
        puppet_result = PuppetModule.with_user(new_user['login'],
                                               new_user['password']).list({
                                                   u'repository-id':
                                                   new_repo2['id'],
                                                   u'per-page':
                                                   False,
                                               })

        # Associate puppet repository to content view
        ContentView.with_user(new_user['login'],
                              new_user['password']).puppet_module_add({
                                  u'content-view-id':
                                  new_cv['id'],
                                  u'id':
                                  puppet_result[0]['id'],
                              })

        # Publish content view
        ContentView.with_user(new_user['login'], new_user['password']).publish(
            {u'id': new_cv['id']})

        # Only after we publish version1 the info is populated.
        result = ContentView.with_user(new_user['login'],
                                       new_user['password']).info(
                                           {u'id': new_cv['id']})

        # Let us now store the version1 id
        version1_id = result['versions'][0]['id']

        # Promote content view to first lifecycle
        ContentView.with_user(new_user['login'],
                              new_user['password']).version_promote({
                                  u'id':
                                  version1_id,
                                  u'to-lifecycle-environment-id':
                                  lifecycle1['id'],
                              })

        # Promote content view to second lifecycle
        ContentView.with_user(new_user['login'],
                              new_user['password']).version_promote({
                                  u'id':
                                  version1_id,
                                  u'to-lifecycle-environment-id':
                                  lifecycle2['id'],
                              })

        # Create a new libvirt compute resource
        self._create(
            new_user, ComputeResource, {
                u'name':
                gen_alphanumeric(),
                u'provider':
                u'Libvirt',
                u'url':
                u'qemu+tcp://{0}:16509/system'.format(
                    settings.server.hostname),
            })

        # Create a new subnet
        new_subnet = self._create(
            new_user, Subnet, {
                u'name': gen_alphanumeric(),
                u'network': gen_ipaddr(ip3=True),
                u'mask': u'255.255.255.0',
            })

        # Create a domain
        new_domain = self._create(new_user, Domain, {
            u'name': gen_alphanumeric(),
        })

        # Fetch Puppet environment for second lifecycle
        # (unfortunately it is not straight forward to extract this)

        # The puppet environment we want has a name like this...
        env_name = u'KT_{0}_{1}_'.format(
            #  Hyphens are replaced by underscores
            new_org['label'].replace(
                '-',
                '_',
            ),
            lifecycle2['label'].replace('-', '_'))
        # We fetch all the puppet environments for our organization...
        result = Environment.with_user(
            new_user['login'], new_user['password']).list({
                u'search':
                u'organization="{0}"'.format(new_org['name']),
            })
        # Now look for the puppet environment that matches lifecycle2
        puppet_env = [
            env for env in result if env['name'].startswith(env_name)
        ]
        self.assertEqual(len(puppet_env), 1)

        # Create a hostgroup...
        new_hg = self._create(
            new_user, HostGroup, {
                u'domain-id': new_domain['id'],
                u'environment-id': puppet_env[0]['id'],
                u'name': gen_alphanumeric(),
                u'subnet-id': new_subnet['id'],
            })
        # ...and add it to the organization
        Org.with_user(new_user['login'], new_user['password']).add_hostgroup({
            u'hostgroup-id':
            new_hg['id'],
            u'id':
            new_org['id'],
        })