diff --git a/pytest_fixtures/core/contenthosts.py b/pytest_fixtures/core/contenthosts.py index b7742fdcd3b..5100bd36868 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 2c7ae61c45d..ffc12d8924d 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1534,6 +1534,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 d5d1b2b0187..21d6a721a52 100644 --- a/tests/foreman/api/test_remoteexecution.py +++ b/tests/foreman/api/test_remoteexecution.py @@ -82,7 +82,7 @@ def test_positive_run_capsule_update_playbook(module_capsule_configured, target_ @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'], @@ -95,7 +95,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 @@ -111,12 +111,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( @@ -127,7 +128,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, @@ -142,13 +143,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 @@ -162,7 +161,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', }, ) @@ -193,7 +192,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( @@ -208,15 +207,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'], @@ -229,7 +228,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 @@ -245,13 +244,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( @@ -262,7 +261,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, @@ -286,7 +285,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 20d545b250d..5718324b451 100644 --- a/tests/foreman/cli/test_remoteexecution.py +++ b/tests/foreman/cli/test_remoteexecution.py @@ -89,17 +89,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 ): @@ -140,7 +136,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 ): @@ -183,7 +179,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 @@ -360,7 +356,7 @@ def test_positive_run_job_effective_user( ids=["global-param-sudo"], indirect=True, ) - @pytest.mark.rhel_ver_list([9]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_run_job_ssh_user_from_global_param( self, rex_contenthost, @@ -459,7 +455,7 @@ def test_positive_run_job_ssh_user_from_global_param( ids=["settings"], indirect=True, ) - @pytest.mark.rhel_ver_list([9]) + @pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) def test_positive_run_job_effective_user_from_settings( self, rex_contenthost, @@ -570,7 +566,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 ): @@ -608,7 +604,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' ) @@ -672,7 +668,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' ) @@ -723,7 +719,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' ) @@ -774,7 +770,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 @@ -805,7 +801,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 @@ -884,7 +880,7 @@ def test_positive_time_expressions(self, rex_contenthost, target_sat): ) @pytest.mark.tier3 - @pytest.mark.rhel_ver_list([8]) + @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 @@ -1029,7 +1025,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, @@ -1131,7 +1127,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, @@ -1191,7 +1186,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'], @@ -1205,7 +1199,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 @@ -1218,12 +1212,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( @@ -1234,7 +1229,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, @@ -1246,54 +1241,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'], @@ -1307,7 +1295,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 @@ -1320,12 +1308,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( @@ -1336,7 +1325,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, @@ -1349,8 +1338,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 @@ -1358,7 +1347,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 @@ -1369,21 +1358,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 @@ -1392,7 +1379,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}", } ) @@ -1401,7 +1388,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'], @@ -1415,7 +1401,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 @@ -1431,12 +1417,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( @@ -1447,7 +1434,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, @@ -1460,20 +1447,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') @@ -1481,26 +1466,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 @@ -1513,7 +1494,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}', } ) @@ -1529,7 +1510,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, } ) @@ -1538,7 +1519,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, @@ -1546,7 +1526,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 @@ -1558,12 +1538,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( @@ -1573,7 +1554,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, @@ -1586,38 +1567,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'], @@ -1631,7 +1610,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 @@ -1648,12 +1627,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( @@ -1664,7 +1644,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, @@ -1677,22 +1657,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