Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CC Automation] Update API test to use refresh-all and add CLI test for bulk actions #15451

Merged
merged 8 commits into from
Jun 28, 2024
28 changes: 27 additions & 1 deletion robottelo/cli/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[ARG] ... Subcommand arguments

Subcommands::

bulk Modify alternate content sources in bulk
vsedmik marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -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))
19 changes: 19 additions & 0 deletions tests/foreman/api/test_acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
sambible marked this conversation as resolved.
Show resolved Hide resolved
4. Cleanup the rest.

Expand Down Expand Up @@ -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'
Expand Down
49 changes: 49 additions & 0 deletions tests/foreman/cli/test_acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,52 @@ 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

:Verifies: SAT-18199

: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]})
Loading