Skip to content

Commit 246b8c0

Browse files
committed
install 3/n: attach VDIs to VMs using VBDs
Signed-off-by: Yann Dirson <[email protected]>
1 parent 3d6bcac commit 246b8c0

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ def create_vms(request, host):
380380
> template="CentOS 7",
381381
> vdis=[dict(name="vm 2 system disk",
382382
> size="100GiB",
383+
> device="xvda",
384+
> userdevice="0",
383385
> )],
384386
>
385387
> ))
@@ -399,6 +401,7 @@ def create_vms(request, host):
399401
try:
400402
vms = []
401403
vdis = []
404+
vbds = []
402405
for vm_def in marker.args:
403406
vm_name = vm_def["name"]
404407
vm_template = vm_def["template"]
@@ -415,6 +418,10 @@ def create_vms(request, host):
415418
sr = SR(host.main_sr_uuid(), host.pool)
416419
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
417420
vdis.append(vdi)
421+
# connect to VM
422+
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
423+
vbds.append(vbd)
424+
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])
418425

419426
yield vms
420427

@@ -423,6 +430,9 @@ def create_vms(request, host):
423430
raise
424431

425432
finally:
433+
for vbd in vbds:
434+
logging.info("<< Destroy VBD %s", vbd.uuid)
435+
vbd.destroy()
426436
for vdi in vdis:
427437
logging.info("<< Destroy VDI %s", vdi.uuid)
428438
vdi.destroy()

lib/vbd.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
3+
from lib.common import _param_get, _param_remove, _param_set
4+
5+
class VBD:
6+
xe_prefix = "vbd"
7+
8+
def __init__(self, uuid, vm, device):
9+
self.uuid = uuid
10+
self.vm = vm
11+
self.device = device
12+
13+
def param_get(self, param_name, key=None, accept_unknown_key=False):
14+
return _param_get(self.vm.host, VBD.xe_prefix, self.uuid, param_name, key, accept_unknown_key)
15+
16+
def param_set(self, param_name, value, key=None):
17+
_param_set(self.vm.host, VBD.xe_prefix, self.uuid, param_name, value, key)
18+
19+
def param_remove(self, param_name, key, accept_unknown_key=False):
20+
_param_remove(self.vm.host, VBD.xe_prefix, self.uuid, param_name, key, accept_unknown_key)
21+
22+
def destroy(self):
23+
logging.info("Destroy %s", self)
24+
self.vm.host.pool.master.xe('vbd-destroy', {'uuid': self.uuid})
25+
26+
def __str__(self):
27+
return f"VBD {self.uuid} for {self.device} of VM {self.vm.uuid}"

lib/vm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from lib.basevm import BaseVM
1010
from lib.common import PackageManagerEnum, parse_xe_dict, safe_split, wait_for, wait_for_not
1111
from lib.snapshot import Snapshot
12+
from lib.vbd import VBD
1213
from lib.vif import VIF
1314

1415
class VM(BaseVM):
@@ -477,6 +478,15 @@ def destroy_vtpm(self):
477478
logging.info("Destroying vTPM %s" % vtpm_uuid)
478479
return self.host.xe('vtpm-destroy', {'uuid': vtpm_uuid}, force=True)
479480

481+
def create_vbd(self, device, vdi_uuid):
482+
logging.info("Create VBD %r for VDI %r on VM %s", device, vdi_uuid, self.uuid)
483+
vbd_uuid = self.host.xe('vbd-create', {'vm-uuid': self.uuid,
484+
'device': device,
485+
'vdi-uuid': vdi_uuid,
486+
})
487+
logging.info("New VBD %s", vbd_uuid)
488+
return VBD(vbd_uuid, self, device)
489+
480490
def clone(self):
481491
name = self.name()
482492
if not name.endswith('_clone_for_tests'):

tests/install/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +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")],
8+
vdis=[dict(name="vm 1 system disk", size="100GiB", device="xvda", userdevice="0")],
99
))
1010
def test_nested_821_uefi(self, create_vms):
1111
assert len(create_vms) == 1

0 commit comments

Comments
 (0)