Example #1
0
def find_content_view(module, name, organization, failsafe=False):
    content_view = ContentView(name=name, organization=organization)
    return handle_find_response(module,
                                content_view.search(),
                                message="No content view found for %s" % name,
                                failsafe=failsafe)
Example #2
0
class IncrementalUpdateTestCase(TestCase):
    """Tests for the Incremental Update feature"""

    @classmethod
    @skip_if_not_set('clients')
    def setUpClass(cls):
        """Creates the pre-requisites for the Incremental updates that used in
        all test"""
        super(IncrementalUpdateTestCase, cls).setUpClass()
        # Create a new Organization
        cls.org = Organization(name=gen_alpha()).create()

        # Create two lifecycle environments - DEV, QE
        cls.dev_lce = LifecycleEnvironment(
            name='DEV',
            organization=cls.org
        ).create()
        cls.qe_lce = LifecycleEnvironment(
            name='QE',
            prior=cls.dev_lce,
            organization=cls.org
        ).create()

        # Upload manifest
        with manifests.clone() as manifest:
            upload_manifest(cls.org.id, manifest.content)

        # Enable repositories - RHE Virtualization Agents and rhel6 sat6tools
        rhva_6_repo_id = enable_rhrepo_and_fetchid(
            basearch=DEFAULT_ARCHITECTURE,
            org_id=cls.org.id,
            product=PRDS['rhel'],
            repo=REPOS['rhva6']['name'],
            reposet=REPOSET['rhva6'],
            releasever=DEFAULT_RELEASE_VERSION,
        )
        rhel6_sat6tools_repo_id = enable_rhrepo_and_fetchid(
            basearch=DEFAULT_ARCHITECTURE,
            org_id=cls.org.id,
            product=PRDS['rhel'],
            repo=REPOS['rhst6']['name'],
            reposet=REPOSET['rhst6'],
            releasever=None,
        )

        # Read the repositories
        cls.rhva_6_repo = Repository(id=rhva_6_repo_id).read()
        cls.rhel6_sat6tools_repo = Repository(
            id=rhel6_sat6tools_repo_id
        ).read()

        # Sync the enabled repositories
        try:
            cls.old_task_timeout = entity_mixins.TASK_TIMEOUT
            # Update timeout to 15 minutes to finish sync
            entity_mixins.TASK_TIMEOUT = 900
            for repo in [cls.rhva_6_repo, cls.rhel6_sat6tools_repo]:
                assert Repository(id=repo.id).sync()['result'] == u'success'
        finally:
            entity_mixins.TASK_TIMEOUT = cls.old_task_timeout

    def setUp(self):
        """Creates the pre-requisites for the Incremental updates that used per
        each test"""
        super(IncrementalUpdateTestCase, self).setUp()
        # Create content view that will be used filtered erratas
        self.rhel_6_partial_cv = ContentView(
            organization=self.org,
            name=gen_alpha(),
            repository=[self.rhva_6_repo, self.rhel6_sat6tools_repo]
        ).create()

        # Create a content view filter to filter out errata
        rhel_6_partial_cvf = ErratumContentViewFilter(
            content_view=self.rhel_6_partial_cv,
            type='erratum',
            name='rhel_6_partial_cv_filter',
            repository=[self.rhva_6_repo]
        ).create()

        # Create a content view filter rule - filtering out errata in the last
        # 365 days
        start_date = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d')
        ContentViewFilterRule(
            content_view_filter=rhel_6_partial_cvf,
            types=['security', 'enhancement', 'bugfix'],
            start_date=start_date,
            end_date=date.today().strftime('%Y-%m-%d')
        ).create()

        # Publish content view and re-read it

        self.rhel_6_partial_cv.publish()
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()

        # Promote content view to 'DEV' and 'QE'
        assert len(self.rhel_6_partial_cv.version) == 1
        for env in (self.dev_lce, self.qe_lce):
            promote(self.rhel_6_partial_cv.version[0], env.id)

        # Create host collection
        self.rhel_6_partial_hc = HostCollection(
            organization=self.org, name=gen_alpha(), max_hosts=5).create()

        # Create activation key for content view
        kwargs = {'organization': self.org, 'environment': self.qe_lce.id}
        rhel_6_partial_ak = ActivationKey(
            name=gen_alpha(),
            content_view=self.rhel_6_partial_cv,
            host_collection=[self.rhel_6_partial_hc],
            **kwargs
        ).create()

        # Assign subscription to activation key. Fetch available subscriptions
        subs = Subscription(organization=self.org).search()
        assert len(subs) > 0

        # Add subscription to activation key
        sub_found = False
        for sub in subs:
            if sub.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME:
                rhel_6_partial_ak.add_subscriptions(data={
                    u'subscription_id': sub.id
                })
                sub_found = True
        assert sub_found

        # Enable product content in activation key
        rhel_6_partial_ak.content_override(data={'content_override': {
            u'content_label': REPOS['rhst6']['id'],
            u'value': u'1'
        }})

        # Create client machine and register it to satellite with
        # rhel_6_partial_ak
        self.vm = VirtualMachine(distro=DISTRO_RHEL6, tag='incupdate')
        self.addCleanup(vm_cleanup, self.vm)
        self.setup_vm(self.vm, rhel_6_partial_ak.name, self.org.label)
        self.vm.enable_repo(REPOS['rhva6']['id'])
        self.vm.run('yum install -y {0}'.format(REAL_0_RH_PACKAGE))

        # Find the content hosts and save them
        hosts = Host(organization=str(self.org.id)).search()
        self.partial_hosts = []
        for host in hosts:
            self.partial_hosts.append(host)

    @staticmethod
    def setup_vm(client, act_key, org_name):
        """Creates the vm and registers it to the satellite"""
        client.create()
        client.install_katello_ca()

        # Register content host, install katello-agent
        client.register_contenthost(
            org_name,
            act_key,
            releasever=DEFAULT_RELEASE_VERSION
        )
        assert client.subscribed
        client.install_katello_agent()
        client.run('katello-package-upload')

    @staticmethod
    def get_applicable_errata(repo):
        """Retrieves applicable errata for the given repo"""
        return Errata(repository=repo).search(
            query={'errata_restrict_applicable': True}
        )

    @run_only_on('sat')
    @tier4
    def test_positive_noapply_api(self):
        """Check if api incremental update can be done without
        actually applying it

        :id: 481c5ff2-801f-4eff-b1e0-95ea5bb37f95

        :Setup:  The prerequisites are already covered in the setUpClass() but
            for easy debug, get the content view id, Repository id and
            Lifecycle environment id using hammer and plug these statements on
            the top of the test. For example::

                self.rhel_6_partial_cv = ContentView(id=38).read()
                self.rhva_6_repo = Repository(id=164).read()
                self.qe_lce = LifecycleEnvironment(id=46).read()

        :expectedresults: Incremental update completed with no errors and
            Content view has a newer version

        :CaseLevel: System
        """
        # Get the content view versions and use the recent one.  API always
        # returns the versions in ascending order so it is safe to assume the
        # last one in the list is the recent
        cv_versions = self.rhel_6_partial_cv.version

        # Get the applicable errata
        errata_list = self.get_applicable_errata(self.rhva_6_repo)
        self.assertGreater(len(errata_list), 0)

        # Apply incremental update using the first applicable errata
        ContentViewVersion().incremental_update(data={
            'content_view_version_environments': [{
                'content_view_version_id': cv_versions[-1].id,
                'environment_ids': [self.qe_lce.id]
            }],
            'add_content': {
                'errata_ids': [errata_list[0].id]
            }
        })

        # Re-read the content view to get the latest versions
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()
        self.assertGreater(
            len(self.rhel_6_partial_cv.version),
            len(cv_versions)
        )

    @run_only_on('sat')
    @tier4
    def test_positive_noapply_cli(self):
        """Check if cli incremental update can be done without
        actually applying it

        :id: f25b0919-74cb-4e2c-829e-482558990b3c

        :expectedresults: Incremental update completed with no errors and
            Content view has a newer version

        :CaseLevel: System
        """
        # Get the content view versions and use the recent one.  API always
        # returns the versions in ascending order so it is safe to assume the
        # last one in the list is the recent

        cv_versions = self.rhel_6_partial_cv.version

        # Get the applicable errata
        errata_list = self.get_applicable_errata(self.rhva_6_repo)
        self.assertGreater(len(errata_list), 0)

        # Apply incremental update using the first applicable errata
        ContentViewCLI.version_incremental_update({
            u'content-view-version-id': cv_versions[-1].id,
            u'lifecycle-environment-ids': self.qe_lce.id,
            u'errata-ids': errata_list[0].id,
        })

        # Re-read the content view to get the latest versions
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()
        self.assertGreater(
            len(self.rhel_6_partial_cv.version),
            len(cv_versions)
        )
Example #3
0
    def setUp(self):
        """Creates the pre-requisites for the Incremental updates that used per
        each test"""
        super(IncrementalUpdateTestCase, self).setUp()
        # Create content view that will be used filtered erratas
        self.rhel_6_partial_cv = ContentView(
            organization=self.org,
            name=gen_alpha(),
            repository=[self.rhva_6_repo, self.rhel6_sat6tools_repo]
        ).create()

        # Create a content view filter to filter out errata
        rhel_6_partial_cvf = ErratumContentViewFilter(
            content_view=self.rhel_6_partial_cv,
            type='erratum',
            name='rhel_6_partial_cv_filter',
            repository=[self.rhva_6_repo]
        ).create()

        # Create a content view filter rule - filtering out errata in the last
        # 365 days
        start_date = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d')
        ContentViewFilterRule(
            content_view_filter=rhel_6_partial_cvf,
            types=['security', 'enhancement', 'bugfix'],
            start_date=start_date,
            end_date=date.today().strftime('%Y-%m-%d')
        ).create()

        # Publish content view and re-read it

        self.rhel_6_partial_cv.publish()
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()

        # Promote content view to 'DEV' and 'QE'
        assert len(self.rhel_6_partial_cv.version) == 1
        for env in (self.dev_lce, self.qe_lce):
            promote(self.rhel_6_partial_cv.version[0], env.id)

        # Create host collection
        self.rhel_6_partial_hc = HostCollection(
            organization=self.org, name=gen_alpha(), max_hosts=5).create()

        # Create activation key for content view
        kwargs = {'organization': self.org, 'environment': self.qe_lce.id}
        rhel_6_partial_ak = ActivationKey(
            name=gen_alpha(),
            content_view=self.rhel_6_partial_cv,
            host_collection=[self.rhel_6_partial_hc],
            **kwargs
        ).create()

        # Assign subscription to activation key. Fetch available subscriptions
        subs = Subscription(organization=self.org).search()
        assert len(subs) > 0

        # Add subscription to activation key
        sub_found = False
        for sub in subs:
            if sub.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME:
                rhel_6_partial_ak.add_subscriptions(data={
                    u'subscription_id': sub.id
                })
                sub_found = True
        assert sub_found

        # Enable product content in activation key
        rhel_6_partial_ak.content_override(data={'content_override': {
            u'content_label': REPOS['rhst6']['id'],
            u'value': u'1'
        }})

        # Create client machine and register it to satellite with
        # rhel_6_partial_ak
        self.vm = VirtualMachine(distro=DISTRO_RHEL6, tag='incupdate')
        self.addCleanup(vm_cleanup, self.vm)
        self.setup_vm(self.vm, rhel_6_partial_ak.name, self.org.label)
        self.vm.enable_repo(REPOS['rhva6']['id'])
        self.vm.run('yum install -y {0}'.format(REAL_0_RH_PACKAGE))

        # Find the content hosts and save them
        hosts = Host(organization=str(self.org.id)).search()
        self.partial_hosts = []
        for host in hosts:
            self.partial_hosts.append(host)
Example #4
0
    def setUpClass(cls):
        """Creates all the pre-requisites for the Incremental updates test"""
        super(IncrementalUpdateTestCase, cls).setUpClass()
        # Step 1 - Create a new Organization
        cls.org = Organization(name=gen_alpha()).create()

        # Step 2 - Create two life cycle environments - DEV, QE
        cls.dev_lce = LifecycleEnvironment(name='DEV',
                                           organization=cls.org).create()
        cls.qe_lce = LifecycleEnvironment(name='QE',
                                          prior=cls.dev_lce,
                                          organization=cls.org).create()

        # Step 3: Upload manifest
        with manifests.clone() as manifest:
            upload_manifest(cls.org.id, manifest.content)

        # Step 4: Enable repositories - 6Server and rhel6 sat6tools
        rhel_66_repo_id = enable_rhrepo_and_fetchid(
            basearch=PRD_SETS['rhel_66']['arch'],
            org_id=cls.org.id,
            product=PRD_SETS['rhel_66']['product'],
            repo=PRD_SETS['rhel_66']['reponame'],
            reposet=PRD_SETS['rhel_66']['reposet'],
            releasever=PRD_SETS['rhel_66']['releasever'])
        rhel6_sat6tools_repo_id = enable_rhrepo_and_fetchid(
            basearch=PRD_SETS['rhel6_sat6tools']['arch'],
            org_id=cls.org.id,
            product=PRD_SETS['rhel6_sat6tools']['product'],
            repo=PRD_SETS['rhel6_sat6tools']['reponame'],
            reposet=PRD_SETS['rhel6_sat6tools']['reposet'],
            releasever=PRD_SETS['rhel6_sat6tools']['releasever'])

        # Step 5: Read the repositories
        cls.rhel_66_repo = Repository(id=rhel_66_repo_id).read()
        cls.rhel6_sat6tools_repo = Repository(
            id=rhel6_sat6tools_repo_id).read()

        # Step 6: Sync the enabled repositories
        try:
            cls.old_task_timeout = entity_mixins.TASK_TIMEOUT
            # Update timeout to 2 hours to finish sync
            entity_mixins.TASK_TIMEOUT = 7200
            for repo in [cls.rhel_66_repo, cls.rhel6_sat6tools_repo]:
                assert Repository(id=repo.id).sync()['result'] == u'success'
        finally:
            entity_mixins.TASK_TIMEOUT = cls.old_task_timeout

        # Step 7: Create two content views - one will be used with all erratas
        # and another with erratas filtered
        for cv_name in ('rhel_6_cv', 'rhel_6_partial_cv'):
            setattr(
                cls, cv_name,
                ContentView(
                    organization=cls.org,
                    name=cv_name,
                    repository=[cls.rhel_66_repo,
                                cls.rhel6_sat6tools_repo]).create())

        # Step 8: Create a content view filter to filter out errata
        rhel_6_partial_cvf = ErratumContentViewFilter(
            content_view=cls.rhel_6_partial_cv,
            type='erratum',
            name='rhel_6_partial_cv_filter',
            repository=[cls.rhel_66_repo]).create()

        # Step 9: Create a content view filter rule - filtering out errata in
        # the last 365 days
        start_date = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d')
        ContentViewFilterRule(
            content_view_filter=rhel_6_partial_cvf,
            types=['security', 'enhancement', 'bugfix'],
            start_date=start_date,
            end_date=date.today().strftime('%Y-%m-%d')).create()

        # Step 10: Publish both the content views and re-read the content views

        # Changing the nailgun timeout time for the rest of the steps as
        # publish/promote of larger repos take more than 5 minutes
        entity_mixins.TASK_TIMEOUT = 3600
        for content_view in (cls.rhel_6_cv, cls.rhel_6_partial_cv):
            content_view.publish()
        cls.rhel_6_cv = cls.rhel_6_cv.read()
        cls.rhel_6_partial_cv = cls.rhel_6_partial_cv.read()

        # Step 11: Promote both content views to 'DEV' and 'QE'
        for content_view in (cls.rhel_6_cv, cls.rhel_6_partial_cv):
            assert len(content_view.version) == 1
            for env in (cls.dev_lce, cls.qe_lce):
                promote(content_view.version[0], env.id)

        # Step 12: Create host collections
        for hc_name in ('rhel_6_hc', 'rhel_6_partial_hc'):
            setattr(
                cls, hc_name,
                HostCollection(organization=cls.org,
                               name=hc_name,
                               max_content_hosts=5).create())

        # Step 13: Create activation keys for both content views
        kwargs = {'organization': cls.org, 'environment': cls.qe_lce.id}
        rhel_6_ak = ActivationKey(name=u'rhel_6_ak',
                                  content_view=cls.rhel_6_cv,
                                  host_collection=[cls.rhel_6_hc],
                                  **kwargs).create()
        rhel_6_partial_ak = ActivationKey(
            name=u'rhel_6_partial_ak',
            content_view=cls.rhel_6_partial_cv,
            host_collection=[cls.rhel_6_partial_hc],
            **kwargs).create()

        # Step 14: Assign subscriptions to activation keys
        # Fetch available subscriptions
        subs = Subscription(organization=cls.org).search()
        assert len(subs) > 0

        # Add subscriptions to activation key
        sub_found = False
        for sub in subs:
            if sub.read_json()['product_name'] == u'Employee SKU':
                for act_key in [rhel_6_ak, rhel_6_partial_ak]:
                    act_key.add_subscriptions(
                        data={u'subscription_id': sub.id})
                sub_found = True
        assert sub_found

        # Step 15: Enable product content in activation keys
        for act_key in [rhel_6_ak, rhel_6_partial_ak]:
            act_key.content_override(
                data={
                    'content_override': {
                        u'content_label': PRD_SETS['rhel6_sat6tools']['label'],
                        u'value': u'1'
                    }
                })

        # Step 16: Create three client machines and register them to satellite
        # Register the first vm with rhel_6_ak and the other two vms with
        # rhel_6_partial_ak
        cls.vm = [
            VirtualMachine(distro='rhel67', tag='incupdate') for _ in range(3)
        ]
        cls.setup_vm(cls.vm[0], rhel_6_ak.name, cls.org.label)
        for i in range(1, 3):
            cls.setup_vm(cls.vm[i], rhel_6_partial_ak.name, cls.org.label)

        # Find the content hosts (systems) and save them
        systems = System(organization=cls.org).search()
        cls.systems = []
        cls.partial_systems = []

        for system in systems:
            if system.content_view.read().name == cls.rhel_6_cv.name:
                cls.systems.append(system)
            else:
                cls.partial_systems.append(system)
Example #5
0
class IncrementalUpdateTestCase(TestCase):
    """Tests for the Incremental Update feature"""

    @classmethod
    @skip_if_not_set('clients')
    def setUpClass(cls):
        """Creates the pre-requisites for the Incremental updates that used in
        all test"""
        super(IncrementalUpdateTestCase, cls).setUpClass()
        # Create a new Organization
        cls.org = Organization(name=gen_alpha()).create()

        # Create two lifecycle environments - DEV, QE
        cls.dev_lce = LifecycleEnvironment(
            name='DEV',
            organization=cls.org
        ).create()
        cls.qe_lce = LifecycleEnvironment(
            name='QE',
            prior=cls.dev_lce,
            organization=cls.org
        ).create()

        # Upload manifest
        with manifests.clone() as manifest:
            upload_manifest(cls.org.id, manifest.content)

        # Enable repositories - RHE Virtualization Agents and rhel6 sat6tools
        rhva_6_repo_id = enable_rhrepo_and_fetchid(
            basearch=DEFAULT_ARCHITECTURE,
            org_id=cls.org.id,
            product=PRDS['rhel'],
            repo=REPOS['rhva6']['name'],
            reposet=REPOSET['rhva6'],
            releasever=DEFAULT_RELEASE_VERSION,
        )
        rhel6_sat6tools_repo_id = enable_rhrepo_and_fetchid(
            basearch=DEFAULT_ARCHITECTURE,
            org_id=cls.org.id,
            product=PRDS['rhel'],
            repo=REPOS['rhst6']['name'],
            reposet=REPOSET['rhst6'],
            releasever=None,
        )

        # Read the repositories
        cls.rhva_6_repo = Repository(id=rhva_6_repo_id).read()
        cls.rhel6_sat6tools_repo = Repository(
            id=rhel6_sat6tools_repo_id
        ).read()

        # Sync the enabled repositories
        try:
            cls.old_task_timeout = entity_mixins.TASK_TIMEOUT
            # Update timeout to 15 minutes to finish sync
            entity_mixins.TASK_TIMEOUT = 900
            for repo in [cls.rhva_6_repo, cls.rhel6_sat6tools_repo]:
                assert Repository(id=repo.id).sync()['result'] == u'success'
        finally:
            entity_mixins.TASK_TIMEOUT = cls.old_task_timeout

    def setUp(self):
        """Creates the pre-requisites for the Incremental updates that used per
        each test"""
        super(IncrementalUpdateTestCase, self).setUp()
        # Create content view that will be used filtered erratas
        self.rhel_6_partial_cv = ContentView(
            organization=self.org,
            name=gen_alpha(),
            repository=[self.rhva_6_repo, self.rhel6_sat6tools_repo]
        ).create()

        # Create a content view filter to filter out errata
        rhel_6_partial_cvf = ErratumContentViewFilter(
            content_view=self.rhel_6_partial_cv,
            type='erratum',
            name='rhel_6_partial_cv_filter',
            repository=[self.rhva_6_repo]
        ).create()

        # Create a content view filter rule - filtering out errata in the last
        # 365 days
        start_date = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d')
        ContentViewFilterRule(
            content_view_filter=rhel_6_partial_cvf,
            types=['security', 'enhancement', 'bugfix'],
            start_date=start_date,
            end_date=date.today().strftime('%Y-%m-%d')
        ).create()

        # Publish content view and re-read it

        self.rhel_6_partial_cv.publish()
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()

        # Promote content view to 'DEV' and 'QE'
        assert len(self.rhel_6_partial_cv.version) == 1
        for env in (self.dev_lce, self.qe_lce):
            promote(self.rhel_6_partial_cv.version[0], env.id)

        # Create host collection
        self.rhel_6_partial_hc = HostCollection(
            organization=self.org, name=gen_alpha(), max_hosts=5).create()

        # Create activation key for content view
        kwargs = {'organization': self.org, 'environment': self.qe_lce.id}
        rhel_6_partial_ak = ActivationKey(
            name=gen_alpha(),
            content_view=self.rhel_6_partial_cv,
            host_collection=[self.rhel_6_partial_hc],
            **kwargs
        ).create()

        # Assign subscription to activation key. Fetch available subscriptions
        subs = Subscription(organization=self.org).search()
        assert len(subs) > 0

        # Add subscription to activation key
        sub_found = False
        for sub in subs:
            if sub.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME:
                rhel_6_partial_ak.add_subscriptions(data={
                    u'subscription_id': sub.id
                })
                sub_found = True
        assert sub_found

        # Enable product content in activation key
        rhel_6_partial_ak.content_override(data={'content_override': {
            u'content_label': REPOS['rhst6']['id'],
            u'value': u'1'
        }})

        # Create client machine and register it to satellite with
        # rhel_6_partial_ak
        self.vm = VirtualMachine(distro=DISTRO_RHEL6, tag='incupdate')
        self.addCleanup(vm_cleanup, self.vm)
        self.setup_vm(self.vm, rhel_6_partial_ak.name, self.org.label)
        self.vm.enable_repo(REPOS['rhva6']['id'])
        self.vm.run('yum install -y {0}'.format(REAL_0_RH_PACKAGE))

        # Find the content hosts and save them
        hosts = Host(organization=str(self.org.id)).search()
        self.partial_hosts = []
        for host in hosts:
            self.partial_hosts.append(host)

    @staticmethod
    def setup_vm(client, act_key, org_name):
        """Creates the vm and registers it to the satellite"""
        client.create()
        client.install_katello_ca()

        # Register content host, install katello-agent
        client.register_contenthost(
            org_name,
            act_key,
            releasever=DEFAULT_RELEASE_VERSION
        )
        assert client.subscribed
        client.install_katello_agent()
        client.run('katello-package-upload')

    @staticmethod
    def get_applicable_errata(repo):
        """Retrieves applicable errata for the given repo"""
        return Errata(repository=repo).search(
            query={'errata_restrict_applicable': True}
        )

    @run_only_on('sat')
    @tier4
    def test_positive_noapply_api(self):
        """Check if api incremental update can be done without
        actually applying it

        :id: 481c5ff2-801f-4eff-b1e0-95ea5bb37f95

        :Setup:  The prerequisites are already covered in the setUpClass() but
            for easy debug, get the content view id, Repository id and
            Lifecycle environment id using hammer and plug these statements on
            the top of the test. For example::

                self.rhel_6_partial_cv = ContentView(id=38).read()
                self.rhva_6_repo = Repository(id=164).read()
                self.qe_lce = LifecycleEnvironment(id=46).read()

        :expectedresults: Incremental update completed with no errors and
            Content view has a newer version

        :CaseLevel: System
        """
        # Get the content view versions and use the recent one.  API always
        # returns the versions in ascending order so it is safe to assume the
        # last one in the list is the recent
        cv_versions = self.rhel_6_partial_cv.version

        # Get the applicable errata
        errata_list = self.get_applicable_errata(self.rhva_6_repo)
        self.assertGreater(len(errata_list), 0)

        # Apply incremental update using the first applicable errata
        ContentViewVersion().incremental_update(data={
            'content_view_version_environments': [{
                'content_view_version_id': cv_versions[-1].id,
                'environment_ids': [self.qe_lce.id]
            }],
            'add_content': {
                'errata_ids': [errata_list[0].id]
            }
        })

        # Re-read the content view to get the latest versions
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()
        self.assertGreater(
            len(self.rhel_6_partial_cv.version),
            len(cv_versions)
        )

    @run_only_on('sat')
    @tier4
    def test_positive_noapply_cli(self):
        """Check if cli incremental update can be done without
        actually applying it

        :id: f25b0919-74cb-4e2c-829e-482558990b3c

        :expectedresults: Incremental update completed with no errors and
            Content view has a newer version

        :CaseLevel: System
        """
        # Get the content view versions and use the recent one.  API always
        # returns the versions in ascending order so it is safe to assume the
        # last one in the list is the recent

        cv_versions = self.rhel_6_partial_cv.version

        # Get the applicable errata
        errata_list = self.get_applicable_errata(self.rhva_6_repo)
        self.assertGreater(len(errata_list), 0)

        # Apply incremental update using the first applicable errata
        ContentViewCLI.version_incremental_update({
            u'content-view-version-id': cv_versions[-1].id,
            u'lifecycle-environment-ids': self.qe_lce.id,
            u'errata-ids': errata_list[0].id,
        })

        # Re-read the content view to get the latest versions
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()
        self.assertGreater(
            len(self.rhel_6_partial_cv.version),
            len(cv_versions)
        )
Example #6
0
    def setUp(self):
        """Creates the pre-requisites for the Incremental updates that used per
        each test"""
        super(IncrementalUpdateTestCase, self).setUp()
        # Create content view that will be used filtered erratas
        self.rhel_6_partial_cv = ContentView(
            organization=self.org,
            name=gen_alpha(),
            repository=[self.rhva_6_repo, self.rhel6_sat6tools_repo]
        ).create()

        # Create a content view filter to filter out errata
        rhel_6_partial_cvf = ErratumContentViewFilter(
            content_view=self.rhel_6_partial_cv,
            type='erratum',
            name='rhel_6_partial_cv_filter',
            repository=[self.rhva_6_repo]
        ).create()

        # Create a content view filter rule - filtering out errata in the last
        # 365 days
        start_date = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d')
        ContentViewFilterRule(
            content_view_filter=rhel_6_partial_cvf,
            types=['security', 'enhancement', 'bugfix'],
            start_date=start_date,
            end_date=date.today().strftime('%Y-%m-%d')
        ).create()

        # Publish content view and re-read it

        self.rhel_6_partial_cv.publish()
        self.rhel_6_partial_cv = self.rhel_6_partial_cv.read()

        # Promote content view to 'DEV' and 'QE'
        assert len(self.rhel_6_partial_cv.version) == 1
        for env in (self.dev_lce, self.qe_lce):
            promote(self.rhel_6_partial_cv.version[0], env.id)

        # Create host collection
        self.rhel_6_partial_hc = HostCollection(
            organization=self.org, name=gen_alpha(), max_hosts=5).create()

        # Create activation key for content view
        kwargs = {'organization': self.org, 'environment': self.qe_lce.id}
        rhel_6_partial_ak = ActivationKey(
            name=gen_alpha(),
            content_view=self.rhel_6_partial_cv,
            host_collection=[self.rhel_6_partial_hc],
            **kwargs
        ).create()

        # Assign subscription to activation key. Fetch available subscriptions
        subs = Subscription(organization=self.org).search()
        assert len(subs) > 0

        # Add subscription to activation key
        sub_found = False
        for sub in subs:
            if sub.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME:
                rhel_6_partial_ak.add_subscriptions(data={
                    u'subscription_id': sub.id
                })
                sub_found = True
        assert sub_found

        # Enable product content in activation key
        rhel_6_partial_ak.content_override(data={'content_override': {
            u'content_label': REPOS['rhst6']['id'],
            u'value': u'1'
        }})

        # Create client machine and register it to satellite with
        # rhel_6_partial_ak
        self.vm = VirtualMachine(distro=DISTRO_RHEL6, tag='incupdate')
        self.addCleanup(vm_cleanup, self.vm)
        self.setup_vm(self.vm, rhel_6_partial_ak.name, self.org.label)
        self.vm.enable_repo(REPOS['rhva6']['id'])
        self.vm.run('yum install -y {0}'.format(REAL_0_RH_PACKAGE))

        # Find the content hosts and save them
        hosts = Host(organization=str(self.org.id)).search()
        self.partial_hosts = []
        for host in hosts:
            self.partial_hosts.append(host)