From 294f7120914bbf6b4510dd0decdaf9859a03519f Mon Sep 17 00:00:00 2001 From: yanpliu Date: Wed, 10 Jan 2024 01:05:40 -0500 Subject: [PATCH] virtwho config hammer deploy option name organization-title and location-id support (#13632) * virtwho config hammer option name organization-title and location-id support * use fstring and optimize duplicated code * remove print * Update pytest_fixtures/component/virtwho_config.py Co-authored-by: Shubham Ganar <67952129+shubhamsg199@users.noreply.github.com> * Update pytest_fixtures/component/virtwho_config.py Co-authored-by: Shubham Ganar <67952129+shubhamsg199@users.noreply.github.com> * Update pytest_fixtures/component/virtwho_config.py Co-authored-by: Shubham Ganar <67952129+shubhamsg199@users.noreply.github.com> * Update pytest_fixtures/component/virtwho_config.py Co-authored-by: Shubham Ganar <67952129+shubhamsg199@users.noreply.github.com> --------- Co-authored-by: Shubham Ganar <67952129+shubhamsg199@users.noreply.github.com> --- pytest_fixtures/component/virtwho_config.py | 21 +++++++++++++++------ robottelo/utils/virtwho.py | 14 ++++++++++++++ tests/foreman/virtwho/cli/test_esx_sca.py | 8 ++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/pytest_fixtures/component/virtwho_config.py b/pytest_fixtures/component/virtwho_config.py index fc7a262e802..b8970232136 100644 --- a/pytest_fixtures/component/virtwho_config.py +++ b/pytest_fixtures/component/virtwho_config.py @@ -6,6 +6,7 @@ deploy_configure_by_command, deploy_configure_by_script, get_configure_command, + get_configure_command_option, get_guest_info, ) @@ -271,21 +272,29 @@ def deploy_type_cli( form_data_cli, virtwho_config_cli, target_sat, + default_location, ): deploy_type = request.param.lower() assert virtwho_config_cli['status'] == 'No Report Yet' - if "id" in deploy_type: - command = get_configure_command(virtwho_config_cli['id'], org_module.name) - hypervisor_name, guest_name = deploy_configure_by_command( - command, form_data_cli['hypervisor-type'], debug=True, org=org_module.label - ) - elif "script" in deploy_type: + if 'script' in deploy_type: script = target_sat.cli.VirtWhoConfig.fetch( {'id': virtwho_config_cli['id']}, output_format='base' ) hypervisor_name, guest_name = deploy_configure_by_script( script, form_data_cli['hypervisor-type'], debug=True, org=org_module.label ) + elif deploy_type == 'organization-title': + virtwho_config_cli['organization-title'] = org_module.title + elif deploy_type == 'location-id': + virtwho_config_cli['location-id'] = default_location.id + if deploy_type in ['id', 'name', 'organization-title', 'location-id']: + if 'id' in deploy_type: + command = get_configure_command(virtwho_config_cli['id'], org_module.name) + else: + command = get_configure_command_option(deploy_type, virtwho_config_cli, org_module.name) + hypervisor_name, guest_name = deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], debug=True, org=org_module.label + ) return hypervisor_name, guest_name diff --git a/robottelo/utils/virtwho.py b/robottelo/utils/virtwho.py index aaae57d7c97..2f176d55341 100644 --- a/robottelo/utils/virtwho.py +++ b/robottelo/utils/virtwho.py @@ -526,3 +526,17 @@ def create_http_proxy(org, name=None, url=None, http_type='https'): organization=[org.id], ).create() return http_proxy.url, http_proxy.name, http_proxy.id + + +def get_configure_command_option(deploy_type, args, org=DEFAULT_ORG): + """Return the deploy command line based on option. + :param str option: the unique id of the configure file you have created. + :param str org: the satellite organization name. + """ + username, password = Base._get_username_password() + if deploy_type == 'location-id': + return f"hammer -u {username} -p {password} virt-who-config deploy --id {args['id']} --location-id '{args['location-id']}' " + elif deploy_type == 'organization-title': + return f"hammer -u {username} -p {password} virt-who-config deploy --id {args['id']} --organization-title '{args['organization-title']}' " + elif deploy_type == 'name': + return f"hammer -u {username} -p {password} virt-who-config deploy --name {args['name']} --organization '{org}' " diff --git a/tests/foreman/virtwho/cli/test_esx_sca.py b/tests/foreman/virtwho/cli/test_esx_sca.py index b09cabef912..7c5a4f5bc20 100644 --- a/tests/foreman/virtwho/cli/test_esx_sca.py +++ b/tests/foreman/virtwho/cli/test_esx_sca.py @@ -32,8 +32,12 @@ class TestVirtWhoConfigforEsx: @pytest.mark.tier2 @pytest.mark.upgrade - @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) - def test_positive_deploy_configure_by_id_script( + @pytest.mark.parametrize( + 'deploy_type_cli', + ['id', 'script', 'name', 'location-id', 'organization-title'], + indirect=True, + ) + def test_positive_deploy_configure_by_id_script_name_locationid_organizationtitle( self, module_sca_manifest_org, target_sat, virtwho_config_cli, deploy_type_cli ): """Verify "hammer virt-who-config deploy & fetch"