diff --git a/robottelo/constants/__init__.py b/robottelo/constants/__init__.py index afde9b4340d..5be876bc35d 100644 --- a/robottelo/constants/__init__.py +++ b/robottelo/constants/__init__.py @@ -1538,8 +1538,6 @@ class Colored(Box): 'mail': 'mail', } -OSCAP_TARGET_CORES = 4 -OSCAP_TARGET_MEMORY = '16GiB' OSCAP_PERIOD = {'weekly': 'Weekly', 'monthly': 'Monthly', 'custom': 'Custom'} OSCAP_TAILORING_FILE = 'ssg-rhel7-ds-tailoring.xml' diff --git a/robottelo/hosts.py b/robottelo/hosts.py index dc9e4a73d4c..7a72e3bc403 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -682,8 +682,8 @@ def register( using a global registration template. :param target: Satellite or Capusle object to register to, required. - :param org: Organization to register content host for, required. - :param loc: Location to register content host for, required. + :param org: Organization to register content host to. Previously required, pass None to omit + :param loc: Location to register content host for, Previously required, pass None to omit. :param activation_keys: Activation key name to register content host with, required. :param setup_insights: Install and register Insights client, requires OS repo. :param setup_remote_execution: Copy remote execution SSH key. @@ -703,11 +703,25 @@ def register( """ options = { 'activation-keys': activation_keys, - 'organization-id': org.id, - 'location-id': loc.id, 'insecure': str(insecure).lower(), 'update-packages': str(update_packages).lower(), } + if org is not None: + if isinstance(org, entities.Organization): + options['organization-id'] = org.id + elif isinstance(org, dict): + options['organization-id'] = org['id'] + else: + raise ValueError('org must be a dict or an Organization object') + + if loc is not None: + if isinstance(loc, entities.Location): + options['location-id'] = loc.id + elif isinstance(loc, dict): + options['location-id'] = loc['id'] + else: + raise ValueError('loc must be a dict or a Location object') + if target.__class__.__name__ == 'Capsule': options['smart-proxy'] = target.hostname elif target is not None and target.__class__.__name__ not in ['Capsule', 'Satellite']: diff --git a/tests/foreman/longrun/test_oscap.py b/tests/foreman/longrun/test_oscap.py index def5d9873a0..8f187c06487 100644 --- a/tests/foreman/longrun/test_oscap.py +++ b/tests/foreman/longrun/test_oscap.py @@ -21,7 +21,6 @@ from fauxfactory import gen_string from nailgun import entities -from robottelo.api.utils import wait_for_tasks from robottelo.cli.ansible import Ansible from robottelo.cli.arfreport import Arfreport from robottelo.cli.factory import make_hostgroup @@ -34,8 +33,6 @@ from robottelo.constants import OSCAP_DEFAULT_CONTENT from robottelo.constants import OSCAP_PERIOD from robottelo.constants import OSCAP_PROFILE -from robottelo.constants import OSCAP_TARGET_CORES -from robottelo.constants import OSCAP_TARGET_MEMORY from robottelo.constants import OSCAP_WEEKDAY from robottelo.exceptions import ProxyError from robottelo.hosts import ContentHost @@ -123,22 +120,23 @@ def activation_key(module_target_sat, module_org, lifecycle_env, content_view): @pytest.fixture(scope='module', autouse=True) -def update_scap_content(module_org): +def update_scap_content(module_org, module_target_sat): """Update default scap contents""" for content in rhel8_content, rhel7_content, rhel6_content: - content = Scapcontent.info({'title': content}, output_format='json') + content = module_target_sat.cli.Scapcontent.info({'title': content}, output_format='json') organization_ids = [content_org['id'] for content_org in content.get('organizations', [])] organization_ids.append(module_org.id) - Scapcontent.update({'title': content['title'], 'organization-ids': organization_ids}) + module_target_sat.cli.Scapcontent.update( + {'title': content['title'], 'organization-ids': organization_ids} + ) -@pytest.mark.skip_if_open('BZ:2211437') @pytest.mark.e2e @pytest.mark.upgrade @pytest.mark.tier4 @pytest.mark.parametrize('distro', ['rhel7', 'rhel8']) def test_positive_oscap_run_via_ansible( - module_org, default_proxy, content_view, lifecycle_env, distro, target_sat + module_org, module_location, default_proxy, content_view, lifecycle_env, distro, target_sat ): """End-to-End Oscap run via ansible @@ -153,7 +151,7 @@ def test_positive_oscap_run_via_ansible( 1. Create a valid scap content 2. Import Ansible role theforeman.foreman_scap_client 3. Import Ansible Variables needed for the role - 4. Create a scap policy with anisble as deploy option + 4. Create a scap policy with ansible as deploy option 5. Associate the policy with a hostgroup 6. Provision a host using the hostgroup 7. Configure REX and associate the Ansible role to created host @@ -199,29 +197,13 @@ def test_positive_oscap_run_via_ansible( 'organizations': module_org.name, } ) - with Broker( - nick=distro, - host_class=ContentHost, - target_cores=OSCAP_TARGET_CORES, - target_memory=OSCAP_TARGET_MEMORY, - ) as vm: - host_name, _, host_domain = vm.hostname.partition('.') - vm.install_katello_ca(target_sat) - vm.register_contenthost(module_org.name, ak_name[distro]) - assert vm.subscribed - Host.set_parameter( - { - 'host': vm.hostname.lower(), - 'name': 'remote_execution_connect_by_ip', - 'value': 'True', - 'parameter-type': 'boolean', - } - ) + with Broker(nick=distro, host_class=ContentHost, deploy_flavor=settings.flavors.default) as vm: if distro not in ('rhel7'): vm.create_custom_repos(**rhel_repo) else: vm.create_custom_repos(**{distro: rhel_repo}) - vm.add_rex_key(satellite=target_sat) + result = vm.register(module_org, module_location, ak_name[distro], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' Host.update( { 'name': vm.hostname.lower(), @@ -234,7 +216,7 @@ def test_positive_oscap_run_via_ansible( } ) job_id = Host.ansible_roles_play({'name': vm.hostname.lower()})[0].get('id') - wait_for_tasks( + target_sat.wait_for_tasks( f'resource_type = JobInvocation and resource_id = {job_id} and action ~ "hosts job"' ) try: @@ -255,10 +237,9 @@ def test_positive_oscap_run_via_ansible( assert result is not None -@pytest.mark.skip_if_open('BZ:2211437') @pytest.mark.tier4 def test_positive_oscap_run_via_ansible_bz_1814988( - module_org, default_proxy, content_view, lifecycle_env, target_sat + module_org, module_location, default_proxy, content_view, lifecycle_env, target_sat ): """End-to-End Oscap run via ansible @@ -275,7 +256,7 @@ def test_positive_oscap_run_via_ansible_bz_1814988( 1. Create a valid scap content 2. Import Ansible role theforeman.foreman_scap_client 3. Import Ansible Variables needed for the role - 4. Create a scap policy with anisble as deploy option + 4. Create a scap policy with ansible as deploy option 5. Associate the policy with a hostgroup 6. Provision a host using the hostgroup 7. Harden the host by remediating it with DISA STIG security policy @@ -315,25 +296,10 @@ def test_positive_oscap_run_via_ansible_bz_1814988( 'organizations': module_org.name, } ) - with Broker( - nick='rhel7', - host_class=ContentHost, - target_cores=OSCAP_TARGET_CORES, - target_memory=OSCAP_TARGET_MEMORY, - ) as vm: - host_name, _, host_domain = vm.hostname.partition('.') - vm.install_katello_ca(target_sat) - vm.register_contenthost(module_org.name, ak_name['rhel7']) - assert vm.subscribed - Host.set_parameter( - { - 'host': vm.hostname.lower(), - 'name': 'remote_execution_connect_by_ip', - 'value': 'True', - 'parameter-type': 'boolean', - } - ) + with Broker(nick='rhel7', host_class=ContentHost, deploy_flavor=settings.flavors.default) as vm: vm.create_custom_repos(rhel7=settings.repos.rhel7_os) + result = vm.register(module_org, module_location, ak_name['rhel7'], target_sat) + assert result.status == 0, f'Failed to register host: {result.stderr}' # Harden the rhel7 client with DISA STIG security policy vm.run('yum install -y scap-security-guide') vm.run( @@ -341,7 +307,6 @@ def test_positive_oscap_run_via_ansible_bz_1814988( '--fetch-remote-resources --results-arf results.xml ' '/usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml', ) - vm.add_rex_key(satellite=target_sat) Host.update( { 'name': vm.hostname.lower(), @@ -354,7 +319,7 @@ def test_positive_oscap_run_via_ansible_bz_1814988( } ) job_id = Host.ansible_roles_play({'name': vm.hostname.lower()})[0].get('id') - wait_for_tasks( + target_sat.wait_for_tasks( f'resource_type = JobInvocation and resource_id = {job_id} and action ~ "hosts job"' ) try: