From d4079a663adfdf58deecf94f189ff23aa2ea5b69 Mon Sep 17 00:00:00 2001 From: yanpliu Date: Thu, 30 Nov 2023 09:31:36 -0500 Subject: [PATCH 1/4] fixture support for virt-who config cli : data_form deploy_type virtwho_config delete_host& manifest content move (#12619) * fixture support for virt-who config cli : data_form deploy_type virtwho_config & manifest content move * add fixture for virt-who config * Update virt-who config ui fixture data_form_ui & virtwho_config_ui deploy_type_ui * remove used import * Update virtwho_config.py update the format for import * Update taxonomy.py Revert the changes * Update test_libvirt_sca.py * Update test_libvirt.py * Update test_nutanix.py * Update test_nutanix_sca.py * Update test_esx_sca.py * fix pre-commit issue * use pytest.mark.usefixtures for delete_host * put delete_host to virtwho_config fixture --- conftest.py | 1 + pytest_fixtures/component/virtwho_config.py | 347 ++++++++++++++++++ tests/foreman/virtwho/api/test_esx.py | 2 +- tests/foreman/virtwho/api/test_kubevirt.py | 2 +- tests/foreman/virtwho/api/test_nutanix.py | 2 +- tests/foreman/virtwho/cli/test_esx.py | 177 +++++---- tests/foreman/virtwho/cli/test_esx_sca.py | 239 ++++++------ tests/foreman/virtwho/cli/test_hyperv.py | 61 +-- tests/foreman/virtwho/cli/test_hyperv_sca.py | 62 +--- tests/foreman/virtwho/cli/test_kubevirt.py | 59 +-- .../foreman/virtwho/cli/test_kubevirt_sca.py | 59 +-- tests/foreman/virtwho/cli/test_libvirt.py | 60 +-- tests/foreman/virtwho/cli/test_libvirt_sca.py | 60 +-- tests/foreman/virtwho/cli/test_nutanix.py | 118 +++--- tests/foreman/virtwho/cli/test_nutanix_sca.py | 93 ++--- tests/foreman/virtwho/ui/test_esx.py | 2 +- tests/foreman/virtwho/ui/test_esx_sca.py | 2 +- 17 files changed, 680 insertions(+), 666 deletions(-) create mode 100644 pytest_fixtures/component/virtwho_config.py diff --git a/conftest.py b/conftest.py index 4b8575813ee..abb8d33b4cd 100644 --- a/conftest.py +++ b/conftest.py @@ -65,6 +65,7 @@ 'pytest_fixtures.component.templatesync', 'pytest_fixtures.component.user', 'pytest_fixtures.component.user_role', + 'pytest_fixtures.component.virtwho_config', # upgrade 'pytest_plugins.upgrade.scenario_workers', ] diff --git a/pytest_fixtures/component/virtwho_config.py b/pytest_fixtures/component/virtwho_config.py new file mode 100644 index 00000000000..fc7a262e802 --- /dev/null +++ b/pytest_fixtures/component/virtwho_config.py @@ -0,0 +1,347 @@ +import pytest + +from robottelo.config import settings +from robottelo.utils.datafactory import gen_string +from robottelo.utils.virtwho import ( + deploy_configure_by_command, + deploy_configure_by_script, + get_configure_command, + get_guest_info, +) + +LOGGEDOUT = 'Logged out.' + + +@pytest.fixture +def org_module(request, default_org, module_sca_manifest_org): + if 'sca' in request.module.__name__.split('.')[-1]: + org_module = module_sca_manifest_org + else: + org_module = default_org + return org_module + + +@pytest.fixture +def org_session(request, session, session_sca): + if 'sca' in request.module.__name__.split('.')[-1]: + org_session = session_sca + else: + org_session = session + return org_session + + +@pytest.fixture +def form_data_cli(request, target_sat, org_module): + hypervisor_type = request.module.__name__.split('.')[-1].split('_', 1)[-1] + if 'esx' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor-id': 'hostname', + 'hypervisor-type': settings.virtwho.esx.hypervisor_type, + 'hypervisor-server': settings.virtwho.esx.hypervisor_server, + 'organization-id': org_module.id, + 'filtering-mode': 'none', + 'satellite-url': target_sat.hostname, + 'hypervisor-username': settings.virtwho.esx.hypervisor_username, + 'hypervisor-password': settings.virtwho.esx.hypervisor_password, + } + elif 'hyperv' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor-id': 'hostname', + 'hypervisor-type': settings.virtwho.hyperv.hypervisor_type, + 'hypervisor-server': settings.virtwho.hyperv.hypervisor_server, + 'organization-id': org_module.id, + 'filtering-mode': 'none', + 'satellite-url': target_sat.hostname, + 'hypervisor-username': settings.virtwho.hyperv.hypervisor_username, + 'hypervisor-password': settings.virtwho.hyperv.hypervisor_password, + } + elif 'kubevirt' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor-id': 'hostname', + 'hypervisor-type': settings.virtwho.kubevirt.hypervisor_type, + 'organization-id': org_module.id, + 'filtering-mode': 'none', + 'satellite-url': target_sat.hostname, + 'kubeconfig-path': settings.virtwho.kubevirt.hypervisor_config_file, + } + elif 'libvirt' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor-id': 'hostname', + 'hypervisor-type': settings.virtwho.libvirt.hypervisor_type, + 'hypervisor-server': settings.virtwho.libvirt.hypervisor_server, + 'organization-id': org_module.id, + 'filtering-mode': 'none', + 'satellite-url': target_sat.hostname, + 'hypervisor-username': settings.virtwho.libvirt.hypervisor_username, + } + elif 'nutanix' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor-id': 'hostname', + 'hypervisor-type': settings.virtwho.ahv.hypervisor_type, + 'hypervisor-server': settings.virtwho.ahv.hypervisor_server, + 'organization-id': org_module.id, + 'filtering-mode': 'none', + 'satellite-url': target_sat.hostname, + 'hypervisor-username': settings.virtwho.ahv.hypervisor_username, + 'hypervisor-password': settings.virtwho.ahv.hypervisor_password, + 'prism-flavor': settings.virtwho.ahv.prism_flavor, + 'ahv-internal-debug': 'false', + } + return form + + +@pytest.fixture +def form_data_api(request, target_sat, org_module): + hypervisor_type = request.module.__name__.split('.')[-1].split('_', 1)[-1] + if 'esx' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.esx.hypervisor_type, + 'hypervisor_server': settings.virtwho.esx.hypervisor_server, + 'organization_id': org_module.id, + 'filtering_mode': 'none', + 'satellite_url': target_sat.hostname, + 'hypervisor_username': settings.virtwho.esx.hypervisor_username, + 'hypervisor_password': settings.virtwho.esx.hypervisor_password, + } + elif 'hyperv' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.hyperv.hypervisor_type, + 'hypervisor_server': settings.virtwho.hyperv.hypervisor_server, + 'organization_id': org_module.id, + 'filtering_mode': 'none', + 'satellite_url': target_sat.hostname, + 'hypervisor_username': settings.virtwho.hyperv.hypervisor_username, + 'hypervisor_password': settings.virtwho.hyperv.hypervisor_password, + } + elif 'kubevirt' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.kubevirt.hypervisor_type, + 'organization_id': org_module.id, + 'filtering_mode': 'none', + 'satellite_url': target_sat.hostname, + 'kubeconfig_path': settings.virtwho.kubevirt.hypervisor_config_file, + } + elif 'libvirt' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.libvirt.hypervisor_type, + 'hypervisor_server': settings.virtwho.libvirt.hypervisor_server, + 'organization_id': org_module.id, + 'filtering_mode': 'none', + 'satellite_url': target_sat.hostname, + 'hypervisor_username': settings.virtwho.libvirt.hypervisor_username, + } + elif 'nutanix' in hypervisor_type: + form = { + 'name': gen_string('alpha'), + 'debug': 1, + 'interval': '60', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.ahv.hypervisor_type, + 'hypervisor_server': settings.virtwho.ahv.hypervisor_server, + 'organization_id': org_module.id, + 'filtering_mode': 'none', + 'satellite_url': target_sat.hostname, + 'hypervisor_username': settings.virtwho.ahv.hypervisor_username, + 'hypervisor_password': settings.virtwho.ahv.hypervisor_password, + 'prism_flavor': settings.virtwho.ahv.prism_flavor, + 'ahv_internal_debug': 'false', + } + return form + + +@pytest.fixture +def form_data_ui(request, target_sat, org_module): + hypervisor_type = request.module.__name__.split('.')[-1].split('_', 1)[-1] + if 'esx' in hypervisor_type: + form = { + 'debug': True, + 'interval': 'Every hour', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.esx.hypervisor_type, + 'hypervisor_content.server': settings.virtwho.esx.hypervisor_server, + 'hypervisor_content.username': settings.virtwho.esx.hypervisor_username, + 'hypervisor_content.password': settings.virtwho.esx.hypervisor_password, + } + elif 'hyperv' in hypervisor_type: + form = { + 'debug': True, + 'interval': 'Every hour', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.hyperv.hypervisor_type, + 'hypervisor_content.server': settings.virtwho.hyperv.hypervisor_server, + 'hypervisor_content.username': settings.virtwho.hyperv.hypervisor_username, + 'hypervisor_content.password': settings.virtwho.hyperv.hypervisor_password, + } + elif 'kubevirt' in hypervisor_type: + form = { + 'debug': True, + 'interval': 'Every hour', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.kubevirt.hypervisor_type, + 'hypervisor_content.kubeconfig': settings.virtwho.kubevirt.hypervisor_config_file, + } + elif 'libvirt' in hypervisor_type: + form = { + 'debug': True, + 'interval': 'Every hour', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.libvirt.hypervisor_type, + 'hypervisor_content.server': settings.virtwho.libvirt.hypervisor_server, + 'hypervisor_content.username': settings.virtwho.libvirt.hypervisor_username, + } + elif 'nutanix' in hypervisor_type: + form = { + 'debug': True, + 'interval': 'Every hour', + 'hypervisor_id': 'hostname', + 'hypervisor_type': settings.virtwho.ahv.hypervisor_type, + 'hypervisor_content.server': settings.virtwho.ahv.hypervisor_server, + 'hypervisor_content.username': settings.virtwho.ahv.hypervisor_username, + 'hypervisor_content.password': settings.virtwho.ahv.hypervisor_password, + 'hypervisor_content.prism_flavor': "Prism Element", + 'ahv_internal_debug': False, + } + return form + + +@pytest.fixture +def virtwho_config_cli(form_data_cli, target_sat): + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)['general-information'] + yield virtwho_config_cli + target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config_cli['name']}) + assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data_cli['name'])) + + +@pytest.fixture +def virtwho_config_api(form_data_api, target_sat): + virtwho_config_api = target_sat.api.VirtWhoConfig(**form_data_api).create() + yield virtwho_config_api + virtwho_config_api.delete() + assert not target_sat.api.VirtWhoConfig().search( + query={'search': f"name={form_data_api['name']}"} + ) + + +@pytest.fixture +def virtwho_config_ui(form_data_ui, target_sat, org_session): + name = gen_string('alpha') + form_data_ui['name'] = name + with org_session: + org_session.virtwho_configure.create(form_data_ui) + yield virtwho_config_ui + org_session.virtwho_configure.delete(name) + assert not org_session.virtwho_configure.search(name) + + +@pytest.fixture +def deploy_type_cli( + request, + org_module, + form_data_cli, + virtwho_config_cli, + target_sat, +): + 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: + 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 + ) + return hypervisor_name, guest_name + + +@pytest.fixture +def deploy_type_api( + request, + org_module, + form_data_api, + virtwho_config_api, + target_sat, +): + deploy_type = request.param.lower() + assert virtwho_config_api.status == 'unknown' + if "id" in deploy_type: + command = get_configure_command(virtwho_config_api.id, org_module.name) + hypervisor_name, guest_name = deploy_configure_by_command( + command, form_data_api['hypervisor_type'], debug=True, org=org_module.label + ) + elif "script" in deploy_type: + script = virtwho_config_api.deploy_script() + hypervisor_name, guest_name = deploy_configure_by_script( + script['virt_who_config_script'], + form_data_api['hypervisor_type'], + debug=True, + org=org_module.label, + ) + return hypervisor_name, guest_name + + +@pytest.fixture +def deploy_type_ui( + request, + org_module, + form_data_ui, + org_session, + virtwho_config_ui, + target_sat, +): + deploy_type = request.param.lower() + values = org_session.virtwho_configure.read(form_data_ui['name']) + if "id" in deploy_type: + command = values['deploy']['command'] + hypervisor_name, guest_name = deploy_configure_by_command( + command, form_data_ui['hypervisor_type'], debug=True, org=org_module.label + ) + elif "script" in deploy_type: + script = values['deploy']['script'] + hypervisor_name, guest_name = deploy_configure_by_script( + script, form_data_ui['hypervisor_type'], debug=True, org=org_module.label + ) + return hypervisor_name, guest_name + + +@pytest.fixture +def delete_host(form_data_api, target_sat): + guest_name, _ = get_guest_info(form_data_api['hypervisor_type']) + results = target_sat.api.Host().search(query={'search': guest_name}) + if results: + target_sat.api.Host(id=results[0].read_json()['id']).delete() diff --git a/tests/foreman/virtwho/api/test_esx.py b/tests/foreman/virtwho/api/test_esx.py index e7544047d7e..1eda85fde0b 100644 --- a/tests/foreman/virtwho/api/test_esx.py +++ b/tests/foreman/virtwho/api/test_esx.py @@ -30,7 +30,7 @@ ) -@pytest.mark.delete_host +@pytest.mark.usefixtures('delete_host') class TestVirtWhoConfigforEsx: @pytest.mark.tier2 @pytest.mark.parametrize('deploy_type_api', ['id', 'script'], indirect=True) diff --git a/tests/foreman/virtwho/api/test_kubevirt.py b/tests/foreman/virtwho/api/test_kubevirt.py index 88292e772db..b1bfe96a34b 100644 --- a/tests/foreman/virtwho/api/test_kubevirt.py +++ b/tests/foreman/virtwho/api/test_kubevirt.py @@ -27,7 +27,7 @@ ) -@pytest.mark.delete_host +@pytest.mark.usefixtures('delete_host') class TestVirtWhoConfigforKubevirt: @pytest.mark.tier2 @pytest.mark.parametrize('deploy_type_api', ['id', 'script'], indirect=True) diff --git a/tests/foreman/virtwho/api/test_nutanix.py b/tests/foreman/virtwho/api/test_nutanix.py index ae2726cf610..c065f164a5a 100644 --- a/tests/foreman/virtwho/api/test_nutanix.py +++ b/tests/foreman/virtwho/api/test_nutanix.py @@ -30,7 +30,7 @@ ) -@pytest.mark.delete_host +@pytest.mark.usefixtures('delete_host') class TestVirtWhoConfigforNutanix: @pytest.mark.tier2 @pytest.mark.parametrize('deploy_type_api', ['id', 'script'], indirect=True) diff --git a/tests/foreman/virtwho/cli/test_esx.py b/tests/foreman/virtwho/cli/test_esx.py index 60b38821919..b8e110af4f4 100644 --- a/tests/foreman/virtwho/cli/test_esx.py +++ b/tests/foreman/virtwho/cli/test_esx.py @@ -28,7 +28,6 @@ create_http_proxy, deploy_configure_by_command, deploy_configure_by_command_check, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, @@ -37,37 +36,11 @@ ) -@pytest.fixture -def form_data(target_sat, default_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.esx.hypervisor_type, - 'hypervisor-server': settings.virtwho.esx.hypervisor_server, - 'organization-id': default_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.esx.hypervisor_username, - 'hypervisor-password': settings.virtwho.esx.hypervisor_password, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforEsx: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, default_org, form_data, virtwho_config, target_sat, deploy_type + self, default_org, target_sat, virtwho_config_cli, deploy_type_cli ): """Verify " hammer virt-who-config deploy" @@ -79,20 +52,9 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], default_org.name) - hypervisor_name, guest_name = deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - hypervisor_name, guest_name = deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + hypervisor_name, guest_name = deploy_type_cli + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @@ -123,7 +85,7 @@ def test_positive_deploy_configure_by_id_script( assert result.strip() == 'Subscription attached to the host successfully.' @pytest.mark.tier2 - def test_positive_debug_option(self, default_org, form_data, target_sat): + def test_positive_debug_option(self, default_org, form_data_cli, target_sat): """Verify debug option by hammer virt-who-config update" :id: c98bc518-828c-49ba-a644-542db3190263 @@ -134,8 +96,8 @@ def test_positive_debug_option(self, default_org, form_data, target_sat): :CaseImportance: Medium """ - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - assert virtwho_config['name'] == form_data['name'] + virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data_cli)['general-information'] + assert virtwho_config['name'] == form_data_cli['name'] new_name = gen_string('alphanumeric') target_sat.cli.VirtWhoConfig.update({'id': virtwho_config['id'], 'new-name': new_name}) virt_who_instance_name = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ @@ -147,12 +109,14 @@ def test_positive_debug_option(self, default_org, form_data, target_sat): target_sat.cli.VirtWhoConfig.update({'id': virtwho_config['id'], 'debug': key}) command = get_configure_command(virtwho_config['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=default_org.label + command, form_data_cli['hypervisor-type'], org=default_org.label ) assert get_configure_option('debug', ETC_VIRTWHO_CONFIG) == value @pytest.mark.tier2 - def test_positive_interval_option(self, default_org, form_data, virtwho_config, target_sat): + def test_positive_interval_option( + self, default_org, form_data_cli, virtwho_config_cli, target_sat + ): """Verify interval option by hammer virt-who-config update" :id: 5d558bca-534c-4bd4-b401-a0c362033c57 @@ -174,16 +138,16 @@ def test_positive_interval_option(self, default_org, form_data, virtwho_config, '4320': '259200', } for key, value in sorted(options.items(), key=lambda item: int(item[0])): - target_sat.cli.VirtWhoConfig.update({'id': virtwho_config['id'], 'interval': key}) - command = get_configure_command(virtwho_config['id'], default_org.name) + target_sat.cli.VirtWhoConfig.update({'id': virtwho_config_cli['id'], 'interval': key}) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=default_org.label + command, form_data_cli['hypervisor-type'], org=default_org.label ) assert get_configure_option('interval', ETC_VIRTWHO_CONFIG) == value @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -199,19 +163,21 @@ def test_positive_hypervisor_id_option( values = ['uuid', 'hostname', 'hwuuid'] for value in values: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=default_org.label + command, form_data_cli['hypervisor-type'], org=default_org.label ) assert get_configure_option('hypervisor_id', config_file) == value @pytest.mark.tier2 - def test_positive_filter_option(self, default_org, form_data, virtwho_config, target_sat): + def test_positive_filter_option( + self, default_org, form_data_cli, virtwho_config_cli, target_sat + ): """Verify filter option by hammer virt-who-config update" :id: aaf45c5e-9504-47ce-8f25-b8073c2de036 @@ -223,34 +189,48 @@ def test_positive_filter_option(self, default_org, form_data, virtwho_config, ta :CaseImportance: Medium """ regex = '.*redhat.com' - whitelist = {'id': virtwho_config['id'], 'filtering-mode': 'whitelist', 'whitelist': regex} - blacklist = {'id': virtwho_config['id'], 'filtering-mode': 'blacklist', 'blacklist': regex} + whitelist = { + 'id': virtwho_config_cli['id'], + 'filtering-mode': 'whitelist', + 'whitelist': regex, + } + blacklist = { + 'id': virtwho_config_cli['id'], + 'filtering-mode': 'blacklist', + 'blacklist': regex, + } # esx support filter-host-parents and exclude-host-parents options whitelist['filter-host-parents'] = regex blacklist['exclude-host-parents'] = regex - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) # Update Whitelist and check the result target_sat.cli.VirtWhoConfig.update(whitelist) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['filtering'] == 'Whitelist' assert result['connection']['filtered-hosts'] == regex assert result['connection']['filter-host-parents'] == regex - deploy_configure_by_command(command, form_data['hypervisor-type'], org=default_org.label) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=default_org.label + ) assert get_configure_option('filter_hosts', config_file) == regex assert get_configure_option('filter_host_parents', config_file) == regex # Update Blacklist and check the result target_sat.cli.VirtWhoConfig.update(blacklist) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['filtering'] == 'Blacklist' assert result['connection']['excluded-hosts'] == regex assert result['connection']['exclude-host-parents'] == regex - deploy_configure_by_command(command, form_data['hypervisor-type'], org=default_org.label) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=default_org.label + ) assert get_configure_option('exclude_hosts', config_file) == regex assert get_configure_option('exclude_host_parents', config_file) == regex @pytest.mark.tier2 - def test_positive_proxy_option(self, default_org, form_data, virtwho_config, target_sat): + def test_positive_proxy_option( + self, default_org, form_data_cli, virtwho_config_cli, target_sat + ): """Verify http_proxy option by hammer virt-who-config update" :id: 409d108e-e814-482b-93ed-09db89d21dda @@ -267,13 +247,15 @@ def test_positive_proxy_option(self, default_org, form_data, virtwho_config, tar https_proxy_url, https_proxy_name, https_proxy_id = create_http_proxy(org=default_org) no_proxy = 'test.satellite.com' target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'http-proxy': https_proxy_name, 'no-proxy': no_proxy} + {'id': virtwho_config_cli['id'], 'http-proxy': https_proxy_name, 'no-proxy': no_proxy} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['http-proxy']['http-proxy-name'] == https_proxy_name assert result['connection']['ignore-proxy'] == no_proxy - command = get_configure_command(virtwho_config['id'], default_org.name) - deploy_configure_by_command(command, form_data['hypervisor-type'], org=default_org.label) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=default_org.label + ) assert get_configure_option('https_proxy', ETC_VIRTWHO_CONFIG) == https_proxy_url assert get_configure_option('no_proxy', ETC_VIRTWHO_CONFIG) == no_proxy @@ -282,13 +264,15 @@ def test_positive_proxy_option(self, default_org, form_data, virtwho_config, tar http_type='http', org=default_org ) target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'http-proxy-id': http_proxy_id} + {'id': virtwho_config_cli['id'], 'http-proxy-id': http_proxy_id} + ) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=default_org.label ) - deploy_configure_by_command(command, form_data['hypervisor-type'], org=default_org.label) assert get_configure_option('http_proxy', ETC_VIRTWHO_CONFIG) == http_proxy_url @pytest.mark.tier2 - def test_positive_rhsm_option(self, default_org, form_data, virtwho_config, target_sat): + def test_positive_rhsm_option(self, default_org, form_data_cli, virtwho_config_cli, target_sat): """Verify rhsm options in the configure file" :id: b5b93d4d-e780-41c0-9eaa-2407cc1dcc9b @@ -301,9 +285,11 @@ def test_positive_rhsm_option(self, default_org, form_data, virtwho_config, targ :CaseImportance: Medium """ - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) - deploy_configure_by_command(command, form_data['hypervisor-type'], org=default_org.label) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=default_org.label + ) rhsm_username = get_configure_option('rhsm_username', config_file) assert not target_sat.cli.User.exists(search=('login', rhsm_username)) assert get_configure_option('rhsm_hostname', config_file) == target_sat.hostname @@ -339,7 +325,7 @@ def test_positive_post_hypervisors(self, function_org, target_sat): @pytest.mark.tier2 def test_positive_foreman_packages_protection( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """foreman-protector should allow virt-who to be installed @@ -358,16 +344,21 @@ def test_positive_foreman_packages_protection( :BZ: 1783987 """ virtwho_package_locked() - command = get_configure_command(virtwho_config['id'], default_org.name) - deploy_configure_by_command(command, form_data['hypervisor-type'], org=default_org.label) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + command = get_configure_command(virtwho_config_cli['id'], default_org.name) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=default_org.label + ) + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ + 'general-information' + ]['status'] + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @pytest.mark.tier2 def test_positive_deploy_configure_hypervisor_password_with_special_characters( - self, default_org, form_data, target_sat + self, default_org, form_data_cli, target_sat ): """Verify " hammer virt-who-config deploy hypervisor with special characters" @@ -384,8 +375,8 @@ def test_positive_deploy_configure_hypervisor_password_with_special_characters( :customerscenario: true """ # check the hypervisor password contains single quotes - form_data['hypervisor-password'] = "Tes't" - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] + form_data_cli['hypervisor-password'] = "Tes't" + virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data_cli)['general-information'] assert virtwho_config['status'] == 'No Report Yet' command = get_configure_command(virtwho_config['id'], default_org.name) deploy_status = deploy_configure_by_command_check(command) @@ -397,11 +388,11 @@ def test_positive_deploy_configure_hypervisor_password_with_special_characters( == settings.virtwho.esx.hypervisor_username ) target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) + assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data_cli['name'])) # check the hypervisor password contains backtick - form_data['hypervisor-password'] = r"my\`password" - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] + form_data_cli['hypervisor-password'] = r"my\`password" + virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data_cli)['general-information'] assert virtwho_config['status'] == 'No Report Yet' command = get_configure_command(virtwho_config['id'], default_org.name) deploy_status = deploy_configure_by_command_check(command) @@ -414,7 +405,9 @@ def test_positive_deploy_configure_hypervisor_password_with_special_characters( ) @pytest.mark.tier2 - def test_positive_remove_env_option(self, default_org, form_data, virtwho_config, target_sat): + def test_positive_remove_env_option( + self, default_org, form_data_cli, virtwho_config_cli, target_sat + ): """remove option 'env=' from the virt-who configuration file and without any error :id: 509add77-dce7-4ba4-b9e5-2a5818c39731 @@ -431,17 +424,17 @@ def test_positive_remove_env_option(self, default_org, form_data, virtwho_config :customerscenario: true """ - command = get_configure_command(virtwho_config['id'], default_org.name) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label + command, form_data_cli['hypervisor-type'], debug=True, org=default_org.label ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' # Check the option "env=" should be removed from etc/virt-who.d/virt-who.conf option = "env" - config_file = get_configure_file(virtwho_config['id']) + config_file = get_configure_file(virtwho_config_cli['id']) env_error = ( f"option {{\'{option}\'}} is not exist or not be enabled in {{\'{config_file}\'}}" ) diff --git a/tests/foreman/virtwho/cli/test_esx_sca.py b/tests/foreman/virtwho/cli/test_esx_sca.py index fde692addeb..1a54ae9d569 100644 --- a/tests/foreman/virtwho/cli/test_esx_sca.py +++ b/tests/foreman/virtwho/cli/test_esx_sca.py @@ -26,7 +26,6 @@ create_http_proxy, deploy_configure_by_command, deploy_configure_by_command_check, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, @@ -35,38 +34,12 @@ ) -@pytest.fixture -def form_data(target_sat, module_sca_manifest_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.esx.hypervisor_type, - 'hypervisor-server': settings.virtwho.esx.hypervisor_server, - 'organization-id': module_sca_manifest_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.esx.hypervisor_username, - 'hypervisor-password': settings.virtwho.esx.hypervisor_password, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforEsx: @pytest.mark.tier2 @pytest.mark.upgrade - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat, deploy_type + self, module_sca_manifest_org, target_sat, virtwho_config_cli, deploy_type_cli ): """Verify "hammer virt-who-config deploy & fetch" @@ -80,27 +53,15 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) - deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -114,20 +75,20 @@ def test_positive_hypervisor_id_option( """ for value in ['uuid', 'hostname']: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('hypervisor_id', config_file) == value @pytest.mark.tier2 def test_positive_debug_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify debug option by hammer virt-who-config update" @@ -139,19 +100,19 @@ def test_positive_debug_option( :CaseImportance: Medium """ - assert virtwho_config['name'] == form_data['name'] + assert virtwho_config_cli['name'] == form_data_cli['name'] options = {'false': '0', 'no': '0', 'true': '1', 'yes': '1'} for key, value in options.items(): - target_sat.cli.VirtWhoConfig.update({'id': virtwho_config['id'], 'debug': key}) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + target_sat.cli.VirtWhoConfig.update({'id': virtwho_config_cli['id'], 'debug': key}) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('debug', ETC_VIRTWHO_CONFIG) == value @pytest.mark.tier2 def test_positive_name_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify debug option by hammer virt-who-config update" @@ -163,20 +124,20 @@ def test_positive_name_option( :CaseImportance: Medium """ - assert virtwho_config['name'] == form_data['name'] + assert virtwho_config_cli['name'] == form_data_cli['name'] new_name = gen_string('alphanumeric') - target_sat.cli.VirtWhoConfig.update({'id': virtwho_config['id'], 'new-name': new_name}) - virt_who_instance_name = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ - 'general-information' - ]['name'] + target_sat.cli.VirtWhoConfig.update({'id': virtwho_config_cli['id'], 'new-name': new_name}) + virt_who_instance_name = target_sat.cli.VirtWhoConfig.info( + {'id': virtwho_config_cli['id']} + )['general-information']['name'] assert virt_who_instance_name == new_name target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'new-name': form_data['name']} + {'id': virtwho_config_cli['id'], 'new-name': form_data_cli['name']} ) @pytest.mark.tier2 def test_positive_interval_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify interval option by hammer virt-who-config update" @@ -199,10 +160,10 @@ def test_positive_interval_option( '4320': '259200', } for key, value in options.items(): - target_sat.cli.VirtWhoConfig.update({'id': virtwho_config['id'], 'interval': key}) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + target_sat.cli.VirtWhoConfig.update({'id': virtwho_config_cli['id'], 'interval': key}) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('interval', ETC_VIRTWHO_CONFIG) == value @@ -212,8 +173,8 @@ def test_positive_interval_option( def test_positive_filter_option( self, module_sca_manifest_org, - form_data, - virtwho_config, + form_data_cli, + virtwho_config_cli, target_sat, filter_type, option_type, @@ -235,7 +196,7 @@ def test_positive_filter_option( # Update whitelist or blacklist and check the result if filter_type == "whitelist": whitelist = { - 'id': virtwho_config['id'], + 'id': virtwho_config_cli['id'], 'filtering-mode': 'whitelist', 'whitelist': regex, } @@ -244,17 +205,17 @@ def test_positive_filter_option( target_sat.cli.VirtWhoConfig.update(whitelist) elif filter_type == "blacklist": blacklist = { - 'id': virtwho_config['id'], + 'id': virtwho_config_cli['id'], 'filtering-mode': 'blacklist', 'blacklist': regex, } blacklist['exclude-host-parents'] = regex target_sat.cli.VirtWhoConfig.update(blacklist) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) if filter_type == "whitelist": assert result['connection']['filtering'] == 'Whitelist' @@ -270,14 +231,16 @@ def test_positive_filter_option( assert get_configure_option('exclude_host_parents', config_file) == regex elif option_type == "create": # Create a new virt-who config with filtering-mode whitelist or blacklist - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - form_data['filtering-mode'] = filter_type - form_data[filter_type] = regex - form_data['filter-host-parents'] = regex - form_data['exclude-host-parents'] = regex - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config_cli['name']}) + assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data_cli['name'])) + form_data_cli['filtering-mode'] = filter_type + form_data_cli[filter_type] = regex + form_data_cli['filter-host-parents'] = regex + form_data_cli['exclude-host-parents'] = regex + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[ + 'general-information' + ] + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) if filter_type == "whitelist": assert result['connection']['filtering'] == 'Whitelist' assert result['connection']['filtered-hosts'] == regex @@ -286,11 +249,11 @@ def test_positive_filter_option( assert result['connection']['filtering'] == 'Blacklist' assert result['connection']['excluded-hosts'] == regex assert result['connection']['exclude-host-parents'] == regex - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) - config_file = get_configure_file(virtwho_config['id']) + config_file = get_configure_file(virtwho_config_cli['id']) if filter_type == "whitelist": assert get_configure_option('filter_hosts', config_file) == regex assert get_configure_option('filter_host_parents', config_file) == regex @@ -300,7 +263,7 @@ def test_positive_filter_option( @pytest.mark.tier2 def test_positive_proxy_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify http_proxy option by hammer virt-who-config update" @@ -322,14 +285,14 @@ def test_positive_proxy_option( ) no_proxy = 'test.satellite.com' target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'http-proxy': https_proxy_name, 'no-proxy': no_proxy} + {'id': virtwho_config_cli['id'], 'http-proxy': https_proxy_name, 'no-proxy': no_proxy} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['http-proxy']['http-proxy-name'] == https_proxy_name assert result['connection']['ignore-proxy'] == no_proxy - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('https_proxy', ETC_VIRTWHO_CONFIG) == https_proxy_url assert get_configure_option('no_proxy', ETC_VIRTWHO_CONFIG) == no_proxy @@ -339,46 +302,50 @@ def test_positive_proxy_option( http_type='http', org=module_sca_manifest_org ) target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'http-proxy-id': http_proxy_id} + {'id': virtwho_config_cli['id'], 'http-proxy-id': http_proxy_id} ) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('http_proxy', ETC_VIRTWHO_CONFIG) == http_proxy_url - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) + target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config_cli['name']}) + assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data_cli['name'])) # Check the http proxy option, create virt-who config via http proxy id - form_data['http-proxy-id'] = http_proxy_id - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + form_data_cli['http-proxy-id'] = http_proxy_id + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[ + 'general-information' + ] + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('http_proxy', ETC_VIRTWHO_CONFIG) == http_proxy_url - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) + target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config_cli['name']}) + assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data_cli['name'])) # Check the https proxy option, create virt-who config via http proxy name no_proxy = 'test.satellite.com' - form_data['http-proxy'] = https_proxy_name - form_data['no-proxy'] = no_proxy - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + form_data_cli['http-proxy'] = https_proxy_name + form_data_cli['no-proxy'] = no_proxy + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[ + 'general-information' + ] + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['http-proxy']['http-proxy-name'] == https_proxy_name assert result['connection']['ignore-proxy'] == no_proxy - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) - get_configure_file(virtwho_config['id']) + get_configure_file(virtwho_config_cli['id']) assert get_configure_option('https_proxy', ETC_VIRTWHO_CONFIG) == https_proxy_url assert get_configure_option('no_proxy', ETC_VIRTWHO_CONFIG) == no_proxy @pytest.mark.tier2 def test_positive_rhsm_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify rhsm options in the configure file" @@ -392,10 +359,10 @@ def test_positive_rhsm_option( :CaseImportance: Medium """ - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) rhsm_username = get_configure_option('rhsm_username', config_file) assert not target_sat.cli.User.exists(search=('login', rhsm_username)) @@ -432,7 +399,7 @@ def test_positive_post_hypervisors(self, function_org, target_sat): @pytest.mark.tier2 def test_positive_foreman_packages_protection( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """foreman-protector should allow virt-who to be installed @@ -451,18 +418,18 @@ def test_positive_foreman_packages_protection( :BZ: 1783987 """ virtwho_package_locked() - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @pytest.mark.tier2 def test_positive_deploy_configure_hypervisor_password_with_special_characters( - self, module_sca_manifest_org, form_data, target_sat + self, module_sca_manifest_org, form_data_cli, target_sat ): """Verify "hammer virt-who-config deploy hypervisor with special characters" @@ -479,40 +446,44 @@ def test_positive_deploy_configure_hypervisor_password_with_special_characters( :customerscenario: true """ # check the hypervisor password contains single quotes - form_data['hypervisor-password'] = "Tes't" - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - assert virtwho_config['status'] == 'No Report Yet' - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + form_data_cli['hypervisor-password'] = "Tes't" + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[ + 'general-information' + ] + assert virtwho_config_cli['status'] == 'No Report Yet' + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_status = deploy_configure_by_command_check(command) assert deploy_status == 'Finished successfully' - config_file = get_configure_file(virtwho_config['id']) + config_file = get_configure_file(virtwho_config_cli['id']) assert get_configure_option('rhsm_hostname', config_file) == target_sat.hostname assert ( get_configure_option('username', config_file) == settings.virtwho.esx.hypervisor_username ) - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) + target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config_cli['name']}) + assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data_cli['name'])) # check the hypervisor password contains backtick - form_data['hypervisor-password'] = r"my\`password" - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - assert virtwho_config['status'] == 'No Report Yet' - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + form_data_cli['hypervisor-password'] = r"my\`password" + virtwho_config_cli = target_sat.cli.VirtWhoConfig.create(form_data_cli)[ + 'general-information' + ] + assert virtwho_config_cli['status'] == 'No Report Yet' + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_status = deploy_configure_by_command_check(command) assert deploy_status == 'Finished successfully' - config_file = get_configure_file(virtwho_config['id']) + config_file = get_configure_file(virtwho_config_cli['id']) assert get_configure_option('rhsm_hostname', config_file) == target_sat.hostname assert ( get_configure_option('username', config_file) == settings.virtwho.esx.hypervisor_username ) - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) + target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config_cli['name']}) + assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data_cli['name'])) @pytest.mark.tier2 def test_positive_remove_env_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """remove option 'env=' from the virt-who configuration file and without any error @@ -530,17 +501,17 @@ def test_positive_remove_env_option( :customerscenario: true """ - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], debug=True, org=module_sca_manifest_org.label ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' # Check the option "env=" should be removed from etc/virt-who.d/virt-who.conf option = "env" - config_file = get_configure_file(virtwho_config['id']) + config_file = get_configure_file(virtwho_config_cli['id']) env_error = ( f"option {{\'{option}\'}} is not exist or not be enabled in {{\'{config_file}\'}}" ) diff --git a/tests/foreman/virtwho/cli/test_hyperv.py b/tests/foreman/virtwho/cli/test_hyperv.py index 35e90d61eb1..ffc421506f0 100644 --- a/tests/foreman/virtwho/cli/test_hyperv.py +++ b/tests/foreman/virtwho/cli/test_hyperv.py @@ -16,50 +16,22 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest from robottelo.config import settings from robottelo.utils.virtwho import ( deploy_configure_by_command, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, ) -@pytest.fixture -def form_data(target_sat, default_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.hyperv.hypervisor_type, - 'hypervisor-server': settings.virtwho.hyperv.hypervisor_server, - 'organization-id': default_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.hyperv.hypervisor_username, - 'hypervisor-password': settings.virtwho.hyperv.hypervisor_password, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforHyperv: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, default_org, form_data, virtwho_config, target_sat, deploy_type + self, default_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify " hammer virt-who-config deploy & fetch" @@ -73,20 +45,9 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], default_org.name) - hypervisor_name, guest_name = deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - hypervisor_name, guest_name = deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + hypervisor_name, guest_name = deploy_type_cli + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @@ -112,7 +73,7 @@ def test_positive_deploy_configure_by_id_script( @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -127,13 +88,13 @@ def test_positive_hypervisor_id_option( values = ['uuid', 'hostname'] for value in values: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=default_org.label + command, form_data_cli['hypervisor-type'], org=default_org.label ) assert get_configure_option('hypervisor_id', config_file) == value diff --git a/tests/foreman/virtwho/cli/test_hyperv_sca.py b/tests/foreman/virtwho/cli/test_hyperv_sca.py index 6d60e285c9d..4b2725c5432 100644 --- a/tests/foreman/virtwho/cli/test_hyperv_sca.py +++ b/tests/foreman/virtwho/cli/test_hyperv_sca.py @@ -16,50 +16,21 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest -from robottelo.config import settings from robottelo.utils.virtwho import ( deploy_configure_by_command, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, ) -@pytest.fixture -def form_data(target_sat, module_sca_manifest_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.hyperv.hypervisor_type, - 'hypervisor-server': settings.virtwho.hyperv.hypervisor_server, - 'organization-id': module_sca_manifest_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.hyperv.hypervisor_username, - 'hypervisor-password': settings.virtwho.hyperv.hypervisor_password, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforHyperv: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat, deploy_type + self, module_sca_manifest_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify " hammer virt-who-config deploy & fetch" @@ -73,27 +44,16 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) - deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' + @pytest.mark.tier2 @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -107,13 +67,13 @@ def test_positive_hypervisor_id_option( """ for value in ['uuid', 'hostname']: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('hypervisor_id', config_file) == value diff --git a/tests/foreman/virtwho/cli/test_kubevirt.py b/tests/foreman/virtwho/cli/test_kubevirt.py index e003294de87..4b8a5c57f06 100644 --- a/tests/foreman/virtwho/cli/test_kubevirt.py +++ b/tests/foreman/virtwho/cli/test_kubevirt.py @@ -16,48 +16,22 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest from robottelo.config import settings from robottelo.utils.virtwho import ( deploy_configure_by_command, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, ) -@pytest.fixture -def form_data(target_sat, default_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.kubevirt.hypervisor_type, - 'organization-id': default_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'kubeconfig-path': settings.virtwho.kubevirt.hypervisor_config_file, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforKubevirt: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, default_org, form_data, virtwho_config, target_sat, deploy_type + self, default_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify " hammer virt-who-config deploy & fetch" @@ -71,20 +45,9 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], default_org.name) - hypervisor_name, guest_name = deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - hypervisor_name, guest_name = deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + hypervisor_name, guest_name = deploy_type_cli + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @@ -110,7 +73,7 @@ def test_positive_deploy_configure_by_id_script( @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -125,13 +88,13 @@ def test_positive_hypervisor_id_option( values = ['uuid', 'hostname'] for value in values: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=default_org.label + command, form_data_cli['hypervisor-type'], org=default_org.label ) assert get_configure_option('hypervisor_id', config_file) == value diff --git a/tests/foreman/virtwho/cli/test_kubevirt_sca.py b/tests/foreman/virtwho/cli/test_kubevirt_sca.py index 9746d80c34b..2d7fd4fca97 100644 --- a/tests/foreman/virtwho/cli/test_kubevirt_sca.py +++ b/tests/foreman/virtwho/cli/test_kubevirt_sca.py @@ -14,48 +14,21 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest -from robottelo.config import settings from robottelo.utils.virtwho import ( deploy_configure_by_command, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, ) -@pytest.fixture -def form_data(target_sat, module_sca_manifest_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.kubevirt.hypervisor_type, - 'organization-id': module_sca_manifest_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'kubeconfig-path': settings.virtwho.kubevirt.hypervisor_config_file, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforKubevirt: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat, deploy_type + self, module_sca_manifest_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify " hammer virt-who-config deploy & fetch" @@ -69,27 +42,15 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) - deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -102,13 +63,13 @@ def test_positive_hypervisor_id_option( """ for value in ['uuid', 'hostname']: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('hypervisor_id', config_file) == value diff --git a/tests/foreman/virtwho/cli/test_libvirt.py b/tests/foreman/virtwho/cli/test_libvirt.py index 5cd4280e4f3..5c9cfda2dbd 100644 --- a/tests/foreman/virtwho/cli/test_libvirt.py +++ b/tests/foreman/virtwho/cli/test_libvirt.py @@ -16,49 +16,22 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest from robottelo.config import settings from robottelo.utils.virtwho import ( deploy_configure_by_command, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, ) -@pytest.fixture -def form_data(target_sat, default_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.libvirt.hypervisor_type, - 'hypervisor-server': settings.virtwho.libvirt.hypervisor_server, - 'organization-id': default_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.libvirt.hypervisor_username, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforLibvirt: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, default_org, form_data, virtwho_config, target_sat, deploy_type + self, default_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify " hammer virt-who-config deploy & fetch" @@ -72,20 +45,9 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], default_org.name) - hypervisor_name, guest_name = deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - hypervisor_name, guest_name = deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + hypervisor_name, guest_name = deploy_type_cli + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @@ -111,7 +73,7 @@ def test_positive_deploy_configure_by_id_script( @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -126,13 +88,13 @@ def test_positive_hypervisor_id_option( values = ['uuid', 'hostname'] for value in values: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=default_org.label + command, form_data_cli['hypervisor-type'], org=default_org.label ) assert get_configure_option('hypervisor_id', config_file) == value diff --git a/tests/foreman/virtwho/cli/test_libvirt_sca.py b/tests/foreman/virtwho/cli/test_libvirt_sca.py index b1a359c0095..3532bb7983c 100644 --- a/tests/foreman/virtwho/cli/test_libvirt_sca.py +++ b/tests/foreman/virtwho/cli/test_libvirt_sca.py @@ -14,49 +14,21 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest -from robottelo.config import settings from robottelo.utils.virtwho import ( deploy_configure_by_command, - deploy_configure_by_script, get_configure_command, get_configure_file, get_configure_option, ) -@pytest.fixture -def form_data(target_sat, module_sca_manifest_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.libvirt.hypervisor_type, - 'hypervisor-server': settings.virtwho.libvirt.hypervisor_server, - 'organization-id': module_sca_manifest_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.libvirt.hypervisor_username, - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforLibvirt: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat, deploy_type + self, module_sca_manifest_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify " hammer virt-who-config deploy & fetch" @@ -70,27 +42,15 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) - deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -104,13 +64,13 @@ def test_positive_hypervisor_id_option( """ for value in ['uuid', 'hostname']: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('hypervisor_id', config_file) == value diff --git a/tests/foreman/virtwho/cli/test_nutanix.py b/tests/foreman/virtwho/cli/test_nutanix.py index ed9ad20ce49..052101f792f 100644 --- a/tests/foreman/virtwho/cli/test_nutanix.py +++ b/tests/foreman/virtwho/cli/test_nutanix.py @@ -16,7 +16,6 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest from robottelo.config import settings @@ -31,39 +30,11 @@ ) -@pytest.fixture -def form_data(target_sat, default_org): - form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.ahv.hypervisor_type, - 'hypervisor-server': settings.virtwho.ahv.hypervisor_server, - 'organization-id': default_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.ahv.hypervisor_username, - 'hypervisor-password': settings.virtwho.ahv.hypervisor_password, - 'prism-flavor': settings.virtwho.ahv.prism_flavor, - 'ahv-internal-debug': 'false', - } - return form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforNutanix: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, default_org, form_data, virtwho_config, target_sat, deploy_type + self, default_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify "hammer virt-who-config deploy & fetch" @@ -77,20 +48,9 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], default_org.name) - hypervisor_name, guest_name = deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - hypervisor_name, guest_name = deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=default_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + hypervisor_name, guest_name = deploy_type_cli + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @@ -116,7 +76,7 @@ def test_positive_deploy_configure_by_id_script( @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -131,21 +91,21 @@ def test_positive_hypervisor_id_option( values = ['uuid', 'hostname'] for value in values: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=default_org.label + command, form_data_cli['hypervisor-type'], org=default_org.label ) assert get_configure_option('hypervisor_id', config_file) == value @pytest.mark.tier2 @pytest.mark.parametrize('deploy_type', ['id', 'script']) def test_positive_prism_central_deploy_configure_by_id_script( - self, default_org, form_data, target_sat, deploy_type + self, default_org, form_data_cli, target_sat, deploy_type ): """Verify "hammer virt-who-config deploy" on nutanix prism central mode @@ -159,20 +119,20 @@ def test_positive_prism_central_deploy_configure_by_id_script( :CaseImportance: High """ - form_data['prism-flavor'] = "central" - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] + form_data_cli['prism-flavor'] = "central" + virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data_cli)['general-information'] assert virtwho_config['status'] == 'No Report Yet' if deploy_type == "id": command = get_configure_command(virtwho_config['id'], default_org.name) hypervisor_name, guest_name = deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label + command, form_data_cli['hypervisor-type'], debug=True, org=default_org.label ) elif deploy_type == "script": script = target_sat.cli.VirtWhoConfig.fetch( {'id': virtwho_config['id']}, output_format='base' ) hypervisor_name, guest_name = deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=default_org.label + script, form_data_cli['hypervisor-type'], debug=True, org=default_org.label ) # Check the option "prism_central=true" should be set in etc/virt-who.d/virt-who.conf config_file = get_configure_file(virtwho_config['id']) @@ -203,7 +163,7 @@ def test_positive_prism_central_deploy_configure_by_id_script( @pytest.mark.tier2 def test_positive_prism_central_prism_central_option( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify prism_central option by hammer virt-who-config update" @@ -217,19 +177,23 @@ def test_positive_prism_central_prism_central_option( """ value = 'central' result = target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'prism-flavor': value} + {'id': virtwho_config_cli['id'], 'prism-flavor': value} + ) + assert ( + result[0]['message'] == f"Virt Who configuration [{virtwho_config_cli['name']}] updated" ) - assert result[0]['message'] == f"Virt Who configuration [{virtwho_config['name']}] updated" - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['general-information']['ahv-prism-flavor'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], default_org.name) - deploy_configure_by_command(command, form_data['hypervisor-type'], org=default_org.label) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) + deploy_configure_by_command( + command, form_data_cli['hypervisor-type'], org=default_org.label + ) assert get_configure_option("prism_central", config_file) == 'true' @pytest.mark.tier2 def test_positive_ahv_internal_debug_option( - self, default_org, form_data, virtwho_config, target_sat + self, default_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify ahv_internal_debug option by hammer virt-who-config" @@ -250,14 +214,14 @@ def test_positive_ahv_internal_debug_option( :BZ: 2141719 :customerscenario: true """ - command = get_configure_command(virtwho_config['id'], default_org.name) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label + command, form_data_cli['hypervisor-type'], debug=True, org=default_org.label ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['general-information']['enable-ahv-debug'] == 'no' # ahv_internal_debug does not set in virt-who-config-X.conf - config_file = get_configure_file(virtwho_config['id']) + config_file = get_configure_file(virtwho_config_cli['id']) option = 'ahv_internal_debug' env_error = f"option {option} is not exist or not be enabled in {config_file}" with pytest.raises(Exception) as exc_info: # noqa: PT011 - TODO determine better exception @@ -270,18 +234,22 @@ def test_positive_ahv_internal_debug_option( # Update ahv_internal_debug option to true value = 'true' result = target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'ahv-internal-debug': value} + {'id': virtwho_config_cli['id'], 'ahv-internal-debug': value} ) - assert result[0]['message'] == f"Virt Who configuration [{virtwho_config['name']}] updated" - command = get_configure_command(virtwho_config['id'], default_org.name) + assert ( + result[0]['message'] == f"Virt Who configuration [{virtwho_config_cli['name']}] updated" + ) + command = get_configure_command(virtwho_config_cli['id'], default_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=default_org.label + command, form_data_cli['hypervisor-type'], debug=True, org=default_org.label + ) + assert ( + get_hypervisor_ahv_mapping(form_data_cli['hypervisor-type']) == 'Host UUID found for VM' ) - assert get_hypervisor_ahv_mapping(form_data['hypervisor-type']) == 'Host UUID found for VM' - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['general-information']['enable-ahv-debug'] == 'yes' # ahv_internal_debug bas been set to true in virt-who-config-X.conf - config_file = get_configure_file(virtwho_config['id']) + config_file = get_configure_file(virtwho_config_cli['id']) assert get_configure_option("ahv_internal_debug", config_file) == 'true' # check message does not exist in log file /var/log/rhsm/rhsm.log message = 'Value for "ahv_internal_debug" not set, using default: False' diff --git a/tests/foreman/virtwho/cli/test_nutanix_sca.py b/tests/foreman/virtwho/cli/test_nutanix_sca.py index 44876700c23..f41daa8d75c 100644 --- a/tests/foreman/virtwho/cli/test_nutanix_sca.py +++ b/tests/foreman/virtwho/cli/test_nutanix_sca.py @@ -16,10 +16,8 @@ :Upstream: No """ -from fauxfactory import gen_string import pytest -from robottelo.config import settings from robottelo.utils.virtwho import ( deploy_configure_by_command, deploy_configure_by_script, @@ -29,38 +27,11 @@ ) -@pytest.fixture -def form_data(target_sat, module_sca_manifest_org): - sca_form = { - 'name': gen_string('alpha'), - 'debug': 1, - 'interval': '60', - 'hypervisor-id': 'hostname', - 'hypervisor-type': settings.virtwho.ahv.hypervisor_type, - 'hypervisor-server': settings.virtwho.ahv.hypervisor_server, - 'organization-id': module_sca_manifest_org.id, - 'filtering-mode': 'none', - 'satellite-url': target_sat.hostname, - 'hypervisor-username': settings.virtwho.ahv.hypervisor_username, - 'hypervisor-password': settings.virtwho.ahv.hypervisor_password, - 'prism-flavor': settings.virtwho.ahv.prism_flavor, - } - return sca_form - - -@pytest.fixture -def virtwho_config(form_data, target_sat): - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] - yield virtwho_config - target_sat.cli.VirtWhoConfig.delete({'name': virtwho_config['name']}) - assert not target_sat.cli.VirtWhoConfig.exists(search=('name', form_data['name'])) - - class TestVirtWhoConfigforNutanix: @pytest.mark.tier2 - @pytest.mark.parametrize('deploy_type', ['id', 'script']) + @pytest.mark.parametrize('deploy_type_cli', ['id', 'script'], indirect=True) def test_positive_deploy_configure_by_id_script( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat, deploy_type + self, module_sca_manifest_org, virtwho_config_cli, target_sat, deploy_type_cli ): """Verify "hammer virt-who-config deploy & fetch" @@ -74,27 +45,15 @@ def test_positive_deploy_configure_by_id_script( :CaseImportance: High """ - assert virtwho_config['status'] == 'No Report Yet' - if deploy_type == "id": - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) - deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - elif deploy_type == "script": - script = target_sat.cli.VirtWhoConfig.fetch( - {'id': virtwho_config['id']}, output_format='base' - ) - deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label - ) - virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']})[ + assert virtwho_config_cli['status'] == 'No Report Yet' + virt_who_instance = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']})[ 'general-information' ]['status'] assert virt_who_instance == 'OK' @pytest.mark.tier2 def test_positive_hypervisor_id_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify hypervisor_id option by hammer virt-who-config update" @@ -108,21 +67,21 @@ def test_positive_hypervisor_id_option( """ for value in ['uuid', 'hostname']: target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'hypervisor-id': value} + {'id': virtwho_config_cli['id'], 'hypervisor-id': value} ) - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['connection']['hypervisor-id'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option('hypervisor_id', config_file) == value @pytest.mark.tier2 @pytest.mark.parametrize('deploy_type', ['id', 'script']) def test_positive_prism_central_deploy_configure_by_id_script( - self, module_sca_manifest_org, form_data, target_sat, deploy_type + self, module_sca_manifest_org, target_sat, form_data_cli, deploy_type ): """Verify "hammer virt-who-config deploy & fetch" on nutanix prism central mode @@ -137,20 +96,26 @@ def test_positive_prism_central_deploy_configure_by_id_script( :CaseImportance: High """ - form_data['prism-flavor'] = "central" - virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data)['general-information'] + form_data_cli['prism-flavor'] = "central" + virtwho_config = target_sat.cli.VirtWhoConfig.create(form_data_cli)['general-information'] assert virtwho_config['status'] == 'No Report Yet' if deploy_type == "id": command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label + command, + form_data_cli['hypervisor-type'], + debug=True, + org=module_sca_manifest_org.label, ) elif deploy_type == "script": script = target_sat.cli.VirtWhoConfig.fetch( {'id': virtwho_config['id']}, output_format='base' ) deploy_configure_by_script( - script, form_data['hypervisor-type'], debug=True, org=module_sca_manifest_org.label + script, + form_data_cli['hypervisor-type'], + debug=True, + org=module_sca_manifest_org.label, ) # Check the option "prism_central=true" should be set in etc/virt-who.d/virt-who.conf config_file = get_configure_file(virtwho_config['id']) @@ -162,7 +127,7 @@ def test_positive_prism_central_deploy_configure_by_id_script( @pytest.mark.tier2 def test_positive_prism_element_prism_central_option( - self, module_sca_manifest_org, form_data, virtwho_config, target_sat + self, module_sca_manifest_org, form_data_cli, virtwho_config_cli, target_sat ): """Verify prism_central option by hammer virt-who-config update" @@ -176,14 +141,16 @@ def test_positive_prism_element_prism_central_option( """ value = 'central' result = target_sat.cli.VirtWhoConfig.update( - {'id': virtwho_config['id'], 'prism-flavor': value} + {'id': virtwho_config_cli['id'], 'prism-flavor': value} ) - assert result[0]['message'] == f"Virt Who configuration [{virtwho_config['name']}] updated" - result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config['id']}) + assert ( + result[0]['message'] == f"Virt Who configuration [{virtwho_config_cli['name']}] updated" + ) + result = target_sat.cli.VirtWhoConfig.info({'id': virtwho_config_cli['id']}) assert result['general-information']['ahv-prism-flavor'] == value - config_file = get_configure_file(virtwho_config['id']) - command = get_configure_command(virtwho_config['id'], module_sca_manifest_org.name) + config_file = get_configure_file(virtwho_config_cli['id']) + command = get_configure_command(virtwho_config_cli['id'], module_sca_manifest_org.name) deploy_configure_by_command( - command, form_data['hypervisor-type'], org=module_sca_manifest_org.label + command, form_data_cli['hypervisor-type'], org=module_sca_manifest_org.label ) assert get_configure_option("prism_central", config_file) == 'true' diff --git a/tests/foreman/virtwho/ui/test_esx.py b/tests/foreman/virtwho/ui/test_esx.py index 75652da9bd6..7c669a62022 100644 --- a/tests/foreman/virtwho/ui/test_esx.py +++ b/tests/foreman/virtwho/ui/test_esx.py @@ -41,7 +41,7 @@ ) -@pytest.mark.delete_host +@pytest.mark.usefixtures('delete_host') class TestVirtwhoConfigforEsx: @pytest.mark.tier2 @pytest.mark.parametrize('deploy_type_ui', ['id', 'script'], indirect=True) diff --git a/tests/foreman/virtwho/ui/test_esx_sca.py b/tests/foreman/virtwho/ui/test_esx_sca.py index 63c4c55a16b..068b8c9c84c 100644 --- a/tests/foreman/virtwho/ui/test_esx_sca.py +++ b/tests/foreman/virtwho/ui/test_esx_sca.py @@ -38,7 +38,7 @@ ) -@pytest.mark.delete_host +@pytest.mark.usefixtures('delete_host') class TestVirtwhoConfigforEsx: @pytest.mark.tier2 @pytest.mark.upgrade From 40223b27328b11835d165d5d0aa66df5d8fa39ff Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Tue, 28 Nov 2023 15:47:25 +0100 Subject: [PATCH 2/4] Check that concurrency level is honored --- tests/foreman/cli/test_remoteexecution.py | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/foreman/cli/test_remoteexecution.py b/tests/foreman/cli/test_remoteexecution.py index aa376217dbe..e5c0df56783 100644 --- a/tests/foreman/cli/test_remoteexecution.py +++ b/tests/foreman/cli/test_remoteexecution.py @@ -749,6 +749,78 @@ def test_positive_run_concurrent_jobs(self, registered_hosts, target_sat): target_sat.cli.GlobalParameter().delete({'name': param_name}) assert len(target_sat.cli.GlobalParameter().list({'search': param_name})) == 0 + @pytest.mark.tier3 + @pytest.mark.no_containers + def test_positive_run_serial(self, registered_hosts, target_sat): + """Tests subtasks in a job run one by one when concurrency level set to 1 + + :id: 5ce39447-82d0-42df-81be-16ed3d67a2a4 + + :Setup: + 0. Create 2 hosts + + :Steps: + + 0. Run a bash command job with concurrency level 1 + + :expectedresults: First subtask should run immediately, second one after the first one finishes + + :CaseAutomation: Automated + + :CaseLevel: System + + :parametrized: yes + """ + hosts = registered_hosts + output_msgs = [] + template_file = f"/root/{gen_string('alpha')}.template" + target_sat.execute( + f"echo 'rm /root/test-<%= @host %>; echo $(date +%s) >> /root/test-<%= @host %>; sleep 120; echo $(date +%s) >> /root/test-<%= @host %>' > {template_file}" + ) + template = target_sat.cli.JobTemplate.create( + { + 'name': gen_string('alpha'), + 'file': template_file, + 'job-category': 'Commands', + 'provider-type': 'script', + } + ) + invocation = target_sat.cli_factory.job_invocation( + { + 'job-template': template['name'], + 'search-query': f'name ~ {hosts[0].hostname} or name ~ {hosts[1].hostname}', + 'concurrency-level': 1, + } + ) + for vm in hosts: + output_msgs.append( + 'host output from {}: {}'.format( + vm.hostname, + ' '.join( + target_sat.cli.JobInvocation.get_output( + {'id': invocation['id'], 'host': vm.hostname} + ) + ), + ) + ) + result = target_sat.cli.JobInvocation.info({'id': invocation['id']}) + assert result['success'] == '2', output_msgs + # assert for time diffs + file1 = hosts[0].execute('cat /root/test-$(hostname)').stdout + file2 = hosts[1].execute('cat /root/test-$(hostname)').stdout + file1_start, file1_end = map(int, file1.rstrip().split('\n')) + file2_start, file2_end = map(int, file2.rstrip().split('\n')) + if file1_start > file2_start: + file1_start, file1_end, file2_start, file2_end = ( + file2_start, + file2_end, + file1_start, + file1_end, + ) + assert file1_end - file1_start >= 120 + assert file2_end - file2_start >= 120 + assert file2_start >= file1_end # the jobs did NOT run concurrently + @pytest.mark.tier3 @pytest.mark.upgrade @pytest.mark.e2e From 594e37870f3f816821665b97a24572b7e395008a Mon Sep 17 00:00:00 2001 From: Vladimir Sedmik Date: Fri, 24 Nov 2023 15:29:59 +0100 Subject: [PATCH 3/4] Add coverage for BZ#2092039 and update few docstrings --- tests/foreman/cli/test_satellitesync.py | 131 +++++++++++++++++++----- 1 file changed, 105 insertions(+), 26 deletions(-) diff --git a/tests/foreman/cli/test_satellitesync.py b/tests/foreman/cli/test_satellitesync.py index b4b6c7bf21f..151f184433f 100644 --- a/tests/foreman/cli/test_satellitesync.py +++ b/tests/foreman/cli/test_satellitesync.py @@ -579,8 +579,6 @@ def test_positive_export_import_cv_end_to_end( 1. CV version custom contents has been exported to directory. 2. All The exported custom contents has been imported in org/satellite. - :CaseImportance: High - :CaseLevel: System :BZ: 1832858 @@ -772,8 +770,6 @@ def test_positive_export_import_filtered_cvv( 1. Filtered CV version custom contents has been exported to directory 2. Filtered exported custom contents has been imported in org/satellite - :CaseImportance: High - :CaseLevel: System """ exporting_cv_name = importing_cvv = gen_string('alpha') @@ -953,8 +949,6 @@ def test_positive_export_import_redhat_cv( :customerscenario: true - :CaseImportance: High - :CaseLevel: System """ # Create cv and publish @@ -1184,13 +1178,10 @@ def test_negative_import_invalid_path(self, module_org, module_target_sat): :id: 4cc69666-407f-4d66-b3d2-8fe2ed135a5f :steps: - - 1. Import a cv with a path that doesn't exist + 1. Import a CV with a path that doesn't exist. :expectedresults: - - 1. Error 'Unable to sync repositories, no library repository found' should be - displayed + 1. Error 'Unable to sync repositories, no library repository found' should be displayed. """ export_folder = gen_string('alpha') import_path = f'{PULP_IMPORT_DIR}{export_folder}' @@ -1233,7 +1224,6 @@ def test_postive_export_cv_with_mixed_content_repos( :BZ: 1726457 :customerscenario: true - """ content_view = target_sat.cli_factory.make_content_view( {'organization-id': function_org.id} @@ -1342,9 +1332,9 @@ def test_postive_export_import_cv_with_file_content( 1. Product with synced file-type repository. :steps: - 3. Create CV, add the file repo and publish. - 4. Export the CV and import it into another organization. - 5. Check the imported CV has files in it. + 1. Create CV, add the file repo and publish. + 2. Export the CV and import it into another organization. + 3. Check the imported CV has files in it. :expectedresults: 1. Imported CV should have the files present. @@ -1723,7 +1713,7 @@ def test_positive_import_content_for_disconnected_sat_with_existing_content( 1. Import should fail with correct message when existing CV has 'import-only' set False. 2. Import should succeed when existing CV has 'import-only' set True. - :bz: 2030101 + :BZ: 2030101 :customerscenario: true """ @@ -1903,14 +1893,13 @@ def test_positive_reimport_repo(self): :id: b3a71405-d8f0-4085-b728-8fc3513611c8 :steps: - 1. From upstream Export repo fully and import it in downstream. 2. In upstream delete some packages from repo. 3. Re-export the full repo. 4. In downstream, reimport the repo re-exported. - :expectedresults: Deleted packages from upstream are removed from - downstream. + :expectedresults: + 1. Deleted packages from upstream are removed from downstream. :CaseAutomation: NotAutomated @@ -1924,10 +1913,11 @@ def test_negative_export_repo_from_future_datetime(self): :id: 1e8bc352-198f-4d59-b437-1b184141fab4 - :steps: Export the repo incrementally from the future date time. + :steps: + 1. Export the repo incrementally from the future date time. - :expectedresults: Error is raised for attempting to export from future - datetime. + :expectedresults: + 1. Error is raised for attempting to export from future datetime. :CaseAutomation: NotAutomated @@ -1963,8 +1953,6 @@ def test_positive_export_import_incremental_yum_repo( in the importing organization and content counts match. 2. Incremental export and import succeeds, content counts match the updated counts. - :CaseAutomation: Automated - :CaseLevel: System """ export_cc = target_sat.cli.Repository.info({'id': function_synced_custom_repo.id})[ @@ -2022,6 +2010,97 @@ def test_positive_export_import_incremental_yum_repo( export_cc['packages'] = str(int(export_cc['packages']) + 1) assert import_repo['content-counts'] == export_cc, 'Import counts do not match the export.' + @pytest.mark.tier3 + @pytest.mark.parametrize( + 'function_synced_rhel_repo', + ['rhae2'], + indirect=True, + ) + def test_positive_export_import_mismatch_label( + self, + target_sat, + export_import_cleanup_function, + config_export_import_settings, + function_sca_manifest_org, + function_import_org_with_manifest, + function_synced_rhel_repo, + ): + """Export and import repo with mismatched label + + :id: eb2f3e8e-3ee6-4713-80ab-3811a098e079 + + :setup: + 1. Enabled and synced RH yum repository. + + :steps: + 1. Export and import a RH yum repo, verify it was imported. + 2. Export the repo again and change the repository label. + 3. Import the changed repository again, it should succeed without errors. + + :expectedresults: + 1. All exports and imports succeed. + + :CaseLevel: System + + :CaseImportance: Medium + + :BZ: 2092039 + + :customerscenario: true + """ + # Verify export directory is empty + assert target_sat.validate_pulp_filepath(function_sca_manifest_org, PULP_EXPORT_DIR) == '' + # Export the repository and check the export directory + export = target_sat.cli.ContentExport.completeRepository( + {'id': function_synced_rhel_repo['id']} + ) + assert '1.0' in target_sat.validate_pulp_filepath( + function_sca_manifest_org, PULP_EXPORT_DIR + ) + + # Run import and verify the product and repo is created in the importing org + import_path = target_sat.move_pulp_archive(function_sca_manifest_org, export['message']) + target_sat.cli.ContentImport.repository( + {'organization-id': function_import_org_with_manifest.id, 'path': import_path}, + timeout=300000, + ) + import_repo = target_sat.cli.Repository.info( + { + 'name': function_synced_rhel_repo['name'], + 'product': function_synced_rhel_repo['product']['name'], + 'organization-id': function_sca_manifest_org.id, + } + ) + assert import_repo + + # Export again and check the export directory + export = target_sat.cli.ContentExport.completeRepository( + {'id': function_synced_rhel_repo['id']} + ) + assert '2.0' in target_sat.validate_pulp_filepath( + function_sca_manifest_org, PULP_EXPORT_DIR + ) + + # Change the repo label in metadata.json and run the import again + import_path = target_sat.move_pulp_archive(function_sca_manifest_org, export['message']) + target_sat.execute( + f'''sed -i 's/"label":"{function_synced_rhel_repo['label']}"/''' + f'''"label":"{gen_string("alpha")}"/g' {import_path}/metadata.json''' + ) + target_sat.cli.ContentImport.repository( + {'organization-id': function_import_org_with_manifest.id, 'path': import_path}, + timeout=300000, + ) + + # Verify that both import tasks succeeded + tasks = target_sat.cli.Task.list_tasks( + {'search': f"Import Repository organization '{function_import_org_with_manifest.name}'"} + ) + assert len(tasks) == 2, f'Expected 2 import tasks in this Org but found {len(tasks)}' + assert all( + ['success' in task['result'] for task in tasks] + ), 'Not every import task succeeded' + @pytest.mark.stubbed @pytest.mark.tier3 @pytest.mark.upgrade @@ -2040,8 +2119,8 @@ def test_positive_install_package_from_imported_repos(self): 5. Attempt to install a package on a client from imported repo of downstream. - :expectedresults: The package is installed on client from imported repo - of downstream satellite. + :expectedresults: + 1. The package is installed on client from imported repo of downstream satellite. :CaseAutomation: NotAutomated From b0c9d57fa50477b2b533985c7bf959e5c721c241 Mon Sep 17 00:00:00 2001 From: Vladimir Sedmik Date: Wed, 29 Nov 2023 18:21:46 +0100 Subject: [PATCH 4/4] Use better timeout format --- tests/foreman/cli/test_satellitesync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/foreman/cli/test_satellitesync.py b/tests/foreman/cli/test_satellitesync.py index 151f184433f..7fed3bd1586 100644 --- a/tests/foreman/cli/test_satellitesync.py +++ b/tests/foreman/cli/test_satellitesync.py @@ -2062,7 +2062,7 @@ def test_positive_export_import_mismatch_label( import_path = target_sat.move_pulp_archive(function_sca_manifest_org, export['message']) target_sat.cli.ContentImport.repository( {'organization-id': function_import_org_with_manifest.id, 'path': import_path}, - timeout=300000, + timeout='5m', ) import_repo = target_sat.cli.Repository.info( { @@ -2089,7 +2089,7 @@ def test_positive_export_import_mismatch_label( ) target_sat.cli.ContentImport.repository( {'organization-id': function_import_org_with_manifest.id, 'path': import_path}, - timeout=300000, + timeout='5m', ) # Verify that both import tasks succeeded