From 4cfc9d3c89639b331626c121373179779cabf5c0 Mon Sep 17 00:00:00 2001 From: sshmulev Date: Tue, 6 Aug 2024 09:31:29 +0300 Subject: [PATCH 1/7] CIV: Refactor test_yum_group_install https://issues.redhat.com/browse/CLOUDX-837 --- test_suite/cloud/test_aws.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test_suite/cloud/test_aws.py b/test_suite/cloud/test_aws.py index 7487eab5..bda35d6d 100644 --- a/test_suite/cloud/test_aws.py +++ b/test_suite/cloud/test_aws.py @@ -558,12 +558,25 @@ def test_yum_group_install(self, host): pytest.skip('Not applicable to Atomic host AMIs') with host.sudo(): - assert host.run_test('yum -y groupinstall "Development tools"'), \ - 'Error while installing Development tools group' - - package_to_check = 'glibc-devel' - assert host.package(package_to_check).is_installed, \ - f'{package_to_check} is not installed' + attempts = 2 + for attempt in range(attempts): + try: + assert host.run_test('yum -y groupinstall "Development tools"'), \ + 'Error while installing Development tools group' + break + except AssertionError as e: + err_message = "This system is not registered to Red Hat Subscription Management" + if err_message in str(e) and attempt == 0: + host.run( + 'echo -e "enabled=0" > /etc/yum/pluginconf.d/subscription-manager.conf' + ' && yum clean all' + ) + elif attempt == 1: + raise AssertionError('Error while installing Development tools group after retrying') + + package_to_check = 'glibc-devel' + assert host.package(package_to_check).is_installed, \ + f'{package_to_check} is not installed' @pytest.mark.pub @pytest.mark.run_on(['rhel']) From 3be3bf4bdadd123d4b6ed22378b5933f3e589229 Mon Sep 17 00:00:00 2001 From: sshmulev Date: Tue, 6 Aug 2024 11:35:28 +0300 Subject: [PATCH 2/7] Fix for review --- test_suite/cloud/test_aws.py | 44 ++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/test_suite/cloud/test_aws.py b/test_suite/cloud/test_aws.py index bda35d6d..a1340dcd 100644 --- a/test_suite/cloud/test_aws.py +++ b/test_suite/cloud/test_aws.py @@ -558,25 +558,31 @@ def test_yum_group_install(self, host): pytest.skip('Not applicable to Atomic host AMIs') with host.sudo(): - attempts = 2 - for attempt in range(attempts): - try: - assert host.run_test('yum -y groupinstall "Development tools"'), \ - 'Error while installing Development tools group' - break - except AssertionError as e: - err_message = "This system is not registered to Red Hat Subscription Management" - if err_message in str(e) and attempt == 0: - host.run( - 'echo -e "enabled=0" > /etc/yum/pluginconf.d/subscription-manager.conf' - ' && yum clean all' - ) - elif attempt == 1: - raise AssertionError('Error while installing Development tools group after retrying') - - package_to_check = 'glibc-devel' - assert host.package(package_to_check).is_installed, \ - f'{package_to_check} is not installed' + dev_tools_install_command = 'yum -y groupinstall "Development tools"' + result = test_lib.print_host_command_output(host, dev_tools_install_command, capture_result=True) + + if result.failed: + err_message = "This system is not registered to Red Hat Subscription Management" + if err_message in result.stderr: + print('"Development tools" installation attempt failed. Trying to apply a workaround...') + host.run( + 'echo -e "enabled=0" > /etc/yum/pluginconf.d/subscription-manager.conf' + ' && yum clean all' + ) + + result_second_attempt = test_lib.print_host_command_output( + host, dev_tools_install_command, capture_result=True + ) + + assert result_second_attempt.succeeded, ( + 'Error while installing Development tools group after two attempts. ' + 'Check test case output for more details.' + ) + print('"Development tools" installed successfully.') + + package_to_check = 'glibc-devel' + assert host.package(package_to_check).is_installed, \ + f'{package_to_check} is not installed' @pytest.mark.pub @pytest.mark.run_on(['rhel']) From bec272189964ea7cb68520ccd9b63ff3f4f74323 Mon Sep 17 00:00:00 2001 From: sshmulev Date: Wed, 7 Aug 2024 08:48:50 +0300 Subject: [PATCH 3/7] Fix for identaiton --- test_suite/cloud/test_aws.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test_suite/cloud/test_aws.py b/test_suite/cloud/test_aws.py index a1340dcd..4ed2d7fc 100644 --- a/test_suite/cloud/test_aws.py +++ b/test_suite/cloud/test_aws.py @@ -570,15 +570,15 @@ def test_yum_group_install(self, host): ' && yum clean all' ) - result_second_attempt = test_lib.print_host_command_output( - host, dev_tools_install_command, capture_result=True - ) - - assert result_second_attempt.succeeded, ( - 'Error while installing Development tools group after two attempts. ' - 'Check test case output for more details.' - ) - print('"Development tools" installed successfully.') + result_second_attempt = test_lib.print_host_command_output( + host, dev_tools_install_command, capture_result=True + ) + + assert result_second_attempt.succeeded, ( + 'Error while installing Development tools group after two attempts. ' + 'Check test case output for more details.' + ) + print('"Development tools" installed successfully.') package_to_check = 'glibc-devel' assert host.package(package_to_check).is_installed, \ From 2d09e3a4a71076e2e9e823af26c72dbbc05d0022 Mon Sep 17 00:00:00 2001 From: sshmulev Date: Thu, 8 Aug 2024 08:33:59 +0300 Subject: [PATCH 4/7] No capture logs if tests passed. --- test_suite/cloud/test_aws.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test_suite/cloud/test_aws.py b/test_suite/cloud/test_aws.py index 4ed2d7fc..572fef5b 100644 --- a/test_suite/cloud/test_aws.py +++ b/test_suite/cloud/test_aws.py @@ -559,9 +559,10 @@ def test_yum_group_install(self, host): with host.sudo(): dev_tools_install_command = 'yum -y groupinstall "Development tools"' - result = test_lib.print_host_command_output(host, dev_tools_install_command, capture_result=True) + result = host.run(dev_tools_install_command) - if result.failed: + if result.exit_status != 0: + print(f'Command faild with error on first attempt: {result.stderr}') err_message = "This system is not registered to Red Hat Subscription Management" if err_message in result.stderr: print('"Development tools" installation attempt failed. Trying to apply a workaround...') @@ -570,13 +571,9 @@ def test_yum_group_install(self, host): ' && yum clean all' ) - result_second_attempt = test_lib.print_host_command_output( - host, dev_tools_install_command, capture_result=True - ) - - assert result_second_attempt.succeeded, ( - 'Error while installing Development tools group after two attempts. ' - 'Check test case output for more details.' + assert host.run(dev_tools_install_command).succeeded, ( + f'Error while installing Development tools' + f' group after two attempts with error: {result.stderr}' ) print('"Development tools" installed successfully.') From f7f55242e9a08d791bdcf4112e8340fbaf78fff8 Mon Sep 17 00:00:00 2001 From: sshmulev Date: Thu, 8 Aug 2024 08:39:11 +0300 Subject: [PATCH 5/7] Space in line 576 --- test_suite/cloud/test_aws.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_suite/cloud/test_aws.py b/test_suite/cloud/test_aws.py index 572fef5b..443486b5 100644 --- a/test_suite/cloud/test_aws.py +++ b/test_suite/cloud/test_aws.py @@ -572,8 +572,8 @@ def test_yum_group_install(self, host): ) assert host.run(dev_tools_install_command).succeeded, ( - f'Error while installing Development tools' - f' group after two attempts with error: {result.stderr}' + f'Error while installing Development tools ' + f'group after two attempts with error: {result.stderr}' ) print('"Development tools" installed successfully.') From 0419700bbc7d20c658800523e9c287953b46109f Mon Sep 17 00:00:00 2001 From: sshmulev Date: Thu, 8 Aug 2024 08:46:53 +0300 Subject: [PATCH 6/7] Fix for one comment564 --- test_suite/cloud/test_aws.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_suite/cloud/test_aws.py b/test_suite/cloud/test_aws.py index 443486b5..fbe52304 100644 --- a/test_suite/cloud/test_aws.py +++ b/test_suite/cloud/test_aws.py @@ -561,7 +561,7 @@ def test_yum_group_install(self, host): dev_tools_install_command = 'yum -y groupinstall "Development tools"' result = host.run(dev_tools_install_command) - if result.exit_status != 0: + if result.failed: print(f'Command faild with error on first attempt: {result.stderr}') err_message = "This system is not registered to Red Hat Subscription Management" if err_message in result.stderr: From f3a7f0f5f80163b038183d0dfd919e161d87e0dc Mon Sep 17 00:00:00 2001 From: sshmulev Date: Thu, 8 Aug 2024 08:49:41 +0300 Subject: [PATCH 7/7] Fix identaion --- test_suite/cloud/test_aws.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_suite/cloud/test_aws.py b/test_suite/cloud/test_aws.py index fbe52304..38476457 100644 --- a/test_suite/cloud/test_aws.py +++ b/test_suite/cloud/test_aws.py @@ -575,7 +575,7 @@ def test_yum_group_install(self, host): f'Error while installing Development tools ' f'group after two attempts with error: {result.stderr}' ) - print('"Development tools" installed successfully.') + print('"Development tools" installed successfully.') package_to_check = 'glibc-devel' assert host.package(package_to_check).is_installed, \