Skip to content

Commit

Permalink
[6.14.z] fixture support for virt-who config api : data_form deploy_t…
Browse files Browse the repository at this point in the history
…ype virtwho_config (#12865)

fixture support for virt-who config api : data_form deploy_type virtwho_config  (#12620)

* fixture support for virt-who config api : data_form deploy_type virtwho_config

* remove unused import

(cherry picked from commit 059830c)

Co-authored-by: yanpliu <[email protected]>
  • Loading branch information
Satellite-QE and yanpliu authored Oct 10, 2023
1 parent 3421aea commit 255761b
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 737 deletions.
209 changes: 91 additions & 118 deletions tests/foreman/virtwho/api/test_esx.py

Large diffs are not rendered by default.

161 changes: 60 additions & 101 deletions tests/foreman/virtwho/api/test_esx_sca.py

Large diffs are not rendered by default.

62 changes: 11 additions & 51 deletions tests/foreman/virtwho/api/test_hyperv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(default_org, target_sat):
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.api.VirtWhoConfig(**form_data).create()
yield virtwho_config
virtwho_config.delete()
assert not target_sat.api.VirtWhoConfig().search(query={'search': f"name={form_data['name']}"})


class TestVirtWhoConfigforHyperv:
@pytest.mark.tier2
@pytest.mark.parametrize('deploy_type', ['id', 'script'])
@pytest.mark.parametrize('deploy_type_api', ['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_api, target_sat, deploy_type_api
):
"""Verify "POST /foreman_virt_who_configure/api/v2/configs"
Expand All @@ -71,23 +43,11 @@ def test_positive_deploy_configure_by_id_script(
:CaseImportance: High
"""
assert virtwho_config.status == 'unknown'
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 = virtwho_config.deploy_script()
hypervisor_name, guest_name = deploy_configure_by_script(
script['virt_who_config_script'],
form_data['hypervisor_type'],
debug=True,
org=default_org.label,
)
assert virtwho_config_api.status == 'unknown'
hypervisor_name, guest_name = deploy_type_api
virt_who_instance = (
target_sat.api.VirtWhoConfig()
.search(query={'search': f'name={virtwho_config.name}'})[0]
.search(query={'search': f'name={virtwho_config_api.name}'})[0]
.status
)
assert virt_who_instance == 'ok'
Expand Down Expand Up @@ -120,7 +80,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_api, virtwho_config_api, target_sat
):
"""Verify hypervisor_id option by "PUT
Expand All @@ -136,11 +96,11 @@ def test_positive_hypervisor_id_option(
"""
values = ['uuid', 'hostname']
for value in values:
virtwho_config.hypervisor_id = value
virtwho_config.update(['hypervisor_id'])
config_file = get_configure_file(virtwho_config.id)
command = get_configure_command(virtwho_config.id, default_org.name)
virtwho_config_api.hypervisor_id = value
virtwho_config_api.update(['hypervisor_id'])
config_file = get_configure_file(virtwho_config_api.id)
command = get_configure_command(virtwho_config_api.id, default_org.name)
deploy_configure_by_command(
command, form_data['hypervisor_type'], org=default_org.label
command, form_data_api['hypervisor_type'], org=default_org.label
)
assert get_configure_option('hypervisor_id', config_file) == value
62 changes: 10 additions & 52 deletions tests/foreman/virtwho/api/test_hyperv_sca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(module_sca_manifest_org, target_sat):
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.api.VirtWhoConfig(**form_data).create()
yield virtwho_config
virtwho_config.delete()
assert not target_sat.api.VirtWhoConfig().search(query={'search': f"name={form_data['name']}"})


class TestVirtWhoConfigforHyperv:
@pytest.mark.tier2
@pytest.mark.parametrize('deploy_type', ['id', 'script'])
@pytest.mark.parametrize('deploy_type_api', ['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_api, target_sat, deploy_type_api
):
"""Verify "POST /foreman_virt_who_configure/api/v2/configs"
Expand All @@ -71,30 +42,17 @@ def test_positive_deploy_configure_by_id_script(
:CaseImportance: High
"""
assert virtwho_config.status == 'unknown'
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 = virtwho_config.deploy_script()
deploy_configure_by_script(
script['virt_who_config_script'],
form_data['hypervisor_type'],
debug=True,
org=module_sca_manifest_org.label,
)
assert virtwho_config_api.status == 'unknown'
virt_who_instance = (
target_sat.api.VirtWhoConfig()
.search(query={'search': f'name={virtwho_config.name}'})[0]
.search(query={'search': f'name={virtwho_config_api.name}'})[0]
.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_api, virtwho_config_api, target_sat
):
"""Verify hypervisor_id option by "PUT
Expand All @@ -109,11 +67,11 @@ def test_positive_hypervisor_id_option(
:CaseImportance: Medium
"""
for value in ['uuid', 'hostname']:
virtwho_config.hypervisor_id = value
virtwho_config.update(['hypervisor_id'])
config_file = get_configure_file(virtwho_config.id)
command = get_configure_command(virtwho_config.id, module_sca_manifest_org.name)
virtwho_config_api.hypervisor_id = value
virtwho_config_api.update(['hypervisor_id'])
config_file = get_configure_file(virtwho_config_api.id)
command = get_configure_command(virtwho_config_api.id, module_sca_manifest_org.name)
deploy_configure_by_command(
command, form_data['hypervisor_type'], org=module_sca_manifest_org.label
command, form_data_api['hypervisor_type'], org=module_sca_manifest_org.label
)
assert get_configure_option('hypervisor_id', config_file) == value
128 changes: 12 additions & 116 deletions tests/foreman/virtwho/api/test_kubevirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,23 @@
: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,
get_guest_info,
)


@pytest.fixture()
def form_data(default_org, target_sat):
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.api.VirtWhoConfig(**form_data).create()
yield virtwho_config
virtwho_config.delete()
assert not target_sat.api.VirtWhoConfig().search(query={'search': f"name={form_data['name']}"})


@pytest.fixture(autouse=True)
def delete_host(form_data, target_sat):
guest_name, _ = get_guest_info(form_data['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()


@pytest.mark.usefixtures('delete_host')
@pytest.mark.delete_host
class TestVirtWhoConfigforKubevirt:
@pytest.mark.tier2
@pytest.mark.parametrize('deploy_type', ['id', 'script'])
@pytest.mark.parametrize('deploy_type_api', ['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_api, target_sat, deploy_type_api
):
"""Verify "POST /foreman_virt_who_configure/api/v2/configs"
Expand All @@ -79,80 +44,11 @@ def test_positive_deploy_configure_by_id_script(
:CaseImportance: High
"""
assert virtwho_config.status == 'unknown'
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 = virtwho_config.deploy_script()
hypervisor_name, guest_name = deploy_configure_by_script(
script['virt_who_config_script'],
form_data['hypervisor_type'],
debug=True,
org=default_org.label,
)
virt_who_instance = (
target_sat.api.VirtWhoConfig()
.search(query={'search': f'name={virtwho_config.name}'})[0]
.status
)
assert virt_who_instance == 'ok'
hosts = [
(
hypervisor_name,
f'product_id={settings.virtwho.sku.vdc_physical} and type=NORMAL',
),
(
guest_name,
f'product_id={settings.virtwho.sku.vdc_physical} and type=STACK_DERIVED',
),
]
for hostname, sku in hosts:
host = target_sat.cli.Host.list({'search': hostname})[0]
subscriptions = target_sat.cli.Subscription.list(
{'organization': default_org.name, 'search': sku}
)
vdc_id = subscriptions[0]['id']
if 'type=STACK_DERIVED' in sku:
for item in subscriptions:
if hypervisor_name.lower() in item['type']:
vdc_id = item['id']
break
target_sat.api.HostSubscription(host=host['id']).add_subscriptions(
data={'subscriptions': [{'id': vdc_id, 'quantity': 'Automatic'}]}
)
result = target_sat.api.Host().search(query={'search': hostname})[0].read_json()
assert result['subscription_status_label'] == 'Fully entitled'

@pytest.mark.tier2
def test_positive_deploy_configure_by_script(
self, default_org, form_data, virtwho_config, target_sat
):
"""Verify "GET /foreman_virt_who_configure/api/
v2/configs/:id/deploy_script"
:id: 77100dc7-644a-44a4-802a-2da562246cba
:expectedresults: Config can be created and deployed
:CaseLevel: Integration
:CaseImportance: High
"""
assert virtwho_config.status == 'unknown'
script = virtwho_config.deploy_script()
hypervisor_name, guest_name = deploy_configure_by_script(
script['virt_who_config_script'],
form_data['hypervisor_type'],
debug=True,
org=default_org.label,
)
assert virtwho_config_api.status == 'unknown'
hypervisor_name, guest_name = deploy_type_api
virt_who_instance = (
target_sat.api.VirtWhoConfig()
.search(query={'search': f'name={virtwho_config.name}'})[0]
.search(query={'search': f'name={virtwho_config_api.name}'})[0]
.status
)
assert virt_who_instance == 'ok'
Expand Down Expand Up @@ -185,7 +81,7 @@ def test_positive_deploy_configure_by_script(

@pytest.mark.tier2
def test_positive_hypervisor_id_option(
self, default_org, form_data, virtwho_config, target_sat
self, default_org, form_data_api, virtwho_config_api, target_sat
):
"""Verify hypervisor_id option by "PUT
Expand All @@ -201,11 +97,11 @@ def test_positive_hypervisor_id_option(
"""
values = ['uuid', 'hostname']
for value in values:
virtwho_config.hypervisor_id = value
virtwho_config.update(['hypervisor_id'])
config_file = get_configure_file(virtwho_config.id)
command = get_configure_command(virtwho_config.id, default_org.name)
virtwho_config_api.hypervisor_id = value
virtwho_config_api.update(['hypervisor_id'])
config_file = get_configure_file(virtwho_config_api.id)
command = get_configure_command(virtwho_config_api.id, default_org.name)
deploy_configure_by_command(
command, form_data['hypervisor_type'], org=default_org.label
command, form_data_api['hypervisor_type'], org=default_org.label
)
assert get_configure_option('hypervisor_id', config_file) == value
Loading

0 comments on commit 255761b

Please sign in to comment.