From a3caf87c7b4fc57a96b5cdfea15aec317d723251 Mon Sep 17 00:00:00 2001 From: David Moore Date: Thu, 23 May 2024 11:36:25 -0400 Subject: [PATCH] ContentCredentials CLI fix for stream --- tests/foreman/cli/test_contentcredentials.py | 78 ++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/foreman/cli/test_contentcredentials.py b/tests/foreman/cli/test_contentcredentials.py index 14d4ff50718..3695ca3722c 100644 --- a/tests/foreman/cli/test_contentcredentials.py +++ b/tests/foreman/cli/test_contentcredentials.py @@ -45,6 +45,30 @@ 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 repo metadata task(s). + + param sat (satellite): is required. + param org_name (str): is required, rest are optional. + + Scope by use of arguments, entity names, + ie: blank repo_name would return metadata tasks for all repos, + that match the scope of given org name, and product name if any. + + 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 +427,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 +460,12 @@ 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 task(s) before final read/assertions + 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 +492,13 @@ 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 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 repo['gpg-key']['id'] == gpg_key['id'] @@ -482,6 +526,13 @@ 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 task(s) before final read/assertions + wait_for_repo_metadata_tasks( + sat=target_sat, + org_name=module_org.name, + repo_name=repos[0]['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 +617,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 @@ -613,6 +671,12 @@ def test_positive_update_key_for_product_with_repos(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, + 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 @@ -652,6 +716,13 @@ 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 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 repositories repo = target_sat.cli.Repository.info({'id': repo['id']}) assert repo['gpg-key'].get('name') == new_name @@ -697,6 +768,13 @@ 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 task(s) before final read/assertions + 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