From 14bc6e8a7f005c165c3b1d073fda84afcc677f8b Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 20 Dec 2023 13:57:20 +0100 Subject: [PATCH] don't fork when the destination project already exists --- obal/data/modules/copr_fork.py | 5 ++++- tests/fixtures/mockbin/mockbin | 4 ++++ tests/test_functional.py | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/obal/data/modules/copr_fork.py b/obal/data/modules/copr_fork.py index 72a8e72d..fdbaf225 100644 --- a/obal/data/modules/copr_fork.py +++ b/obal/data/modules/copr_fork.py @@ -4,7 +4,7 @@ """ from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module +from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name, project_exists # pylint:disable=import-error,no-name-in-module def main(): @@ -29,6 +29,9 @@ def main(): delete_after_days = module.params['delete_after_days'] config_file = module.params['config_file'] + if project_exists(dest_user, dest_project, module, config_file=config_file): + module.exit_json(changed=False) + command = [ 'fork', full_name(src_user, src_project), diff --git a/tests/fixtures/mockbin/mockbin b/tests/fixtures/mockbin/mockbin index 1c290bb0..9697b005 100755 --- a/tests/fixtures/mockbin/mockbin +++ b/tests/fixtures/mockbin/mockbin @@ -208,5 +208,9 @@ elif prog in ['copr-cli']: print("Build was added to foreman-1234:") print("https://copr.fedorainfracloud.org/coprs/build/5678") print("Created builds: 5678") + elif args.subcommand == 'list': + if args.project == 'existing-fork': + print("Name: foreman-client") + print(" Description: foreman-client") else: print({}) diff --git a/tests/test_functional.py b/tests/test_functional.py index c5ce27cd..9e07ec58 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -857,9 +857,23 @@ def test_copr_project_fork(): assert_obal_success(['copr-project', 'client', '-e copr_project_fork_from=client-test']) expected_log = [ + "copr-cli list example", "copr-cli fork example/client-test example/foreman-client", "copr-cli edit-chroot example/foreman-client/rhel-9-x86_64", "copr-cli edit-chroot example/foreman-client/rhel-8-x86_64", "copr-cli edit-chroot example/foreman-client/rhel-7-x86_64", ] assert_mockbin_log(expected_log) + + +@obal_cli_test(repotype='copr') +def test_copr_project_fork_already_exists(): + assert_obal_success(['copr-project', 'client', '-e copr_project_fork_from=client-test', '-e copr_project_user=existing-fork']) + + expected_log = [ + "copr-cli list existing-fork", + "copr-cli edit-chroot existing-fork/foreman-client/rhel-9-x86_64", + "copr-cli edit-chroot existing-fork/foreman-client/rhel-8-x86_64", + "copr-cli edit-chroot existing-fork/foreman-client/rhel-7-x86_64", + ] + assert_mockbin_log(expected_log)