diff --git a/pytest_fixtures/core/contenthosts.py b/pytest_fixtures/core/contenthosts.py index ed00d741a2f..a73bbccc707 100644 --- a/pytest_fixtures/core/contenthosts.py +++ b/pytest_fixtures/core/contenthosts.py @@ -207,6 +207,20 @@ def katello_host_tools_tracer_host(rex_contenthost, target_sat): return rex_contenthost +@pytest.fixture +def rhel_contenthost_with_repos(request, target_sat): + """Install katello-host-tools-tracer, create custom + repositories on the host""" + with Broker(**host_conf(request), host_class=ContentHost) as host: + # create a custom, rhel version-specific OS repo + rhelver = request.param['rhel_version'] + if rhelver > 7: + host.create_custom_repos(**settings.repos[f'rhel{rhelver}_os']) + else: + host.create_custom_repos(**{f'rhel{rhelver}_os': settings.repos[f'rhel{rhelver}_os']}) + yield host + + @pytest.fixture(scope='module') def module_container_contenthost(request, module_target_sat, module_org, module_activation_key): """Fixture that installs docker on the content host""" diff --git a/pytest_plugins/fixture_markers.py b/pytest_plugins/fixture_markers.py index c2570ec921a..e2098268239 100644 --- a/pytest_plugins/fixture_markers.py +++ b/pytest_plugins/fixture_markers.py @@ -5,6 +5,7 @@ TARGET_FIXTURES = [ 'rhel_contenthost', + 'rhel_contenthost_with_repos', 'module_rhel_contenthost', 'mod_content_hosts', 'content_hosts', diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 39a84585d41..fbe343117ed 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1511,6 +1511,16 @@ def update_host_location(self, location): host.location = location host.update(['location']) + def get_yggdrasil_service_name(self): + return ( + 'yggdrasil' + if ( + self.os_version.major > 9 + or (self.os_version.major == 9 and self.os_version.minor > 5) + ) + else 'yggdrasild' + ) + class Capsule(ContentHost, CapsuleMixins): rex_key_path = '~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub' diff --git a/tests/foreman/api/test_remoteexecution.py b/tests/foreman/api/test_remoteexecution.py index ee90054b140..807b2ad6bbb 100644 --- a/tests/foreman/api/test_remoteexecution.py +++ b/tests/foreman/api/test_remoteexecution.py @@ -40,7 +40,7 @@ def test_positive_find_capsule_upgrade_playbook(target_sat): @pytest.mark.tier3 @pytest.mark.no_containers -@pytest.mark.rhel_ver_list('8') +@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) @pytest.mark.parametrize( 'setting_update', ['remote_execution_global_proxy=False'], @@ -53,7 +53,7 @@ def test_negative_time_to_pickup( smart_proxy_location, module_ak_with_cv, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, setting_update, ): """Time to pickup setting is honored for host registered to mqtt @@ -69,12 +69,13 @@ def test_negative_time_to_pickup( :parametrized: yes """ + client = rhel_contenthost_with_repos client_repo = ohsnap.dogfood_repository( settings.ohsnap, product='client', repo='client', release='client', - os_release=rhel_contenthost.os_version.major, + os_release=client.os_version.major, ) # Update module_capsule_configured_mqtt to include module_org/smart_proxy_location module_target_sat.cli.Capsule.update( @@ -85,7 +86,7 @@ def test_negative_time_to_pickup( } ) # register host with pull provider rex - result = rhel_contenthost.register( + result = client.register( module_org, smart_proxy_location, module_ak_with_cv.name, @@ -100,13 +101,11 @@ def test_negative_time_to_pickup( ) assert result.status == 0, f'Failed to register host: {result.stderr}' # check mqtt client is running - service_name = ( - 'yggdrasil' if float(rhel_contenthost.os_distribution_version) > 9.5 else 'yggdrasild' - ) - result = rhel_contenthost.execute(f'systemctl status {service_name}') + service_name = client.get_yggdrasil_service_name() + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # stop yggdrasil client on host - result = rhel_contenthost.execute(f'systemctl stop {service_name}') + result = client.execute(f'systemctl stop {service_name}') assert result.status == 0, f'Failed to stop yggdrasil on client: {result.stderr}' # run script provider rex command with time_to_pickup @@ -120,7 +119,7 @@ def test_negative_time_to_pickup( 'command': 'ls -la', }, 'targeting_type': 'static_query', - 'search_query': f'name = {rhel_contenthost.hostname}', + 'search_query': f'name = {client.hostname}', 'time_to_pickup': '10', }, ) @@ -151,7 +150,7 @@ def test_negative_time_to_pickup( 'command': 'ls -la', }, 'targeting_type': 'static_query', - 'search_query': f'name = {rhel_contenthost.hostname}', + 'search_query': f'name = {client.hostname}', }, ) module_target_sat.wait_for_tasks( @@ -166,15 +165,15 @@ def test_negative_time_to_pickup( global_ttp.value = default_global_ttp global_ttp.update(['value']) # start yggdrasil client on host - result = rhel_contenthost.execute(f'systemctl start {service_name}') + result = client.execute(f'systemctl start {service_name}') assert result.status == 0, f'Failed to start on client: {result.stderr}' - result = rhel_contenthost.execute(f'systemctl status {service_name}') + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' @pytest.mark.tier3 @pytest.mark.no_containers -@pytest.mark.rhel_ver_list('8') +@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) @pytest.mark.parametrize( 'setting_update', ['remote_execution_global_proxy=False'], @@ -187,7 +186,7 @@ def test_positive_check_longrunning_job( smart_proxy_location, module_ak_with_cv, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, setting_update, ): """Time to pickup setting doesn't disrupt longrunning jobs @@ -203,13 +202,13 @@ def test_positive_check_longrunning_job( :parametrized: yes """ - + client = rhel_contenthost_with_repos client_repo = ohsnap.dogfood_repository( settings.ohsnap, product='client', repo='client', release='client', - os_release=rhel_contenthost.os_version.major, + os_release=client.os_version.major, ) # Update module_capsule_configured_mqtt to include module_org/smart_proxy_location module_target_sat.cli.Capsule.update( @@ -220,7 +219,7 @@ def test_positive_check_longrunning_job( } ) # register host with pull provider rex - result = rhel_contenthost.register( + result = client.register( module_org, smart_proxy_location, module_ak_with_cv.name, @@ -244,7 +243,7 @@ def test_positive_check_longrunning_job( 'command': 'echo start; sleep 25; echo done', }, 'targeting_type': 'static_query', - 'search_query': f'name = {rhel_contenthost.hostname}', + 'search_query': f'name = {client.hostname}', 'time_to_pickup': '20', }, ) diff --git a/tests/foreman/cli/test_leapp_client.py b/tests/foreman/cli/test_leapp_client.py index 26da70cdad1..05bbede92f9 100644 --- a/tests/foreman/cli/test_leapp_client.py +++ b/tests/foreman/cli/test_leapp_client.py @@ -20,17 +20,6 @@ from robottelo.utils import ohsnap -def get_yggdrasil_service_name(rhel_contenthost): - return ( - 'yggdrasil' - if ( - rhel_contenthost.os_version.major > 9 - or (rhel_contenthost.os_version.major == 9 and rhel_contenthost.os_version.minor > 5) - ) - else 'yggdrasild' - ) - - @pytest.mark.e2e @pytest.mark.parametrize( 'upgrade_path', @@ -216,7 +205,7 @@ def test_positive_ygdrassil_client_after_leapp_upgrade( ) assert result.status == 0, f'Failed to register host: {result.stderr}' - service_name = get_yggdrasil_service_name(custom_leapp_host) + service_name = custom_leapp_host.get_yggdrasil_service_name() result = custom_leapp_host.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' @@ -262,7 +251,7 @@ def test_positive_ygdrassil_client_after_leapp_upgrade( assert str(custom_leapp_host.os_version) == upgrade_path['target_version'] # check mqtt still works after upgrade - service_name = get_yggdrasil_service_name(custom_leapp_host) + service_name = custom_leapp_host.get_yggdrasil_service_name() result = custom_leapp_host.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' diff --git a/tests/foreman/cli/test_remoteexecution.py b/tests/foreman/cli/test_remoteexecution.py index 4ef1c4370b0..d930d3ad8b2 100644 --- a/tests/foreman/cli/test_remoteexecution.py +++ b/tests/foreman/cli/test_remoteexecution.py @@ -88,17 +88,13 @@ def assert_job_invocation_status(sat, invocation_command_id, client_hostname, st ) from err -def get_yggdrasil_service_name(rhel_contenthost): - return 'yggdrasil' if float(rhel_contenthost.os_distribution_version) > 9.5 else 'yggdrasild' - - class TestRemoteExecution: """Implements job execution tests in CLI.""" @pytest.mark.tier3 @pytest.mark.pit_client @pytest.mark.pit_server - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_run_default_job_template( self, module_org, rex_contenthost, module_target_sat ): @@ -139,7 +135,7 @@ def test_positive_run_default_job_template( assert 'Internal Server Error' not in out @pytest.mark.tier3 - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_negative_run_default_job_template( self, module_org, rex_contenthost, module_target_sat ): @@ -182,7 +178,7 @@ def test_negative_run_default_job_template( assert 'Exit status: 23' in out @pytest.mark.tier3 - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_timeout_to_kill(self, module_org, rex_contenthost, module_target_sat): """Use timeout to kill setting to cancel the job @@ -553,7 +549,7 @@ def test_positive_run_custom_job_template(self, rex_contenthost, module_org, tar @pytest.mark.tier3 @pytest.mark.upgrade - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_run_default_job_template_multiple_hosts( self, rex_contenthosts, module_target_sat ): @@ -591,7 +587,7 @@ def test_positive_run_default_job_template_multiple_hosts( @pytest.mark.tier3 @pytest.mark.no_containers - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) @pytest.mark.skipif( (not settings.robottelo.repos_hosting_url), reason='Missing repos_hosting_url' ) @@ -655,7 +651,7 @@ def test_positive_install_remove_multiple_packages_with_a_job( @pytest.mark.tier3 @pytest.mark.no_containers - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) @pytest.mark.skipif( (not settings.robottelo.repos_hosting_url), reason='Missing repos_hosting_url' ) @@ -706,7 +702,7 @@ def test_positive_install_remove_packagegroup_with_a_job( @pytest.mark.tier3 @pytest.mark.no_containers - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) @pytest.mark.skipif( (not settings.robottelo.repos_hosting_url), reason='Missing repos_hosting_url' ) @@ -757,7 +753,7 @@ def test_positive_match_feature_templates(self, target_sat, feature): assert result['job-template-name'] == feature['jt_name'] @pytest.mark.tier3 - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_run_recurring_job_with_max_iterations(self, rex_contenthost, target_sat): """Run default job template multiple times with max iteration @@ -788,7 +784,7 @@ def test_positive_run_recurring_job_with_max_iterations(self, rex_contenthost, t assert rec_logic['iteration'] == '2' @pytest.mark.tier3 - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_time_expressions(self, rex_contenthost, target_sat): """Test various expressions for extended cronline syntax @@ -855,7 +851,7 @@ def test_positive_time_expressions(self, rex_contenthost, target_sat): ) @pytest.mark.tier3 - @pytest.mark.rhel_ver_list([9]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_run_scheduled_job_template(self, rex_contenthost, target_sat): """Schedule a job to be ran against a host @@ -997,7 +993,7 @@ def class_rexinfra_user(self, module_org, default_location, class_target_sat): ids=['satellite', 'capsule'], indirect=True, ) - @pytest.mark.rhel_ver_list([8]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) @pytest.mark.no_containers def test_positive_rex_against_infra_hosts( self, @@ -1099,7 +1095,6 @@ class TestAsyncSSHProviderRex: @pytest.mark.tier3 @pytest.mark.e2e @pytest.mark.upgrade - @pytest.mark.rhel_ver_match('[^6].*') def test_positive_run_job_on_host_registered_to_async_ssh_provider( self, module_org, @@ -1159,7 +1154,6 @@ class TestPullProviderRex: @pytest.mark.tier3 @pytest.mark.upgrade @pytest.mark.no_containers - @pytest.mark.rhel_ver_match('[^6].*') @pytest.mark.parametrize( 'setting_update', ['remote_execution_global_proxy=False'], @@ -1173,7 +1167,7 @@ def test_positive_run_job_on_host_converted_to_pull_provider( module_ak_with_cv, module_target_sat, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, setting_update, ): """Run custom template on host converted to mqtt @@ -1186,12 +1180,13 @@ def test_positive_run_job_on_host_converted_to_pull_provider( :parametrized: yes """ + client = rhel_contenthost_with_repos client_repo = ohsnap.dogfood_repository( settings.ohsnap, product='client', repo='client', release='client', - os_release=rhel_contenthost.os_version.major, + os_release=client.os_version.major, ) # Update module_capsule_configured_mqtt to include module_org/smart_proxy_location module_target_sat.cli.Capsule.update( @@ -1202,7 +1197,7 @@ def test_positive_run_job_on_host_converted_to_pull_provider( } ) # register host with rex, enable client repo, install katello-agent - result = rhel_contenthost.register( + result = client.register( module_org, smart_proxy_location, module_ak_with_cv.name, @@ -1214,54 +1209,47 @@ def test_positive_run_job_on_host_converted_to_pull_provider( ) assert result.status == 0, f'Failed to register host: {result.stderr}' - service_name = get_yggdrasil_service_name(rhel_contenthost) + service_name = client.get_yggdrasil_service_name() # install conversion script (SAT-1670) - result = rhel_contenthost.execute('yum install -y katello-pull-transport-migrate') + result = client.execute('yum install -y katello-pull-transport-migrate') assert result.status == 0, 'Failed to install katello-pull-transport-migrate' # check mqtt client is running - result = rhel_contenthost.execute(f'systemctl status {service_name}') + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # run script provider rex command invocation_command = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Run Command - Script Default', 'inputs': 'command=ls', - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", } ) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) # run Ansible rex command to prove ssh provider works, remove katello-agent invocation_command = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Remove Package - Katello Script Default', 'inputs': 'package=katello-agent', - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", } ) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) # check katello-agent removal did not influence ygdrassil (SAT-1672) - result = rhel_contenthost.execute(f'systemctl status {service_name}') + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' invocation_command = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Run Command - Script Default', 'inputs': 'command=ls', - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", } ) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) result = module_target_sat.cli.JobInvocation.info({'id': invocation_command['id']}) @pytest.mark.tier3 @pytest.mark.no_containers - @pytest.mark.rhel_ver_match('[^6].*') @pytest.mark.parametrize( 'setting_update', ['remote_execution_global_proxy=False'], @@ -1275,7 +1263,7 @@ def test_positive_run_job_in_chosen_directory( smart_proxy_location, module_ak_with_cv, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, setting_update, ): """Run job on host registered to mqtt, check it honors run directory @@ -1288,12 +1276,13 @@ def test_positive_run_job_in_chosen_directory( :parametrized: yes """ + client = rhel_contenthost_with_repos client_repo = ohsnap.dogfood_repository( settings.ohsnap, product='client', repo='client', release='client', - os_release=rhel_contenthost.os_version.major, + os_release=client.os_version.major, ) # Update module_capsule_configured_mqtt to include module_org/smart_proxy_location module_target_sat.cli.Capsule.update( @@ -1304,7 +1293,7 @@ def test_positive_run_job_in_chosen_directory( } ) # register host with pull provider rex - result = rhel_contenthost.register( + result = client.register( module_org, smart_proxy_location, module_ak_with_cv.name, @@ -1317,8 +1306,8 @@ def test_positive_run_job_in_chosen_directory( assert result.status == 0, f'Failed to register host: {result.stderr}' # check mqtt client is running - service_name = get_yggdrasil_service_name(rhel_contenthost) - result = rhel_contenthost.execute(f'systemctl status {service_name}') + service_name = client.get_yggdrasil_service_name() + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # create a new directory and set in in yggdrasil @@ -1326,7 +1315,7 @@ def test_positive_run_job_in_chosen_directory( config_path_dir = f'/etc/systemd/system/{service_name}.service.d/' config_path = f'{config_path_dir}/override.conf' assert ( - rhel_contenthost.execute( + client.execute( f'mkdir {path} && mount -t tmpfs tmpfs {path} && mkdir {config_path_dir} && echo -e "[Service]\nEnvironment=FOREMAN_YGG_WORKER_WORKDIR={path}" > {config_path} && systemctl daemon-reload && systemctl restart {service_name}' ).status == 0 @@ -1337,21 +1326,19 @@ def test_positive_run_job_in_chosen_directory( { 'job-template': 'Run Command - Script Default', 'inputs': 'command=printenv', - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", } ) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) assert ( f'FOREMAN_YGG_WORKER_WORKDIR={path}' in module_target_sat.cli.JobInvocation.get_output( - {'id': invocation_command['id'], 'host': rhel_contenthost.hostname} + {'id': invocation_command['id'], 'host': client.hostname} ) ) # remount the directory as noexec - rhel_contenthost.execute(f'mount -o remount,noexec {path}') + client.execute(f'mount -o remount,noexec {path}') # run rex command in the created directory again; # it should fail; if it does not, it is probably not being run in that directory @@ -1360,7 +1347,7 @@ def test_positive_run_job_in_chosen_directory( { 'job-template': 'Run Command - Script Default', 'inputs': 'command=printenv', - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", } ) @@ -1369,7 +1356,6 @@ def test_positive_run_job_in_chosen_directory( @pytest.mark.e2e @pytest.mark.pit_client @pytest.mark.no_containers - @pytest.mark.rhel_ver_match('[^6].*') @pytest.mark.parametrize( 'setting_update', ['remote_execution_global_proxy=False'], @@ -1383,7 +1369,7 @@ def test_positive_run_job_on_host_registered_to_pull_provider( smart_proxy_location, module_ak_with_cv, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, setting_update, ): """Run custom template on host registered to mqtt, check effective user setting @@ -1399,12 +1385,13 @@ def test_positive_run_job_on_host_registered_to_pull_provider( :parametrized: yes """ + client = rhel_contenthost_with_repos client_repo = ohsnap.dogfood_repository( settings.ohsnap, product='client', repo='client', release='client', - os_release=rhel_contenthost.os_version.major, + os_release=client.os_version.major, ) # Update module_capsule_configured_mqtt to include module_org/smart_proxy_location module_target_sat.cli.Capsule.update( @@ -1415,7 +1402,7 @@ def test_positive_run_job_on_host_registered_to_pull_provider( } ) # register host with pull provider rex (SAT-1677) - result = rhel_contenthost.register( + result = client.register( module_org, smart_proxy_location, module_ak_with_cv.name, @@ -1428,20 +1415,18 @@ def test_positive_run_job_on_host_registered_to_pull_provider( assert result.status == 0, f'Failed to register host: {result.stderr}' # check mqtt client is running - service_name = get_yggdrasil_service_name(rhel_contenthost) - result = rhel_contenthost.execute(f'systemctl status {service_name}') + service_name = client.get_yggdrasil_service_name() + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # run script provider rex command invocation_command = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Service Action - Script Default', 'inputs': f'action=status, service={service_name}', - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", } ) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) # create user on host username = gen_string('alpha') filename = gen_string('alpha') @@ -1449,26 +1434,22 @@ def test_positive_run_job_on_host_registered_to_pull_provider( { 'job-template': 'Run Command - Script Default', 'inputs': f"command=useradd -m {username}", - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", } ) - assert_job_invocation_result( - module_target_sat, make_user_job['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, make_user_job['id'], client.hostname) # create a file as new user invocation_command = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Run Command - Script Default', 'inputs': f"command=touch /home/{username}/{filename}", - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", 'effective-user': f'{username}', } ) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) # check the file owner - result = rhel_contenthost.execute( + result = client.execute( f'''stat -c '%U' /home/{username}/{filename}''', ) # assert the file is owned by the effective user @@ -1481,7 +1462,7 @@ def test_positive_run_job_on_host_registered_to_pull_provider( { 'job-template': 'Run Command - Script Default', 'inputs': f"command={command}", - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", 'effective-user': f'{username}', } ) @@ -1497,7 +1478,7 @@ def test_positive_run_job_on_host_registered_to_pull_provider( out = module_target_sat.cli.JobInvocation.get_output( { 'id': job_id, - 'host': rhel_contenthost.hostname, + 'host': client.hostname, 'organization-id': module_org.id, } ) @@ -1506,7 +1487,6 @@ def test_positive_run_job_on_host_registered_to_pull_provider( @pytest.mark.tier3 @pytest.mark.upgrade @pytest.mark.no_containers - @pytest.mark.rhel_ver_match('[^6].*') def test_positive_run_pull_job_on_offline_host( self, module_org, @@ -1514,7 +1494,7 @@ def test_positive_run_pull_job_on_offline_host( smart_proxy_location, module_ak_with_cv, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, ): """Run pull-mqtt job against offline host @@ -1526,12 +1506,13 @@ def test_positive_run_pull_job_on_offline_host( :parametrized: yes """ + client = rhel_contenthost_with_repos client_repo = ohsnap.dogfood_repository( settings.ohsnap, product='client', repo='client', release='client', - os_release=rhel_contenthost.os_version.major, + os_release=client.os_version.major, ) # Update module_capsule_configured_mqtt to include module_org/smart_proxy_location module_target_sat.cli.Capsule.update( @@ -1541,7 +1522,7 @@ def test_positive_run_pull_job_on_offline_host( 'location-ids': smart_proxy_location.id, } ) - result = rhel_contenthost.register( + result = client.register( module_org, smart_proxy_location, module_ak_with_cv.name, @@ -1554,38 +1535,36 @@ def test_positive_run_pull_job_on_offline_host( assert result.status == 0, f'Failed to register host: {result.stderr}' # check mqtt client is running - service_name = get_yggdrasil_service_name(rhel_contenthost) - result = rhel_contenthost.execute(f'systemctl status {service_name}') + service_name = client.get_yggdrasil_service_name() + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # stop the client on host - result = rhel_contenthost.execute(f'systemctl stop {service_name}') + result = client.execute(f'systemctl stop {service_name}') assert result.status == 0, f'Failed to stop yggdrasil on client: {result.stderr}' # run script provider rex command invocation_command = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Run Command - Script Default', 'inputs': 'command=ls', - 'search-query': f'name ~ {rhel_contenthost.hostname}', + 'search-query': f'name ~ {client.hostname}', 'async': True, } ) # assert the job is waiting to be picked up by client assert_job_invocation_status( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname, 'running' + module_target_sat, invocation_command['id'], client.hostname, 'running' ) # start client on host - result = rhel_contenthost.execute(f'systemctl start {service_name}') + result = client.execute(f'systemctl start {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # wait twice the mqtt_resend_interval (set in module_capsule_configured_mqtt) sleep(60) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) @pytest.mark.tier3 @pytest.mark.e2e @pytest.mark.no_containers - @pytest.mark.rhel_ver_match('8') + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) @pytest.mark.parametrize( 'setting_update', ['remote_execution_global_proxy=False'], @@ -1599,7 +1578,7 @@ def test_positive_apply_errata_on_pull_provider_host( smart_proxy_location, module_ak_with_cv, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, setting_update, ): """Apply errata on host registered to mqtt @@ -1616,12 +1595,13 @@ def test_positive_apply_errata_on_pull_provider_host( :parametrized: yes """ + client = rhel_contenthost_with_repos client_repo = ohsnap.dogfood_repository( settings.ohsnap, product='client', repo='client', release='client', - os_release=rhel_contenthost.os_version.major, + os_release=client.os_version.major, ) # Update module_capsule_configured_mqtt to include module_org/smart_proxy_location module_target_sat.cli.Capsule.update( @@ -1632,7 +1612,7 @@ def test_positive_apply_errata_on_pull_provider_host( } ) # register host with pull provider rex (SAT-1677) - result = rhel_contenthost.register( + result = client.register( module_org, smart_proxy_location, module_ak_with_cv.name, @@ -1645,22 +1625,20 @@ def test_positive_apply_errata_on_pull_provider_host( assert result.status == 0, f'Failed to register host: {result.stderr}' # check mqtt client is running - service_name = get_yggdrasil_service_name(rhel_contenthost) - result = rhel_contenthost.execute(f'systemctl status {service_name}') + service_name = client.get_yggdrasil_service_name() + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # enable repo, install old pkg - rhel_contenthost.execute(f'yum-config-manager --add-repo {settings.repos.yum_6.url}') - rhel_contenthost.execute(f'yum install {FAKE_4_CUSTOM_PACKAGE} -y') + client.execute(f'yum-config-manager --add-repo {settings.repos.yum_6.url}') + client.execute(f'yum install {FAKE_4_CUSTOM_PACKAGE} -y') # run script provider rex command to apply errata invocation_command = module_target_sat.cli_factory.job_invocation( { 'feature': 'katello_errata_install', - 'search-query': f"name ~ {rhel_contenthost.hostname}", + 'search-query': f"name ~ {client.hostname}", 'inputs': f'errata={settings.repos.yum_6.errata[0]}', 'organization-id': f'{module_org.id}', } ) - assert_job_invocation_result( - module_target_sat, invocation_command['id'], rhel_contenthost.hostname - ) + assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) diff --git a/tests/foreman/destructive/test_registration.py b/tests/foreman/destructive/test_registration.py index 4e0149b1e15..fc4b7520d9e 100644 --- a/tests/foreman/destructive/test_registration.py +++ b/tests/foreman/destructive/test_registration.py @@ -28,7 +28,7 @@ def test_host_registration_rex_pull_mode( module_location, module_ak_with_cv, module_capsule_configured_mqtt, - rhel_contenthost, + rhel_contenthost_with_repos, ): """Verify content host registration with Satellite/Capsule as MQTT broker @@ -38,10 +38,11 @@ def test_host_registration_rex_pull_mode( :parametrized: yes """ + client = rhel_contenthost_with_repos org = module_org - client_repo = settings.repos.SATCLIENT_REPO[f'rhel{rhel_contenthost.os_version.major}'] + client_repo = settings.repos.SATCLIENT_REPO[f'rhel{client.os_version.major}'] # register host to satellite with pull provider rex - result = rhel_contenthost.api_register( + result = client.api_register( module_satellite_mqtt, organization=org, location=module_location, @@ -52,13 +53,12 @@ def test_host_registration_rex_pull_mode( assert result.status == 0, f'Failed to register host: {result.stderr}' # check mqtt client is running - service_name = ( - 'yggdrasil' if float(rhel_contenthost.os_distribution_version) > 9.5 else 'yggdrasild' - ) - result = rhel_contenthost.execute(f'systemctl status {service_name}') + + service_name = client.get_yggdrasil_service_name() + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' mqtt_url = f'mqtts://{module_satellite_mqtt.hostname}:1883' - assert rhel_contenthost.execute(f'cat /etc/yggdrasil/config.toml | grep {mqtt_url}').status == 0 + assert client.execute(f'cat /etc/yggdrasil/config.toml | grep {mqtt_url}').status == 0 # Update module_capsule_configured_mqtt to include module_org/module_location nc = module_capsule_configured_mqtt.nailgun_smart_proxy @@ -66,7 +66,7 @@ def test_host_registration_rex_pull_mode( module_satellite_mqtt.api.SmartProxy(id=nc.id, location=[module_location]).update(['location']) # register host to capsule with pull provider rex - result = rhel_contenthost.api_register( + result = client.api_register( module_satellite_mqtt, smart_proxy=nc, organization=org, @@ -79,15 +79,9 @@ def test_host_registration_rex_pull_mode( assert result.status == 0, f'Failed to register host: {result.stderr}' # check mqtt client is running - result = rhel_contenthost.execute(f'systemctl status {service_name}') + result = client.execute(f'systemctl status {service_name}') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' new_mqtt_url = f'mqtts://{module_capsule_configured_mqtt.hostname}:1883' - assert ( - rhel_contenthost.execute(f'cat /etc/yggdrasil/config.toml | grep {new_mqtt_url}').status - == 0 - ) + assert client.execute(f'cat /etc/yggdrasil/config.toml | grep {new_mqtt_url}').status == 0 # After force register existing config.toml is saved as backup - assert ( - rhel_contenthost.execute(f'cat /etc/yggdrasil/config.toml.bak | grep {mqtt_url}').status - == 0 - ) + assert client.execute(f'cat /etc/yggdrasil/config.toml.bak | grep {mqtt_url}').status == 0