Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[1LP][RFR] Passed template name as string instead of function #9614

Merged
merged 1 commit into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cfme/fixtures/templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import Mapping

import pytest
from aenum import NamedConstant

from cfme.fixtures.templateloader import TEMPLATES
from cfme.utils.log import logger
Expand All @@ -9,6 +10,21 @@
# TODO restructure these to indirectly parametrize the name, and provide name constants here
# These are getting improperly imported and used as functions

class Templates(NamedConstant):
DPORTGROUP_TEMPLATE = "dportgroup_template"
DPORTGROUP_TEMPLATE_MODSCOPE = "dportgroup_template_modscope"
DUAL_DISK_TEMPLATE = "dual_disk_template"
DUAL_NETWORK_TEMPLATE = "dual_network_template"
RHEL69_TEMPLATE = "rhel69_template"
RHEL7_MINIMAL = "rhel7_minimal"
RHEL7_MINIMAL_MODSCOPE = "rhel7_minimal_modscope"
UBUNTU16_TEMPLATE = "ubuntu16_template"
WIN7_TEMPLATE = "win7_template"
WIN10_TEMPLATE = "win10_template"
WIN2016_TEMPLATE = "win2016_template"
WIN2012_TEMPLATE = "win2012_template"


@pytest.fixture(scope="function")
def template(template_location, provider):
if template_location is not None:
Expand Down
82 changes: 47 additions & 35 deletions cfme/fixtures/v2v_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.fixtures.provider import setup_or_skip
from cfme.fixtures.templates import _get_template
from cfme.fixtures.templates import Templates
from cfme.infrastructure.host import Host
from cfme.infrastructure.provider.rhevm import RHEVMProvider
from cfme.infrastructure.provider.virtualcenter import VMwareProvider
Expand Down Expand Up @@ -398,7 +400,7 @@ def cleanup_target(provider, migrated_vm):
provider.mgmt.delete_volume(*volumes)


def get_vm(request, appliance, source_provider, template, datastore='nfs'):
def get_vm(request, appliance, source_provider, template_type, datastore='nfs'):
""" Helper method that takes template , source provider and datastore
and creates VM on source provider to migrate .

Expand All @@ -416,8 +418,9 @@ def get_vm(request, appliance, source_provider, template, datastore='nfs'):
source_datastore = [d.name for d in source_datastores_list if d.type == datastore][0]
collection = source_provider.appliance.provider_based_collection(source_provider)
vm_name = random_vm_name("v2v-auto")
template = _get_template(source_provider, template_type)
vm_obj = collection.instantiate(
vm_name, source_provider, template_name=template["name"]
vm_name, source_provider, template_name=template.name
)
power_on_vm = True
if 'win10' in template.name:
Expand Down Expand Up @@ -484,10 +487,10 @@ def infra_mapping_default_data(source_provider, provider):


@pytest.fixture(scope="function")
def mapping_data_vm_obj_mini(request, appliance, source_provider, provider, rhel7_minimal):
def mapping_data_vm_obj_mini(request, appliance, source_provider, provider):
"""Fixture to return minimal mapping data and vm object for migration plan"""
infra_mapping_data = infra_mapping_default_data(source_provider, provider)
vm_obj = get_vm(request, appliance, source_provider, template=rhel7_minimal)
vm_obj = get_vm(request, appliance, source_provider, template=Templates.RHEL7_MINIMAL)

infrastructure_mapping_collection = appliance.collections.v2v_infra_mappings
mapping = infrastructure_mapping_collection.create(**infra_mapping_data)
Expand All @@ -501,7 +504,8 @@ def _cleanup():


@pytest.fixture(scope="function")
def mapping_data_multiple_vm_obj_single_datastore(request, appliance, source_provider, provider):
def mapping_data_multiple_vm_obj_single_datastore(request, appliance, source_provider, provider,
source_type, dest_type, template_type):
# this fixture will take list of N VM templates via request and call get_vm for each
cluster = provider.data.get("clusters", [False])[0]
if not cluster:
Expand All @@ -512,28 +516,29 @@ def mapping_data_multiple_vm_obj_single_datastore(request, appliance, source_pro
infra_mapping_data,
{
"description": "Single Datastore migration of VM from {ds_type1} to {ds_type2},".format(
ds_type1=request.param[0], ds_type2=request.param[1]
ds_type1=source_type, ds_type2=dest_type
),
},
)
vm_list = []
for template_name in request.param[2]:
for template_name in template_type:
vm_list.append(get_vm(request, appliance, source_provider, template_name))
return FormDataVmObj(infra_mapping_data=infra_mapping_data, vm_list=vm_list)


@pytest.fixture(scope="function")
def mapping_data_single_datastore(request, source_provider, provider):
def mapping_data_single_datastore(request, source_provider, provider,
source_type, dest_type, template_type):
infra_mapping_data = infra_mapping_default_data(source_provider, provider)
recursive_update(
infra_mapping_data,
{
"description": "Single Datastore migration of VM from {ds_type1} to {ds_type2},".format(
ds_type1=request.param[0], ds_type2=request.param[1]
ds_type1=source_type, ds_type2=dest_type
),
"datastores": [
component_generator(
"datastores", source_provider, provider, request.param[0], request.param[1]
"datastores", source_provider, provider, source_type, dest_type
)
],
},
Expand All @@ -542,17 +547,18 @@ def mapping_data_single_datastore(request, source_provider, provider):


@pytest.fixture(scope="function")
def mapping_data_single_network(request, source_provider, provider):
def mapping_data_single_network(request, source_provider, provider,
source_type, dest_type, template_type):
infra_mapping_data = infra_mapping_default_data(source_provider, provider)
recursive_update(
infra_mapping_data,
{
"description": "Single Network migration of VM from {vlan1} to {vlan2},".format(
vlan1=request.param[0], vlan2=request.param[1]
vlan1=source_type, vlan2=dest_type
),
"networks": [
component_generator(
"vlans", source_provider, provider, request.param[0], request.param[1]
"vlans", source_provider, provider, source_type, dest_type
)
],
}
Expand All @@ -562,6 +568,9 @@ def mapping_data_single_network(request, source_provider, provider):

@pytest.fixture(scope="function")
def mapping_data_dual_vm_obj_dual_datastore(request, appliance, source_provider, provider):
# Picking two datastores on Vmware and Target provider for this test
source_type = dest_type = ['nfs', 'iscsi']

vmware_nw = source_provider.data.get("vlans", [None])[0]
rhvm_nw = provider.data.get("vlans", [None])[0]
cluster = provider.data.get("clusters", [False])[0]
Expand All @@ -573,24 +582,24 @@ def mapping_data_dual_vm_obj_dual_datastore(request, appliance, source_provider,
infra_mapping_data,
{
"description": "Dual DS migration of VM from {dss1} to {dst1},& from {dss2} to {dst2}".
format(dss1=request.param[0][0],
dst1=request.param[0][1],
dss2=request.param[1][0],
dst2=request.param[1][1]),
format(dss1=source_type[0],
dst1=source_type[1],
dss2=dest_type[0],
dst2=dest_type[1]),
"datastores": [
component_generator(
"datastores",
source_provider,
provider,
request.param[0][0],
request.param[0][1],
source_type[0],
source_type[1],
),
component_generator(
"datastores",
source_provider,
provider,
request.param[1][0],
request.param[1][1],
dest_type[0],
dest_type[1],
),
],
"networks": [
Expand All @@ -605,13 +614,14 @@ def mapping_data_dual_vm_obj_dual_datastore(request, appliance, source_provider,
},
)
# creating 2 VMs on two different datastores and returning its object list
vm_obj1 = get_vm(request, appliance, source_provider, request.param[0][2], request.param[0][0])
vm_obj2 = get_vm(request, appliance, source_provider, request.param[1][2], request.param[1][0])
vm_obj1 = get_vm(request, appliance, source_provider, Templates.RHEL7_MINIMAL, source_type[0])
vm_obj2 = get_vm(request, appliance, source_provider, Templates.RHEL7_MINIMAL, dest_type[0])
return FormDataVmObj(infra_mapping_data=infra_mapping_data, vm_list=[vm_obj1, vm_obj2])


@pytest.fixture(scope="function")
def mapping_data_vm_obj_dual_nics(request, appliance, source_provider, provider):
def mapping_data_vm_obj_dual_nics(request, appliance, source_provider, provider,
source_type, dest_type, template_type):
vmware_nw = source_provider.data.get("vlans", [None])[0]
rhvm_nw = provider.data.get("vlans", [None])[0]
cluster = provider.data.get("clusters", [False])[0]
Expand All @@ -623,55 +633,57 @@ def mapping_data_vm_obj_dual_nics(request, appliance, source_provider, provider)
infra_mapping_data,
{
"description": "Dual DS migration of VM from {network1} to {network2}".format(
network1=request.param[0], network2=request.param[1]),
network1=source_type, network2=dest_type),
"networks": [
component_generator(
"vlans", source_provider, provider, request.param[0], request.param[1])
"vlans", source_provider, provider, source_type, dest_type)
]
}
)
vm_obj = get_vm(request, appliance, source_provider, request.param[2])
vm_obj = get_vm(request, appliance, source_provider, template_type)
return FormDataVmObj(infra_mapping_data=infra_mapping_data, vm_list=[vm_obj])


@pytest.fixture(scope="function")
def mapping_data_vm_obj_single_datastore(request, appliance, source_provider, provider):
def mapping_data_vm_obj_single_datastore(request, appliance, source_provider, provider,
source_type, dest_type, template_type):
"""Return Infra Mapping form data and vm object"""
infra_mapping_data = infra_mapping_default_data(source_provider, provider)
recursive_update(
infra_mapping_data,
{
"description": "Single DS migration of VM from {ds_type1} to {ds_type2},".format(
ds_type1=request.param[0], ds_type2=request.param[1]
ds_type1=source_type, ds_type2=dest_type
),
"datastores": [
component_generator(
"datastores", source_provider, provider, request.param[0], request.param[1]
"datastores", source_provider, provider, source_type, dest_type
)
],
},
)
vm_obj = get_vm(request, appliance, source_provider, request.param[2], request.param[0])
vm_obj = get_vm(request, appliance, source_provider, template_type, source_type)
return FormDataVmObj(infra_mapping_data=infra_mapping_data, vm_list=[vm_obj])


@pytest.fixture(scope="function")
def mapping_data_vm_obj_single_network(request, appliance, source_provider, provider):
def mapping_data_vm_obj_single_network(request, appliance, source_provider, provider,
source_type, dest_type, template_type):
infra_mapping_data = infra_mapping_default_data(source_provider, provider)
recursive_update(
infra_mapping_data,
{
"description": "Single Network migration of VM from {vlan1} to {vlan2},".format(
vlan1=request.param[0], vlan2=request.param[1]
vlan1=source_type, vlan2=dest_type
),
"networks": [
component_generator(
"vlans", source_provider, provider, request.param[0], request.param[1]
"vlans", source_provider, provider, source_type, dest_type
)
],
},
)
vm_obj = get_vm(request, appliance, source_provider, request.param[2])
vm_obj = get_vm(request, appliance, source_provider, template_type)
return FormDataVmObj(infra_mapping_data=infra_mapping_data, vm_list=[vm_obj])


Expand Down
17 changes: 8 additions & 9 deletions cfme/tests/v2v/test_migration_throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

from cfme import test_requirements
from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.fixtures.templates import rhel69_template
from cfme.fixtures.templates import rhel7_minimal
from cfme.fixtures.templates import ubuntu16_template
from cfme.fixtures.templates import Templates
from cfme.infrastructure.provider.rhevm import RHEVMProvider
from cfme.infrastructure.provider.virtualcenter import VMwareProvider
from cfme.markers.env_markers.provider import ONE_PER_TYPE
Expand All @@ -33,15 +31,16 @@


@pytest.mark.parametrize(
"mapping_data_multiple_vm_obj_single_datastore",
"source_type, dest_type, template_type",
[
["nfs", "nfs", [rhel7_minimal, rhel69_template, ubuntu16_template]],
["nfs", "nfs", [Templates.RHEL7_MINIMAL,
Templates.RHEL69_TEMPLATE,
Templates.UBUNTU16_TEMPLATE]],
],
indirect=True,
)
def test_migration_throttling(
request, appliance, provider, mapping_data_multiple_vm_obj_single_datastore
):
def test_migration_throttling(request, appliance, provider,
source_type, dest_type, template_type,
mapping_data_multiple_vm_obj_single_datastore):
"""
Polarion:
assignee: sshveta
Expand Down
8 changes: 5 additions & 3 deletions cfme/tests/v2v/test_v2v_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from cfme import test_requirements
from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.fixtures.templates import rhel7_minimal
from cfme.fixtures.templates import Templates
from cfme.fixtures.v2v_fixtures import cleanup_target
from cfme.fixtures.v2v_fixtures import get_migrated_vm
from cfme.infrastructure.provider.rhevm import RHEVMProvider
Expand Down Expand Up @@ -85,10 +85,12 @@ def _cleanup():


@pytest.mark.parametrize(
"mapping_data_vm_obj_single_datastore", [["nfs", "nfs", rhel7_minimal]], indirect=True
"source_type, dest_type, template_type",
[["nfs", "nfs", Templates.RHEL7_MINIMAL]]
)
def test_migration_playbooks(request, appliance, source_provider, provider,
ansible_repository, mapping_data_vm_obj_single_datastore):
ansible_repository, source_type, dest_type,
template_type, mapping_data_vm_obj_single_datastore):
"""
Test for migrating vms with pre and post playbooks

Expand Down
16 changes: 10 additions & 6 deletions cfme/tests/v2v/test_v2v_cancel_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from cfme import test_requirements
from cfme.cloud.provider.openstack import OpenStackProvider
from cfme.fixtures.templates import rhel7_minimal
from cfme.fixtures.templates import Templates
from cfme.infrastructure.provider.rhevm import RHEVMProvider
from cfme.infrastructure.provider.virtualcenter import VMwareProvider
from cfme.markers.env_markers.provider import ONE_PER_TYPE
Expand Down Expand Up @@ -71,10 +71,11 @@ def _get_plan_status_and_cancel():


@pytest.mark.tier(1)
@pytest.mark.parametrize('mapping_data_multiple_vm_obj_single_datastore', [['nfs', 'nfs',
[rhel7_minimal, rhel7_minimal]]],
indirect=True)
@pytest.mark.parametrize('source_type, dest_type, template_type',
[['nfs', 'nfs', [Templates.RHEL7_MINIMAL,
Templates.RHEL7_MINIMAL]]])
def test_dual_vm_cancel_migration(request, appliance, soft_assert, provider,
source_type, dest_type, template_type,
mapping_data_multiple_vm_obj_single_datastore):
"""
Polarion:
Expand Down Expand Up @@ -136,9 +137,12 @@ def _get_plan_status_and_cancel():

@pytest.mark.tier(2)
@pytest.mark.parametrize(
"mapping_data_vm_obj_single_datastore", [["nfs", "nfs", rhel7_minimal]], indirect=True)
"source_type, dest_type, template_type",
[["nfs", "nfs", Templates.RHEL7_MINIMAL]])
def test_cancel_migration_attachments(
request, appliance, soft_assert, provider, mapping_data_vm_obj_single_datastore):
request, appliance, soft_assert, provider,
source_type, dest_type, template_type,
mapping_data_vm_obj_single_datastore):
"""
Test to cancel migration and check attached instance, volume and port is removed from provider
Polarion:
Expand Down
Loading