From 3db8afbd17b2fb6c26fcef22488be0718cdbf29e Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Wed, 24 Jan 2024 23:58:59 +0100 Subject: [PATCH 1/6] CE-SAT-21617 --- robottelo/cli/hammer.py | 6 ++- tests/foreman/cli/test_host.py | 90 +++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 35 deletions(-) diff --git a/robottelo/cli/hammer.py b/robottelo/cli/hammer.py index 6e7b896a0b8..dcc2468ba7c 100644 --- a/robottelo/cli/hammer.py +++ b/robottelo/cli/hammer.py @@ -175,7 +175,8 @@ def get_line_indentation_level(line, tab_spaces=4, indentation_spaces=4): assert get_line_indentation_level(' level 2') == 2 """ - return get_line_indentation_spaces(line, tab_spaces=tab_spaces) // indentation_spaces + spaces = get_line_indentation_spaces(line, tab_spaces=tab_spaces) + return spaces // indentation_spaces + (1 if spaces % indentation_spaces > 0 else 0) def parse_info(output): @@ -249,6 +250,9 @@ def parse_info(output): # URL: /custom/4f84fc90-9ffa-... starts_with_number = re.match(r'(\d+)\)', key) if starts_with_number: + # if this is a numbered list on level 2, do nothing - this script doesn't support it + if current_indent_level >= 2: + continue sub_num = int(starts_with_number.group(1)) # no. 1) we need to change dict() to list() if sub_num == 1: diff --git a/tests/foreman/cli/test_host.py b/tests/foreman/cli/test_host.py index 026168b8f68..b59e8412cc6 100644 --- a/tests/foreman/cli/test_host.py +++ b/tests/foreman/cli/test_host.py @@ -2467,31 +2467,31 @@ def test_positive_host_with_puppet( session_puppet_enabled_sat.cli.target_sat.cli.Host.delete({'id': host['id']}) -@pytest.fixture -def function_proxy(session_puppet_enabled_sat, puppet_proxy_port_range): - proxy = session_puppet_enabled_sat.cli_factory.make_proxy() - yield proxy - session_puppet_enabled_sat.cli.Proxy.delete({'id': proxy['id']}) - - @pytest.fixture def function_host_content_source( - session_puppet_enabled_sat, - session_puppet_enabled_proxy, - module_puppet_lce_library, - module_puppet_org, - module_puppet_published_cv, + target_sat, + module_capsule_configured, + module_lce_library, + module_org, + module_published_cv, + module_ak_with_cv, + rhel_contenthost, ): - host = session_puppet_enabled_sat.cli_factory.make_fake_host( - { - 'content-source-id': session_puppet_enabled_proxy.id, - 'content-view-id': module_puppet_published_cv.id, - 'lifecycle-environment-id': module_puppet_lce_library.id, - 'organization': module_puppet_org.name, - } - ) - yield host - session_puppet_enabled_sat.cli.target_sat.cli.Host.delete({'id': host['id']}) + target_sat.cli.Capsule.update( + {'name': module_capsule_configured.hostname, 'organization-ids': [module_org.id]} + ) + target_sat.cli.Capsule.info({'name': module_capsule_configured.hostname}) + res = rhel_contenthost.register(module_org, None, module_ak_with_cv.name, target_sat) + assert res.status == 0, f'Failed to register host: {res.stderr}' + return res + # host = target_sat.cli_factory.make_fake_host( + # { + # 'content-source-id': capsule['id'], + # 'content-view-id': module_published_cv.id, + # 'lifecycle-environment-id': module_lce_library.id, + # 'organization': module_org.name, + # } + # ) @pytest.mark.tier2 @@ -2637,19 +2637,21 @@ def test_positive_update_host_owner_and_verify_puppet_class_name( @pytest.mark.cli_puppet_enabled @pytest.mark.run_in_one_thread @pytest.mark.tier2 +@pytest.mark.rhel_ver_match('[8]') def test_positive_create_and_update_with_content_source( - session_puppet_enabled_sat, - session_puppet_enabled_proxy, + target_sat, + module_capsule_configured, + module_org, + module_lce_library, + module_repo, + rhel_contenthost, function_host_content_source, - function_proxy, ): """Create a host with content source specified and update content source :id: 5712f4db-3610-447d-b1da-0fe461577d59 - :customerscenario: true - :BZ: 1260697, 1483252, 1313056, 1488465 :expectedresults: A host is created with expected content source @@ -2657,13 +2659,33 @@ def test_positive_create_and_update_with_content_source( :CaseImportance: High """ - host = function_host_content_source + host = target_sat.cli.Host.info({'name': rhel_contenthost.hostname}) assert ( - host['content-information']['content-source']['name'] == session_puppet_enabled_proxy.name + host['content-information']['content-source']['name'] == target_sat.hostname + or host['content-information']['content-source']['name'] == '' ) - new_content_source = function_proxy - session_puppet_enabled_sat.cli.target_sat.cli.Host.update( - {'id': host['id'], 'content-source-id': new_content_source.id} + + # set a new proxy + target_sat.cli.Capsule.update( + {'name': module_capsule_configured.hostname, 'organization-id': module_org.id} ) - host = session_puppet_enabled_sat.cli.target_sat.cli.Host.info({'id': host['id']}) - assert host['content-information']['content-source']['name'] == new_content_source.name + target_sat.cli.Capsule.content_add_lifecycle_environment( + { + 'name': module_capsule_configured.hostname, + 'organization-id': module_org.id, + 'environment-id': module_lce_library.id, + } + ) + target_sat.cli.Host.update( + {'id': host['id'], 'content-source': module_capsule_configured.hostname} + ) + host = target_sat.cli.Host.info({'id': host['id']}) + assert ( + host['content-information']['content-source']['name'] == module_capsule_configured.hostname + ) + + # test that the new content source is really used to get content + assert not host.execute('rpm -q emacs') + assert not host.execute('dnf install emacs') + # TODO: sync capsule + assert host.execute('dnf install emacs') From 371326da9a1beee18c981571cdc28d684292f0f3 Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Thu, 25 Jan 2024 14:25:50 +0100 Subject: [PATCH 2/6] Works but CV is not published --- tests/foreman/cli/test_host.py | 46 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/tests/foreman/cli/test_host.py b/tests/foreman/cli/test_host.py index b59e8412cc6..26a2bc736d3 100644 --- a/tests/foreman/cli/test_host.py +++ b/tests/foreman/cli/test_host.py @@ -2475,8 +2475,22 @@ def function_host_content_source( module_org, module_published_cv, module_ak_with_cv, + module_repo, rhel_contenthost, ): + product = target_sat.cli.Product.info( + {'id': module_repo.product.id, 'organization-id': module_org.id} + ) + module_ak_with_cv.content_override( + data={ + 'content_overrides': [ + { + 'content_label': '_'.join([module_org.name, product['name'], module_repo.name]), + 'value': '1', + } + ] + } + ) target_sat.cli.Capsule.update( {'name': module_capsule_configured.hostname, 'organization-ids': [module_org.id]} ) @@ -2484,14 +2498,6 @@ def function_host_content_source( res = rhel_contenthost.register(module_org, None, module_ak_with_cv.name, target_sat) assert res.status == 0, f'Failed to register host: {res.stderr}' return res - # host = target_sat.cli_factory.make_fake_host( - # { - # 'content-source-id': capsule['id'], - # 'content-view-id': module_published_cv.id, - # 'lifecycle-environment-id': module_lce_library.id, - # 'organization': module_org.name, - # } - # ) @pytest.mark.tier2 @@ -2638,11 +2644,12 @@ def test_positive_update_host_owner_and_verify_puppet_class_name( @pytest.mark.run_in_one_thread @pytest.mark.tier2 @pytest.mark.rhel_ver_match('[8]') +@pytest.mark.no_containers def test_positive_create_and_update_with_content_source( target_sat, module_capsule_configured, module_org, - module_lce_library, + module_lce, module_repo, rhel_contenthost, function_host_content_source, @@ -2673,7 +2680,7 @@ def test_positive_create_and_update_with_content_source( { 'name': module_capsule_configured.hostname, 'organization-id': module_org.id, - 'environment-id': module_lce_library.id, + 'environment-id': module_lce.id, } ) target_sat.cli.Host.update( @@ -2684,8 +2691,19 @@ def test_positive_create_and_update_with_content_source( host['content-information']['content-source']['name'] == module_capsule_configured.hostname ) + # run an ansible job that makes a host aware that it should use a different content source + target_sat.cli_factory.job_invocation( + { + 'job-template': 'Configure host for new content source', + 'search-query': f"name ~ {rhel_contenthost.hostname}", + } + ) + # TODO enable testing repo on the host + # test that the new content source is really used to get content - assert not host.execute('rpm -q emacs') - assert not host.execute('dnf install emacs') - # TODO: sync capsule - assert host.execute('dnf install emacs') + assert rhel_contenthost.execute('rpm -q squirrel').status != 0 + assert rhel_contenthost.execute('dnf install squirrel').status != 0 + target_sat.cli.Repository.synchronize({'id': module_repo.id}) + target_sat.cli.Capsule.content_synchronize({'name': module_capsule_configured.hostname}) + assert rhel_contenthost.execute('dnf install squirrel').status == 0 + assert rhel_contenthost.execute('rpm -q squirrel').status == 0 From 0ba74a6075f13bc29c60c8c81a392c29fee938d2 Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Thu, 25 Jan 2024 18:42:15 +0100 Subject: [PATCH 3/6] Correct package name --- pytest_fixtures/component/activationkey.py | 10 ++++++ tests/foreman/cli/test_host.py | 36 ++++++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/pytest_fixtures/component/activationkey.py b/pytest_fixtures/component/activationkey.py index fa7b53d0189..b0f7c77bd8a 100644 --- a/pytest_fixtures/component/activationkey.py +++ b/pytest_fixtures/component/activationkey.py @@ -35,6 +35,16 @@ def module_ak_with_cv(module_lce, module_org, module_promoted_cv, module_target_ return ak +@pytest.fixture(scope='module') +def module_ak_with_cv_repo(module_lce, module_org, module_cv_repo, module_target_sat): + ak = module_target_sat.api.ActivationKey( + content_view=module_cv_repo, + environment=module_lce, + organization=module_org, + ).create() + return ak + + @pytest.fixture(scope='module') def module_ak_with_synced_repo(module_org, module_target_sat): """Prepare an activation key with synced repository for host registration""" diff --git a/tests/foreman/cli/test_host.py b/tests/foreman/cli/test_host.py index 26a2bc736d3..5a32fccf06d 100644 --- a/tests/foreman/cli/test_host.py +++ b/tests/foreman/cli/test_host.py @@ -2473,19 +2473,20 @@ def function_host_content_source( module_capsule_configured, module_lce_library, module_org, - module_published_cv, - module_ak_with_cv, - module_repo, + module_ak_with_cv_repo, + module_product, + module_repository, + module_cv_repo, rhel_contenthost, ): - product = target_sat.cli.Product.info( - {'id': module_repo.product.id, 'organization-id': module_org.id} - ) - module_ak_with_cv.content_override( + target_sat.cli.Product.info({'id': module_product.id, 'organization-id': module_org.id}) + module_ak_with_cv_repo.content_override( data={ 'content_overrides': [ { - 'content_label': '_'.join([module_org.name, product['name'], module_repo.name]), + 'content_label': '_'.join( + [module_org.name, module_product.name, module_repository.name] + ), 'value': '1', } ] @@ -2494,8 +2495,8 @@ def function_host_content_source( target_sat.cli.Capsule.update( {'name': module_capsule_configured.hostname, 'organization-ids': [module_org.id]} ) - target_sat.cli.Capsule.info({'name': module_capsule_configured.hostname}) - res = rhel_contenthost.register(module_org, None, module_ak_with_cv.name, target_sat) + # target_sat.cli.Capsule.info({'name': module_capsule_configured.hostname}) + res = rhel_contenthost.register(module_org, None, module_ak_with_cv_repo.name, target_sat) assert res.status == 0, f'Failed to register host: {res.stderr}' return res @@ -2650,7 +2651,7 @@ def test_positive_create_and_update_with_content_source( module_capsule_configured, module_org, module_lce, - module_repo, + module_repository, rhel_contenthost, function_host_content_source, ): @@ -2666,6 +2667,8 @@ def test_positive_create_and_update_with_content_source( :CaseImportance: High """ + target_sat.cli.Repository.synchronize({'id': module_repository.id}) + host = target_sat.cli.Host.info({'name': rhel_contenthost.hostname}) assert ( host['content-information']['content-source']['name'] == target_sat.hostname @@ -2698,12 +2701,11 @@ def test_positive_create_and_update_with_content_source( 'search-query': f"name ~ {rhel_contenthost.hostname}", } ) - # TODO enable testing repo on the host # test that the new content source is really used to get content - assert rhel_contenthost.execute('rpm -q squirrel').status != 0 - assert rhel_contenthost.execute('dnf install squirrel').status != 0 - target_sat.cli.Repository.synchronize({'id': module_repo.id}) + package = 'bc' + assert rhel_contenthost.execute(f'rpm -q {package}').status != 0 + assert rhel_contenthost.execute(f'dnf -y install {package}').status != 0 target_sat.cli.Capsule.content_synchronize({'name': module_capsule_configured.hostname}) - assert rhel_contenthost.execute('dnf install squirrel').status == 0 - assert rhel_contenthost.execute('rpm -q squirrel').status == 0 + assert rhel_contenthost.execute(f'dnf -y install {package}').status == 0 + assert rhel_contenthost.execute(f'rpm -q {package}').status == 0 From 43230288c037a3c5ff82f3a583900be6b8e27711 Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Fri, 26 Jan 2024 00:30:52 +0100 Subject: [PATCH 4/6] Change package to one that doesn't cause dependency issues on RHEL8 --- tests/foreman/cli/test_host.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/foreman/cli/test_host.py b/tests/foreman/cli/test_host.py index 5a32fccf06d..2b9985b5b08 100644 --- a/tests/foreman/cli/test_host.py +++ b/tests/foreman/cli/test_host.py @@ -2703,7 +2703,7 @@ def test_positive_create_and_update_with_content_source( ) # test that the new content source is really used to get content - package = 'bc' + package = 'at' assert rhel_contenthost.execute(f'rpm -q {package}').status != 0 assert rhel_contenthost.execute(f'dnf -y install {package}').status != 0 target_sat.cli.Capsule.content_synchronize({'name': module_capsule_configured.hostname}) From d98e3940c21caaadbe7f3c7f69c4ca2b5a25fde9 Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Fri, 26 Jan 2024 01:33:28 +0100 Subject: [PATCH 5/6] Mark customerscenario --- tests/foreman/cli/test_host.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/foreman/cli/test_host.py b/tests/foreman/cli/test_host.py index 2b9985b5b08..b9ea7cd71a3 100644 --- a/tests/foreman/cli/test_host.py +++ b/tests/foreman/cli/test_host.py @@ -2660,12 +2660,14 @@ def test_positive_create_and_update_with_content_source( :id: 5712f4db-3610-447d-b1da-0fe461577d59 - :BZ: 1260697, 1483252, 1313056, 1488465 + :BZ: 1260697, 1483252, 1313056, 1488465, 1361309 :expectedresults: A host is created with expected content source assigned and then content source is successfully updated :CaseImportance: High + + :customerscenario: true """ target_sat.cli.Repository.synchronize({'id': module_repository.id}) From a48ba989e9e30e45ad4562a8080140deabd2e9db Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Fri, 26 Jan 2024 02:11:22 +0100 Subject: [PATCH 6/6] Wrong BZ --- tests/foreman/cli/test_host.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/foreman/cli/test_host.py b/tests/foreman/cli/test_host.py index b9ea7cd71a3..2b9985b5b08 100644 --- a/tests/foreman/cli/test_host.py +++ b/tests/foreman/cli/test_host.py @@ -2660,14 +2660,12 @@ def test_positive_create_and_update_with_content_source( :id: 5712f4db-3610-447d-b1da-0fe461577d59 - :BZ: 1260697, 1483252, 1313056, 1488465, 1361309 + :BZ: 1260697, 1483252, 1313056, 1488465 :expectedresults: A host is created with expected content source assigned and then content source is successfully updated :CaseImportance: High - - :customerscenario: true """ target_sat.cli.Repository.synchronize({'id': module_repository.id})