From 923740e5d8bb1c42b0155f4a8cfe37ecc1220162 Mon Sep 17 00:00:00 2001 From: vsedmik <46570670+vsedmik@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:48:19 +0100 Subject: [PATCH] Fix flaky SyncPlans in cli_factory (#14337) (cherry picked from commit 2b8c8e98df53efc059358ebc3027b37f1b4392a9) --- robottelo/cli/syncplan.py | 11 +++++++++++ robottelo/host_helpers/cli_factory.py | 4 +++- tests/foreman/cli/test_syncplan.py | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/robottelo/cli/syncplan.py b/robottelo/cli/syncplan.py index 3f8b9b8b347..151a72acb84 100644 --- a/robottelo/cli/syncplan.py +++ b/robottelo/cli/syncplan.py @@ -17,9 +17,20 @@ update """ from robottelo.cli.base import Base +from robottelo.exceptions import CLIError class SyncPlan(Base): """Manipulates Katello engine's sync-plan command.""" command_base = 'sync-plan' + + @classmethod + def create(cls, options=None): + """Create a SyncPlan""" + cls.command_sub = 'create' + + if options.get('interval') == 'custom cron' and options.get('cron-expression') is None: + raise CLIError('Missing "cron-expression" option for "custom cron" interval.') + + return super().create(options) diff --git a/robottelo/host_helpers/cli_factory.py b/robottelo/host_helpers/cli_factory.py index 0db645d04f6..84ef66de1c2 100644 --- a/robottelo/host_helpers/cli_factory.py +++ b/robottelo/host_helpers/cli_factory.py @@ -140,7 +140,9 @@ def create_object(cli_object, options, values=None, credentials=None): 'sync_plan': { 'description': gen_alpha, 'enabled': 'true', - 'interval': lambda: random.choice(list(constants.SYNC_INTERVAL.values())), + 'interval': lambda: random.choice( + [i for i in constants.SYNC_INTERVAL.values() if i != 'custom cron'] + ), 'name': gen_alpha, 'sync-date': lambda: datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), }, diff --git a/tests/foreman/cli/test_syncplan.py b/tests/foreman/cli/test_syncplan.py index 86f33b68ffb..8669cd49a18 100644 --- a/tests/foreman/cli/test_syncplan.py +++ b/tests/foreman/cli/test_syncplan.py @@ -705,7 +705,7 @@ def test_positive_synchronize_rh_product_future_sync_date( # Verify product has not been synced yet with pytest.raises(AssertionError): validate_task_status(target_sat, repo['id'], org.id, max_tries=1) - validate_repo_content(repo, ['errata', 'packages'], after_sync=False) + validate_repo_content(target_sat, repo, ['errata', 'packages'], after_sync=False) # Wait the rest of expected time logger.info( f"Waiting {(delay * 4 / 5)} seconds to check product {product['name']}" @@ -714,7 +714,7 @@ def test_positive_synchronize_rh_product_future_sync_date( sleep(delay * 4 / 5) # Verify product was synced successfully validate_task_status(target_sat, repo['id'], org.id) - validate_repo_content(repo, ['errata', 'packages']) + validate_repo_content(target_sat, repo, ['errata', 'packages']) @pytest.mark.tier3