Skip to content

Commit a110cab

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

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
@@ -357,6 +357,8 @@ def create_vms(request, host):
357357
> template="CentOS 7",
358358
> vdis=[dict(name="vm 2 system disk",
359359
> size="100GiB",
360+
> device="xvda",
361+
> userdevice="0",
360362
> )],
361363
>
362364
> ))
@@ -376,6 +378,7 @@ def create_vms(request, host):
376378
try:
377379
vms = []
378380
vdis = []
381+
vbds = []
379382
for vm_def in marker.args:
380383
vm_name = vm_def["name"]
381384
vm_template = vm_def["template"]
@@ -392,6 +395,10 @@ def create_vms(request, host):
392395
sr = SR(host.main_sr_uuid(), host.pool)
393396
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
394397
vdis.append(vdi)
398+
# connect to VM
399+
vbd = vm.create_vbd(vdi_def["device"], vdi.uuid)
400+
vbds.append(vbd)
401+
vbd.param_set(param_name="userdevice", value=vdi_def["userdevice"])
395402

396403
yield vms
397404

@@ -400,6 +407,9 @@ def create_vms(request, host):
400407
raise
401408

402409
finally:
410+
for vbd in vbds:
411+
logging.info("<< Destroy VBD %s", vbd.uuid)
412+
vbd.destroy()
403413
for vdi in vdis:
404414
logging.info("<< Destroy VDI %s", vdi.uuid)
405415
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)