Merge lp:~blamar/nova/libvirt-cleanup-branch into lp:~hudson-openstack/nova/trunk
- libvirt-cleanup-branch
- Merge into trunk
Status: | Work in progress |
---|---|
Proposed branch: | lp:~blamar/nova/libvirt-cleanup-branch |
Merge into: | lp:~hudson-openstack/nova/trunk |
Diff against target: |
433 lines (+123/-139) 6 files modified
nova/tests/test_libvirt.py (+8/-52) nova/utils.py (+15/-0) nova/virt/libvirt/__init__.py (+85/-0) nova/virt/libvirt/connection.py (+13/-82) nova/virt/libvirt/firewall.py (+1/-5) tools/pip-requires (+1/-0) |
To merge this branch: | bzr merge lp:~blamar/nova/libvirt-cleanup-branch |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Monty Taylor (community) | Needs Fixing | ||
Devin Carlen (community) | Approve | ||
Ed Leafe (community) | Approve | ||
William Wolf (community) | Approve | ||
Alex Meade (community) | Approve | ||
Review via email: mp+66064@code.launchpad.net |
Commit message
Moved libvirt flag defines to libvirt/
Description of the change
Two small cleanups in libvirt:
1) Moved flag defines to __init__.py
2) Replaced lazy-loading of imports with utils.optional_
One unrelated change is the addition of unittest2 to pip-requires. I'm
using the unittest.skipIf method in test_libvirt.py and unittest2 has
backported all Python 2.7 unittest improvements.
Brian Waldon (bcwaldon) wrote : | # |
Good refactoring, Brian. one minor thing:
164: Can you rephrase this log line to not repeat the word 'import'? And should it be info or debug?
Ed Leafe (ed-leafe) wrote : | # |
358 + """Retrieve a libvirt connection object.
359 +
360 + :param read_only: If True, the libvirt connection will be read only.
361 + :returns: `nova.virt.
362 +
363 + """
Can this be reduced to a single line docstring? The param name makes its use obvious, and the return value type is what the docstring already stated.
Also, is there a reason not to change all uses of unittest to unittest2? Or is that planned as part of another merge?
- 1219. By Brian Lamar
-
review feedback from bcwaldon and ed leafe
Brian Lamar (blamar) wrote : | # |
Shortened comment to single-line (you're very right, it was unnecessarily redundant!) and re-worded the log line for bcwaldon.
Ed, there is not a blueprint I'm aware of, so I made one. Great suggestion. I'm not going to actively pursue it now, but it will be something to point to when I do get the time or someone else feels like taking it on.
William Wolf (throughnothing) wrote : | # |
This looks good
OpenStack Infra (hudson-openstack) wrote : | # |
The attempt to merge lp:~blamar/nova/libvirt-cleanup-branch into lp:nova failed. Below is the output from the failed tests.
FloatingIpTest
test_
test_
test_
test_
test_
test_
test_
FlavorsExtraSpe
test_create OK 0.04
test_
test_delete OK 0.04
test_index OK 0.05
test_
test_show OK 0.05
test_
test_
test_
test_
test_
AccountsTest
test_
test_
test_
test_
AdminAPITest
test_
test_
APITest
test_
test_
test_
Test
test_
test_
test_
test_
test_bad_token OK 0.05
test_
test_
test_no_user OK 0.06
test_
test_
TestFunctional
test_
test_
TestLimiter
test_
LimiterTest
test_
- 1220. By Brian Lamar
-
Merged trunk.
- 1221. By Brian Lamar
-
Merged trunk
OpenStack Infra (hudson-openstack) wrote : | # |
The attempt to merge lp:~blamar/nova/libvirt-cleanup-branch into lp:nova failed. Below is the output from the failed tests.
FloatingIpTest
test_
test_
test_
test_
test_
test_
test_
FixedIpTest
test_
test_
test_
test_
FlavorsExtraSpe
test_create OK 0.04
test_
test_delete OK 0.05
test_index OK 0.05
test_
test_show OK 0.05
test_
test_
test_
test_
test_
AccountsTest
test_
test_
test_
test_
AdminAPITest
test_
test_
APITest
test_
test_
test_
Test
test_
test_
test_
test_
test_bad_token OK 0.06
test_
test_
test_no_user OK 0.05
test_
test_
OpenStack Infra (hudson-openstack) wrote : | # |
The attempt to merge lp:~blamar/nova/libvirt-cleanup-branch into lp:nova failed. Below is the output from the failed tests.
FloatingIpTest
test_
test_
test_
test_
test_
test_
test_
FixedIpTest
test_
test_
test_
test_
FlavorsExtraSpe
test_create OK 0.05
test_
test_delete OK 0.05
test_index OK 0.05
test_
test_show OK 0.05
test_
test_
test_
test_
test_
AccountsTest
test_
test_
test_
test_
AdminAPITest
test_
test_
APITest
test_
test_
test_
Test
test_
test_
test_
test_
test_bad_token OK 0.06
test_
test_
test_no_user OK 0.06
test_
test_
Monty Taylor (mordred) wrote : | # |
skipIf seems like an excellent way to describe conditional skipping... except that now it's throwing a SkipTest error.
The other tests which skip things use skip_test ... could you look in to fixing things so that skipIf does not throw a SkipTest error (or that the test harness understands that we skipped that on purpose)
OR
If unittest2 was added to get skipIf and skipIf is causing these problems - perhaps just use skip_test and remove the unittest2 need? (I mean, unless there is some grand scheme for migrating to unittest2 underway)
Unmerged revisions
- 1221. By Brian Lamar
-
Merged trunk
- 1220. By Brian Lamar
-
Merged trunk.
- 1219. By Brian Lamar
-
review feedback from bcwaldon and ed leafe
- 1218. By Brian Lamar
-
Two small cleanups in libvirt:
1) Moved flag defines to __init__.py
2) Replaced lazy-loading of imports with utils.optional_import (new) One unrelated change is the addition of unittest2 to pip-requires. I'm
using the unittest.skipIf method in test_libvirt.py and unittest2 has
backported all Python 2.7 unittest improvements.
Preview Diff
1 | === modified file 'nova/tests/test_libvirt.py' | |||
2 | --- nova/tests/test_libvirt.py 2011-06-28 16:20:02 +0000 | |||
3 | +++ nova/tests/test_libvirt.py 2011-07-08 00:31:40 +0000 | |||
4 | @@ -22,6 +22,7 @@ | |||
5 | 22 | import shutil | 22 | import shutil |
6 | 23 | import sys | 23 | import sys |
7 | 24 | 24 | ||
8 | 25 | import unittest2 as unittest | ||
9 | 25 | from xml.etree.ElementTree import fromstring as xml_to_tree | 26 | from xml.etree.ElementTree import fromstring as xml_to_tree |
10 | 26 | from xml.dom.minidom import parseString as xml_to_dom | 27 | from xml.dom.minidom import parseString as xml_to_dom |
11 | 27 | 28 | ||
12 | @@ -37,7 +38,12 @@ | |||
13 | 37 | from nova.virt.libvirt import connection | 38 | from nova.virt.libvirt import connection |
14 | 38 | from nova.virt.libvirt import firewall | 39 | from nova.virt.libvirt import firewall |
15 | 39 | 40 | ||
17 | 40 | libvirt = None | 41 | |
18 | 42 | libvirt = utils.optional_import("libvirt") | ||
19 | 43 | libxml2 = utils.optional_import("libxml2") | ||
20 | 44 | Template = utils.optional_import("Cheetah.Template") | ||
21 | 45 | |||
22 | 46 | |||
23 | 41 | FLAGS = flags.FLAGS | 47 | FLAGS = flags.FLAGS |
24 | 42 | flags.DECLARE('instances_path', 'nova.compute.manager') | 48 | flags.DECLARE('instances_path', 'nova.compute.manager') |
25 | 43 | 49 | ||
26 | @@ -147,7 +153,6 @@ | |||
27 | 147 | 153 | ||
28 | 148 | def setUp(self): | 154 | def setUp(self): |
29 | 149 | super(LibvirtConnTestCase, self).setUp() | 155 | super(LibvirtConnTestCase, self).setUp() |
30 | 150 | connection._late_load_cheetah() | ||
31 | 151 | self.flags(fake_call=True) | 156 | self.flags(fake_call=True) |
32 | 152 | self.manager = manager.AuthManager() | 157 | self.manager = manager.AuthManager() |
33 | 153 | 158 | ||
34 | @@ -188,20 +193,6 @@ | |||
35 | 188 | 'image_ref': '123456', | 193 | 'image_ref': '123456', |
36 | 189 | 'instance_type_id': '5'} # m1.small | 194 | 'instance_type_id': '5'} # m1.small |
37 | 190 | 195 | ||
38 | 191 | def lazy_load_library_exists(self): | ||
39 | 192 | """check if libvirt is available.""" | ||
40 | 193 | # try to connect libvirt. if fail, skip test. | ||
41 | 194 | try: | ||
42 | 195 | import libvirt | ||
43 | 196 | import libxml2 | ||
44 | 197 | except ImportError: | ||
45 | 198 | return False | ||
46 | 199 | global libvirt | ||
47 | 200 | libvirt = __import__('libvirt') | ||
48 | 201 | connection.libvirt = __import__('libvirt') | ||
49 | 202 | connection.libxml2 = __import__('libxml2') | ||
50 | 203 | return True | ||
51 | 204 | |||
52 | 205 | def create_fake_libvirt_mock(self, **kwargs): | 196 | def create_fake_libvirt_mock(self, **kwargs): |
53 | 206 | """Defining mocks for LibvirtConnection(libvirt is not used).""" | 197 | """Defining mocks for LibvirtConnection(libvirt is not used).""" |
54 | 207 | 198 | ||
55 | @@ -337,9 +328,6 @@ | |||
56 | 337 | self._check_xml_and_container(instance_data) | 328 | self._check_xml_and_container(instance_data) |
57 | 338 | 329 | ||
58 | 339 | def test_snapshot(self): | 330 | def test_snapshot(self): |
59 | 340 | if not self.lazy_load_library_exists(): | ||
60 | 341 | return | ||
61 | 342 | |||
62 | 343 | FLAGS.image_service = 'nova.image.fake.FakeImageService' | 331 | FLAGS.image_service = 'nova.image.fake.FakeImageService' |
63 | 344 | 332 | ||
64 | 345 | # Start test | 333 | # Start test |
65 | @@ -372,9 +360,6 @@ | |||
66 | 372 | self.assertEquals(snapshot['name'], snapshot_name) | 360 | self.assertEquals(snapshot['name'], snapshot_name) |
67 | 373 | 361 | ||
68 | 374 | def test_snapshot_no_image_architecture(self): | 362 | def test_snapshot_no_image_architecture(self): |
69 | 375 | if not self.lazy_load_library_exists(): | ||
70 | 376 | return | ||
71 | 377 | |||
72 | 378 | FLAGS.image_service = 'nova.image.fake.FakeImageService' | 363 | FLAGS.image_service = 'nova.image.fake.FakeImageService' |
73 | 379 | 364 | ||
74 | 380 | # Start test | 365 | # Start test |
75 | @@ -649,10 +634,6 @@ | |||
76 | 649 | 634 | ||
77 | 650 | def test_ensure_filtering_rules_for_instance_timeout(self): | 635 | def test_ensure_filtering_rules_for_instance_timeout(self): |
78 | 651 | """ensure_filtering_fules_for_instance() finishes with timeout.""" | 636 | """ensure_filtering_fules_for_instance() finishes with timeout.""" |
79 | 652 | # Skip if non-libvirt environment | ||
80 | 653 | if not self.lazy_load_library_exists(): | ||
81 | 654 | return | ||
82 | 655 | |||
83 | 656 | # Preparing mocks | 637 | # Preparing mocks |
84 | 657 | def fake_none(self): | 638 | def fake_none(self): |
85 | 658 | return | 639 | return |
86 | @@ -690,12 +671,9 @@ | |||
87 | 690 | 671 | ||
88 | 691 | db.instance_destroy(self.context, instance_ref['id']) | 672 | db.instance_destroy(self.context, instance_ref['id']) |
89 | 692 | 673 | ||
90 | 674 | @unittest.skipIf(libvirt is None, "libvirt required for this test") | ||
91 | 693 | def test_live_migration_raises_exception(self): | 675 | def test_live_migration_raises_exception(self): |
92 | 694 | """Confirms recover method is called when exceptions are raised.""" | 676 | """Confirms recover method is called when exceptions are raised.""" |
93 | 695 | # Skip if non-libvirt environment | ||
94 | 696 | if not self.lazy_load_library_exists(): | ||
95 | 697 | return | ||
96 | 698 | |||
97 | 699 | # Preparing data | 677 | # Preparing data |
98 | 700 | self.compute = utils.import_object(FLAGS.compute_manager) | 678 | self.compute = utils.import_object(FLAGS.compute_manager) |
99 | 701 | instance_dict = {'host': 'fake', 'state': power_state.RUNNING, | 679 | instance_dict = {'host': 'fake', 'state': power_state.RUNNING, |
100 | @@ -741,10 +719,6 @@ | |||
101 | 741 | 719 | ||
102 | 742 | @test.skip_test("test needs rewrite: instance no longer has mac_address") | 720 | @test.skip_test("test needs rewrite: instance no longer has mac_address") |
103 | 743 | def test_spawn_with_network_info(self): | 721 | def test_spawn_with_network_info(self): |
104 | 744 | # Skip if non-libvirt environment | ||
105 | 745 | if not self.lazy_load_library_exists(): | ||
106 | 746 | return | ||
107 | 747 | |||
108 | 748 | # Preparing mocks | 722 | # Preparing mocks |
109 | 749 | def fake_none(self, instance): | 723 | def fake_none(self, instance): |
110 | 750 | return | 724 | return |
111 | @@ -829,20 +803,6 @@ | |||
112 | 829 | self.fw = firewall.IptablesFirewallDriver( | 803 | self.fw = firewall.IptablesFirewallDriver( |
113 | 830 | get_connection=lambda: self.fake_libvirt_connection) | 804 | get_connection=lambda: self.fake_libvirt_connection) |
114 | 831 | 805 | ||
115 | 832 | def lazy_load_library_exists(self): | ||
116 | 833 | """check if libvirt is available.""" | ||
117 | 834 | # try to connect libvirt. if fail, skip test. | ||
118 | 835 | try: | ||
119 | 836 | import libvirt | ||
120 | 837 | import libxml2 | ||
121 | 838 | except ImportError: | ||
122 | 839 | return False | ||
123 | 840 | global libvirt | ||
124 | 841 | libvirt = __import__('libvirt') | ||
125 | 842 | connection.libvirt = __import__('libvirt') | ||
126 | 843 | connection.libxml2 = __import__('libxml2') | ||
127 | 844 | return True | ||
128 | 845 | |||
129 | 846 | def tearDown(self): | 806 | def tearDown(self): |
130 | 847 | self.manager.delete_project(self.project) | 807 | self.manager.delete_project(self.project) |
131 | 848 | self.manager.delete_user(self.user) | 808 | self.manager.delete_user(self.user) |
132 | @@ -1056,10 +1016,6 @@ | |||
133 | 1056 | 1016 | ||
134 | 1057 | @test.skip_test("skip libvirt test project_get_network no longer exists") | 1017 | @test.skip_test("skip libvirt test project_get_network no longer exists") |
135 | 1058 | def test_unfilter_instance_undefines_nwfilter(self): | 1018 | def test_unfilter_instance_undefines_nwfilter(self): |
136 | 1059 | # Skip if non-libvirt environment | ||
137 | 1060 | if not self.lazy_load_library_exists(): | ||
138 | 1061 | return | ||
139 | 1062 | |||
140 | 1063 | admin_ctxt = context.get_admin_context() | 1019 | admin_ctxt = context.get_admin_context() |
141 | 1064 | 1020 | ||
142 | 1065 | fakefilter = NWFilterFakes() | 1021 | fakefilter = NWFilterFakes() |
143 | 1066 | 1022 | ||
144 | === modified file 'nova/utils.py' | |||
145 | --- nova/utils.py 2011-06-30 19:20:59 +0000 | |||
146 | +++ nova/utils.py 2011-07-08 00:31:40 +0000 | |||
147 | @@ -75,6 +75,21 @@ | |||
148 | 75 | return cls() | 75 | return cls() |
149 | 76 | 76 | ||
150 | 77 | 77 | ||
151 | 78 | def optional_import(import_str): | ||
152 | 79 | """Attempt to import the given string, but fall back to returning None. | ||
153 | 80 | |||
154 | 81 | :param import_str: The name of the module to import. | ||
155 | 82 | :returns: The requested module, or None if unable to import. | ||
156 | 83 | |||
157 | 84 | """ | ||
158 | 85 | try: | ||
159 | 86 | __import__(import_str) | ||
160 | 87 | return sys.modules[import_str] | ||
161 | 88 | except ImportError: | ||
162 | 89 | LOG.info(_("Unable to import optional module: %s") % import_str) | ||
163 | 90 | return None | ||
164 | 91 | |||
165 | 92 | |||
166 | 78 | def vpn_ping(address, port, timeout=0.05, session_id=None): | 93 | def vpn_ping(address, port, timeout=0.05, session_id=None): |
167 | 79 | """Sends a vpn negotiation packet and returns the server session. | 94 | """Sends a vpn negotiation packet and returns the server session. |
168 | 80 | 95 | ||
169 | 81 | 96 | ||
170 | === modified file 'nova/virt/libvirt/__init__.py' | |||
171 | --- nova/virt/libvirt/__init__.py 2011-04-22 16:47:09 +0000 | |||
172 | +++ nova/virt/libvirt/__init__.py 2011-07-08 00:31:40 +0000 | |||
173 | @@ -0,0 +1,85 @@ | |||
174 | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
175 | 2 | |||
176 | 3 | # Copyright 2011 OpenStack, LLC | ||
177 | 4 | # | ||
178 | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
179 | 6 | # not use this file except in compliance with the License. You may obtain | ||
180 | 7 | # a copy of the License at | ||
181 | 8 | # | ||
182 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
183 | 10 | # | ||
184 | 11 | # Unless required by applicable law or agreed to in writing, software | ||
185 | 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
186 | 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
187 | 14 | # License for the specific language governing permissions and limitations | ||
188 | 15 | # under the License. | ||
189 | 16 | |||
190 | 17 | from nova import flags | ||
191 | 18 | from nova import utils | ||
192 | 19 | |||
193 | 20 | |||
194 | 21 | FLAGS = flags.FLAGS | ||
195 | 22 | |||
196 | 23 | |||
197 | 24 | flags.DECLARE('live_migration_retry_count', 'nova.compute.manager') | ||
198 | 25 | |||
199 | 26 | flags.DEFINE_string('rescue_image_id', | ||
200 | 27 | 'ami-rescue', 'Rescue ami image') | ||
201 | 28 | |||
202 | 29 | flags.DEFINE_string('rescue_kernel_id', | ||
203 | 30 | 'aki-rescue', 'Rescue aki image') | ||
204 | 31 | |||
205 | 32 | flags.DEFINE_string('rescue_ramdisk_id', | ||
206 | 33 | 'ari-rescue', | ||
207 | 34 | 'Rescue ari image') | ||
208 | 35 | |||
209 | 36 | flags.DEFINE_string('libvirt_xml_template', | ||
210 | 37 | utils.abspath('virt/libvirt.xml.template'), | ||
211 | 38 | 'Libvirt XML Template') | ||
212 | 39 | |||
213 | 40 | flags.DEFINE_string('libvirt_type', | ||
214 | 41 | 'kvm', | ||
215 | 42 | 'Libvirt driver (kvm, lxc, qemu, uml, or xen)') | ||
216 | 43 | |||
217 | 44 | flags.DEFINE_string('libvirt_uri', | ||
218 | 45 | '', | ||
219 | 46 | 'Override the default libvirt URI set by libvirt_type') | ||
220 | 47 | |||
221 | 48 | flags.DEFINE_string('ajaxterm_portrange', | ||
222 | 49 | '10000-12000', | ||
223 | 50 | 'Range of ports that ajaxterm should randomly try to bind') | ||
224 | 51 | |||
225 | 52 | flags.DEFINE_string('firewall_driver', | ||
226 | 53 | 'nova.virt.libvirt.firewall.IptablesFirewallDriver', | ||
227 | 54 | 'Firewall driver (defaults to iptables)') | ||
228 | 55 | |||
229 | 56 | flags.DEFINE_string('cpuinfo_xml_template', | ||
230 | 57 | utils.abspath('virt/cpuinfo.xml.template'), | ||
231 | 58 | 'CpuInfo XML Template (Used only live migration now)') | ||
232 | 59 | |||
233 | 60 | flags.DEFINE_string('live_migration_uri', | ||
234 | 61 | "qemu+tcp://%s/system", | ||
235 | 62 | 'Define protocol used by live_migration feature') | ||
236 | 63 | |||
237 | 64 | flags.DEFINE_string('live_migration_flag', | ||
238 | 65 | "VIR_MIGRATE_UNDEFINE_SOURCE, VIR_MIGRATE_PEER2PEER", | ||
239 | 66 | 'Define live migration behavior.') | ||
240 | 67 | |||
241 | 68 | flags.DEFINE_string('qemu_img', 'qemu-img', | ||
242 | 69 | 'binary to use for qemu-img commands') | ||
243 | 70 | |||
244 | 71 | flags.DEFINE_integer('live_migration_bandwidth', 0, | ||
245 | 72 | 'Define live migration behavior') | ||
246 | 73 | |||
247 | 74 | flags.DEFINE_bool('start_guests_on_host_boot', | ||
248 | 75 | False, | ||
249 | 76 | 'Whether to restart guests when the host reboots') | ||
250 | 77 | |||
251 | 78 | flags.DEFINE_bool('allow_project_net_traffic', | ||
252 | 79 | True, | ||
253 | 80 | 'Whether to allow in project network traffic') | ||
254 | 81 | |||
255 | 82 | flags.DEFINE_bool('use_cow_images', | ||
256 | 83 | True, | ||
257 | 84 | 'Whether to use cow images') | ||
258 | 85 | |||
259 | 0 | 86 | ||
260 | === modified file 'nova/virt/libvirt/connection.py' | |||
261 | --- nova/virt/libvirt/connection.py 2011-07-07 18:30:47 +0000 | |||
262 | +++ nova/virt/libvirt/connection.py 2011-07-08 00:31:40 +0000 | |||
263 | @@ -17,23 +17,10 @@ | |||
264 | 17 | # License for the specific language governing permissions and limitations | 17 | # License for the specific language governing permissions and limitations |
265 | 18 | # under the License. | 18 | # under the License. |
266 | 19 | 19 | ||
269 | 20 | """ | 20 | """Provides logic for connecting to a hypervisor through libvirt. |
268 | 21 | A connection to a hypervisor through libvirt. | ||
270 | 22 | 21 | ||
271 | 23 | Supports KVM, LXC, QEMU, UML, and XEN. | 22 | Supports KVM, LXC, QEMU, UML, and XEN. |
272 | 24 | 23 | ||
273 | 25 | **Related Flags** | ||
274 | 26 | |||
275 | 27 | :libvirt_type: Libvirt domain type. Can be kvm, qemu, uml, xen | ||
276 | 28 | (default: kvm). | ||
277 | 29 | :libvirt_uri: Override for the default libvirt URI (depends on libvirt_type). | ||
278 | 30 | :libvirt_xml_template: Libvirt XML Template. | ||
279 | 31 | :rescue_image_id: Rescue ami image (default: ami-rescue). | ||
280 | 32 | :rescue_kernel_id: Rescue aki image (default: aki-rescue). | ||
281 | 33 | :rescue_ramdisk_id: Rescue ari image (default: ari-rescue). | ||
282 | 34 | :injected_network_template: Template file for injected network | ||
283 | 35 | :allow_project_net_traffic: Whether to allow in project network traffic | ||
284 | 36 | |||
285 | 37 | """ | 24 | """ |
286 | 38 | 25 | ||
287 | 39 | import hashlib | 26 | import hashlib |
288 | @@ -71,83 +58,27 @@ | |||
289 | 71 | from nova.virt.libvirt import netutils | 58 | from nova.virt.libvirt import netutils |
290 | 72 | 59 | ||
291 | 73 | 60 | ||
295 | 74 | libvirt = None | 61 | libvirt = utils.optional_import("libvirt") |
296 | 75 | libxml2 = None | 62 | libxml2 = utils.optional_import("libxml2") |
297 | 76 | Template = None | 63 | Template = utils.optional_import("Cheetah.Template") |
298 | 77 | 64 | ||
299 | 78 | 65 | ||
300 | 79 | LOG = logging.getLogger('nova.virt.libvirt_conn') | 66 | LOG = logging.getLogger('nova.virt.libvirt_conn') |
301 | 80 | |||
302 | 81 | |||
303 | 82 | FLAGS = flags.FLAGS | 67 | FLAGS = flags.FLAGS |
304 | 83 | flags.DECLARE('live_migration_retry_count', 'nova.compute.manager') | ||
305 | 84 | # TODO(vish): These flags should probably go into a shared location | ||
306 | 85 | flags.DEFINE_string('rescue_image_id', 'ami-rescue', 'Rescue ami image') | ||
307 | 86 | flags.DEFINE_string('rescue_kernel_id', 'aki-rescue', 'Rescue aki image') | ||
308 | 87 | flags.DEFINE_string('rescue_ramdisk_id', 'ari-rescue', 'Rescue ari image') | ||
309 | 88 | flags.DEFINE_string('libvirt_xml_template', | ||
310 | 89 | utils.abspath('virt/libvirt.xml.template'), | ||
311 | 90 | 'Libvirt XML Template') | ||
312 | 91 | flags.DEFINE_string('libvirt_type', | ||
313 | 92 | 'kvm', | ||
314 | 93 | 'Libvirt domain type (valid options are: ' | ||
315 | 94 | 'kvm, lxc, qemu, uml, xen)') | ||
316 | 95 | flags.DEFINE_string('libvirt_uri', | ||
317 | 96 | '', | ||
318 | 97 | 'Override the default libvirt URI (which is dependent' | ||
319 | 98 | ' on libvirt_type)') | ||
320 | 99 | flags.DEFINE_bool('allow_project_net_traffic', | ||
321 | 100 | True, | ||
322 | 101 | 'Whether to allow in project network traffic') | ||
323 | 102 | flags.DEFINE_bool('use_cow_images', | ||
324 | 103 | True, | ||
325 | 104 | 'Whether to use cow images') | ||
326 | 105 | flags.DEFINE_string('ajaxterm_portrange', | ||
327 | 106 | '10000-12000', | ||
328 | 107 | 'Range of ports that ajaxterm should randomly try to bind') | ||
329 | 108 | flags.DEFINE_string('firewall_driver', | ||
330 | 109 | 'nova.virt.libvirt.firewall.IptablesFirewallDriver', | ||
331 | 110 | 'Firewall driver (defaults to iptables)') | ||
332 | 111 | flags.DEFINE_string('cpuinfo_xml_template', | ||
333 | 112 | utils.abspath('virt/cpuinfo.xml.template'), | ||
334 | 113 | 'CpuInfo XML Template (Used only live migration now)') | ||
335 | 114 | flags.DEFINE_string('live_migration_uri', | ||
336 | 115 | "qemu+tcp://%s/system", | ||
337 | 116 | 'Define protocol used by live_migration feature') | ||
338 | 117 | flags.DEFINE_string('live_migration_flag', | ||
339 | 118 | "VIR_MIGRATE_UNDEFINE_SOURCE, VIR_MIGRATE_PEER2PEER", | ||
340 | 119 | 'Define live migration behavior.') | ||
341 | 120 | flags.DEFINE_integer('live_migration_bandwidth', 0, | ||
342 | 121 | 'Define live migration behavior') | ||
343 | 122 | flags.DEFINE_string('qemu_img', 'qemu-img', | ||
344 | 123 | 'binary to use for qemu-img commands') | ||
345 | 124 | flags.DEFINE_bool('start_guests_on_host_boot', False, | ||
346 | 125 | 'Whether to restart guests when the host reboots') | ||
347 | 126 | 68 | ||
348 | 127 | 69 | ||
349 | 128 | def get_connection(read_only): | 70 | def get_connection(read_only): |
356 | 129 | # These are loaded late so that there's no need to install these | 71 | """Retrieve a libvirt connection object.""" |
351 | 130 | # libraries when not using libvirt. | ||
352 | 131 | # Cheetah is separate because the unit tests want to load Cheetah, | ||
353 | 132 | # but not libvirt. | ||
354 | 133 | global libvirt | ||
355 | 134 | global libxml2 | ||
357 | 135 | if libvirt is None: | 72 | if libvirt is None: |
359 | 136 | libvirt = __import__('libvirt') | 73 | raise ImportError(_("Unable to import libvirt")) |
360 | 137 | if libxml2 is None: | 74 | if libxml2 is None: |
363 | 138 | libxml2 = __import__('libxml2') | 75 | raise ImportError(_("Unable to import libxml2")) |
364 | 139 | _late_load_cheetah() | 76 | if Template is None: |
365 | 77 | raise ImportError(_("Unable to import Cheetah.Template")) | ||
366 | 78 | |||
367 | 140 | return LibvirtConnection(read_only) | 79 | return LibvirtConnection(read_only) |
368 | 141 | 80 | ||
369 | 142 | 81 | ||
370 | 143 | def _late_load_cheetah(): | ||
371 | 144 | global Template | ||
372 | 145 | if Template is None: | ||
373 | 146 | t = __import__('Cheetah.Template', globals(), locals(), | ||
374 | 147 | ['Template'], -1) | ||
375 | 148 | Template = t.Template | ||
376 | 149 | |||
377 | 150 | |||
378 | 151 | def _strip_dev(mount_path): | 82 | def _strip_dev(mount_path): |
379 | 152 | return re.sub(r'^/dev/', '', mount_path) | 83 | return re.sub(r'^/dev/', '', mount_path) |
380 | 153 | 84 | ||
381 | @@ -896,7 +827,7 @@ | |||
382 | 896 | nets.append(net_info) | 827 | nets.append(net_info) |
383 | 897 | 828 | ||
384 | 898 | if have_injected_networks: | 829 | if have_injected_networks: |
386 | 899 | net = str(Template(ifc_template, | 830 | net = str(Template.Template(ifc_template, |
387 | 900 | searchList=[{'interfaces': nets, | 831 | searchList=[{'interfaces': nets, |
388 | 901 | 'use_ipv6': FLAGS.use_ipv6}])) | 832 | 'use_ipv6': FLAGS.use_ipv6}])) |
389 | 902 | 833 | ||
390 | @@ -1035,7 +966,7 @@ | |||
391 | 1035 | LOG.debug(_('instance %s: starting toXML method'), instance['name']) | 966 | LOG.debug(_('instance %s: starting toXML method'), instance['name']) |
392 | 1036 | xml_info = self._prepare_xml_info(instance, rescue, network_info, | 967 | xml_info = self._prepare_xml_info(instance, rescue, network_info, |
393 | 1037 | block_device_mapping) | 968 | block_device_mapping) |
395 | 1038 | xml = str(Template(self.libvirt_xml, searchList=[xml_info])) | 969 | xml = str(Template.Template(self.libvirt_xml, searchList=[xml_info])) |
396 | 1039 | LOG.debug(_('instance %s: finished toXML method'), instance['name']) | 970 | LOG.debug(_('instance %s: finished toXML method'), instance['name']) |
397 | 1040 | return xml | 971 | return xml |
398 | 1041 | 972 | ||
399 | @@ -1439,7 +1370,7 @@ | |||
400 | 1439 | 1370 | ||
401 | 1440 | LOG.info(_('Instance launched has CPU info:\n%s') % cpu_info) | 1371 | LOG.info(_('Instance launched has CPU info:\n%s') % cpu_info) |
402 | 1441 | dic = utils.loads(cpu_info) | 1372 | dic = utils.loads(cpu_info) |
404 | 1442 | xml = str(Template(self.cpuinfo_xml, searchList=dic)) | 1373 | xml = str(Template.Template(self.cpuinfo_xml, searchList=dic)) |
405 | 1443 | LOG.info(_('to xml...\n:%s ' % xml)) | 1374 | LOG.info(_('to xml...\n:%s ' % xml)) |
406 | 1444 | 1375 | ||
407 | 1445 | u = "http://libvirt.org/html/libvirt-libvirt.html#virCPUCompareResult" | 1376 | u = "http://libvirt.org/html/libvirt-libvirt.html#virCPUCompareResult" |
408 | 1446 | 1377 | ||
409 | === modified file 'nova/virt/libvirt/firewall.py' | |||
410 | --- nova/virt/libvirt/firewall.py 2011-06-27 21:48:03 +0000 | |||
411 | +++ nova/virt/libvirt/firewall.py 2011-07-08 00:31:40 +0000 | |||
412 | @@ -32,11 +32,7 @@ | |||
413 | 32 | FLAGS = flags.FLAGS | 32 | FLAGS = flags.FLAGS |
414 | 33 | 33 | ||
415 | 34 | 34 | ||
421 | 35 | try: | 35 | libvirt = utils.optional_import("libvirt") |
417 | 36 | import libvirt | ||
418 | 37 | except ImportError: | ||
419 | 38 | LOG.warn(_("Libvirt module could not be loaded. NWFilterFirewall will " | ||
420 | 39 | "not work correctly.")) | ||
422 | 40 | 36 | ||
423 | 41 | 37 | ||
424 | 42 | class FirewallDriver(object): | 38 | class FirewallDriver(object): |
425 | 43 | 39 | ||
426 | === modified file 'tools/pip-requires' | |||
427 | --- tools/pip-requires 2011-06-30 18:11:03 +0000 | |||
428 | +++ tools/pip-requires 2011-07-08 00:31:40 +0000 | |||
429 | @@ -33,3 +33,4 @@ | |||
430 | 33 | nosexcover | 33 | nosexcover |
431 | 34 | GitPython | 34 | GitPython |
432 | 35 | paramiko | 35 | paramiko |
433 | 36 | unittest2 |
I like it