Skip to content

Commit 7dd6617

Browse files
committed
WIP install 2/n: create VDIs for VMs
This only creates the VDIs, and does not connect them yet to the VM. TODO: - early check of optional vdis contents
1 parent 165d8a9 commit 7dd6617

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

conftest.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
1212
from lib.netutil import is_ipv6
1313
from lib.pool import Pool
14+
from lib.sr import SR
1415
from lib.vm import VM
1516
from lib.xo import xo_cli
1617

@@ -343,10 +344,22 @@ def create_vms(request, host):
343344
- `name`: name of the VM to create (str)
344345
- `template`: name (or UUID) of template to use (str)
345346
347+
Optional keys:
348+
- `vdis`: dict-specifications for VDIs (Iterable[dict[str, str]])
349+
Mandatory keys:
350+
- `name`
351+
- `size`
352+
346353
Example:
347354
-------
348355
> @pytest.mark.vm_definitions(dict(name="vm 1", template="Other install media"),
349-
> dict(name="vm 2", template="CentOS 7"))
356+
> dict(name="vm 2",
357+
> template="CentOS 7",
358+
> vdis=[dict(name="vm 2 system disk",
359+
> size="100GiB",
360+
> )],
361+
>
362+
> ))
350363
> def test_foo(create_vms):
351364
> ...
352365
@@ -357,10 +370,12 @@ def create_vms(request, host):
357370
for vm_def in marker.args:
358371
assert "name" in vm_def
359372
assert "template" in vm_def
373+
# FIXME should check optional vdis contents
360374
# FIXME should check for extra args
361375

362376
try:
363377
vms = []
378+
vdis = []
364379
for vm_def in marker.args:
365380
vm_name = vm_def["name"]
366381
vm_template = vm_def["template"]
@@ -369,15 +384,25 @@ def create_vms(request, host):
369384

370385
vm = host.vm_from_template(vm_name, vm_template)
371386

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

390+
if "vdis" in marker:
391+
for vdi_def in marker["vdis"]:
392+
sr = SR(host.main_sr_uuid(), host.pool)
393+
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
394+
vdis.append(vdi)
395+
374396
yield vms
375397

376398
except Exception:
377399
logging.error("exception caught...")
378400
raise
379401

380402
finally:
403+
for vdi in vdis:
404+
logging.info("<< Destroy VDI %s", vdi.uuid)
405+
vdi.destroy()
381406
for vm in vms:
382407
logging.info("<< Destroy VM %s", vm.uuid)
383408
vm.destroy(verify=True)

tests/install/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class TestNested:
55
@pytest.mark.vm_definitions(
66
dict(name="vm 1",
77
template="Other install media",
8+
vdis=[dict(name="vm 1 system disk", size="100GiB")],
89
))
910
def test_nested_821_uefi(self, create_vms):
1011
assert len(create_vms) == 1

0 commit comments

Comments
 (0)