Skip to content

Commit 3d6bcac

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 44192d7 commit 3d6bcac

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

@@ -366,10 +367,22 @@ def create_vms(request, host):
366367
- `name`: name of the VM to create (str)
367368
- `template`: name (or UUID) of template to use (str)
368369
370+
Optional keys:
371+
- `vdis`: dict-specifications for VDIs (Iterable[dict[str, str]])
372+
Mandatory keys:
373+
- `name`
374+
- `size`
375+
369376
Example:
370377
-------
371378
> @pytest.mark.vm_definitions(dict(name="vm 1", template="Other install media"),
372-
> dict(name="vm 2", template="CentOS 7"))
379+
> dict(name="vm 2",
380+
> template="CentOS 7",
381+
> vdis=[dict(name="vm 2 system disk",
382+
> size="100GiB",
383+
> )],
384+
>
385+
> ))
373386
> def test_foo(create_vms):
374387
> ...
375388
@@ -380,10 +393,12 @@ def create_vms(request, host):
380393
for vm_def in marker.args:
381394
assert "name" in vm_def
382395
assert "template" in vm_def
396+
# FIXME should check optional vdis contents
383397
# FIXME should check for extra args
384398

385399
try:
386400
vms = []
401+
vdis = []
387402
for vm_def in marker.args:
388403
vm_name = vm_def["name"]
389404
vm_template = vm_def["template"]
@@ -392,15 +407,25 @@ def create_vms(request, host):
392407

393408
vm = host.vm_from_template(vm_name, vm_template)
394409

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

413+
if "vdis" in marker:
414+
for vdi_def in marker["vdis"]:
415+
sr = SR(host.main_sr_uuid(), host.pool)
416+
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
417+
vdis.append(vdi)
418+
397419
yield vms
398420

399421
except Exception:
400422
logging.error("exception caught...")
401423
raise
402424

403425
finally:
426+
for vdi in vdis:
427+
logging.info("<< Destroy VDI %s", vdi.uuid)
428+
vdi.destroy()
404429
for vm in vms:
405430
logging.info("<< Destroy VM %s", vm.uuid)
406431
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)