Skip to content

Commit

Permalink
WIP split _create_vm out of create_vms fixture
Browse files Browse the repository at this point in the history
Will help implementing vm import as alternative to creation
  • Loading branch information
ydirson committed May 23, 2024
1 parent cfa9905 commit 54dd773
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,35 +503,7 @@ def create_vms(request, host):
vdis = []
vbds = []
for marker in markers.args:
vm_name = marker["name"]
vm_template = marker["template"]

logging.info(">> Install VM %r from template %r", vm_name, vm_template)

vm = host.vm_from_template(vm_name, vm_template)

# VM is now created, make sure we clean it up on any subsequent failure
vms.append(vm)

if "vdis" in marker:
for vdi_def in marker["vdis"]:
sr = SR(host.main_sr_uuid(), host.pool)
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
vdis.append(vdi)
# connect to VM
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
vbds.append(vbd)
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])

if "vifs" in marker:
for vif_def in marker["vifs"]:
vm.create_vif(vif_def["index"], vif_def["network_uuid"])

if "params" in marker:
for param_def in marker["params"]:
logging.info("Setting param %s", param_def)
vm.param_set(**param_def)

_create_vm(marker, host, vms, vdis, vbds)
yield vms

except Exception:
Expand All @@ -549,6 +521,36 @@ def create_vms(request, host):
logging.info("<< Destroy VM %s", vm.uuid)
vm.destroy(verify=True)

def _create_vm(marker, host, vms, vdis, vbds):
vm_name = marker["name"]
vm_template = marker["template"]

logging.info(">> Install VM %r from template %r", vm_name, vm_template)

vm = host.vm_from_template(vm_name, vm_template)

# VM is now created, make sure we clean it up on any subsequent failure
vms.append(vm)

if "vdis" in marker:
for vdi_def in marker["vdis"]:
sr = SR(host.main_sr_uuid(), host.pool)
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
vdis.append(vdi)
# connect to VM
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
vbds.append(vbd)
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])

if "vifs" in marker:
for vif_def in marker["vifs"]:
vm.create_vif(vif_def["index"], vif_def["network_uuid"])

if "params" in marker:
for param_def in marker["params"]:
logging.info("Setting param %s", param_def)
vm.param_set(**param_def)

@pytest.fixture(scope="module")
def running_vm(imported_vm):
vm = imported_vm
Expand Down

0 comments on commit 54dd773

Please sign in to comment.