Exemplo n.º 1
0
def test_positive_incremental_update_puppet():
    """Incrementally update a CVV with a puppet module.

    :id: 19b2fe3b-6c91-4713-9910-17517fba661f

    :expectedresults: The incremental update succeeds with no errors, and
        the content view is given an additional version.

    :CaseLevel: Integration
    """
    # Create a content view and add a yum repository to it. Publish the CV.
    product = entities.Product().create()
    yum_repo = entities.Repository(content_type='yum',
                                   product=product).create()
    content_view = entities.ContentView(organization=product.organization,
                                        repository=[yum_repo]).create()
    content_view.publish()
    content_view = content_view.read()

    # Create a puppet repository and upload a puppet module into it.
    puppet_repo = entities.Repository(content_type='puppet',
                                      product=product).create()
    with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
        puppet_repo.upload_content(files={'content': handle})
    # Extract all the available puppet modules.
    puppet_modules = content_view.available_puppet_modules()['results']
    # Make sure that we have results. Uploading content does not
    # seem to create a task so we cannot poll it for status. We
    # should then check that we have some results back before
    # proceeding.
    assert len(puppet_modules) > 0
    puppet_module = entities.PuppetModule(id=puppet_modules[0]['id'])

    # Incrementally update the CVV with the puppet module.
    payload = {
        'content_view_version_environments': [{
            'content_view_version_id':
            content_view.version[0].id,
            'environment_ids': [
                environment.id
                for environment in content_view.version[0].read().environment
            ],
        }],
        'add_content': {
            'puppet_module_ids': [puppet_module.id]
        },
    }
    content_view.version[0].incremental_update(data=payload)
    content_view = content_view.read()

    # The CV now has two versions. The first version has no puppet modules,
    # and the second version has one puppet module. Let's verify this.
    # NOTE: The `read_json` lines should be refactored after the 'minor'
    assert len(content_view.version) == 2
    for i in range(len(content_view.version)):
        content_view.version[i] = content_view.version[i].read()
    content_view.version.sort(key=lambda cvv: cvv.read_json()['minor'])
    assert len(content_view.version[0].puppet_module) == 0
    assert len(content_view.version[1].puppet_module) == 1
    assert content_view.version[1].puppet_module[0].id == puppet_module.id
    def test_positive_search_no_results(self):
        """Search for puppet modules in an empty repository.

        @Assert: No puppet modules are returned.

        @Feature: PuppetModule
        """
        query = {'repository_id': self.repository.id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 0)
Exemplo n.º 3
0
    def test_positive_search_no_results(self):
        """Search for puppet modules in an empty repository.

        @id: eafc7a71-d550-4983-9941-b87aa57b83e9

        @Assert: No puppet modules are returned.
        """
        query = {'repository_id': self.repository.id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 0)
Exemplo n.º 4
0
    def test_positive_search_no_results(self, blank_repo):
        """Search for puppet modules in an empty repository.

        :id: eafc7a71-d550-4983-9941-b87aa57b83e9

        :expectedresults: No puppet modules are returned.

        :CaseImportance: Critical
        """
        query = {'repository_id': blank_repo.id}
        assert len(entities.PuppetModule().search(query=query)) == 0
    def test_positive_search_no_results(self):
        """Search for puppet modules in an emtpy content view version.

        @Assert: No puppet modules are found.

        @Feature: PuppetModule
        """
        self.content_view.publish()
        self.content_view = self.content_view.read()
        query = {'content_view_version_id': self.content_view.version[0].id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 0)
    def test_positive_search_single_result(self):
        """Search for puppet modules in a non-empty repository.

        @Assert: Only the modules in that repository are returned.

        @Feature: PuppetModule
        """
        with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
            self.repository.upload_content(files={'content': handle})
        query = {'repository_id': self.repository.id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 1)
Exemplo n.º 7
0
    def test_positive_search_no_results(self):
        """Search for puppet modules in an emtpy content view version.

        @id: 3a59e2fc-5c95-405e-bf4a-f1fe78e73300

        @Assert: No puppet modules are found.
        """
        self.content_view.publish()
        self.content_view = self.content_view.read()
        query = {'content_view_version_id': self.content_view.version[0].id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 0)
Exemplo n.º 8
0
    def test_positive_search_single_result(self, make_cv):
        """Search for puppet modules in a CVV with one puppet module.

        :id: cc358a91-8640-48e3-851d-383e55ba42c3

        :expectedresults: One puppet module is found.

        :CaseImportance: Critical
        """
        # Find the puppet module created in fixture and assign it
        # to `make_cv`. Publish the content view.
        puppet_module = entities.PuppetModule(
            id=make_cv.available_puppet_modules()['results'][0]['id'])
        entities.ContentViewPuppetModule(content_view=make_cv,
                                         id=puppet_module.id).create()
        make_cv.publish()

        # Search for all puppet modules in the new content view version.
        make_cv = make_cv.read()
        query = {'content_view_version_id': make_cv.version[0].id}
        assert len(entities.PuppetModule().search(query=query)) == 1
Exemplo n.º 9
0
    def test_positive_search_no_results(self, make_cv):
        """Search for puppet modules in an emtpy content view version.

        :id: 3a59e2fc-5c95-405e-bf4a-f1fe78e73300

        :expectedresults: No puppet modules are found.

        :CaseImportance: Critical
        """
        make_cv.publish()
        make_cv = make_cv.read()
        query = {'content_view_version_id': make_cv.version[0].id}
        assert len(entities.PuppetModule().search(query=query)) == 0
Exemplo n.º 10
0
    def test_positive_search_single_result(self):
        """Search for puppet modules in a CVV with one puppet module.

        @Assert: One puppet module is found.

        @Feature: PuppetModule
        """
        # Find the puppet module in `self.repository` and assign it to
        # `self.content_view`. Publish the content view.
        puppet_module = entities.PuppetModule(
            id=self.content_view.available_puppet_modules()['results'][0]['id']
        )
        entities.ContentViewPuppetModule(
            content_view=self.content_view,
            puppet_module=puppet_module,
        ).create()
        self.content_view.publish()

        # Search for all puppet modules in the new content view version.
        self.content_view = self.content_view.read()
        query = {'content_view_version_id': self.content_view.version[0].id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 1)
Exemplo n.º 11
0
    def test_positive_search_single_result(self):
        """Search for puppet modules in a CVV with one puppet module.

        :id: cc358a91-8640-48e3-851d-383e55ba42c3

        :expectedresults: One puppet module is found.

        :CaseImportance: Critical
        """
        # Find the puppet module in `self.repository` and assign it to
        # `self.content_view`. Publish the content view.
        puppet_module = entities.PuppetModule(
            id=self.content_view.available_puppet_modules()['results'][0]
            ['id'])
        entities.ContentViewPuppetModule(content_view=self.content_view,
                                         id=puppet_module.id).create()
        self.content_view.publish()

        # Search for all puppet modules in the new content view version.
        self.content_view = self.content_view.read()
        query = {'content_view_version_id': self.content_view.version[0].id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 1)
Exemplo n.º 12
0
    def test_positive_search_single_result(self):
        """Search for puppet modules in a non-empty repository.

        :id: 5337b2be-e207-4580-8407-19b88cb40403

        :expectedresults: Only the modules in that repository are returned.

        :CaseImportance: Critical
        """
        with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
            self.repository.upload_content(files={'content': handle})
        query = {'repository_id': self.repository.id}
        self.assertEqual(len(entities.PuppetModule().search(query=query)), 1)
Exemplo n.º 13
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, 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=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_ip)
        with self.assertNotRaises(StopIteration):
            next(
                filename for filename in stored_modules
                if '{}-{}'.format(module_name, module_versions[1]) in filename)
Exemplo n.º 14
0
    def test_positive_incremental_update_propagate_composite(self):
        """Incrementally update a CVV in composite CV with
        `propagate_all_composites` flag set

        :BZ: 1288148

        :id: 1ddcb2ef-3819-442e-b070-cf44aba58dcd

        :customerscenario: true

        :Steps:

            1. Create and publish CV with some content
            2. Create composite CV, add previously created CV inside it
            3. Publish composite CV
            4. Create a puppet repository and upload a puppet module into it
            5. Incrementally update the CVV with the puppet module with
               `propagate_all_composites` flag set to `True`

        :expectedresults:

            1. The incremental update succeeds with no errors
            2. New incremental CVV contains new puppet module
            3. New incremental composite CVV contains new puppet module

        :CaseLevel: Integration

        :CaseImportance: Medium
        """
        product = entities.Product().create()
        yum_repo = entities.Repository(
            content_type='yum',
            product=product,
        ).create()
        yum_repo.sync()
        content_view = entities.ContentView(
            organization=product.organization,
            repository=[yum_repo],
        ).create()
        content_view.publish()
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 1)
        self.assertEqual(len(content_view.version[0].read().puppet_module), 0)
        comp_content_view = entities.ContentView(
            component=[content_view.version[0].id],
            composite=True,
            organization=product.organization,
        ).create()
        comp_content_view.publish()
        comp_content_view = comp_content_view.read()
        self.assertEqual(len(comp_content_view.version), 1)
        self.assertEqual(
            len(comp_content_view.version[0].read().puppet_module), 0)
        puppet_repo = entities.Repository(
            content_type='puppet',
            product=product,
        ).create()
        with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
            puppet_repo.upload_content(files={'content': handle})
        puppet_modules = content_view.available_puppet_modules()['results']
        self.assertGreater(len(puppet_modules), 0)
        puppet_module = entities.PuppetModule(id=puppet_modules[0]['id'])
        content_view.version[0].incremental_update(
            data={
                'content_view_version_environments': [{
                    'content_view_version_id':
                    content_view.version[0].id,
                    'environment_ids': [
                        environment.id for environment in
                        content_view.version[0].read().environment
                    ],
                }],
                'add_content': {
                    'puppet_module_ids': [puppet_module.id]
                },
                'propagate_all_composites':
                True,
            })
        content_view = content_view.read()
        self.assertEqual(len(content_view.version), 2)
        cvv = content_view.version[-1].read()
        self.assertEqual(len(cvv.puppet_module), 1)
        self.assertEqual(cvv.puppet_module[0].id, puppet_module.id)
        comp_content_view = comp_content_view.read()
        self.assertEqual(len(comp_content_view.version), 2)
        comp_cvv = comp_content_view.version[-1].read()
        self.assertEqual(len(comp_cvv.puppet_module), 1)
        self.assertEqual(comp_cvv.puppet_module[0].id, puppet_module.id)
Exemplo n.º 15
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_incremental_update_puppet(self):
        """Incrementally update a CVV with a puppet module.

        @Assert: The incremental update succeeds with no errors, and the
        content view is given an additional version.

        @Feature: ContentViewVersion
        """
        # Create a content view and add a yum repository to it. Publish the CV.
        product = entities.Product().create()
        yum_repo = entities.Repository(
            content_type='yum',
            product=product,
        ).create()
        content_view = entities.ContentView(
            organization=product.organization,
            repository=[yum_repo],
        ).create()
        content_view.publish()
        content_view = content_view.read()

        # Create a puppet repository and upload a puppet module into it.
        puppet_repo = entities.Repository(
            content_type='puppet',
            product=product,
        ).create()
        with open(get_data_file(PUPPET_MODULE_NTP_PUPPETLABS), 'rb') as handle:
            puppet_repo.upload_content(files={'content': handle})
        # Extract all the available puppet modules.
        puppet_modules = content_view.available_puppet_modules()['results']
        # Make sure that we have results. Uploading content does not
        # seem to create a task so we cannot pool it for status. We
        # should then check that we have some results back before
        # proceeding.
        self.assertGreater(len(puppet_modules), 0)
        puppet_module = entities.PuppetModule(id=puppet_modules[0]['id'])

        # Incrementally update the CVV with the puppet module.
        payload = {
            'content_view_version_environments': [{
                'content_view_version_id':
                content_view.version[0].id,
                'environment_ids': [
                    environment.id for environment in
                    content_view.version[0].read().environment
                ],
            }],
            'add_content': {
                'puppet_module_ids': [puppet_module.id]
            },
        }
        content_view.version[0].incremental_update(data=payload)
        content_view = content_view.read()

        # The CV now has two versions. The first version has no puppet modules,
        # and the second version has one puppet module. Let's verify this.
        # NOTE: The `read_json` lines should be refactored after the 'minor'
        # attribute is added to the ContentViewVersion entity class.
        self.assertEqual(len(content_view.version), 2)
        for i in range(len(content_view.version)):
            content_view.version[i] = content_view.version[i].read()
        content_view.version.sort(key=lambda cvv: cvv.read_json()['minor'])
        self.assertEqual(len(content_view.version[0].puppet_module), 0)
        self.assertEqual(len(content_view.version[1].puppet_module), 1)
        self.assertEqual(
            content_view.version[1].puppet_module[0].id,
            puppet_module.id,
        )