From f40d81a13de7bb6e81c6f8544edfc5acdc5e0718 Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Thu, 30 May 2024 03:45:50 -0400 Subject: [PATCH] [6.16.z] ContentCredentials CLI fix for stream (#15228) --- tests/foreman/cli/test_contentcredentials.py | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/foreman/cli/test_contentcredentials.py b/tests/foreman/cli/test_contentcredentials.py index 14d4ff50718..c80851b2b8f 100644 --- a/tests/foreman/cli/test_contentcredentials.py +++ b/tests/foreman/cli/test_contentcredentials.py @@ -45,6 +45,27 @@ def create_gpg_key_file(content=None): return None +def wait_for_repo_metadata_tasks(sat, org_name, repo_name='', product_name=''): + """Search and wait for any repository metadata generate task(s). + + param sat (satellite): is required. + param org_name (str): is required, rest are optional. + Scope by use of repo/product name, if desired. + + return: the matching completed task(s) + """ + task_query = ( + f'Metadata generate repository "{repo_name}";' + f' product "{product_name}";' + f' organization "{org_name}"' + ) + return sat.wait_for_tasks( + search_query=task_query, + search_rate=15, + max_tries=10, + ) + + search_key = 'name' @@ -403,6 +424,13 @@ def test_positive_add_product_with_repo(target_sat, module_org): target_sat.cli.Product.update( {'gpg-key-id': gpg_key['id'], 'id': product['id'], 'organization-id': module_org.id} ) + # wait for repo metadata task(s) before final read/assertions + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + repo_name=repo['name'], + product_name=product['name'], + ) product = target_sat.cli.Product.info({'id': product['id'], 'organization-id': module_org.id}) repo = target_sat.cli.Repository.info({'id': repo['id']}) assert product['gpg']['gpg-key-id'] == gpg_key['id'] @@ -429,6 +457,11 @@ def test_positive_add_product_with_repos(target_sat, module_org): target_sat.cli.Product.update( {'gpg-key-id': gpg_key['id'], 'id': product['id'], 'organization-id': module_org.id} ) + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + product_name=product['name'], + ) product = target_sat.cli.Product.info({'id': product['id'], 'organization-id': module_org.id}) assert product['gpg']['gpg-key-id'] == gpg_key['id'] for repo in repos: @@ -455,6 +488,12 @@ def test_positive_add_repo_from_product_with_repo(target_sat, module_org): target_sat.cli.Repository.update( {'gpg-key-id': gpg_key['id'], 'id': repo['id'], 'organization-id': module_org.id} ) + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + repo_name=repo['name'], + product_name=product['name'], + ) product = target_sat.cli.Product.info({'id': product['id'], 'organization-id': module_org.id}) repo = target_sat.cli.Repository.info({'id': repo['id']}) assert repo['gpg-key']['id'] == gpg_key['id'] @@ -482,6 +521,11 @@ def test_positive_add_repo_from_product_with_repos(target_sat, module_org): target_sat.cli.Repository.update( {'gpg-key-id': gpg_key['id'], 'id': repos[0]['id'], 'organization-id': module_org.id} ) + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + product_name=product['name'], + ) product = target_sat.cli.Product.info({'id': product['id'], 'organization-id': module_org.id}) assert product['gpg'].get('gpg-key-id') != gpg_key['id'] # First repo should have a valid gpg key assigned @@ -566,6 +610,13 @@ def test_positive_update_key_for_product_with_repo(target_sat, module_org): {'id': gpg_key['id'], 'organization-id': module_org.id} ) assert gpg_key['name'] == new_name + # wait for repo metadata task(s) before final read/assertions + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + repo_name=repo['name'], + product_name=product['name'], + ) # Verify changes are reflected in the product product = target_sat.cli.Product.info({'id': product['id'], 'organization-id': module_org.id}) assert product['gpg']['gpg-key'] == new_name @@ -601,6 +652,12 @@ def test_positive_update_key_for_product_with_repos(target_sat, module_org): product = target_sat.cli.Product.info({'id': product['id'], 'organization-id': module_org.id}) assert product['gpg']['gpg-key'] == gpg_key['name'] for repo in repos: + # one metadata task per repo associated w/ GPG + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + product_name=product['name'], + ) repo = target_sat.cli.Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('name') == gpg_key['name'] # Update the gpg key @@ -616,6 +673,11 @@ def test_positive_update_key_for_product_with_repos(target_sat, module_org): # Verify changes are reflected in the product product = target_sat.cli.Product.info({'id': product['id'], 'organization-id': module_org.id}) assert product['gpg']['gpg-key'] == new_name + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + product_name=product['name'], + ) # Verify changes are reflected in the repositories for repo in repos: repo = target_sat.cli.Repository.info({'id': repo['id']}) @@ -652,6 +714,12 @@ def test_positive_update_key_for_repo_from_product_with_repo(target_sat, module_ {'id': gpg_key['id'], 'organization-id': module_org.id} ) assert gpg_key['name'] == new_name + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + repo_name=repo['name'], + product_name=product['name'], + ) # Verify changes are reflected in the repositories repo = target_sat.cli.Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('name') == new_name @@ -697,6 +765,12 @@ def test_positive_update_key_for_repo_from_product_with_repos(target_sat, module {'id': gpg_key['id'], 'organization-id': module_org.id} ) assert gpg_key['name'] == new_name + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + repo_name=repos[0]['name'], + product_name=product['name'], + ) # Verify changes are reflected in the associated repository repos[0] = target_sat.cli.Repository.info({'id': repos[0]['id']}) assert repos[0]['gpg-key'].get('name') == new_name