From 5d4202dfc428c81fb161084c21c1cb98b772da16 Mon Sep 17 00:00:00 2001 From: Sam Bible Date: Tue, 18 Jun 2024 12:20:28 -0500 Subject: [PATCH 1/5] Update API test to use refresh-all and add CLI test for bulk --- robottelo/cli/acs.py | 28 ++++++++++++++++++++- tests/foreman/api/test_acs.py | 19 ++++++++++++++ tests/foreman/cli/test_acs.py | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/robottelo/cli/acs.py b/robottelo/cli/acs.py index f610a5e983..a2a20b0931 100644 --- a/robottelo/cli/acs.py +++ b/robottelo/cli/acs.py @@ -9,7 +9,7 @@ [ARG] ... Subcommand arguments Subcommands:: - + bulk Modify alternate content sources in bulk create Create an alternate content source to download content from during repository syncing. Note: alternate content sources are global and affect ALL sync actions on their capsules regardless of organization. @@ -37,3 +37,29 @@ def refresh(cls, options=None): """Refresh the ACS""" cls.command_sub = 'refresh' return cls.execute(cls._construct_command(options)) + + +class ACSBulk(Base): + """ + Manipulates Alternate Content Sources in bulk + """ + + command_base = 'alternate-content-source bulk' + + @classmethod + def destroy(cls, options=None): + """Destroy the ACS(s)""" + cls.command_sub = 'destroy' + return cls.execute(cls._construct_command(options)) + + @classmethod + def refresh(cls, options=None): + """Refresh the ACS(s)""" + cls.command_sub = 'refresh' + return cls.execute(cls._construct_command(options)) + + @classmethod + def refresh_all(cls, options=None): + """Refresh all ACSs""" + cls.command_sub = 'refresh-all' + return cls.execute(cls._construct_command(options)) diff --git a/tests/foreman/api/test_acs.py b/tests/foreman/api/test_acs.py index a8b24345bc..dd62cdfb3c 100644 --- a/tests/foreman/api/test_acs.py +++ b/tests/foreman/api/test_acs.py @@ -116,6 +116,7 @@ def test_positive_run_bulk_actions(module_target_sat, module_yum_repo): :steps: 1. Create several ACSes. 2. Bulk refresh them all. + 3. Add 1 more ACS, then use bulk refresh all. 3. Bulk destroy some of them. 4. Cleanup the rest. @@ -143,6 +144,24 @@ def test_positive_run_bulk_actions(module_target_sat, module_yum_repo): for id in acs_ids ] ) + # Add another ACS and then bulk refresh all + acs = module_target_sat.api.AlternateContentSource( + name=gen_string('alpha'), + alternate_content_source_type='simplified', + content_type='yum', + smart_proxy_ids=[module_target_sat.nailgun_capsule.id], + product_ids=[module_yum_repo.product.id], + ).create() + acs_ids.append(acs.id) + res = module_target_sat.api.AlternateContentSource().bulk_refresh_all() + assert res['result'] == 'success' + assert all( + [ + module_target_sat.api.AlternateContentSource(id=id).read().last_refresh['result'] + == 'success' + for id in acs_ids + ] + ) res = module_target_sat.api.AlternateContentSource().bulk_destroy(data={'ids': acs_ids[1:]}) assert res['result'] == 'success' diff --git a/tests/foreman/cli/test_acs.py b/tests/foreman/cli/test_acs.py index 50c82d6944..9762b39969 100644 --- a/tests/foreman/cli/test_acs.py +++ b/tests/foreman/cli/test_acs.py @@ -255,3 +255,50 @@ def test_negative_check_simplified_validations( ) assert f'Upstream username {VAL_MUST_BLANK}' in context.value.message assert f'Upstream password {VAL_MUST_BLANK}' in context.value.message + + +def test_bulk_actions(module_target_sat, module_yum_repo): + """Perform bulk actions with an ACS through CLI. + + :id: cf798893-cbc3-40c8-aa8a-03a6dedb0828 + + :CaseImportance: Medium + + :BZ: 2159967 + + :steps: + 1. Create several ACSes. + 2. Bulk refresh them all by ID + 3. Bulk refresh them all by refresh-all + 3. Bulk destroy some of them. + 4. Cleanup the rest. + + :expectedresults: + 1. All ACSes can be refreshed via bulk action. + 2. Only the proper ACSes are deleted on bulk destroy. + """ + acs_ids = [] + for _ in range(3): + # Create + acs = module_target_sat.cli.ACS.create( + { + 'name': gen_alphanumeric(), + 'alternate-content-source-type': 'simplified', + 'content-type': 'yum', + 'smart-proxy-ids': module_target_sat.nailgun_capsule.id, + 'product-ids': [module_yum_repo.product.id], + } + ) + acs_ids.append(acs['id']) + res = module_target_sat.cli.ACSBulk.refresh({'ids': acs_ids}) + assert res.strip() == 'Successfully refreshed specified alternate content sources' + res = module_target_sat.cli.ACSBulk.refresh_all() + assert res.strip() == 'Successfully refreshed all alternate content sources' + res = module_target_sat.cli.ACSBulk.destroy({'ids': acs_ids[1:]}) + assert res.strip() == 'Sucessfully destroyed specified alternate content sources' + + list = [item['id'] for item in module_target_sat.cli.ACS.list()] + # assert the first stayed and rest was deleted + assert acs_ids[0] in list + assert acs_ids[1:] not in list + module_target_sat.cli.ACS.delete({'id': acs_ids[0]}) From bdd08a4ac9ed24cbb6dc2bfa5ed99e0c9f1f0e27 Mon Sep 17 00:00:00 2001 From: Sam Bible Date: Tue, 18 Jun 2024 13:43:27 -0500 Subject: [PATCH 2/5] Add Verifies docstring section --- tests/foreman/cli/test_acs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/foreman/cli/test_acs.py b/tests/foreman/cli/test_acs.py index 9762b39969..4080c62b49 100644 --- a/tests/foreman/cli/test_acs.py +++ b/tests/foreman/cli/test_acs.py @@ -266,6 +266,8 @@ def test_bulk_actions(module_target_sat, module_yum_repo): :BZ: 2159967 + :Verifies: SAT-18199 + :steps: 1. Create several ACSes. 2. Bulk refresh them all by ID From f000f2df1a6afca6c850e369b7b87e54451d76d6 Mon Sep 17 00:00:00 2001 From: Samuel Bible Date: Wed, 26 Jun 2024 07:49:21 -0500 Subject: [PATCH 3/5] Update docstring Co-authored-by: vsedmik <46570670+vsedmik@users.noreply.github.com> --- tests/foreman/api/test_acs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/foreman/api/test_acs.py b/tests/foreman/api/test_acs.py index dd62cdfb3c..877db16cf8 100644 --- a/tests/foreman/api/test_acs.py +++ b/tests/foreman/api/test_acs.py @@ -117,7 +117,8 @@ def test_positive_run_bulk_actions(module_target_sat, module_yum_repo): 1. Create several ACSes. 2. Bulk refresh them all. 3. Add 1 more ACS, then use bulk refresh all. - 3. Bulk destroy some of them. + 4. Bulk destroy some of them. + 5. Cleanup the rest. 4. Cleanup the rest. :expectedresults: From f767f87df2d09426ffd4608a4ac809da3b28c130 Mon Sep 17 00:00:00 2001 From: Sam Bible Date: Thu, 27 Jun 2024 14:47:51 -0500 Subject: [PATCH 4/5] Fix docstrings for api and cli --- tests/foreman/api/test_acs.py | 1 - tests/foreman/cli/test_acs.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/foreman/api/test_acs.py b/tests/foreman/api/test_acs.py index 877db16cf8..771b3de94e 100644 --- a/tests/foreman/api/test_acs.py +++ b/tests/foreman/api/test_acs.py @@ -119,7 +119,6 @@ def test_positive_run_bulk_actions(module_target_sat, module_yum_repo): 3. Add 1 more ACS, then use bulk refresh all. 4. Bulk destroy some of them. 5. Cleanup the rest. - 4. Cleanup the rest. :expectedresults: 1. All ACSes can be refreshed via bulk action. diff --git a/tests/foreman/cli/test_acs.py b/tests/foreman/cli/test_acs.py index 4080c62b49..19620afeea 100644 --- a/tests/foreman/cli/test_acs.py +++ b/tests/foreman/cli/test_acs.py @@ -272,8 +272,8 @@ def test_bulk_actions(module_target_sat, module_yum_repo): 1. Create several ACSes. 2. Bulk refresh them all by ID 3. Bulk refresh them all by refresh-all - 3. Bulk destroy some of them. - 4. Cleanup the rest. + 4. Bulk destroy some of them. + 5. Cleanup the rest. :expectedresults: 1. All ACSes can be refreshed via bulk action. From 8700fe1ba4923d0c828ec6cf4bf481a11349d3ff Mon Sep 17 00:00:00 2001 From: vsedmik <46570670+vsedmik@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:11:38 +0200 Subject: [PATCH 5/5] Newline to robottelo/cli/acs.py --- robottelo/cli/acs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/robottelo/cli/acs.py b/robottelo/cli/acs.py index a2a20b0931..ea379ff12a 100644 --- a/robottelo/cli/acs.py +++ b/robottelo/cli/acs.py @@ -9,6 +9,7 @@ [ARG] ... Subcommand arguments Subcommands:: + bulk Modify alternate content sources in bulk create Create an alternate content source to download content from during repository syncing. Note: alternate content sources are global and affect ALL sync actions