Skip to content

Commit 3349e96

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.
1 parent 44363c7 commit 3349e96

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

conftest.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
1111
from lib.netutil import is_ipv6
1212
from lib.pool import Pool
13+
from lib.sr import SR
1314
from lib.vm import VM
1415
from lib.xo import xo_cli
1516

@@ -309,7 +310,8 @@ def imported_vm(host, vm_ref):
309310

310311
@pytest.fixture(scope="class")
311312
def create_vms(request, host):
312-
"""Returns list of VM objects created from `vm_definitions` marker.
313+
"""
314+
Returns list of VM objects created from `vm_definitions` marker.
313315
314316
`vm_definitions` marker test author to specify one or more VMs,
315317
using one `dict` per VM.
@@ -318,11 +320,25 @@ def create_vms(request, host):
318320
- `name`: name of the VM to create (str)
319321
- `template`: name (or UUID) of template to use (str)
320322
323+
Optional keys:
324+
- `vdis`: dict-specifications for VDIs (Iterable[dict[str, str]])
325+
Mandatory keys:
326+
- `name`
327+
- `size`
328+
321329
Example:
322-
> @pytest.mark.vm_definitions(dict(name="vm 1", template="Other install media"),
323-
> dict(name="vm 2", template="CentOS 7"))
324-
> def test_foo(create_vms):
325-
> ...
330+
-------
331+
> @pytest.mark.vm_definitions(dict(name="vm 1", template="Other install media"),
332+
> dict(name="vm 2",
333+
> template="CentOS 7",
334+
> vdis=[dict(name="vm 2 system disk",
335+
> size="1GiB",
336+
> )],
337+
>
338+
> ))
339+
> def test_foo(create_vms):
340+
> ...
341+
326342
"""
327343
vm_name = "Test VM from scratch"
328344
markers = request.node.get_closest_marker("vm_definitions")
@@ -331,10 +347,12 @@ def create_vms(request, host):
331347
for marker in markers.args:
332348
assert "name" in marker
333349
assert "template" in marker
350+
# FIXME should check optional vdis contents
334351
# FIXME should check for extra args
335352

336353
try:
337354
vms = []
355+
vdis = []
338356
for marker in markers.args:
339357
vm_name = marker["name"]
340358
vm_template = marker["template"]
@@ -343,15 +361,25 @@ def create_vms(request, host):
343361

344362
vm = host.vm_from_template(vm_name, vm_template)
345363

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

367+
if "vdis" in marker:
368+
for vdi_def in marker["vdis"]:
369+
sr = SR(host.main_sr_uuid(), host.pool)
370+
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
371+
vdis.append(vdi)
372+
348373
yield vms
349374

350375
except Exception:
351376
logging.error("exception caught...")
352377
raise
353378

354379
finally:
380+
for vdi in vdis:
381+
logging.info("<< Destroy VDI %s", vdi.uuid)
382+
vdi.destroy()
355383
for vm in vms:
356384
logging.info("<< Destroy VM %s", vm.uuid)
357385
vm.destroy(verify=True)

tests/install/test_install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
@pytest.mark.vm_definitions(dict(name="vm 1",
55
template="Other install media",
6+
vdis=[dict(name="vm 1 system disk", size="1GiB")],
67
))
78
class TestInstallNested:
89
def test_install_nested_821(self, create_vms):

0 commit comments

Comments
 (0)