def test_vm_install_package(value):
    """Install a package with all supported distros and cdn not cdn variants

    :id: b2a6065a-69f6-4805-a28b-eaaa812e0f4b

    :expectedresults: Package is install is installed
    """
    # the value is support distro DISTRO_RH6 or DISTRO_RH7
    # this will create 4 tests:
    #  - one test with disto rhel6 cdn False
    #  - one test with distro rhel7 cdn False
    #  - one test with disto rhel6 cdn True
    #  - one test with distro rhel7 cdn True
    distro, cdn = value
    org = make_org()
    lce = make_lifecycle_environment({'organization-id': org['id']})
    repos_collection = RepositoryCollection(
        distro=distro,
        repositories=[
            SatelliteToolsRepository(cdn=cdn),
            YumRepository(url=FAKE_0_YUM_REPO)
        ])
    # this will create repositories , content view and activation key
    repos_collection.setup_content(org['id'], lce['id'], upload_manifest=True)
    with VirtualMachine(distro=distro) as vm:
        # this will install katello ca, register vm host, enable rh repos,
        # install katello-agent
        repos_collection.setup_virtual_machine(vm)
        # install a package
        result = vm.run('yum -y install {0}'.format(FAKE_0_CUSTOM_PACKAGE))
        assert result.return_code == 0
Example #2
0
def test_positive_end_to_end_register(session, rhel7_contenthost, default_sat):
    """Create activation key and use it during content host registering

    :id: dfaecf6a-ba61-47e1-87c5-f8966a319b41

    :expectedresults: Content host was registered successfully using activation
        key, association is reflected on webUI

    :CaseLevel: System

    :parametrized: yes

    :CaseImportance: High
    """
    org = entities.Organization().create()
    lce = entities.LifecycleEnvironment(organization=org).create()
    repos_collection = RepositoryCollection(
        distro=constants.DISTRO_RHEL7,
        repositories=[SatelliteToolsRepository()])
    repos_collection.setup_content(org.id, lce.id, upload_manifest=True)
    ak_name = repos_collection.setup_content_data['activation_key']['name']

    repos_collection.setup_virtual_machine(rhel7_contenthost, default_sat)
    with session:
        session.organization.select(org.name)
        chost = session.contenthost.read(rhel7_contenthost.hostname,
                                         widget_names='details')
        assert chost['details']['registered_by'] == f'Activation Key {ak_name}'
        ak_values = session.activationkey.read(ak_name,
                                               widget_names='content_hosts')
        assert len(ak_values['content_hosts']['table']) == 1
        assert ak_values['content_hosts']['table'][0][
            'Name'] == rhel7_contenthost.hostname
Example #3
0
def test_positive_reposet_disable(session):
    """Enable RH repo, sync it and then disable

    :id: de596c56-1327-49e8-86d5-a1ab907f26aa

    :expectedresults: RH repo was disabled

    :CaseLevel: Integration
    """
    org = entities.Organization().create()
    manifests.upload_manifest_locked(org.id)
    sat_tools_repo = SatelliteToolsRepository(distro=DISTRO_RHEL7, cdn=True)
    repository_name = sat_tools_repo.data['repository']
    with session:
        session.organization.select(org.name)
        session.redhatrepository.enable(
            sat_tools_repo.data['repository-set'],
            sat_tools_repo.data['arch'],
            version=sat_tools_repo.data['releasever'])
        results = session.redhatrepository.search(
            'name = "{0}"'.format(repository_name), category='Enabled')
        assert results[0]['name'] == repository_name
        results = session.sync_status.synchronize([
            (sat_tools_repo.data['product'], sat_tools_repo.data['releasever'],
             sat_tools_repo.data['arch'], repository_name)
        ])
        assert results and all(
            [result == 'Syncing Complete.' for result in results])
        session.redhatrepository.disable(repository_name)
        assert not session.redhatrepository.search(
            'name = "{0}"'.format(repository_name), category='Enabled')
def test_vm_install_package(org, lce, distro, cdn):
    """Install a package with all supported distros and cdn / non-cdn variants

    :id: b2a6065a-69f6-4805-a28b-eaaa812e0f4b

    :parametrized: yes

    :expectedresults: Package is install is installed
    """
    if distro == DISTRO_RHEL6:
        pytest.skip(f'{DISTRO_RHEL6!s} skipped until ELS subscriptions are in manifest.')
    repos_collection = RepositoryCollection(
        distro=distro,
        repositories=[
            SatelliteToolsRepository(cdn=cdn, distro=distro),
            YumRepository(url=FAKE_0_YUM_REPO),
            DockerRepository(url=CONTAINER_REGISTRY_HUB, upstream_name=CONTAINER_UPSTREAM_NAME),
            PuppetRepository(
                url=CUSTOM_PUPPET_REPO, modules=[dict(name='generic_1', author='robottelo')]
            ),
        ],
    )
    # Create repos, content view, and activation key.
    repos_collection.setup_content(org['id'], lce['id'], upload_manifest=True)
    with VMBroker(nick=distro, host_classes={'host': ContentHost}) as host:
        # install katello-agent
        repos_collection.setup_virtual_machine(
            host, enable_custom_repos=True, install_katello_agent=False
        )
        # install a package from custom repo
        result = host.execute(f'yum -y install {FAKE_0_CUSTOM_PACKAGE}')
        assert result.status == 0
Example #5
0
def test_vm_install_package(value, module_org, module_lce):
    """Install a package with all supported distros and cdn not cdn variants

    :id: b2a6065a-69f6-4805-a28b-eaaa812e0f4b

    :expectedresults: Package is install is installed
    """
    # the value is support distro DISTRO_RH6 or DISTRO_RH7
    # this will create 4 tests:
    #  - one test with disto rhel6 cdn False
    #  - one test with distro rhel7 cdn False
    #  - one test with disto rhel6 cdn True
    #  - one test with distro rhel7 cdn True
    distro, cdn = value
    repos_collection = RepositoryCollection(
        distro=distro,
        repositories=[
            SatelliteToolsRepository(cdn=cdn),
            YumRepository(url=FAKE_0_YUM_REPO),
            DockerRepository(url=DOCKER_REGISTRY_HUB, upstream_name=DOCKER_UPSTREAM_NAME),
            PuppetRepository(
                url=CUSTOM_PUPPET_REPO, modules=[dict(name='generic_1', author='robottelo')]
            ),
        ],
    )
    # this will create repositories , content view and activation key
    repos_collection.setup_content(module_org['id'], module_lce['id'], upload_manifest=True)
    with VirtualMachine(distro=distro) as vm:
        # this will install katello ca, register vm host, enable rh repos,
        # install katello-agent
        repos_collection.setup_virtual_machine(vm, enable_custom_repos=True)
        # install a package
        result = vm.run('yum -y install {0}'.format(FAKE_0_CUSTOM_PACKAGE))
        assert result.return_code == 0
Example #6
0
def test_positive_reposet_disable_after_manifest_deleted(session):
    """Enable RH repo and sync it. Remove manifest and then disable
    repository

    :id: f22baa8e-80a4-4487-b1bd-f7265555d9a3

    :customerscenario: true

    :expectedresults: RH repo was disabled

    :BZ: 1344391

    :CaseLevel: Integration
    """
    org = entities.Organization().create()
    manifests.upload_manifest_locked(org.id)
    sub = entities.Subscription(organization=org)
    sat_tools_repo = SatelliteToolsRepository(distro=DISTRO_RHEL7, cdn=True)
    repository_name = sat_tools_repo.data['repository']
    repository_name_orphaned = f'{repository_name} (Orphaned)'
    with session:
        session.organization.select(org.name)
        # Enable RH repository
        session.redhatrepository.enable(
            sat_tools_repo.data['repository-set'],
            sat_tools_repo.data['arch'],
            version=sat_tools_repo.data['releasever'],
        )
        results = session.redhatrepository.search(
            f'name = "{repository_name}"', category='Enabled'
        )
        assert results[0]['name'] == repository_name
        # Sync the repo and verify sync was successful
        results = session.sync_status.synchronize(
            [
                (
                    sat_tools_repo.data['product'],
                    sat_tools_repo.data['releasever'],
                    sat_tools_repo.data['arch'],
                    repository_name,
                )
            ]
        )
        assert results and all([result == 'Syncing Complete.' for result in results])
        # Delete manifest
        sub.delete_manifest(data={'organization_id': org.id})
        # Verify that the displayed repository name is correct
        results = session.redhatrepository.search(
            f'name = "{repository_name}"', category='Enabled'
        )
        assert results[0]['name'] == repository_name_orphaned
        # Disable the orphaned repository
        session.redhatrepository.disable(repository_name, orphaned=True)
        assert not session.redhatrepository.search(
            f'name = "{repository_name}"', category='Enabled'
        )
Example #7
0
def module_rhva_repos_col(module_org, module_lce):
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL6,
        repositories=[
            SatelliteToolsRepository(),
            YumRepository(url=CUSTOM_REPO_URL),
            VirtualizationAgentsRepository(cdn=True),
        ])
    repos_collection.setup_content(module_org.id, module_lce.id)
    return repos_collection
Example #8
0
def module_repos_collection(module_org, module_lce):
    repos_collection = RepositoryCollection(
        distro=DISTRO_DEFAULT,
        repositories=[
            SatelliteToolsRepository(),
            YumRepository(url=FAKE_1_YUM_REPO),
            YumRepository(url=FAKE_6_YUM_REPO),
        ],
    )
    repos_collection.setup_content(module_org.id, module_lce.id, upload_manifest=True)
    return repos_collection
Example #9
0
def module_repos_col(module_org, module_lce):
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            SatelliteToolsRepository(),
            # As Satellite Tools may be added as custom repo and to have a "Fully entitled" host,
            # force the host to consume an RH product with adding a cdn repo.
            RHELAnsibleEngineRepository(cdn=True),
            YumRepository(url=CUSTOM_REPO_URL),
        ])
    repos_collection.setup_content(module_org.id, module_lce.id)
    return repos_collection
Example #10
0
def repos_collection(module_org):
    """Adds required repositories, AK, LCE and CV for content host testing"""
    lce = entities.LifecycleEnvironment(organization=module_org).create()
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            RHELAnsibleEngineRepository(cdn=True),
            SatelliteToolsRepository(),
            YumRepository(url=FAKE_1_YUM_REPO),
            YumRepository(url=FAKE_6_YUM_REPO)
        ])
    repos_collection.setup_content(module_org.id, lce.id, upload_manifest=True)
    return repos_collection
Example #11
0
def module_rh_repo(module_org):
    manifests.upload_manifest_locked(module_org.id, manifests.clone())
    rhst = SatelliteToolsRepository(cdn=True)
    repo_id = enable_rhrepo_and_fetchid(
        basearch=rhst.data['arch'],
        org_id=module_org.id,
        product=rhst.data['product'],
        repo=rhst.data['repository'],
        reposet=rhst.data['repository-set'],
        releasever=rhst.data['releasever'],
    )
    entities.Repository(id=repo_id).sync()
    return entities.Repository(id=repo_id).read()
Example #12
0
def module_repos_collection(module_org, module_lce):
    repos_collection = RepositoryCollection(
        distro=constants.DISTRO_DEFAULT,
        repositories=[
            SatelliteToolsRepository(),
            YumRepository(url=settings.repos.yum_1.url),
            YumRepository(url=settings.repos.yum_6.url),
        ],
    )
    repos_collection.setup_content(module_org.id,
                                   module_lce.id,
                                   upload_manifest=True)
    return repos_collection
Example #13
0
def module_erratatype_repos_col(module_org, module_lce):
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            SatelliteToolsRepository(),
            # As Satellite Tools may be added as custom repo and to have a "Fully entitled" host,
            # force the host to consume an RH product with adding a cdn repo.
            RHELAnsibleEngineRepository(cdn=True),
            # add a repo with errata of different types (security, advisory, etc)
            YumRepository(url=FAKE_9_YUM_REPO),
        ],
    )
    repos_collection.setup_content(module_org.id, module_lce.id)
    return repos_collection
Example #14
0
def test_positive_content_host_subscription_status(session):
    """Check if the Content Host Subscription Status is working in the
    Dashboard UI

    :id: ce0d7b0c-ae6a-4361-8173-e50f6381194a

    :Steps:

        1. Register Content Host and subscribe it
        2. Navigate Monitor -> Dashboard
        3. Review the Content Host Subscription Status
        4. Click each link:

            a. Invalid Subscriptions
            b. Valid Subscriptions

    :expectedresults: The widget is updated with all details for Valid,
        and Invalid Subscriptions

    :CaseLevel: System
    """
    org = entities.Organization().create()
    env = entities.LifecycleEnvironment(organization=org).create()
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            SatelliteToolsRepository(cdn=True),
        ]
    )
    repos_collection.setup_content(org.id, env.id, upload_manifest=True)
    with VirtualMachine(distro=DISTRO_RHEL7) as client:
        repos_collection.setup_virtual_machine(client)
        assert client.subscribed
        with session:
            session.organization.select(org_name=org.name)
            session.dashboard.action({'HostSubscription': {'type': 'Invalid'}})
            values = session.contenthost.read_all()
            assert values['searchbox'] == 'subscription_status = invalid'
            assert len(values['table']) == 0
            session.dashboard.action({'HostSubscription': {'type': 'Valid'}})
            values = session.contenthost.read_all()
            assert values['searchbox'] == 'subscription_status = valid'
            assert len(values['table']) == 1
            assert values['table'][0]['Name'] == client.hostname
            assert values['table'][0]['Lifecycle Environment'] == env.name
            cv_name = repos_collection._setup_content_data[
                'content_view']['name']
            assert values['table'][0]['Content View'] == cv_name
Example #15
0
def test_positive_delete_rhel_repo(session, module_org):
    """Enable and sync a Red Hat Repository, and then delete it

    :id: e96f369d-3e58-4824-802e-0b7e99d6d207

    :customerscenario: true

    :expectedresults: Repository can be successfully deleted

    :CaseLevel: Integration

    :BZ: 1152672
    """

    manifests.upload_manifest_locked(module_org.id)
    sat_tools_repo = SatelliteToolsRepository(distro=DISTRO_RHEL7, cdn=True)
    repository_name = sat_tools_repo.data['repository']
    product_name = sat_tools_repo.data['product']
    with session:
        session.organization.select(module_org.name)
        session.redhatrepository.enable(
            sat_tools_repo.data['repository-set'],
            sat_tools_repo.data['arch'],
            version=sat_tools_repo.data['releasever'],
        )
        results = session.redhatrepository.search(
            f'name = "{repository_name}"', category='Enabled')
        assert results[0]['name'] == repository_name
        results = session.sync_status.synchronize([(
            sat_tools_repo.data['product'],
            sat_tools_repo.data['releasever'],
            sat_tools_repo.data['arch'],
            repository_name,
        )])
        assert results and all(
            [result == 'Syncing Complete.' for result in results])
        session.repository.delete(product_name, repository_name)
        assert not session.redhatrepository.search(
            f'name = "{repository_name}"', category='Enabled')
        assert ('Your search returned zero Products'
                in session.product.search(product_name)[0]['Name'])
Example #16
0
def test_positive_filtered_errata_status_installable_param(
        session, errata_status_installable):
    """Filter errata for specific content view and verify that host that
    was registered using that content view has different states in
    correspondence to filtered errata and `errata status installable`
    settings flag value

    :id: ed94cf34-b8b9-4411-8edc-5e210ea6af4f

    :Steps:

        1. Prepare setup: Create Lifecycle Environment, Content View,
            Activation Key and all necessary repos
        2. Register Content Host using created data
        3. Create necessary Content View Filter and Rule for repository errata
        4. Publish and Promote Content View to a new version.
        5. Go to created Host page and check its properties
        6. Change 'errata status installable' flag in the settings and
            check host properties once more

    :expectedresults: Check that 'errata status installable' flag works as intended

    :BZ: 1368254

    :CaseLevel: System
    """
    org = entities.Organization().create()
    lce = entities.LifecycleEnvironment(organization=org).create()
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            SatelliteToolsRepository(),
            # As Satellite Tools may be added as custom repo and to have a "Fully entitled" host,
            # force the host to consume an RH product with adding a cdn repo.
            RHELAnsibleEngineRepository(cdn=True),
            YumRepository(url=CUSTOM_REPO_URL),
        ],
    )
    repos_collection.setup_content(org.id, lce.id, upload_manifest=True)
    with VirtualMachine(distro=repos_collection.distro) as client:
        repos_collection.setup_virtual_machine(client)
        assert _install_client_package(client,
                                       FAKE_1_CUSTOM_PACKAGE,
                                       errata_applicability=True)
        # Adding content view filter and content view filter rule to exclude errata for the
        # installed package.
        content_view = entities.ContentView(
            id=repos_collection.setup_content_data['content_view']
            ['id']).read()
        cv_filter = entities.ErratumContentViewFilter(
            content_view=content_view, inclusion=False).create()
        errata = entities.Errata(
            content_view_version=content_view.version[-1]).search(query=dict(
                search=f'errata_id="{CUSTOM_REPO_ERRATA_ID}"'))[0]
        entities.ContentViewFilterRule(content_view_filter=cv_filter,
                                       errata=errata).create()
        content_view.publish()
        content_view = content_view.read()
        content_view_version = content_view.version[-1]
        promote(content_view_version, lce.id)
        with session:
            session.organization.select(org_name=org.name)
            _set_setting_value(errata_status_installable, True)
            expected_values = {
                'Status': 'OK',
                'Errata': 'All errata applied',
                'Subscription': 'Fully entitled',
            }
            host_details_values = session.host.get_details(client.hostname)
            actual_values = {
                key: value
                for key, value in host_details_values['properties']
                ['properties_table'].items() if key in expected_values
            }
            for key in actual_values:
                assert expected_values[key] in actual_values[
                    key], 'Expected text not found'
            _set_setting_value(errata_status_installable, False)
            expected_values = {
                'Status': 'Error',
                'Errata': 'Security errata applicable',
                'Subscription': 'Fully entitled',
            }
            # navigate to host main page by making a search, to refresh the host details page
            session.host.search(client.hostname)
            host_details_values = session.host.get_details(client.hostname)
            actual_values = {
                key: value
                for key, value in host_details_values['properties']
                ['properties_table'].items() if key in expected_values
            }
            for key in actual_values:
                assert expected_values[key] in actual_values[
                    key], 'Expected text not found'
Example #17
0
def test_end_to_end(session):
    """Create all entities required for errata, set up applicable host,
    read errata details and apply it to host

    :id: a26182fc-f31a-493f-b094-3f5f8d2ece47

    :expectedresults: Errata details are the same as expected, errata
        installation is successful

    :CaseLevel: System
    """
    ERRATA_DETAILS = {
        'advisory':
        'RHEA-2012:0055',
        'cves':
        'N/A',
        'type':
        'Security Advisory',
        'severity':
        'N/A',
        'issued':
        '1/27/12',
        'last_updated_on':
        '1/27/12',
        'reboot_suggested':
        'No',
        'topic':
        '',
        'description':
        'Sea_Erratum',
        'solution':
        '',
        'affected_packages': [
            'penguin-0.9.1-1.noarch', 'shark-0.1-1.noarch',
            'walrus-5.21-1.noarch'
        ]
    }
    org = entities.Organization().create()
    lce = entities.LifecycleEnvironment(organization=org).create()
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            SatelliteToolsRepository(),
            YumRepository(url=CUSTOM_REPO_URL)
        ])
    repos_collection.setup_content(org.id, lce.id, upload_manifest=True)
    with VirtualMachine(distro=DISTRO_RHEL7) as client:
        repos_collection.setup_virtual_machine(client)
        assert client.subscribed
        client.run('yum install -y {0}'.format(FAKE_1_CUSTOM_PACKAGE))
        with session:
            session.organization.select(org.name)
            errata = session.errata.read(CUSTOM_REPO_ERRATA_ID)
            assert errata['details'] == ERRATA_DETAILS
            assert (errata['repositories']['table'][0]['Name'] ==
                    repos_collection.custom_repos_info[-1]['name'])
            assert (errata['repositories']['table'][0]['Product'] ==
                    repos_collection.custom_product['name'])
            result = session.errata.install(CUSTOM_REPO_ERRATA_ID,
                                            client.hostname)
            assert result['result'] == 'success'
Example #18
0
def test_positive_end_to_end(session):
    """Create all entities required for content host, set up host, register it
    as a content host, read content host details, install package and errata.

    :id: f43f2826-47c1-4069-9c9d-2410fd1b622c

    :expectedresults: content host details are the same as expected, package
        and errata installation are successful

    :CaseLevel: System
    """
    org = entities.Organization().create()
    lce = entities.LifecycleEnvironment(organization=org).create()
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            SatelliteToolsRepository(),
            YumRepository(url=FAKE_1_YUM_REPO)
        ])
    repos_collection.setup_content(org.id, lce.id, upload_manifest=True)
    with VirtualMachine(distro=DISTRO_RHEL7) as vm:
        repos_collection.setup_virtual_machine(vm)
        result = vm.run('yum -y install {0}'.format(FAKE_1_CUSTOM_PACKAGE))
        assert result.return_code == 0
        with session:
            session.organization.select(org.name)
            # Ensure content host is searchable
            assert session.contenthost.search(
                vm.hostname)[0]['Name'] == vm.hostname
            chost = session.contenthost.read(vm.hostname)
            # Ensure all content host fields/tabs have appropriate values
            assert chost['details']['name'] == vm.hostname
            assert (chost['details']['content_view'] == repos_collection.
                    setup_content_data['content_view']['name'])
            assert chost['details']['lce'][lce.name][lce.name]
            assert (chost['details']['registered_by'] ==
                    'Activation Key {}'.format(
                        repos_collection.setup_content_data['activation_key']
                        ['name']))
            assert chost['provisioning_details']['name'] == vm.hostname
            assert (
                chost['subscriptions']['resources']['assigned'][0]
                ['Repository Name'] == repos_collection.custom_product['name'])
            actual_repos = {
                repo['Repository Name']
                for repo in chost['repository_sets']['table']
            }
            expected_repos = {
                repo['name']
                for repo in repos_collection.custom_repos_info
            }
            assert actual_repos == expected_repos
            # Install package
            result = session.contenthost.execute_package_action(
                vm.hostname,
                'Package Install',
                FAKE_0_CUSTOM_PACKAGE_NAME,
            )
            assert result['result'] == 'success'
            # Ensure package installed
            packages = session.contenthost.search_package(
                vm.hostname, FAKE_0_CUSTOM_PACKAGE_NAME)
            assert packages[0]['Installed Package'] == FAKE_0_CUSTOM_PACKAGE
            # Install errata
            result = session.contenthost.install_errata(
                vm.hostname, FAKE_1_ERRATA_ID)
            assert result['result'] == 'success'
            # Ensure errata installed
            packages = session.contenthost.search_package(
                vm.hostname, FAKE_2_CUSTOM_PACKAGE_NAME)
            assert packages[0]['Installed Package'] == FAKE_2_CUSTOM_PACKAGE
            # Delete content host
            session.contenthost.delete(vm.hostname)
            assert not session.contenthost.search(vm.hostname)
Example #19
0
def test_content_host_errata_page_pagination(session, org, lce):
    """
    # Test per-page pagination for BZ#1662254
    # Test apply by REX using Select All for BZ#1846670

    :id: 6363eda7-a162-4a4a-b70f-75decbd8202e

    :Steps:
        1. Install more than 20 packages that need errata
        2. View Content Host's Errata page
        3. Assert total_pages > 1
        4. Change per-page setting to 100
        5. Assert table has more than 20 errata
        6. Use the selection box on the left to select all on the page.
            The following is displayed at the top of the table:
            All 20 items on this page are selected. Select all YYY.

        7. Click the "Select all" text and assert more than 20 results are selected.
        8. Click the drop down arrow to the right of "Apply Selected", and select
            "via remote execution"
        9. Click Submit
        10. Assert Errata are applied as expected.

    :expectedresults: More than page of errata can be selected and applied using REX while
        changing per-page settings.


    :BZ: 1662254, 1846670

    :CaseLevel: System
    """
    pkgs = ' '.join(FAKE_3_YUM_OUTDATED_PACKAGES)
    repos_collection = RepositoryCollection(
        distro=DISTRO_RHEL7,
        repositories=[
            SatelliteToolsRepository(),
            YumRepository(url=FAKE_3_YUM_REPO),
        ],
    )
    repos_collection.setup_content(org.id, lce.id, upload_manifest=True)
    with VMBroker(nick=repos_collection.distro,
                  host_classes={'host': ContentHost}) as client:
        # add_remote_execution_ssh_key for REX
        add_remote_execution_ssh_key(client.ip_addr)
        # Add repo and install packages that need errata
        repos_collection.setup_virtual_machine(client)
        assert _install_client_package(client, pkgs)
        with session:
            # Go to content host's Errata tab and read the page's pagination widgets
            session.organization.select(org_name=org.name)
            page_values = session.contenthost.read(
                client.hostname, widget_names=['errata.pagination'])
            assert int(page_values['errata']['pagination']['per_page']) == 20
            # assert total_pages > 1 with default page settings
            assert int(page_values['errata']['pagination']['pages']) > 1

            view = session.contenthost.navigate_to(session.contenthost,
                                                   'Edit',
                                                   entity_name=client.hostname)
            per_page_value = view.errata.pagination.per_page
            # Change per-page setting to 100 and assert there is now only one page
            assert per_page_value.fill('100')
            page_values = session.contenthost.read(
                client.hostname, widget_names=['errata.pagination'])
            assert int(page_values['errata']['pagination']['per_page']) == 100
            assert int(page_values['errata']['pagination']['pages']) == 1
            # assert at least the 28 errata from fake repo are present
            assert int(
                page_values['errata']['pagination']['total_items']) >= 28

            # install all errata using REX
            status = session.contenthost.install_errata(client.hostname,
                                                        'All',
                                                        install_via='rex')
            # Assert errata are listed on job invocation page
            assert status['overview']['job_status'] == 'Success'
            assert status['overview']['job_status_progress'] == '100%'
            # check that there are no applicable errata left on the CHost's errata page
            page_values = session.contenthost.read(
                client.hostname, widget_names=['errata.pagination'])
            assert int(page_values['errata']['pagination']['total_items']) == 0
Example #20
0
def test_positive_user_access_with_host_filter(test_name, module_loc,
                                               rhel7_contenthost):
    """Check if user with necessary host permissions can access dashboard
    and required widgets are rendered with proper values

    :id: 24b4b371-cba0-4bc8-bc6a-294c62e0586d

    :Steps:

        1. Specify proper filter with permission for your role
        2. Create new user and assign role to it
        3. Login into application using this new user
        4. Check dashboard and widgets on it
        5. Register new content host to populate some values into dashboard widgets

    :expectedresults: Dashboard and Errata Widget rendered without errors and
        contain proper values

    :BZ: 1417114

    :CaseLevel: System
    """
    user_login = gen_string('alpha')
    user_password = gen_string('alphanumeric')
    org = entities.Organization().create()
    lce = entities.LifecycleEnvironment(organization=org).create()
    # create a role with necessary permissions
    role = entities.Role().create()
    user_permissions = {
        'Organization': ['view_organizations'],
        'Location': ['view_locations'],
        None: ['access_dashboard'],
        'Host': ['view_hosts'],
    }
    create_role_permissions(role, user_permissions)
    # create a user and assign the above created role
    entities.User(
        default_organization=org,
        organization=[org],
        default_location=module_loc,
        location=[module_loc],
        role=[role],
        login=user_login,
        password=user_password,
    ).create()
    with Session(test_name, user=user_login,
                 password=user_password) as session:
        assert session.dashboard.read(
            'HostConfigurationStatus')['total_count'] == 0
        assert len(session.dashboard.read('LatestErrata')) == 0
        repos_collection = RepositoryCollection(
            distro=DISTRO_RHEL7,
            repositories=[
                SatelliteToolsRepository(),
                YumRepository(url=FAKE_6_YUM_REPO)
            ],
        )
        repos_collection.setup_content(org.id, lce.id, upload_manifest=True)
        repos_collection.setup_virtual_machine(rhel7_contenthost)
        result = rhel7_contenthost.run(
            f'yum install -y {FAKE_1_CUSTOM_PACKAGE}')
        assert result.status == 0
        hostname = rhel7_contenthost.hostname
        # Check UI for values
        assert session.host.search(hostname)[0]['Name'] == hostname
        hosts_values = session.dashboard.read('HostConfigurationStatus')
        assert hosts_values['total_count'] == 1
        errata_values = session.dashboard.read('LatestErrata')['erratas']
        assert len(errata_values) == 1
        assert errata_values[0]['Type'] == 'security'
        assert FAKE_2_ERRATA_ID in errata_values[0]['Errata']