Skip to content

Commit 3548e77

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 00e6296 commit 3548e77

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
@@ -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

@@ -319,10 +320,22 @@ def create_vms(request, host):
319320
- `name`: name of the VM to create (str)
320321
- `template`: name (or UUID) of template to use (str)
321322
323+
Optional keys:
324+
- `vdis`: dict-specifications for VDIs (Iterable[dict[str, str]])
325+
Mandatory keys:
326+
- `name`
327+
- `size`
328+
322329
Example:
323330
-------
324331
> @pytest.mark.vm_definitions(dict(name="vm 1", template="Other install media"),
325-
> dict(name="vm 2", template="CentOS 7"))
332+
> dict(name="vm 2",
333+
> template="CentOS 7",
334+
> vdis=[dict(name="vm 2 system disk",
335+
> size="100GiB",
336+
> )],
337+
>
338+
> ))
326339
> def test_foo(create_vms):
327340
> ...
328341
@@ -334,10 +347,12 @@ def create_vms(request, host):
334347
for marker in markers.args:
335348
assert "name" in marker
336349
assert "template" in marker
350+
# FIXME should check optional vdis contents
337351
# FIXME should check for extra args
338352

339353
try:
340354
vms = []
355+
vdis = []
341356
for marker in markers.args:
342357
vm_name = marker["name"]
343358
vm_template = marker["template"]
@@ -346,15 +361,25 @@ def create_vms(request, host):
346361

347362
vm = host.vm_from_template(vm_name, vm_template)
348363

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

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+
351373
yield vms
352374

353375
except Exception:
354376
logging.error("exception caught...")
355377
raise
356378

357379
finally:
380+
for vdi in vdis:
381+
logging.info("<< Destroy VDI %s", vdi.uuid)
382+
vdi.destroy()
358383
for vm in vms:
359384
logging.info("<< Destroy VM %s", vm.uuid)
360385
vm.destroy(verify=True)

tests/install/test_install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@pytest.mark.vm_definitions(
55
dict(name="vm 1",
66
template="Other install media",
7+
vdis=[dict(name="vm 1 system disk", size="100GiB")],
78
))
89
class TestInstallNested:
910
def test_install_nested_821_uefi(self, create_vms):

0 commit comments

Comments
 (0)