Merge ~paride/utah/+git/utah:server-vm-xml into utah:master

Proposed by Paride Legovini
Status: Merged
Merged at revision: 47f31216fd163027cb1d770475689410dc08b9df
Proposed branch: ~paride/utah/+git/utah:server-vm-xml
Merge into: utah:master
Diff against target: 526 lines (+275/-59)
9 files modified
conf/utah/default-vm.xml (+4/-4)
conf/utah/server-vm-amd64-secureboot.xml (+61/-0)
conf/utah/server-vm-amd64-uefi.xml (+60/-0)
conf/utah/server-vm-amd64.xml (+58/-0)
conf/utah/server-vm-arm64.xml (+53/-0)
conf/utah/server-vm-ppc64el.xml (+5/-5)
conf/utah/server-vm-s390x.xml (+1/-1)
utah/provisioning/live_server.py (+21/-35)
utah/provisioning/vm.py (+12/-14)
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+375441@code.launchpad.net

Commit message

Introduce the server-vm-ARCH.xml libvirt template files

This change adds server-vm-ARCH.xml libvirt template files to be used
when testing server images. The server-vm-ARCH-ARCHVARIANT.xml pattern
is also supported to test arch "variants", e.g. UEFI or Secure Boot on
amd64.

This change also switches the default VM arch from i686 to x86_64.

To post a comment you must log in.
Revision history for this message
Paride Legovini (paride) wrote :

This branch is the one currently running on venonat.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Seems ok to me. In some sense it would be nice to store a default vm definition and have some kind of way of applying a delta to convert it to the uefi/secure boot but well.

"one day"(tm) (but not until after 20.04 most likely) we'd like to install with uefi and boot for testing with bios and vice versa. Can you see a way towards doing that? (seems to conflict a bit with the general way utah operates to me)

review: Approve
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Actually in general we will want to support testing booting a degraded multipath or raid setup one day, which also falls in the general category of "different vm definition for testing vs installing". Something to think about (and in no way needing to block this branch!)

Revision history for this message
Paride Legovini (paride) wrote :

Thanks for reviewing this one Michael. Well you said it: currently there is no easy way in utah to alter the test environment, utah hasn't been thought to do so. We're already deviating a bit from what I believe are its original design decision, moving from very generic libvirt XML files to arch-specific ones from which we inherit part of the machine configuration, without rewriting it. I see how testing different boot environments is important; we'll have to find a way.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/conf/utah/default-vm.xml b/conf/utah/default-vm.xml
index df0ce52..aa9a860 100644
--- a/conf/utah/default-vm.xml
+++ b/conf/utah/default-vm.xml
@@ -1,5 +1,5 @@
1<!-- 1<!--
2 Copyright (C) 2010-2012, Canonical Ltd (http://www.canonical.com/)2 Copyright (C) 2010-2019, Canonical Ltd (http://www.canonical.com/)
3 3
4 This file is part of utah.4 This file is part of utah.
5 5
@@ -17,14 +17,14 @@
17 along with ubuntu-server-iso-testing. If not, see 17 along with ubuntu-server-iso-testing. If not, see
18 <http://www.gnu.org/licenses/>.18 <http://www.gnu.org/licenses/>.
19--> 19-->
20<domain type='qemu'>20<domain type='kvm'>
21 <name>Utah Example</name>21 <name>Utah Template</name>
22 <uuid>00000000-0000-0000-0000-000000000000</uuid>22 <uuid>00000000-0000-0000-0000-000000000000</uuid>
23 <memory>1048576</memory>23 <memory>1048576</memory>
24 <currentMemory>1048576</currentMemory>24 <currentMemory>1048576</currentMemory>
25 <vcpu>1</vcpu>25 <vcpu>1</vcpu>
26 <os>26 <os>
27 <type arch='i686' machine='pc'>hvm</type>27 <type arch='x86_64' machine='pc'>hvm</type>
28 <boot dev='hd'/>28 <boot dev='hd'/>
29 </os>29 </os>
30 <features>30 <features>
diff --git a/conf/utah/server-vm-amd64-secureboot.xml b/conf/utah/server-vm-amd64-secureboot.xml
31new file mode 10064431new file mode 100644
index 0000000..6c4a540
--- /dev/null
+++ b/conf/utah/server-vm-amd64-secureboot.xml
@@ -0,0 +1,61 @@
1<!--
2 Copyright (C) 2010-2019, Canonical Ltd (http://www.canonical.com/)
3
4 This file is part of utah.
5
6 utah is free software: you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 utah is distributed in the hope that it will
12 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with ubuntu-server-iso-testing. If not, see
18 <http://www.gnu.org/licenses/>.
19-->
20<domain type='kvm'>
21 <name>Utah Template</name>
22 <uuid>00000000-0000-0000-0000-000000000000</uuid>
23 <memory>1536000</memory>
24 <currentMemory>1536000</currentMemory>
25 <vcpu>1</vcpu>
26 <os firmware='efi'>
27 <type arch='x86_64' machine='q35'>hvm</type>
28 <loader readonly='yes' type='pflash' secure="yes">/usr/share/OVMF/OVMF_CODE.fd</loader>
29 <nvram template='/usr/share/OVMF/OVMF_VARS.fd'>/tmp/nvram.fd</nvram>
30 <boot dev='hd'/>
31 </os>
32 <features>
33 <acpi/>
34 <apic/>
35 <pae/>
36 <smm state='on'/>
37 </features>
38 <clock offset='utc'/>
39 <on_poweroff>destroy</on_poweroff>
40 <on_reboot>restart</on_reboot>
41 <on_crash>destroy</on_crash><!-- this could also be 'preserve' -->
42 <devices>
43 <disk type='file' device='cdrom'>
44 <driver name='qemu' type='raw'/>
45 <target dev='sdc' bus='sata'/>
46 <readonly/>
47 </disk>
48 <interface type='bridge'>
49 <mac address='52:54:00:3e:92:26'/>
50 <source bridge='virbr0'/>
51 <target dev='vnet1'/>
52 <alias name='net0'/>
53 <model type='virtio'/>
54 </interface>
55 <graphics type='vnc' autoport='yes'/>
56 <video>
57 <model type='qxl' vram='16384' heads='1'/>
58 </video>
59 </devices>
60</domain>
61
diff --git a/conf/utah/server-vm-amd64-uefi.xml b/conf/utah/server-vm-amd64-uefi.xml
0new file mode 10064462new file mode 100644
index 0000000..2596982
--- /dev/null
+++ b/conf/utah/server-vm-amd64-uefi.xml
@@ -0,0 +1,60 @@
1<!--
2 Copyright (C) 2010-2019, Canonical Ltd (http://www.canonical.com/)
3
4 This file is part of utah.
5
6 utah is free software: you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 utah is distributed in the hope that it will
12 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with ubuntu-server-iso-testing. If not, see
18 <http://www.gnu.org/licenses/>.
19-->
20<domain type='kvm'>
21 <name>Utah Template</name>
22 <uuid>00000000-0000-0000-0000-000000000000</uuid>
23 <memory>1536000</memory>
24 <currentMemory>1536000</currentMemory>
25 <vcpu>1</vcpu>
26 <os firmware='efi'>
27 <type arch='x86_64' machine='pc'>hvm</type>
28 <loader readonly='yes' type='pflash' secure='no'>/usr/share/OVMF/OVMF_CODE.fd</loader>
29 <nvram template='/usr/share/OVMF/OVMF_VARS.fd'>/tmp/nvram.fd</nvram>
30 <boot dev='hd'/>
31 </os>
32 <features>
33 <acpi/>
34 <apic/>
35 <pae/>
36 </features>
37 <clock offset='utc'/>
38 <on_poweroff>destroy</on_poweroff>
39 <on_reboot>restart</on_reboot>
40 <on_crash>destroy</on_crash><!-- this could also be 'preserve' -->
41 <devices>
42 <disk type='file' device='cdrom'>
43 <driver name='qemu' type='raw'/>
44 <target dev='sdc' bus='sata'/>
45 <readonly/>
46 </disk>
47 <interface type='bridge'>
48 <mac address='52:54:00:3e:92:26'/>
49 <source bridge='virbr0'/>
50 <target dev='vnet1'/>
51 <alias name='net0'/>
52 <model type='virtio'/>
53 </interface>
54 <graphics type='vnc' autoport='yes'/>
55 <video>
56 <model type='qxl' vram='16384' heads='1'/>
57 </video>
58 </devices>
59</domain>
60
diff --git a/conf/utah/server-vm-amd64.xml b/conf/utah/server-vm-amd64.xml
0new file mode 10064461new file mode 100644
index 0000000..6e05524
--- /dev/null
+++ b/conf/utah/server-vm-amd64.xml
@@ -0,0 +1,58 @@
1<!--
2 Copyright (C) 2010-2019, Canonical Ltd (http://www.canonical.com/)
3
4 This file is part of utah.
5
6 utah is free software: you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 utah is distributed in the hope that it will
12 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with ubuntu-server-iso-testing. If not, see
18 <http://www.gnu.org/licenses/>.
19-->
20<domain type='kvm'>
21 <name>Utah Template</name>
22 <uuid>00000000-0000-0000-0000-000000000000</uuid>
23 <memory>1536000</memory>
24 <currentMemory>1536000</currentMemory>
25 <vcpu>1</vcpu>
26 <os>
27 <type arch='x86_64' machine='pc'>hvm</type>
28 <boot dev='hd'/>
29 </os>
30 <features>
31 <acpi/>
32 <apic/>
33 <pae/>
34 </features>
35 <clock offset='utc'/>
36 <on_poweroff>destroy</on_poweroff>
37 <on_reboot>restart</on_reboot>
38 <on_crash>destroy</on_crash><!-- this could also be 'preserve' -->
39 <devices>
40 <disk type='file' device='cdrom'>
41 <driver name='qemu' type='raw'/>
42 <target dev='sdc' bus='sata'/>
43 <readonly/>
44 </disk>
45 <interface type='bridge'>
46 <mac address='52:54:00:3e:92:26'/>
47 <source bridge='virbr0'/>
48 <target dev='vnet1'/>
49 <alias name='net0'/>
50 <model type='virtio'/>
51 </interface>
52 <graphics type='vnc' autoport='yes'/>
53 <video>
54 <model type='qxl' vram='16384' heads='1'/>
55 </video>
56 </devices>
57</domain>
58
diff --git a/conf/utah/server-vm-arm64.xml b/conf/utah/server-vm-arm64.xml
0new file mode 10064459new file mode 100644
index 0000000..51e98c1
--- /dev/null
+++ b/conf/utah/server-vm-arm64.xml
@@ -0,0 +1,53 @@
1<!--
2 Copyright (C) 2010-2019, Canonical Ltd (http://www.canonical.com/)
3
4 This file is part of utah.
5
6 utah is free software: you can redistribute it
7 and/or modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 utah is distributed in the hope that it will
12 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with ubuntu-server-iso-testing. If not, see
18 <http://www.gnu.org/licenses/>.
19-->
20<domain type='kvm'>
21 <name>Utah Template</name>
22 <uuid>00000000-0000-0000-0000-000000000000</uuid>
23 <memory>1048576</memory>
24 <currentMemory>1048576</currentMemory>
25 <vcpu>1</vcpu>
26 <cpu mode='host-passthrough' />
27 <os>
28 <type arch='aarch64' machine='virt'>hvm</type>
29 <loader readonly='yes' type='pflash'>/usr/share/AAVMF/AAVMF_CODE.fd</loader>
30 <nvram template='/usr/share/AAVMF/AAVMF_VARS.fd'>/tmp/AAVMF_VARS.fd</nvram>
31 <boot dev='hd'/>
32 </os>
33 <features>
34 <acpi/>
35 </features>
36 <clock offset='utc'/>
37 <on_poweroff>destroy</on_poweroff>
38 <on_reboot>restart</on_reboot>
39 <on_crash>destroy</on_crash><!-- this could also be 'preserve' -->
40 <devices>
41 <controller type='scsi' index='0' model='virtio-scsi'/>
42 <disk type='file' device='cdrom'>
43 <driver name='qemu' type='raw'/>
44 <target dev='sdc' bus='scsi'/>
45 <readonly/>
46 </disk>
47 <interface type='network'>
48 <mac address='52:54:00:3e:92:26'/>
49 <source network='default'/>
50 <model type='virtio'/>
51 </interface>
52 </devices>
53</domain>
diff --git a/conf/utah/default-vm-ppc64.xml b/conf/utah/server-vm-ppc64el.xml
0similarity index 90%54similarity index 90%
1rename from conf/utah/default-vm-ppc64.xml55rename from conf/utah/default-vm-ppc64.xml
2rename to conf/utah/server-vm-ppc64el.xml56rename to conf/utah/server-vm-ppc64el.xml
index b0ea237..e510b4c 100644
--- a/conf/utah/default-vm-ppc64.xml
+++ b/conf/utah/server-vm-ppc64el.xml
@@ -1,5 +1,5 @@
1<!--1<!--
2 Copyright (C) 2017, Canonical Ltd (http://www.canonical.com/)2 Copyright (C) 2017-2019, Canonical Ltd (http://www.canonical.com/)
3 3
4 This file is part of utah.4 This file is part of utah.
5 5
@@ -16,9 +16,9 @@
16 You should have received a copy of the GNU General Public License16 You should have received a copy of the GNU General Public License
17 along with ubuntu-server-iso-testing. If not, see 17 along with ubuntu-server-iso-testing. If not, see
18 <http://www.gnu.org/licenses/>.18 <http://www.gnu.org/licenses/>.
19--> 19-->
20<domain type='qemu' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>20<domain type='kvm'>
21 <name>Utah Example</name>21 <name>Utah Template</name>
22 <uuid>00000000-0000-0000-0000-000000000000</uuid>22 <uuid>00000000-0000-0000-0000-000000000000</uuid>
23 <memory>1048576</memory>23 <memory>1048576</memory>
24 <currentMemory>1048576</currentMemory>24 <currentMemory>1048576</currentMemory>
@@ -43,7 +43,7 @@
43 <disk type='file' device='cdrom'>43 <disk type='file' device='cdrom'>
44 <driver name='qemu' type='raw'/>44 <driver name='qemu' type='raw'/>
45 <backingStore/>45 <backingStore/>
46 <target dev='hdc' bus='sata'/>46 <target dev='sdc' bus='scsi'/>
47 <readonly/>47 <readonly/>
48 </disk>48 </disk>
49 <interface type='bridge'>49 <interface type='bridge'>
diff --git a/conf/utah/default-vm-s390x.xml b/conf/utah/server-vm-s390x.xml
50similarity index 97%50similarity index 97%
51rename from conf/utah/default-vm-s390x.xml51rename from conf/utah/default-vm-s390x.xml
52rename to conf/utah/server-vm-s390x.xml52rename to conf/utah/server-vm-s390x.xml
index b41d965..22a9013 100644
--- a/conf/utah/default-vm-s390x.xml
+++ b/conf/utah/server-vm-s390x.xml
@@ -18,7 +18,7 @@
18 <http://www.gnu.org/licenses/>.18 <http://www.gnu.org/licenses/>.
19-->19-->
20<domain type='kvm'>20<domain type='kvm'>
21 <name>Utah Example</name>21 <name>Utah Template</name>
22 <uuid>00000000-0000-0000-0000-000000000000</uuid>22 <uuid>00000000-0000-0000-0000-000000000000</uuid>
23 <memory>1048576</memory>23 <memory>1048576</memory>
24 <currentMemory>1048576</currentMemory>24 <currentMemory>1048576</currentMemory>
diff --git a/utah/provisioning/live_server.py b/utah/provisioning/live_server.py
index 550bbf1..6ea1deb 100644
--- a/utah/provisioning/live_server.py
+++ b/utah/provisioning/live_server.py
@@ -189,31 +189,21 @@ class LiveServerVM(SSHMixin, LibvirtVM):
189 self.disks.append(disk)189 self.disks.append(disk)
190 self.logger.debug('Adding disk %s to list', disk)190 self.logger.debug('Adding disk %s to list', disk)
191191
192 def _installxml_rewrite_nvram(self, xmlt):
193 ose = xmlt.find('os')
194 nvram = ose.find('nvram')
195
196 if nvram is None:
197 # No nvram set (legacy, non-uefi boot)
198 return
199
200 ose.find('nvram').text = self.directory + '/nvram.fd'
201
192 def _installxml_rewrite_boot(self, xmlt):202 def _installxml_rewrite_boot(self, xmlt):
193 # Set the arch appropriately, remove any configuration of203 # Set the arch appropriately, remove any configuration of
194 # kernel/initrd/commandline and configure the VM to boot from204 # kernel/initrd/commandline and configure the VM to boot from
195 # CD.205 # CD.
196 xmlt.getroot().set('type', 'kvm')
197 ose = xmlt.find('os')206 ose = xmlt.find('os')
198 if self.image.arch == 'i386':
199 ose.find('type').set('arch', 'i686')
200 elif self.image.arch == 'amd64':
201 ose.find('type').set('arch', 'x86_64')
202 elif self.image.arch == 'ppc64el':
203 ose.find('type').set('arch', 'ppc64le')
204 ose.find('type').set('machine', 'pseries')
205 elif self.image.arch == 's390x':
206 ose.find('type').set('arch', 's390x')
207 ose.find('type').set('machine', 's390-ccw-virtio')
208 else:
209 ose.find('type').set('arch', self.image.arch)
210 self.logger.debug('Setting up boot info')
211 for kernele in list(ose.iterfind('kernel')):
212 ose.remove(kernele)
213 for initrde in list(ose.iterfind('initrd')):
214 ose.remove(initrde)
215 for cmdlinee in list(ose.iterfind('cmdline')):
216 ose.remove(cmdlinee)
217 ose.find('boot').set('dev', 'cdrom')207 ose.find('boot').set('dev', 'cdrom')
218208
219 def _installxml_rewrite_disks(self, devices, image):209 def _installxml_rewrite_disks(self, devices, image):
@@ -227,14 +217,6 @@ class LiveServerVM(SSHMixin, LibvirtVM):
227 self.logger.debug('Removed existing disk')217 self.logger.debug('Removed existing disk')
228 # TODO: Add a cdrom if none exists218 # TODO: Add a cdrom if none exists
229 if disk.get('device') == 'cdrom':219 if disk.get('device') == 'cdrom':
230 if self.image.arch == 'ppc64el':
231 disk.find('target').set('bus', 'virtio')
232 elif self.image.arch == 's390x':
233 disk.find('target').set('bus', 'virtio')
234 else:
235 disk.find('target').set('bus', 'ide')
236 for address in list(disk.iterfind('address')):
237 disk.remove(address)
238 if disk.find('source') is not None:220 if disk.find('source') is not None:
239 disk.find('source').set('file', image)221 disk.find('source').set('file', image)
240 self.logger.debug('Rewrote existing CD-ROM')222 self.logger.debug('Rewrote existing CD-ROM')
@@ -252,6 +234,7 @@ class LiveServerVM(SSHMixin, LibvirtVM):
252 driver = ElementTree.Element('driver')234 driver = ElementTree.Element('driver')
253 driver.set('name', 'qemu')235 driver.set('name', 'qemu')
254 driver.set('type', disk['type'])236 driver.set('type', disk['type'])
237 driver.set('cache', 'unsafe')
255 diske.append(driver)238 diske.append(driver)
256 if 'mpath' in disk and disk['mpath']:239 if 'mpath' in disk and disk['mpath']:
257 diske.append(ElementTree.Element('shareable'))240 diske.append(ElementTree.Element('shareable'))
@@ -336,6 +319,7 @@ class LiveServerVM(SSHMixin, LibvirtVM):
336 self._installxml_rewrite_disks(devices, image)319 self._installxml_rewrite_disks(devices, image)
337 self._installxml_rewrite_nics(devices)320 self._installxml_rewrite_nics(devices)
338 self._installxml_add_serial(devices)321 self._installxml_add_serial(devices)
322 self._installxml_rewrite_nvram(xmlt)
339 xmlt.write(os.path.join(tmpdir, 'install.xml'))323 xmlt.write(os.path.join(tmpdir, 'install.xml'))
340 self.logger.info('Installation XML ready')324 self.logger.info('Installation XML ready')
341 return xmlt325 return xmlt
@@ -363,22 +347,23 @@ class LiveServerVM(SSHMixin, LibvirtVM):
363 self.logger.info('Logs will be written to %s', log_filename)347 self.logger.info('Logs will be written to %s', log_filename)
364348
365 before = time.time()349 before = time.time()
350
351 vm = lv.defineXML(ElementTree.tostring(xml.getroot()))
352
366 try:353 try:
367 vm = lv.defineXML(ElementTree.tostring(xml.getroot()))354 vm = lv.defineXML(ElementTree.tostring(xml.getroot()))
368 vm.create()355 vm.create()
369 while vm.isActive() is not 0:356 while vm.isActive() is not 0:
370 time.sleep(1)357 time.sleep(1)
358 time.sleep(5)
371 finally: # This stops us from leaking VMs on exceptions359 finally: # This stops us from leaking VMs on exceptions
372 try:360 try:
361 vm.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_NVRAM)
373 vm.destroy()362 vm.destroy()
374 except libvirt.libvirtError:363 time.sleep(5) # Workaround for LP: #1822096
375 pass
376 finally:
377 # Workaround for LP: #1822096
378 # To be removed once fixed in libvirtd.
379 time.sleep(5)
380
381 vm.undefine()364 vm.undefine()
365 except (libvirt.libvirtError, UnboundLocalError):
366 pass
382367
383 after = time.time()368 after = time.time()
384 self.logger.info('Installation complete in %s seconds' %369 self.logger.info('Installation complete in %s seconds' %
@@ -438,6 +423,7 @@ class LiveServerVM(SSHMixin, LibvirtVM):
438 self.logger.info('Setting up final VM')423 self.logger.info('Setting up final VM')
439 self.logger.info(ElementTree.tostring(xml.getroot()))424 self.logger.info(ElementTree.tostring(xml.getroot()))
440 self.vm = self.lv.defineXML(ElementTree.tostring(xml.getroot()))425 self.vm = self.lv.defineXML(ElementTree.tostring(xml.getroot()))
426 self.cleanfunction(self.vm.undefineFlags, False, libvirt.VIR_DOMAIN_UNDEFINE_NVRAM)
441 self.cleanfunction(self.vm.destroy)427 self.cleanfunction(self.vm.destroy)
442 self.cleanfunction(self.vm.undefine)428 self.cleanfunction(self.vm.undefine)
443 if self.poweroff:429 if self.poweroff:
diff --git a/utah/provisioning/vm.py b/utah/provisioning/vm.py
index 21ed2be..755c95f 100644
--- a/utah/provisioning/vm.py
+++ b/utah/provisioning/vm.py
@@ -331,12 +331,6 @@ class CustomVM(CustomInstallMixin, SSHMixin, LibvirtVM):
331 ose = xmlt.find('os')331 ose = xmlt.find('os')
332 if self.image.arch == ('i386'):332 if self.image.arch == ('i386'):
333 ose.find('type').set('arch', 'i686')333 ose.find('type').set('arch', 'i686')
334 elif self.image.arch == ('amd64'):
335 ose.find('type').set('arch', 'x86_64')
336 elif self.image.arch == ('ppc64el'):
337 ose.find('type').set('arch', 'ppc64le')
338 else:
339 ose.find('type').set('arch', self.image.arch)
340 self.logger.debug('Setting up boot info')334 self.logger.debug('Setting up boot info')
341 for kernele in list(ose.iterfind('kernel')):335 for kernele in list(ose.iterfind('kernel')):
342 ose.remove(kernele)336 ose.remove(kernele)
@@ -379,6 +373,7 @@ class CustomVM(CustomInstallMixin, SSHMixin, LibvirtVM):
379 driver = ElementTree.Element('driver')373 driver = ElementTree.Element('driver')
380 driver.set('name', 'qemu')374 driver.set('name', 'qemu')
381 driver.set('type', disk['type'])375 driver.set('type', disk['type'])
376 driver.set('cache', 'unsafe')
382 diske.append(driver)377 diske.append(driver)
383 source = ElementTree.Element('source')378 source = ElementTree.Element('source')
384 source.set('file', disk['file'])379 source.set('file', disk['file'])
@@ -451,6 +446,10 @@ class CustomVM(CustomInstallMixin, SSHMixin, LibvirtVM):
451 serial.append(target)446 serial.append(target)
452 devices.append(serial)447 devices.append(serial)
453448
449 nvram = ose.find('nvram')
450 if nvram is not None:
451 ose.find('nvram').text = self.directory + '/nvram.fd'
452
454 def _installvm(self, lv=None, tmpdir=None, xml=None):453 def _installvm(self, lv=None, tmpdir=None, xml=None):
455 """Install a VM, then undefine it in libvirt.454 """Install a VM, then undefine it in libvirt.
456455
@@ -473,22 +472,20 @@ class CustomVM(CustomInstallMixin, SSHMixin, LibvirtVM):
473 self.logger.info('Logs will be written to %s', log_filename)472 self.logger.info('Logs will be written to %s', log_filename)
474473
475 before = time.time()474 before = time.time()
475 vm = lv.defineXML(ElementTree.tostring(xml.getroot()))
476 try:476 try:
477 vm = lv.defineXML(ElementTree.tostring(xml.getroot()))
478 vm.create()477 vm.create()
479 while vm.isActive() is not 0:478 while vm.isActive() is not 0:
480 time.sleep(1)479 time.sleep(1)
480 time.sleep(5)
481 finally: # This stops us from leaking VMs on exceptions481 finally: # This stops us from leaking VMs on exceptions
482 try:482 try:
483 vm.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_NVRAM)
483 vm.destroy()484 vm.destroy()
484 except libvirt.libvirtError:485 time.sleep(5) # Workaround for LP: #1822096
485 pass
486 finally:
487 # Workaround for LP: #1822096
488 # To be removed once fixed in libvirtd.
489 time.sleep(5)
490
491 vm.undefine()486 vm.undefine()
487 except (libvirt.libvirtError, UnboundLocalError):
488 pass
492489
493 after = time.time()490 after = time.time()
494 self.logger.info('Installation complete in %s seconds' %491 self.logger.info('Installation complete in %s seconds' %
@@ -606,6 +603,7 @@ class CustomVM(CustomInstallMixin, SSHMixin, LibvirtVM):
606603
607 self.logger.info('Setting up final VM')604 self.logger.info('Setting up final VM')
608 self.vm = self.lv.defineXML(ElementTree.tostring(xml.getroot()))605 self.vm = self.lv.defineXML(ElementTree.tostring(xml.getroot()))
606 self.cleanfunction(self.vm.undefineFlags, False, libvirt.VIR_DOMAIN_UNDEFINE_NVRAM)
609 self.cleanfunction(self.vm.destroy)607 self.cleanfunction(self.vm.destroy)
610 self.cleanfunction(self.vm.undefine)608 self.cleanfunction(self.vm.undefine)
611 if self.poweroff:609 if self.poweroff:

Subscribers

People subscribed via source and target branches