diff --git a/tests/foreman/cli/test_contentview.py b/tests/foreman/cli/test_contentview.py index f9b6829f348..fe1470c07e6 100644 --- a/tests/foreman/cli/test_contentview.py +++ b/tests/foreman/cli/test_contentview.py @@ -353,6 +353,84 @@ def test_positive_delete_version_by_id(self, module_org, module_product, module_ new_cv = module_target_sat.cli.ContentView.info({'id': new_cv['id']}) assert len(new_cv['versions']) == 0 + @pytest.mark.tier2 + def test_negative_publish_during_repo_sync( + self, + module_target_sat, + module_org, + module_product, + ): + """Attempt to publish a new version of the content-view, + while an associated repository is being synced. + + :id: 94b53947-9b1d-414d-8319-f9a24e9170a6 + + :BZ: 1957144 + + :setup: A newly created repository and content-view. + + :steps: + 1. Add a larger repository to the content-view. + 2. Perform asynchronous repository sync. + 3. Attempt to publish a version of the content-view, while repo sync ongoing. + + :expectedresults: + 1. User cannot publish during repository sync. + 2. CLIReturnCodeError raised, publish task failed for expected reason, + repo sync task_id found in humanized error, content-view versions unchanged. + """ + custom_repo = module_target_sat.cli_factory.make_repository( + { + 'content-type': 'yum', + 'product-id': module_product.id, + 'url': settings.repos.rhel8_os.appstream, + } + ) + content_view = module_target_sat.cli_factory.make_content_view( + {'organization-id': module_org.id} + ) + # Associate repo to created CV + module_target_sat.cli.ContentView.add_repository( + { + 'id': content_view['id'], + 'organization-id': module_org.id, + 'repository-id': custom_repo['id'], + } + ) + # read updated CV info + content_view = module_target_sat.cli.ContentView.info({'id': content_view['id']}) + existing_versions = content_view['versions'] + # perform async repository sync + repo_task = module_target_sat.cli.Repository.synchronize( + { + 'id': custom_repo['id'], + 'async': True, + } + ) + repo_task_id = repo_task.split()[-1].rstrip('.') + result = None + # attempt to publish a new version of the content view + with pytest.raises(CLIReturnCodeError) as err: + result = module_target_sat.cli.ContentView.publish({'id': content_view['id']}) + assert 'Could not publish' in err.value.stderr + assert repo_task_id in err.value.stderr + assert result is None + # content-view-versions are unchanged + content_view = module_target_sat.cli.ContentView.info({'id': content_view['id']}) + assert content_view['versions'] == existing_versions + # search for failed publish task + task_search = f'action ~ Publish content_view and action ~ {content_view["name"]}' + cv_tasks = module_target_sat.cli.Task.list_tasks({'search': task_search}) + assert len(cv_tasks) > 0 + publish_task = cv_tasks[0] + assert content_view['name'] in publish_task['action'] + assert module_org.name in publish_task['action'] + # failed for expected reason + assert publish_task['result'] == 'error' + humanized = publish_task['task-errors'] + assert 'Pending tasks detected' in humanized + assert repo_task_id in humanized + @pytest.mark.tier2 def test_negative_delete_version_by_id(self, module_org, module_target_sat): """Create content view and publish it. Try to delete content