Skip to content

Commit d8d56db

Browse files
committed
WIP install 3/n: attach VDIs to VMs using VBDs
TODO: - hardcoded values, move to vdis[]
1 parent 3548e77 commit d8d56db

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def create_vms(request, host):
353353
try:
354354
vms = []
355355
vdis = []
356+
vbds = []
356357
for marker in markers.args:
357358
vm_name = marker["name"]
358359
vm_template = marker["template"]
@@ -369,6 +370,10 @@ def create_vms(request, host):
369370
sr = SR(host.main_sr_uuid(), host.pool)
370371
vdi = sr.create_vdi(vdi_def["name"], vdi_def["size"])
371372
vdis.append(vdi)
373+
# connect to VM
374+
vbd = vm.create_vbd("xvda", vdi.uuid) # FIXME
375+
vbds.append(vbd)
376+
vbd.param_set(param_name="userdevice", value="0") # FIXME
372377

373378
yield vms
374379

@@ -377,6 +382,9 @@ def create_vms(request, host):
377382
raise
378383

379384
finally:
385+
for vbd in vbds:
386+
logging.info("<< Destroy VBD %s", vbd.uuid)
387+
vbd.destroy()
380388
for vdi in vdis:
381389
logging.info("<< Destroy VDI %s", vdi.uuid)
382390
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() + '_clone_for_tests'
482492
logging.info("Clone VM")

0 commit comments

Comments
 (0)