Ejemplo n.º 1
0
def organization_ak_setup(module_org):
    with manifests.clone() as manifest:
        upload_manifest(module_org.id, manifest.content)
    ak = entities.ActivationKey(
        content_view=module_org.default_content_view,
        organization=module_org,
        environment=entities.LifecycleEnvironment(id=module_org.library.id),
        auto_attach=True,
    ).create()
    subscription = entities.Subscription(organization=module_org).search(
        query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'})[0]
    ak.add_subscriptions(data={
        "quantity": 10,
        "subscription_id": subscription.id
    })
    return module_org, ak
Ejemplo n.º 2
0
    def test_positive_create_limited_hosts(self):
        """Create an activation key with limited hosts.

        :id: 9bbba620-fd98-4139-a44b-af8ce330c7a4

        :expectedresults: Check that activation key is created and that hosts
            number is limited

        :CaseImportance: Critical
        """
        for max_host in _good_max_hosts():
            with self.subTest(max_host):
                act_key = entities.ActivationKey(
                    max_hosts=max_host, unlimited_hosts=False).create()
                self.assertEqual(act_key.max_hosts, max_host)
                self.assertFalse(act_key.unlimited_hosts)
Ejemplo n.º 3
0
    def test_positive_add_docker_repo_cv(self):
        """Add Docker-type repository to a non-composite content view
        and publish it. Then create an activation key and associate it with the
        Docker content view.

        @Assert: Docker-based content view can be added to activation key

        @Feature: Docker
        """
        ak = entities.ActivationKey(
            content_view=self.content_view,
            environment=self.lce,
            organization=self.org,
        ).create()
        self.assertEqual(ak.content_view.id, self.content_view.id)
        self.assertEqual(ak.content_view.read().repository[0].id, self.repo.id)
Ejemplo n.º 4
0
    def test_positive_get_releases_status_code(self):
        """Get an activation key's releases. Check response format.

        :id: e1ea4797-8d92-4bec-ae6b-7a26599825ab

        :expectedresults: HTTP 200 is returned with an ``application/json``
            content-type

        :CaseLevel: Integration
        """
        act_key = entities.ActivationKey().create()
        path = act_key.path('releases')
        response = client.get(path, auth=settings.server.get_credentials(), verify=False)
        status_code = http.client.OK
        self.assertEqual(status_code, response.status_code)
        self.assertIn('application/json', response.headers['content-type'])
Ejemplo n.º 5
0
def test_positive_create_limited_hosts(max_host):
    """Create an activation key with limited hosts.

    :id: 9bbba620-fd98-4139-a44b-af8ce330c7a4

    :expectedresults: Check that activation key is created and that hosts
        number is limited

    :CaseImportance: Critical

    :parametrized: yes
    """
    act_key = entities.ActivationKey(max_hosts=max_host,
                                     unlimited_hosts=False).create()
    assert act_key.max_hosts == max_host
    assert act_key.unlimited_hosts is False
Ejemplo n.º 6
0
 def setUpClass(cls):
     """Create hosts that can be shared by tests."""
     super(HostCollectionTestCase, cls).setUpClass()
     cls.org = entities.Organization().create()
     cls.hosts = [
         entities.Host(organization=cls.org).create() for _ in range(2)
     ]
     cls.lce = entities.LifecycleEnvironment(organization=cls.org).create()
     cls.content_view = entities.ContentView(organization=cls.org).create()
     cls.content_view.publish()
     cls.content_view = cls.content_view.read()
     promote(cls.content_view.version[0], environment_id=cls.lce.id)
     cls.activation_key = entities.ActivationKey(
         content_view=cls.content_view,
         environment=cls.lce,
         organization=cls.org).create()
Ejemplo n.º 7
0
 def setUpClass(cls):
     """Set up single org with subscription to 1 RH and 1 custom products to
     reuse in tests
     """
     super(ErrataTestCase, cls).setUpClass()
     cls.env = entities.LifecycleEnvironment(
         organization=cls.session_org).create()
     cls.content_view = entities.ContentView(
         organization=cls.session_org).create()
     cls.activation_key = entities.ActivationKey(
         environment=cls.env,
         organization=cls.session_org,
     ).create()
     setup_org_for_a_rh_repo(
         {
             'product': PRDS['rhel'],
             'repository-set': REPOSET['rhst7'],
             'repository': REPOS['rhst7']['name'],
             'organization-id': cls.session_org.id,
             'content-view-id': cls.content_view.id,
             'lifecycle-environment-id': cls.env.id,
             'activationkey-id': cls.activation_key.id,
         },
         force_manifest_upload=True)
     cls.custom_entitites = setup_org_for_a_custom_repo({
         'url':
         CUSTOM_REPO_URL,
         'organization-id':
         cls.session_org.id,
         'content-view-id':
         cls.content_view.id,
         'lifecycle-environment-id':
         cls.env.id,
         'activationkey-id':
         cls.activation_key.id,
     })
     rhva_repo = enable_rhrepo_and_fetchid(
         basearch=DEFAULT_ARCHITECTURE,
         org_id=cls.session_org.id,
         product=PRDS['rhel'],
         repo=REPOS['rhva6']['name'],
         reposet=REPOSET['rhva6'],
         releasever=DEFAULT_RELEASE_VERSION,
     )
     assert entities.Repository(id=rhva_repo).sync()['result'] == 'success'
     cls.rhva_errata_id = REAL_4_ERRATA_ID
     cls.rhva_errata_cves = REAL_4_ERRATA_CVES
Ejemplo n.º 8
0
def test_positive_get_diff_for_cv_envs():
    """Generate a difference in errata between a set of environments
    for a content view

    :id: 96732506-4a89-408c-8d7e-f30c8d469769

    :Setup:

        1. Errata synced on satellite server.
        2. Multiple environments present.

    :Steps: GET /katello/api/compare

    :expectedresults: Difference in errata between a set of environments
        for a content view is retrieved.

    :CaseLevel: System
    """
    org = entities.Organization().create()
    env = entities.LifecycleEnvironment(organization=org).create()
    content_view = entities.ContentView(organization=org).create()
    activation_key = entities.ActivationKey(environment=env,
                                            organization=org).create()
    for repo_url in [settings.repos.yum_9.url, CUSTOM_REPO_URL]:
        setup_org_for_a_custom_repo({
            'url': repo_url,
            'organization-id': org.id,
            'content-view-id': content_view.id,
            'lifecycle-environment-id': env.id,
            'activationkey-id': activation_key.id,
        })
    new_env = entities.LifecycleEnvironment(organization=org,
                                            prior=env).create()
    cvvs = content_view.read().version[-2:]
    promote(cvvs[-1], new_env.id)
    result = entities.Errata().compare(
        data={
            'content_view_version_ids': [cvv.id for cvv in cvvs],
            'per_page': '9999'
        })
    cvv2_only_errata = next(errata for errata in result['results']
                            if errata['errata_id'] == CUSTOM_REPO_ERRATA_ID)
    assert cvvs[-1].id in cvv2_only_errata['comparison']
    both_cvvs_errata = next(
        errata for errata in result['results']
        if errata['errata_id'] in constants.FAKE_9_YUM_SECURITY_ERRATUM)
    assert {cvv.id for cvv in cvvs} == set(both_cvvs_errata['comparison'])
Ejemplo n.º 9
0
    def test_positive_re_register_host(self):
        """Re-register a host which was un-registered earlier from content-host

        @id: 898695dc-36ff-45b8-85be-6734e6a232d6

        @steps:
        1.  Re-register a host which was unregistered before
        2.  View host under content hosts
        3.  View host under 'All hosts'

        @assert: A single entry of host should appear at both places on
        re-registering

        @CaseLevel: System
        """
        org = entities.Organization().create()
        env = entities.LifecycleEnvironment(organization=org).create()
        content_view = entities.ContentView(organization=org).create()
        activation_key = entities.ActivationKey(
            environment=env,
            organization=org,
        ).create()
        setup_org_for_a_rh_repo({
            'product': PRDS['rhel'],
            'repository-set': REPOSET['rhst7'],
            'repository': REPOS['rhst7']['name'],
            'organization-id': org.id,
            'content-view-id': content_view.id,
            'lifecycle-environment-id': env.id,
            'activationkey-id': activation_key.id,
        })
        with VirtualMachine(distro=DISTRO_RHEL7) as vm:
            vm.install_katello_ca()
            result = vm.register_contenthost(org.label, activation_key.name)
            self.assertEqual(result.return_code, 0)
            with Session(self.browser) as session:
                session.nav.go_to_select_org(org.name)
                self.contenthost.unregister(vm.hostname)
                self.contenthost.validate_subscription_status(
                    vm.hostname, False)
                result = vm.register_contenthost(org.label,
                                                 activation_key.name)
                self.assertEqual(result.return_code, 0)
                self.contenthost.validate_subscription_status(
                    vm.hostname, True)
                self.assertIsNotNone(self.contenthost.search(vm.hostname))
                self.assertIsNotNone(self.hosts.search(vm.hostname))
Ejemplo n.º 10
0
    def test_post_subscription_scenario_autoattach(self, request, dependent_scenario_name):
        """Run subscription auto-attach on pre-upgrade content host registered
        with Satellite.

        :id: postupgrade-940fc78c-ffa6-4d9a-9c4b-efa1b9480a22

        :steps:
            1. Run subscription auto-attach on content host.
            2. Delete the content host, activation key, location & organization.

        :expectedresults: After upgrade,
            1. Pre-upgrade content host should get subscribed.
            2. All the cleanup should be completed successfully.
        """
        docker_vm = settings.upgrade.docker_vm
        pre_test_name = dependent_scenario_name
        docker_container_name = f'{pre_test_name}' + "_docker_client"
        docker_hostname = execute(
            docker_execute_command,
            docker_container_name,
            'hostname',
            host=docker_vm,
        )[docker_vm]
        org = entities.Organization().search(query={'search': f'name="{pre_test_name}_org"'})[0]
        request.addfinalizer(org.delete)
        loc = entities.Location().search(query={'search': f'name="{pre_test_name}_loc"'})[0]
        request.addfinalizer(loc.delete)
        act_key = entities.ActivationKey(organization=org).search(
            query={'search': f'name="{pre_test_name}_ak"'}
        )[0]
        request.addfinalizer(act_key.delete)
        host = entities.Host(organization=org).search(
            query={'search': f'name="{docker_hostname.casefold()}"'}
        )[0]
        delete_manifest(org.name)
        request.addfinalizer(host.delete)
        subscription = execute(
            docker_execute_command,
            docker_container_name,
            'subscription-manager attach --auto',
            host=docker_vm,
        )[docker_vm]
        assert 'Subscribed' in subscription
        ssh.command(
            f"docker stop {docker_container_name}; docker rm {docker_container_name}",
            hostname=f'{docker_vm}',
        )
Ejemplo n.º 11
0
    def test_post_user_scenario_capsule_sync(self, request,
                                             dependent_scenario_name):
        """Post-upgrade scenario that sync capsule from satellite and then
        verifies if the repo/rpm of pre-upgrade scenario is synced to capsule


        :id: postupgrade-eb8970fa-98cc-4a99-99fb-1c12c4e319c9

        :steps:
            1. Run capsule sync post upgrade.
            2. Check if the repo/rpm is been synced to capsule.

        :expectedresults:
            1. The capsule sync should be successful
            2. The repos/rpms from satellite should be synced to satellite

        """
        request.addfinalizer(lambda: cleanup(content_view, repo, product))
        org = entities.Organization().search(
            query={'search': f'name="{DEFAULT_ORG}"'})[0]
        pre_test_name = dependent_scenario_name
        rpm_name = rpm1.split('/')[-1]
        cap_host = settings.upgrade.rhev_cap_host or settings.upgrade.capsule_hostname
        activation_key = settings.upgrade.rhev_capsule_ak or settings.upgrade.capsule_ak
        ak = entities.ActivationKey(organization=org.id).search(
            query={'search': f'name={activation_key}'})[0]
        repo = entities.Repository(organization=org.id).search(
            query={'search': f'name={pre_test_name}_repo'})[0]
        product = entities.Product(organization=org.id).search(
            query={'search': f'name={pre_test_name}_prod'})[0]
        env_name = ak.environment.read()
        org_name = env_name.organization.read_json()['label']

        content_view = entities.ContentView(organization=f'{org.id}').search(
            query={'search': f'name={pre_test_name}_cv'})[0]
        capsule = entities.SmartProxy().search(
            query={'search': f'name={cap_host}'})[0]
        call_entity_method_with_timeout(
            entities.Capsule(id=capsule.id).content_sync, timeout=3600)
        result = execute(
            lambda: run(
                f'[ -f /var/lib/pulp/published/yum/http/repos/'
                f'{org_name}/{env_name.name}/{content_view.name}/custom/{pre_test_name}_prod/'
                f'{pre_test_name}_repo/Packages/b/{rpm_name} ]; echo $?'),
            host=cap_host,
        )[cap_host]
        assert result == '0'
Ejemplo n.º 12
0
    def test_pre_user_scenario_capsule_sync(self, request):
        """Pre-upgrade scenario that creates and sync repository with
        rpm in satellite which will be synced in post upgrade scenario.

        :id: preupgrade-eb8970fa-98cc-4a99-99fb-1c12c4e319c9

        :steps:
            1. Before Satellite upgrade, Sync a repo/rpm in satellite

        :expectedresults:
            1. The repo/rpm should be synced to satellite
            2. Activation key's environment id should be available in the content views environment
            id's list

        """
        pre_test_name = request.node.name
        repo_name = f"{pre_test_name}_repo"
        repo_path = f'/var/www/html/pub/{repo_name}/'
        activation_key = (
            settings.upgrade.capsule_ak[settings.upgrade.os]
            or settings.upgrade.custom_capsule_ak[settings.upgrade.os])
        prod_name = f"{pre_test_name}_prod"
        cv_name = f"{pre_test_name}_cv"
        repo_url = f'http://{settings.server.hostname}/pub/{repo_name}'
        org = entities.Organization().search(
            query={'search': f'name="{DEFAULT_ORG}"'})[0]
        ak = entities.ActivationKey(organization=org.id).search(
            query={'search': f'name={activation_key}'})[0]
        ak_env = ak.environment.read()

        product = entities.Product(name=prod_name,
                                   organization=org.id).create()
        create_repo(rpm1, repo_path)
        repo = entities.Repository(product=product.id,
                                   name=repo_name,
                                   url=repo_url).create()
        repo.sync()
        content_view = entities.ContentView(name=cv_name,
                                            organization=org.id).create()
        content_view.repository = [repo]
        content_view = content_view.update(['repository'])
        content_view.publish()
        promote(content_view.read().version[0], ak_env.id)
        content_view_env_id = [
            env.id for env in content_view.read().environment
        ]
        assert ak_env.id in content_view_env_id
Ejemplo n.º 13
0
    def test_post_user_scenario_capsule_sync_2(self):
        """Post-upgrade scenario that creates and sync repository with
        rpm, sync capsule with satellite and verifies if the repo/rpm in
        satellite is synced to capsule.


        :id: postupgrade-7c1d3441-3e8d-4ac2-8102-30e18274658c

        :steps:
            1. Post Upgrade , Sync a repo/rpm in satellite.
            2. Run capsule sync.
            3. Check if the repo/rpm is been synced to capsule.

        :expectedresults:
            1. The repo/rpm should be synced to satellite
            2. Capsule sync should be successful
            3. The repo/rpm from satellite should be synced to capsule

        """
        ak = entities.ActivationKey(organization=self.org_id).search(
            query={'search': 'name={}'.format(self.activation_key)})[0]
        ak_env = ak.environment.read()
        product = entities.Product(name=self.prod_name,
                                   organization=self.org_id).create()
        create_repo(rpm2, self.repo_path)
        repo = entities.Repository(product=product.id,
                                   name=self.repo_name,
                                   url=self.repo_url).create()
        repo.sync()
        content_view = entities.ContentView(name=self.cv_name,
                                            organization=self.org_id).create()
        content_view.repository = [repo]
        content_view = content_view.update(['repository'])
        content_view.publish()
        promote(content_view.read().version[0], ak_env.id)
        self.assertEqual(content_view.read().environment[-1].id, ak_env.id)
        wait_untill_capsule_sync(self.cap_host)
        org_name = entities.Organization().search(
            query={'search': 'id={}'.format(self.org_id)})[0].label
        result = execute(
            lambda: run('[ -f /var/lib/pulp/published/yum/http/repos/'
                        '{0}/{1}/{2}/custom/{3}/{4}/Packages/c/{5} ]; echo $?'.
                        format(org_name, ak_env.name, self.cv_name, self.
                               prod_name, self.repo_name, self.rpm_name)),
            host=self.cap_host)[self.cap_host]
        self.assertEqual('0', result)
Ejemplo n.º 14
0
    def test_positive_fetch_product_content(self):
        """Associate RH & custom product with AK and fetch AK's product content

        :id: 4c37fb12-ea2a-404e-b7cc-a2735e8dedb6

        :expectedresults: Both Red Hat and custom product subscriptions are
            assigned as Activation Key's product content

        :BZ: 1426386, 1432285

        :CaseLevel: Integration
        """
        org = entities.Organization().create()
        with manifests.clone() as manifest:
            upload_manifest(org.id, manifest.content)
        rh_repo_id = enable_rhrepo_and_fetchid(
            basearch='x86_64',
            org_id=org.id,
            product=PRDS['rhel'],
            repo=REPOS['rhst7']['name'],
            reposet=REPOSET['rhst7'],
            releasever=None,
        )
        rh_repo = entities.Repository(id=rh_repo_id).read()
        rh_repo.sync()
        custom_product = entities.Product(organization=org).create()
        custom_repo = entities.Repository(
            name=gen_string('alphanumeric').upper(),  # first letter is always
            # uppercase on product content page, workarounding it for
            # successful checks
            product=custom_product).create()
        custom_repo.sync()
        cv = entities.ContentView(
            organization=org,
            repository=[rh_repo_id, custom_repo.id],
        ).create()
        cv.publish()
        ak = entities.ActivationKey(content_view=cv, organization=org).create()
        with Session(self) as session:
            set_context(session, org=org.name)
            self.activationkey.associate_product(
                ak.name, [custom_product.name, DEFAULT_SUBSCRIPTION_NAME])
            self.assertEqual(
                set(self.activationkey.fetch_repository_sets(ak.name)),
                {custom_repo.name, REPOSET['rhst7']}
            )
Ejemplo n.º 15
0
def organization_ak_setup(module_manifest_org):
    """A module-level fixture to create an Activation key in module_org"""
    ak = entities.ActivationKey(
        content_view=module_manifest_org.default_content_view,
        organization=module_manifest_org,
        environment=entities.LifecycleEnvironment(
            id=module_manifest_org.library.id),
        auto_attach=True,
    ).create()
    subscription = entities.Subscription(
        organization=module_manifest_org).search(
            query={'search': f'name="{DEFAULT_SUBSCRIPTION_NAME}"'})[0]
    ak.add_subscriptions(data={
        'quantity': 10,
        'subscription_id': subscription.id
    })
    return module_manifest_org, ak
Ejemplo n.º 16
0
    def test_negative_create_with_no_host_limit_set_max(self):
        """Create activation key with unlimited hosts and set max hosts of
        varied values.

        :id: 71b9b000-b978-4a95-b6f8-83c09ed39c01

        :expectedresults: Activation key is not created

        :CaseImportance: Low

        :BZ: 1156555
        """
        for max_host in _bad_max_hosts():
            with self.subTest(max_host):
                with self.assertRaises(HTTPError):
                    entities.ActivationKey(max_hosts=max_host,
                                           unlimited_hosts=True).create()
Ejemplo n.º 17
0
    def test_positive_get_releases_content(self):
        """Get an activation key's releases. Check response contents.

        :id: 2fec3d71-33e9-40e5-b934-90b03afc26a1

        :expectedresults: A list of results is returned.

        :CaseLevel: Integration
        """
        act_key = entities.ActivationKey().create()
        response = client.get(
            act_key.path('releases'),
            auth=settings.server.get_credentials(),
            verify=False,
        ).json()
        self.assertIn('results', response.keys())
        self.assertEqual(type(response['results']), list)
Ejemplo n.º 18
0
    def test_positive_add_docker_repo_cv(self, module_lce, module_org, repo,
                                         content_view_publish_promote):
        """Add Docker-type repository to a non-composite content view
        and publish it. Then create an activation key and associate it with the
        Docker content view.

        :id: ce4ae928-49c7-4782-a032-08885050dd83

        :expectedresults: Docker-based content view can be added to activation
            key
        """
        content_view = content_view_publish_promote
        ak = entities.ActivationKey(content_view=content_view,
                                    environment=module_lce,
                                    organization=module_org).create()
        assert ak.content_view.id == content_view.id
        assert ak.content_view.read().repository[0].id == repo.id
Ejemplo n.º 19
0
    def test_positive_add_docker_repo_cv(self):
        """Add Docker-type repository to a non-composite content view
        and publish it. Then create an activation key and associate it with the
        Docker content view.

        :id: ce4ae928-49c7-4782-a032-08885050dd83

        :expectedresults: Docker-based content view can be added to activation
            key
        """
        ak = entities.ActivationKey(
            content_view=self.content_view,
            environment=self.lce,
            organization=self.org,
        ).create()
        self.assertEqual(ak.content_view.id, self.content_view.id)
        self.assertEqual(ak.content_view.read().repository[0].id, self.repo.id)
Ejemplo n.º 20
0
    def test_positive_update_limited_host(self):
        """Create activation key then update it to limited hosts.

        :id: 34ca8303-8135-4694-9cf7-b20f8b4b0a1e

        :expectedresults: Activation key is created, updated to limited host
        """
        # unlimited_hosts defaults to True.
        act_key = entities.ActivationKey().create()
        for max_host in _good_max_hosts():
            want = {'max_hosts': max_host, 'unlimited_hosts': False}
            for key, value in want.items():
                setattr(act_key, key, value)
            with self.subTest(want):
                act_key = act_key.update(want.keys())
                actual = {attr: getattr(act_key, attr) for attr in want.keys()}
                self.assertEqual(want, actual)
Ejemplo n.º 21
0
    def test_positive_get_releases_status_code(self):
        """Get an activation key's releases. Check response format.

        @Assert: HTTP 200 is returned with an ``application/json`` content-type

        @Feature: ActivationKey
        """
        act_key = entities.ActivationKey().create()
        path = act_key.path('releases')
        response = client.get(
            path,
            auth=settings.server.get_credentials(),
            verify=False,
        )
        status_code = http_client.OK
        self.assertEqual(status_code, response.status_code)
        self.assertIn('application/json', response.headers['content-type'])
Ejemplo n.º 22
0
def test_positive_delete_manifest(session):
    """Check if deleting a manifest removes it from Activation key

    :id: 512d8e41-b937-451e-a9c6-840457d3d7d4

    :Steps:
        1. Create Activation key
        2. Associate a manifest to the Activation Key
        3. Delete the manifest

    :expectedresults: Deleting a manifest removes it from the Activation
        key

    :CaseLevel: Integration
    """
    # Upload manifest
    org = entities.Organization().create()
    with manifests.clone() as manifest:
        upload_manifest(org.id, manifest.content)
    # Create activation key
    activation_key = entities.ActivationKey(organization=org).create()
    # Associate a manifest to the activation key
    subscription = entities.Subscription(organization=org).search(
        query={'search': f'name="{constants.DEFAULT_SUBSCRIPTION_NAME}"'})[0]
    activation_key.add_subscriptions(data={
        'quantity': 1,
        'subscription_id': subscription.id
    })
    with session:
        session.organization.select(org.name)
        # Verify subscription is assigned to activation key
        ak = session.activationkey.read(activation_key.name,
                                        widget_names='subscriptions')
        assert (ak['subscriptions']['resources']['assigned'][0]
                ['Repository Name'] == constants.DEFAULT_SUBSCRIPTION_NAME)
        # Delete the manifest
        # Ignore "404 Not Found" as server will connect to upstream subscription service to verify
        # the consumer uuid, that will be displayed in flash error messages
        # Note: this happen only when using clone manifest.
        session.subscription.delete_manifest(
            ignore_error_messages='404 Not Found')
        assert not session.subscription.has_manifest
        # Verify subscription is not assigned to activation key anymore
        ak = session.activationkey.read(activation_key.name,
                                        widget_names='subscriptions')
        assert not ak['subscriptions']['resources']['assigned']
Ejemplo n.º 23
0
    def test_pre_subscription_scenario_autoattach(self):
        """Create content host and register with Satellite

        :id: preupgrade-940fc78c-ffa6-4d9a-9c4b-efa1b9480a22

        :steps:
            1. Before Satellite upgrade.
            2. Create new Organization and Location
            3. Upload a manifest in it.
            4. Create a AK with 'auto-attach False' and without Subscription add in it.
            5. Create a content host.
            6. Update content host location.

        :expectedresults:
            1. Content host should be created.
            2. Content host location should be updated.
        """
        org = entities.Organization().create()
        loc = entities.Location(organization=[org]).create()
        manifests.upload_manifest_locked(org.id, interface=manifests.INTERFACE_API)
        act_key = entities.ActivationKey(auto_attach=False, organization=org.id,
                                         environment=org.library.id).create()
        rhel7_client = dockerize(
            ak_name=act_key.name, distro='rhel7', org_label=org.label)
        client_container_id = [value for value in rhel7_client.values()][0]
        client_container_name = [key for key in rhel7_client.keys()][0]
        host_location_update(client_container_name=client_container_name,
                             logger_obj=self.logger, loc=loc)

        wait_for(
            lambda: org.name in execute(docker_execute_command, client_container_id,
                                        'subscription-manager identity',
                                        host=self.docker_vm)[self.docker_vm],
            timeout=100,
            delay=2,
            logger=self.logger
        )
        status = execute(docker_execute_command, client_container_id,
                         'subscription-manager identity',
                         host=self.docker_vm)[self.docker_vm]
        self.assertIn(org.name, status)

        global_dict = {
            self.__class__.__name__: {'client_container_id': client_container_id}
        }
        create_dict(global_dict)
Ejemplo n.º 24
0
def test_positive_update_limited_host(max_host):
    """Create activation key then update it to limited hosts.

    :id: 34ca8303-8135-4694-9cf7-b20f8b4b0a1e

    :expectedresults: Activation key is created, updated to limited host

    :parametrized: yes
    """
    # unlimited_hosts defaults to True.
    act_key = entities.ActivationKey().create()
    want = {'max_hosts': max_host, 'unlimited_hosts': False}
    for key, value in want.items():
        setattr(act_key, key, value)
    act_key = act_key.update(want.keys())
    actual = {attr: getattr(act_key, attr) for attr in want.keys()}
    assert want == actual
Ejemplo n.º 25
0
    def test_positive_delete_manifest(self):
        """Check if deleting a manifest removes it from Activation key

        @Feature: Activation key - Manifest

        @Steps:
        1. Create Activation key
        2. Associate a manifest to the Activation Key
        3. Delete the manifest

        @Assert: Deleting a manifest removes it from the Activation key
        """
        # Upload manifest
        org = entities.Organization().create()
        sub = entities.Subscription(organization=org)
        with manifests.clone() as manifest:
            upload_manifest(org.id, manifest.content)
        # Create activation key
        activation_key = entities.ActivationKey(organization=org, ).create()
        # Associate a manifest to the activation key
        for subs in sub.search():
            if subs.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME:
                activation_key.add_subscriptions(data={
                    'quantity': 1,
                    'subscription_id': subs.id,
                })
                break
        with Session(self.browser) as session:
            session.nav.go_to_select_org(org.name)
            # Verify subscription is assigned to activation key
            self.navigator.go_to_activation_keys()
            self.assertIsNotNone(
                self.activationkey.search_key_subscriptions(
                    activation_key.name, DEFAULT_SUBSCRIPTION_NAME))
            # Delete the manifest
            self.navigator.go_to_red_hat_subscriptions()
            self.subscriptions.delete()
            self.assertIsNotNone(
                self.subscriptions.wait_until_element(
                    common_locators['alert.success']))
            # Verify the subscription was removed from the activation key
            self.navigator.go_to_activation_keys()
            self.assertIsNone(
                self.activationkey.search_key_subscriptions(
                    activation_key.name, DEFAULT_SUBSCRIPTION_NAME))
Ejemplo n.º 26
0
    def test_positive_delete_manifest(self):
        """Check if deleting a manifest removes it from Activation key

        :id: 512d8e41-b937-451e-a9c6-840457d3d7d4

        :Steps:
            1. Create Activation key
            2. Associate a manifest to the Activation Key
            3. Delete the manifest

        :expectedresults: Deleting a manifest removes it from the Activation
            key

        :CaseLevel: Integration
        """
        # Upload manifest
        org = entities.Organization().create()
        sub = entities.Subscription(organization=org)
        with manifests.clone() as manifest:
            upload_manifest(org.id, manifest.content)
        # Create activation key
        activation_key = entities.ActivationKey(organization=org, ).create()
        # Associate a manifest to the activation key
        for subs in sub.search():
            if subs.read_json()['product_name'] == DEFAULT_SUBSCRIPTION_NAME:
                activation_key.add_subscriptions(data={
                    'quantity': 1,
                    'subscription_id': subs.id,
                })
                break
        with Session(self) as session:
            session.nav.go_to_select_org(org.name)
            # Verify subscription is assigned to activation key
            self.assertIsNotNone(
                self.activationkey.search_key_subscriptions(
                    activation_key.name, DEFAULT_SUBSCRIPTION_NAME))
            # Delete the manifest
            self.navigator.go_to_red_hat_subscriptions()
            self.subscriptions.delete()
            self.assertIsNotNone(
                self.subscriptions.wait_until_element(
                    locators['subs.import_history.deleted']))
            self.assertIsNone(
                self.activationkey.search_key_subscriptions(
                    activation_key.name, DEFAULT_SUBSCRIPTION_NAME))
Ejemplo n.º 27
0
    def test_positive_update_limited_chost(self):
        """Create activation key then update it to limited content
        hosts.

        @Assert: Activation key is created, updated to limited content host

        @Feature: ActivationKey
        """
        # unlimited_content_hosts defaults to True.
        act_key = entities.ActivationKey().create()
        for mch in _good_max_content_hosts():
            want = {'max_content_hosts': mch, 'unlimited_content_hosts': False}
            for key, value in want.items():
                setattr(act_key, key, value)
            with self.subTest(want):
                act_key = act_key.update(want.keys())
                actual = {attr: getattr(act_key, attr) for attr in want.keys()}
                self.assertEqual(want, actual)
Ejemplo n.º 28
0
def activation_key_setup(request):
    """
    The purpose of this fixture is to setup the activation key based on the provided organization,
    content_view and activation key name.
    """
    org = entities.Organization(name=request.param + "_org").create()
    custom_repo = entities.Repository(product=entities.Product(
        organization=org).create()).create()
    custom_repo.sync()
    cv = entities.ContentView(organization=org,
                              repository=[custom_repo.id],
                              name=request.param + "_cv").create()
    cv.publish()
    ak = entities.ActivationKey(content_view=cv,
                                organization=org,
                                name=request.param + "_ak").create()
    ak_details = {'org': org, "cv": cv, 'ak': ak, 'custom_repo': custom_repo}
    yield ak_details
Ejemplo n.º 29
0
def test_positive_delete_manifest(session):
    """Check if deleting a manifest removes it from Activation key

    :id: 512d8e41-b937-451e-a9c6-840457d3d7d4

    :Steps:
        1. Create Activation key
        2. Associate a manifest to the Activation Key
        3. Delete the manifest

    :expectedresults: Deleting a manifest removes it from the Activation
        key

    :CaseLevel: Integration
    """
    # Upload manifest
    org = entities.Organization().create()
    with manifests.clone() as manifest:
        upload_manifest(org.id, manifest.content)
    # Create activation key
    activation_key = entities.ActivationKey(
        organization=org,
    ).create()
    # Associate a manifest to the activation key
    subscription = entities.Subscription(organization=org).search(query={
        'search': 'name="{}"'.format(DEFAULT_SUBSCRIPTION_NAME)})[0]
    activation_key.add_subscriptions(data={
        'quantity': 1,
        'subscription_id': subscription.id,
    })
    with session:
        session.organization.select(org.name)
        # Verify subscription is assigned to activation key
        ak = session.activationkey.read(activation_key.name)
        assert (
            ak['subscriptions']['resources']['assigned'][0]['Repository Name']
            == DEFAULT_SUBSCRIPTION_NAME
        )
        # Delete the manifest
        session.subscription.delete_manifest()
        assert not session.subscription.has_manifest
        # Verify subscription is not assigned to activation key anymore
        ak = session.activationkey.read(activation_key.name)
        assert not ak['subscriptions']['resources']['assigned']
Ejemplo n.º 30
0
    def test_positive_remove_docker_repo_cv(self, module_org, module_lce,
                                            content_view_publish_promote):
        """Create an activation key and associate it with the Docker content view. Then remove
        this content view from the activation key.

        :id: 6a887a67-6700-47ac-9230-deaa0e382f22

        :expectedresults: Docker-based content view can be added and then
            removed from the activation key.

        :CaseLevel: Integration
        """
        content_view = content_view_publish_promote
        ak = entities.ActivationKey(content_view=content_view,
                                    environment=module_lce,
                                    organization=module_org).create()
        assert ak.content_view.id == content_view.id
        ak.content_view = None
        assert ak.update(['content_view']).content_view is None