Merge lp://staging/~aheck/vmbuilder/vmbuilder-hypervisor-check into lp://staging/vmbuilder/trunk

Proposed by Andreas Heck
Status: Needs review
Proposed branch: lp://staging/~aheck/vmbuilder/vmbuilder-hypervisor-check
Merge into: lp://staging/vmbuilder/trunk
Diff against target: 157 lines
8 files modified
VMBuilder/host.py (+31/-0)
VMBuilder/hypervisor.py (+25/-0)
VMBuilder/plugins/kvm/vm.py (+1/-0)
VMBuilder/plugins/virtualbox/vm.py (+1/-0)
VMBuilder/plugins/vmware/vm.py (+1/-0)
VMBuilder/plugins/xen/vm.py (+1/-0)
VMBuilder/vm.py (+3/-0)
tests.py (+5/-2)
To merge this branch: bzr merge lp://staging/~aheck/vmbuilder/vmbuilder-hypervisor-check
Reviewer Review Type Date Requested Status
Soren Hansen Pending
Review via email: mp+12843@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Andreas Heck (aheck) wrote :

Each hypervisor has a list of required programs now and vmbuilder checks before building the VM that those required programs are available

This prevents the unfortunate situation that you build a VM and at the very end the build process fails because vmbuilder doesn't find the program for the image conversion.

Unmerged revisions

352. By Andreas Heck

Added required_programs for the hypervisors

351. By Andreas Heck

Hypervisors must now declare the programs that are needed for vmbuilder to build a VM for the hypervisor in question

If one or more such programs can't be found on the build host vmbuilder will
refuse to build the VM and raise a VMBuilderUserError exception that tells the
user which programs are missing.

Need to declare those dependencies for all hypervisors tomorrow.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'VMBuilder/host.py'
2--- VMBuilder/host.py 1970-01-01 00:00:00 +0000
3+++ VMBuilder/host.py 2009-10-04 13:55:19 +0000
4@@ -0,0 +1,31 @@
5+#
6+# Uncomplicated VM Builder
7+# Copyright (C) 2007-2009 Canonical Ltd.
8+#
9+# See AUTHORS for list of contributors
10+#
11+# This program is free software: you can redistribute it and/or modify
12+# it under the terms of the GNU General Public License version 3, as
13+# published by the Free Software Foundation.
14+#
15+# This program is distributed in the hope that it will be useful,
16+# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+# GNU General Public License for more details.
19+#
20+# You should have received a copy of the GNU General Public License
21+# along with this program. If not, see <http://www.gnu.org/licenses/>.
22+#
23+# Provides all functionality that is related to the host operating system
24+
25+import os
26+
27+def has_program(program):
28+ """Check if a given program is available"""
29+ paths = os.environ['PATH'].split(':')
30+ for p in paths:
31+ abspath = p + '/' + program
32+ if os.path.exists(abspath) and os.path.isfile(abspath):
33+ return True
34+
35+ return False
36
37=== modified file 'VMBuilder/hypervisor.py'
38--- VMBuilder/hypervisor.py 2009-06-10 13:40:41 +0000
39+++ VMBuilder/hypervisor.py 2009-10-04 13:55:19 +0000
40@@ -18,12 +18,37 @@
41 #
42 # Hypervisor super class
43
44+import VMBuilder.host
45 import VMBuilder.plugins
46+from VMBuilder.exception import VMBuilderException
47+from VMBuilder.exception import VMBuilderUserError
48
49 STORAGE_DISK_IMAGE = 0
50 STORAGE_FS_IMAGE = 1
51
52 class Hypervisor(VMBuilder.plugins.Plugin):
53+ # Subclasses need to provide a list of required programs (even an empty
54+ # one) here. Otherwise no virtual machines will be able to be built with
55+ # that hypervisor because this list is part of the contract of this
56+ # superclass.
57+ required_programs = None
58+
59 def finalize(self):
60 raise NotImplemented('Hypervisor subclasses need to implement the finalize method')
61
62+ def check_dependencies(self):
63+ """Check if all the dependencies of the hypervisor are met"""
64+
65+ if self.required_programs == None:
66+ raise VMBuilderException, 'Hypervisor needs to declare its required programs'
67+
68+ missing = []
69+ for program in self.required_programs:
70+ if not VMBuilder.host.has_program(program):
71+ missing.append(program)
72+
73+ if len(missing) > 0:
74+ if len(missing) == 1:
75+ raise VMBuilderUserError, 'Following program is needed for the selected hypervisor but could not be found: ' + ', '.join(missing)
76+ else:
77+ raise VMBuilderUserError, 'Following programs are needed for the selected hypervisor but could not be found: ' + ', '.join(missing)
78
79=== modified file 'VMBuilder/plugins/kvm/vm.py'
80--- VMBuilder/plugins/kvm/vm.py 2009-06-10 13:40:41 +0000
81+++ VMBuilder/plugins/kvm/vm.py 2009-10-04 13:55:19 +0000
82@@ -24,6 +24,7 @@
83 import stat
84
85 class KVM(Hypervisor):
86+ required_programs = ['kvm', 'kvm-img']
87 name = 'KVM'
88 arg = 'kvm'
89 filetype = 'qcow2'
90
91=== modified file 'VMBuilder/plugins/virtualbox/vm.py'
92--- VMBuilder/plugins/virtualbox/vm.py 2009-06-10 13:40:41 +0000
93+++ VMBuilder/plugins/virtualbox/vm.py 2009-10-04 13:55:19 +0000
94@@ -26,6 +26,7 @@
95 import VMBuilder.hypervisor
96
97 class VirtualBox(Hypervisor):
98+ required_programs = ['VBoxManage', 'qemu-img']
99 preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE
100 needs_bootloader = True
101 name = 'VirtualBox'
102
103=== modified file 'VMBuilder/plugins/vmware/vm.py'
104--- VMBuilder/plugins/vmware/vm.py 2009-06-10 13:40:41 +0000
105+++ VMBuilder/plugins/vmware/vm.py 2009-10-04 13:55:19 +0000
106@@ -26,6 +26,7 @@
107 from math import floor
108
109 class VMWare(Hypervisor):
110+ required_programs = ['qemu-img']
111 filetype = 'vmdk'
112 preferred_storage = VMBuilder.hypervisor.STORAGE_DISK_IMAGE
113 needs_bootloader = True
114
115=== modified file 'VMBuilder/plugins/xen/vm.py'
116--- VMBuilder/plugins/xen/vm.py 2009-06-10 13:40:41 +0000
117+++ VMBuilder/plugins/xen/vm.py 2009-10-04 13:55:19 +0000
118@@ -25,6 +25,7 @@
119 import stat
120
121 class Xen(Hypervisor):
122+ required_programs = []
123 name = 'Xen'
124 arg = 'xen'
125 preferred_storage = VMBuilder.hypervisor.STORAGE_FS_IMAGE
126
127=== modified file 'VMBuilder/vm.py'
128--- VMBuilder/vm.py 2009-08-18 15:00:16 +0000
129+++ VMBuilder/vm.py 2009-10-04 13:55:19 +0000
130@@ -439,6 +439,9 @@
131
132 testnet.close()
133
134+ # test if all the dependencies of the hypervisor can be met
135+ self.hypervisor.check_dependencies()
136+
137 def install_file(self, path, contents=None, source=None, mode=None):
138 fullpath = '%s%s' % (self.installdir, path)
139 if source and not contents:
140
141=== modified file 'tests.py'
142--- tests.py 2009-06-10 13:40:41 +0000
143+++ tests.py 2009-10-04 13:55:19 +0000
144@@ -64,8 +64,11 @@
145 self.assertTrue("foobarbaztest" in
146 run_cmd("env", env={'foobarbaztest' : 'bar' }))
147
148-
149+class TestHost(unittest.TestCase):
150+ def test_has_program(self):
151+ from VMBuilder.host import has_program
152+ self.assertFalse(has_program('program_that_does_not_exist'))
153+ self.assertTrue(has_program('bash'))
154
155 if __name__ == '__main__':
156 unittest.main()
157-

Subscribers

People subscribed via source and target branches