Skip to content

Commit 2ac66c2

Browse files
committed
WIP install 3/n: attach VDIs to VMs using VBDs
1 parent 3349e96 commit 2ac66c2

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

conftest.py

Lines changed: 7 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,9 @@ 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("sda", vdi.uuid)
375+
vbds.append(vbd)
372376

373377
yield vms
374378

@@ -377,6 +381,9 @@ def create_vms(request, host):
377381
raise
378382

379383
finally:
384+
for vbd in vbds:
385+
logging.info("<< Destroy VBD %s", vbd.uuid)
386+
vbd.destroy()
380387
for vdi in vdis:
381388
logging.info("<< Destroy VDI %s", vdi.uuid)
382389
vdi.destroy()

lib/vbd.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import logging
2+
3+
class VBD:
4+
def __init__(self, uuid, vm, device):
5+
self.uuid = uuid
6+
self.vm = vm
7+
self.device = device
8+
9+
def destroy(self):
10+
logging.info("Destroy %s", self)
11+
self.vm.host.pool.master.xe('vbd-destroy', {'uuid': self.uuid})
12+
13+
def __str__(self):
14+
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)