Skip to content

Commit 6f630b5

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

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
@@ -364,6 +364,8 @@ def create_vms(request, host):
364364
> template="CentOS 7",
365365
> vdis=[dict(name="vm 2 system disk",
366366
> size="100GiB",
367+
> device="xvda",
368+
> userdevice="0",
367369
> )],
368370
>
369371
> ))
@@ -383,6 +385,7 @@ def create_vms(request, host):
383385
try:
384386
vms = []
385387
vdis = []
388+
vbds = []
386389
for marker in markers.args:
387390
vm_name = marker["name"]
388391
vm_template = marker["template"]
@@ -399,6 +402,10 @@ def create_vms(request, host):
399402
sr = SR(host.main_sr_uuid(), host.pool)
400403
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
401404
vdis.append(vdi)
405+
# connect to VM
406+
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
407+
vbds.append(vbd)
408+
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])
402409

403410
yield vms
404411

@@ -407,6 +414,9 @@ def create_vms(request, host):
407414
raise
408415

409416
finally:
417+
for vbd in vbds:
418+
logging.info("<< Destroy VBD %s", vbd.uuid)
419+
vbd.destroy()
410420
for vdi in vdis:
411421
logging.info("<< Destroy VDI %s", vdi.uuid)
412422
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_install.py

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

0 commit comments

Comments
 (0)