Skip to content

Commit d396193

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 95fd89b commit d396193

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

@@ -350,10 +351,22 @@ def create_vms(request, host):
350351
- `name`: name of the VM to create (str)
351352
- `template`: name (or UUID) of template to use (str)
352353
354+
Optional keys:
355+
- `vdis`: dict-specifications for VDIs (Iterable[dict[str, str]])
356+
Mandatory keys:
357+
- `name`
358+
- `size`
359+
353360
Example:
354361
-------
355362
> @pytest.mark.vm_definitions(dict(name="vm 1", template="Other install media"),
356-
> dict(name="vm 2", template="CentOS 7"))
363+
> dict(name="vm 2",
364+
> template="CentOS 7",
365+
> vdis=[dict(name="vm 2 system disk",
366+
> size="100GiB",
367+
> )],
368+
>
369+
> ))
357370
> def test_foo(create_vms):
358371
> ...
359372
@@ -364,10 +377,12 @@ def create_vms(request, host):
364377
for marker in markers.args:
365378
assert "name" in marker
366379
assert "template" in marker
380+
# FIXME should check optional vdis contents
367381
# FIXME should check for extra args
368382

369383
try:
370384
vms = []
385+
vdis = []
371386
for marker in markers.args:
372387
vm_name = marker["name"]
373388
vm_template = marker["template"]
@@ -376,15 +391,25 @@ def create_vms(request, host):
376391

377392
vm = host.vm_from_template(vm_name, vm_template)
378393

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

397+
if "vdis" in marker:
398+
for vdi_def in marker["vdis"]:
399+
sr = SR(host.main_sr_uuid(), host.pool)
400+
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
401+
vdis.append(vdi)
402+
381403
yield vms
382404

383405
except Exception:
384406
logging.error("exception caught...")
385407
raise
386408

387409
finally:
410+
for vdi in vdis:
411+
logging.info("<< Destroy VDI %s", vdi.uuid)
412+
vdi.destroy()
388413
for vm in vms:
389414
logging.info("<< Destroy VM %s", vm.uuid)
390415
vm.destroy(verify=True)

tests/install/test_install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class TestInstallNested:
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_install_nested_821_uefi(self, create_vms):
1011
assert len(create_vms) == 1

0 commit comments

Comments
 (0)