From d8947e0feae3d85f54f5ed0ee0ef1896a81b1a6a Mon Sep 17 00:00:00 2001 From: Peter Ondrejka Date: Mon, 8 Jan 2024 14:47:44 +0100 Subject: [PATCH] fixing a forgotten make_job_invocaiton call --- tests/foreman/cli/test_remoteexecution.py | 36 +++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/tests/foreman/cli/test_remoteexecution.py b/tests/foreman/cli/test_remoteexecution.py index 688f014eff1..319577f7ca2 100644 --- a/tests/foreman/cli/test_remoteexecution.py +++ b/tests/foreman/cli/test_remoteexecution.py @@ -1036,7 +1036,6 @@ def test_positive_run_job_on_host_registered_to_pull_provider( module_ak_with_cv, module_capsule_configured_mqtt, rhel_contenthost, - target_sat, ): """Run custom template on host registered to mqtt @@ -1080,7 +1079,7 @@ def test_positive_run_job_on_host_registered_to_pull_provider( result = rhel_contenthost.execute('yggdrasil status') assert result.status == 0, f'Failed to start yggdrasil on client: {result.stderr}' # run script provider rex command - invocation_command = target_sat.cli_factory.job_invocation( + invocation_command = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Service Action - Script Default', 'inputs': 'action=status, service=yggdrasild', @@ -1088,5 +1087,36 @@ def test_positive_run_job_on_host_registered_to_pull_provider( } ) assert_job_invocation_result( - target_sat, invocation_command['id'], rhel_contenthost.hostname + module_target_sat, invocation_command['id'], rhel_contenthost.hostname + ) + # create user on host + username = gen_string('alpha') + filename = gen_string('alpha') + make_user_job = module_target_sat.cli_factory.job_invocation( + { + 'job-template': 'Run Command - Script Default', + 'inputs': f"command=useradd -m {username}", + 'search-query': f"name ~ {rhel_contenthost.hostname}", + } + ) + assert_job_invocation_result( + module_target_sat, make_user_job['id'], rhel_contenthost.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}", + 'effective-user': f'{username}', + } + ) + assert_job_invocation_result( + module_target_sat, invocation_command['id'], rhel_contenthost.hostname + ) + # check the file owner + result = rhel_contenthost.execute( + f'''stat -c '%U' /home/{username}/{filename}''', ) + # assert the file is owned by the effective user + assert username == result.stdout.strip('\n')