Merge lp:~blamar/nova/libvirt-cleanup-branch into lp:~hudson-openstack/nova/trunk

Proposed by Brian Lamar
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
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/__init__.py, and modified lazy loading of libvirt/libxml2/Cheetah to use nova.utils.optional_import.

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_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.

To post a comment you must log in.
Revision history for this message
Alex Meade (alex-meade) wrote :

I like it

review: Approve
Revision history for this message
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?

Revision history for this message
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.libvirt.connection:LibvirtConnection`
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?

review: Needs Information
1219. By Brian Lamar

review feedback from bcwaldon and ed leafe

Revision history for this message
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.

https://blueprints.launchpad.net/nova/+spec/nova-unittest2

Revision history for this message
William Wolf (throughnothing) wrote :

This looks good

review: Approve
Revision history for this message
Ed Leafe (ed-leafe) wrote :

ok, lgtm.

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (71.0 KiB)

The attempt to merge lp:~blamar/nova/libvirt-cleanup-branch into lp:nova failed. Below is the output from the failed tests.

FloatingIpTest
    test_floating_ip_allocate OK 0.14
    test_floating_ip_associate OK 0.21
    test_floating_ip_disassociate OK 0.09
    test_floating_ip_release OK 0.09
    test_floating_ip_show OK 0.09
    test_floating_ips_list OK 0.09
    test_translate_floating_ip_view OK 0.04
FlavorsExtraSpecsTest
    test_create OK 0.04
    test_create_empty_body OK 0.04
    test_delete OK 0.04
    test_index OK 0.05
    test_index_no_data OK 0.04
    test_show OK 0.05
    test_show_spec_not_found OK 0.25
    test_update_item OK 0.05
    test_update_item_body_uri_mismatch OK 0.04
    test_update_item_empty_body OK 0.04
    test_update_item_too_many_keys OK 0.04
AccountsTest
    test_account_create OK 0.17
    test_account_delete OK 0.17
    test_account_update OK 0.18
    test_get_account OK 0.40
AdminAPITest
    test_admin_disabled OK 0.13
    test_admin_enabled OK 0.16
APITest
    test_exceptions_are_converted_to_faults OK 0.01
    test_malformed_json OK 0.05
    test_malformed_xml OK 0.06
Test
    test_authorize_project OK 0.09
    test_authorize_token OK 0.34
    test_authorize_user OK 0.05
    test_bad_project OK 0.09
    test_bad_token OK 0.05
    test_bad_user_bad_key OK 0.05
    test_bad_user_good_key OK 0.05
    test_no_user OK 0.06
    test_not_existing_project OK 0.08
    test_token_expiry OK 0.27
TestFunctional
    test_token_doesnotexist OK 0.06
    test_token_expiry OK 0.08
TestLimiter
    test_authorize_token OK 0.10
LimiterTest
    test_limiter_custom_max_limit ...

1220. By Brian Lamar

Merged trunk.

1221. By Brian Lamar

Merged trunk

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (170.5 KiB)

The attempt to merge lp:~blamar/nova/libvirt-cleanup-branch into lp:nova failed. Below is the output from the failed tests.

FloatingIpTest
    test_floating_ip_allocate OK 0.29
    test_floating_ip_associate OK 0.10
    test_floating_ip_disassociate OK 0.09
    test_floating_ip_release OK 0.10
    test_floating_ip_show OK 0.10
    test_floating_ips_list OK 0.10
    test_translate_floating_ip_view OK 0.04
FixedIpTest
    test_add_fixed_ip OK 0.08
    test_add_fixed_ip_no_network OK 0.08
    test_remove_fixed_ip OK 0.08
    test_remove_fixed_ip_no_address OK 0.27
FlavorsExtraSpecsTest
    test_create OK 0.04
    test_create_empty_body OK 0.05
    test_delete OK 0.05
    test_index OK 0.05
    test_index_no_data OK 0.05
    test_show OK 0.05
    test_show_spec_not_found OK 0.04
    test_update_item OK 0.05
    test_update_item_body_uri_mismatch OK 0.05
    test_update_item_empty_body OK 0.05
    test_update_item_too_many_keys OK 0.06
AccountsTest
    test_account_create OK 0.36
    test_account_delete OK 0.17
    test_account_update OK 0.18
    test_get_account OK 0.18
AdminAPITest
    test_admin_disabled OK 0.15
    test_admin_enabled OK 0.42
APITest
    test_exceptions_are_converted_to_faults OK 0.03
    test_malformed_json OK 0.05
    test_malformed_xml OK 0.08
Test
    test_authorize_project OK 0.10
    test_authorize_token OK 0.10
    test_authorize_user OK 0.06
    test_bad_project OK 0.34
    test_bad_token OK 0.06
    test_bad_user_bad_key OK 0.06
    test_bad_user_good_key OK 0.06
    test_no_user OK 0.05
    test_not_existing_project OK 0.10
    test_token_expiry OK ...

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :
Download full text (182.4 KiB)

The attempt to merge lp:~blamar/nova/libvirt-cleanup-branch into lp:nova failed. Below is the output from the failed tests.

FloatingIpTest
    test_floating_ip_allocate OK 0.29
    test_floating_ip_associate OK 0.10
    test_floating_ip_disassociate OK 0.10
    test_floating_ip_release OK 0.10
    test_floating_ip_show OK 0.10
    test_floating_ips_list OK 0.09
    test_translate_floating_ip_view OK 0.04
FixedIpTest
    test_add_fixed_ip OK 0.08
    test_add_fixed_ip_no_network OK 0.08
    test_remove_fixed_ip OK 0.28
    test_remove_fixed_ip_no_address OK 0.07
FlavorsExtraSpecsTest
    test_create OK 0.05
    test_create_empty_body OK 0.05
    test_delete OK 0.05
    test_index OK 0.05
    test_index_no_data OK 0.05
    test_show OK 0.05
    test_show_spec_not_found OK 0.05
    test_update_item OK 0.05
    test_update_item_body_uri_mismatch OK 0.05
    test_update_item_empty_body OK 0.05
    test_update_item_too_many_keys OK 0.05
AccountsTest
    test_account_create OK 0.39
    test_account_delete OK 0.17
    test_account_update OK 0.18
    test_get_account OK 0.18
AdminAPITest
    test_admin_disabled OK 0.14
    test_admin_enabled OK 0.47
APITest
    test_exceptions_are_converted_to_faults OK 0.01
    test_malformed_json OK 0.06
    test_malformed_xml OK 0.06
Test
    test_authorize_project OK 0.10
    test_authorize_token OK 0.10
    test_authorize_user OK 0.06
    test_bad_project OK 0.35
    test_bad_token OK 0.06
    test_bad_user_bad_key OK 0.06
    test_bad_user_good_key OK 0.06
    test_no_user OK 0.06
    test_not_existing_project OK 0.10
    test_token_expiry OK ...

Revision history for this message
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)

review: Needs Fixing

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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/tests/test_libvirt.py'
--- nova/tests/test_libvirt.py 2011-06-28 16:20:02 +0000
+++ nova/tests/test_libvirt.py 2011-07-08 00:31:40 +0000
@@ -22,6 +22,7 @@
22import shutil22import shutil
23import sys23import sys
2424
25import unittest2 as unittest
25from xml.etree.ElementTree import fromstring as xml_to_tree26from xml.etree.ElementTree import fromstring as xml_to_tree
26from xml.dom.minidom import parseString as xml_to_dom27from xml.dom.minidom import parseString as xml_to_dom
2728
@@ -37,7 +38,12 @@
37from nova.virt.libvirt import connection38from nova.virt.libvirt import connection
38from nova.virt.libvirt import firewall39from nova.virt.libvirt import firewall
3940
40libvirt = None41
42libvirt = utils.optional_import("libvirt")
43libxml2 = utils.optional_import("libxml2")
44Template = utils.optional_import("Cheetah.Template")
45
46
41FLAGS = flags.FLAGS47FLAGS = flags.FLAGS
42flags.DECLARE('instances_path', 'nova.compute.manager')48flags.DECLARE('instances_path', 'nova.compute.manager')
4349
@@ -147,7 +153,6 @@
147153
148 def setUp(self):154 def setUp(self):
149 super(LibvirtConnTestCase, self).setUp()155 super(LibvirtConnTestCase, self).setUp()
150 connection._late_load_cheetah()
151 self.flags(fake_call=True)156 self.flags(fake_call=True)
152 self.manager = manager.AuthManager()157 self.manager = manager.AuthManager()
153158
@@ -188,20 +193,6 @@
188 'image_ref': '123456',193 'image_ref': '123456',
189 'instance_type_id': '5'} # m1.small194 'instance_type_id': '5'} # m1.small
190195
191 def lazy_load_library_exists(self):
192 """check if libvirt is available."""
193 # try to connect libvirt. if fail, skip test.
194 try:
195 import libvirt
196 import libxml2
197 except ImportError:
198 return False
199 global libvirt
200 libvirt = __import__('libvirt')
201 connection.libvirt = __import__('libvirt')
202 connection.libxml2 = __import__('libxml2')
203 return True
204
205 def create_fake_libvirt_mock(self, **kwargs):196 def create_fake_libvirt_mock(self, **kwargs):
206 """Defining mocks for LibvirtConnection(libvirt is not used)."""197 """Defining mocks for LibvirtConnection(libvirt is not used)."""
207198
@@ -337,9 +328,6 @@
337 self._check_xml_and_container(instance_data)328 self._check_xml_and_container(instance_data)
338329
339 def test_snapshot(self):330 def test_snapshot(self):
340 if not self.lazy_load_library_exists():
341 return
342
343 FLAGS.image_service = 'nova.image.fake.FakeImageService'331 FLAGS.image_service = 'nova.image.fake.FakeImageService'
344332
345 # Start test333 # Start test
@@ -372,9 +360,6 @@
372 self.assertEquals(snapshot['name'], snapshot_name)360 self.assertEquals(snapshot['name'], snapshot_name)
373361
374 def test_snapshot_no_image_architecture(self):362 def test_snapshot_no_image_architecture(self):
375 if not self.lazy_load_library_exists():
376 return
377
378 FLAGS.image_service = 'nova.image.fake.FakeImageService'363 FLAGS.image_service = 'nova.image.fake.FakeImageService'
379364
380 # Start test365 # Start test
@@ -649,10 +634,6 @@
649634
650 def test_ensure_filtering_rules_for_instance_timeout(self):635 def test_ensure_filtering_rules_for_instance_timeout(self):
651 """ensure_filtering_fules_for_instance() finishes with timeout."""636 """ensure_filtering_fules_for_instance() finishes with timeout."""
652 # Skip if non-libvirt environment
653 if not self.lazy_load_library_exists():
654 return
655
656 # Preparing mocks637 # Preparing mocks
657 def fake_none(self):638 def fake_none(self):
658 return639 return
@@ -690,12 +671,9 @@
690671
691 db.instance_destroy(self.context, instance_ref['id'])672 db.instance_destroy(self.context, instance_ref['id'])
692673
674 @unittest.skipIf(libvirt is None, "libvirt required for this test")
693 def test_live_migration_raises_exception(self):675 def test_live_migration_raises_exception(self):
694 """Confirms recover method is called when exceptions are raised."""676 """Confirms recover method is called when exceptions are raised."""
695 # Skip if non-libvirt environment
696 if not self.lazy_load_library_exists():
697 return
698
699 # Preparing data677 # Preparing data
700 self.compute = utils.import_object(FLAGS.compute_manager)678 self.compute = utils.import_object(FLAGS.compute_manager)
701 instance_dict = {'host': 'fake', 'state': power_state.RUNNING,679 instance_dict = {'host': 'fake', 'state': power_state.RUNNING,
@@ -741,10 +719,6 @@
741719
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")
743 def test_spawn_with_network_info(self):721 def test_spawn_with_network_info(self):
744 # Skip if non-libvirt environment
745 if not self.lazy_load_library_exists():
746 return
747
748 # Preparing mocks722 # Preparing mocks
749 def fake_none(self, instance):723 def fake_none(self, instance):
750 return724 return
@@ -829,20 +803,6 @@
829 self.fw = firewall.IptablesFirewallDriver(803 self.fw = firewall.IptablesFirewallDriver(
830 get_connection=lambda: self.fake_libvirt_connection)804 get_connection=lambda: self.fake_libvirt_connection)
831805
832 def lazy_load_library_exists(self):
833 """check if libvirt is available."""
834 # try to connect libvirt. if fail, skip test.
835 try:
836 import libvirt
837 import libxml2
838 except ImportError:
839 return False
840 global libvirt
841 libvirt = __import__('libvirt')
842 connection.libvirt = __import__('libvirt')
843 connection.libxml2 = __import__('libxml2')
844 return True
845
846 def tearDown(self):806 def tearDown(self):
847 self.manager.delete_project(self.project)807 self.manager.delete_project(self.project)
848 self.manager.delete_user(self.user)808 self.manager.delete_user(self.user)
@@ -1056,10 +1016,6 @@
10561016
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")
1058 def test_unfilter_instance_undefines_nwfilter(self):1018 def test_unfilter_instance_undefines_nwfilter(self):
1059 # Skip if non-libvirt environment
1060 if not self.lazy_load_library_exists():
1061 return
1062
1063 admin_ctxt = context.get_admin_context()1019 admin_ctxt = context.get_admin_context()
10641020
1065 fakefilter = NWFilterFakes()1021 fakefilter = NWFilterFakes()
10661022
=== modified file 'nova/utils.py'
--- nova/utils.py 2011-06-30 19:20:59 +0000
+++ nova/utils.py 2011-07-08 00:31:40 +0000
@@ -75,6 +75,21 @@
75 return cls()75 return cls()
7676
7777
78def optional_import(import_str):
79 """Attempt to import the given string, but fall back to returning None.
80
81 :param import_str: The name of the module to import.
82 :returns: The requested module, or None if unable to import.
83
84 """
85 try:
86 __import__(import_str)
87 return sys.modules[import_str]
88 except ImportError:
89 LOG.info(_("Unable to import optional module: %s") % import_str)
90 return None
91
92
78def vpn_ping(address, port, timeout=0.05, session_id=None):93def vpn_ping(address, port, timeout=0.05, session_id=None):
79 """Sends a vpn negotiation packet and returns the server session.94 """Sends a vpn negotiation packet and returns the server session.
8095
8196
=== modified file 'nova/virt/libvirt/__init__.py'
--- nova/virt/libvirt/__init__.py 2011-04-22 16:47:09 +0000
+++ nova/virt/libvirt/__init__.py 2011-07-08 00:31:40 +0000
@@ -0,0 +1,85 @@
1# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2011 OpenStack, LLC
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17from nova import flags
18from nova import utils
19
20
21FLAGS = flags.FLAGS
22
23
24flags.DECLARE('live_migration_retry_count', 'nova.compute.manager')
25
26flags.DEFINE_string('rescue_image_id',
27 'ami-rescue', 'Rescue ami image')
28
29flags.DEFINE_string('rescue_kernel_id',
30 'aki-rescue', 'Rescue aki image')
31
32flags.DEFINE_string('rescue_ramdisk_id',
33 'ari-rescue',
34 'Rescue ari image')
35
36flags.DEFINE_string('libvirt_xml_template',
37 utils.abspath('virt/libvirt.xml.template'),
38 'Libvirt XML Template')
39
40flags.DEFINE_string('libvirt_type',
41 'kvm',
42 'Libvirt driver (kvm, lxc, qemu, uml, or xen)')
43
44flags.DEFINE_string('libvirt_uri',
45 '',
46 'Override the default libvirt URI set by libvirt_type')
47
48flags.DEFINE_string('ajaxterm_portrange',
49 '10000-12000',
50 'Range of ports that ajaxterm should randomly try to bind')
51
52flags.DEFINE_string('firewall_driver',
53 'nova.virt.libvirt.firewall.IptablesFirewallDriver',
54 'Firewall driver (defaults to iptables)')
55
56flags.DEFINE_string('cpuinfo_xml_template',
57 utils.abspath('virt/cpuinfo.xml.template'),
58 'CpuInfo XML Template (Used only live migration now)')
59
60flags.DEFINE_string('live_migration_uri',
61 "qemu+tcp://%s/system",
62 'Define protocol used by live_migration feature')
63
64flags.DEFINE_string('live_migration_flag',
65 "VIR_MIGRATE_UNDEFINE_SOURCE, VIR_MIGRATE_PEER2PEER",
66 'Define live migration behavior.')
67
68flags.DEFINE_string('qemu_img', 'qemu-img',
69 'binary to use for qemu-img commands')
70
71flags.DEFINE_integer('live_migration_bandwidth', 0,
72 'Define live migration behavior')
73
74flags.DEFINE_bool('start_guests_on_host_boot',
75 False,
76 'Whether to restart guests when the host reboots')
77
78flags.DEFINE_bool('allow_project_net_traffic',
79 True,
80 'Whether to allow in project network traffic')
81
82flags.DEFINE_bool('use_cow_images',
83 True,
84 'Whether to use cow images')
85
086
=== modified file 'nova/virt/libvirt/connection.py'
--- nova/virt/libvirt/connection.py 2011-07-07 18:30:47 +0000
+++ nova/virt/libvirt/connection.py 2011-07-08 00:31:40 +0000
@@ -17,23 +17,10 @@
17# License for the specific language governing permissions and limitations17# License for the specific language governing permissions and limitations
18# under the License.18# under the License.
1919
20"""20"""Provides logic for connecting to a hypervisor through libvirt.
21A connection to a hypervisor through libvirt.
2221
23Supports KVM, LXC, QEMU, UML, and XEN.22Supports KVM, LXC, QEMU, UML, and XEN.
2423
25**Related Flags**
26
27:libvirt_type: Libvirt domain type. Can be kvm, qemu, uml, xen
28 (default: kvm).
29:libvirt_uri: Override for the default libvirt URI (depends on libvirt_type).
30:libvirt_xml_template: Libvirt XML Template.
31:rescue_image_id: Rescue ami image (default: ami-rescue).
32:rescue_kernel_id: Rescue aki image (default: aki-rescue).
33:rescue_ramdisk_id: Rescue ari image (default: ari-rescue).
34:injected_network_template: Template file for injected network
35:allow_project_net_traffic: Whether to allow in project network traffic
36
37"""24"""
3825
39import hashlib26import hashlib
@@ -71,83 +58,27 @@
71from nova.virt.libvirt import netutils58from nova.virt.libvirt import netutils
7259
7360
74libvirt = None61libvirt = utils.optional_import("libvirt")
75libxml2 = None62libxml2 = utils.optional_import("libxml2")
76Template = None63Template = utils.optional_import("Cheetah.Template")
7764
7865
79LOG = logging.getLogger('nova.virt.libvirt_conn')66LOG = logging.getLogger('nova.virt.libvirt_conn')
80
81
82FLAGS = flags.FLAGS67FLAGS = flags.FLAGS
83flags.DECLARE('live_migration_retry_count', 'nova.compute.manager')
84# TODO(vish): These flags should probably go into a shared location
85flags.DEFINE_string('rescue_image_id', 'ami-rescue', 'Rescue ami image')
86flags.DEFINE_string('rescue_kernel_id', 'aki-rescue', 'Rescue aki image')
87flags.DEFINE_string('rescue_ramdisk_id', 'ari-rescue', 'Rescue ari image')
88flags.DEFINE_string('libvirt_xml_template',
89 utils.abspath('virt/libvirt.xml.template'),
90 'Libvirt XML Template')
91flags.DEFINE_string('libvirt_type',
92 'kvm',
93 'Libvirt domain type (valid options are: '
94 'kvm, lxc, qemu, uml, xen)')
95flags.DEFINE_string('libvirt_uri',
96 '',
97 'Override the default libvirt URI (which is dependent'
98 ' on libvirt_type)')
99flags.DEFINE_bool('allow_project_net_traffic',
100 True,
101 'Whether to allow in project network traffic')
102flags.DEFINE_bool('use_cow_images',
103 True,
104 'Whether to use cow images')
105flags.DEFINE_string('ajaxterm_portrange',
106 '10000-12000',
107 'Range of ports that ajaxterm should randomly try to bind')
108flags.DEFINE_string('firewall_driver',
109 'nova.virt.libvirt.firewall.IptablesFirewallDriver',
110 'Firewall driver (defaults to iptables)')
111flags.DEFINE_string('cpuinfo_xml_template',
112 utils.abspath('virt/cpuinfo.xml.template'),
113 'CpuInfo XML Template (Used only live migration now)')
114flags.DEFINE_string('live_migration_uri',
115 "qemu+tcp://%s/system",
116 'Define protocol used by live_migration feature')
117flags.DEFINE_string('live_migration_flag',
118 "VIR_MIGRATE_UNDEFINE_SOURCE, VIR_MIGRATE_PEER2PEER",
119 'Define live migration behavior.')
120flags.DEFINE_integer('live_migration_bandwidth', 0,
121 'Define live migration behavior')
122flags.DEFINE_string('qemu_img', 'qemu-img',
123 'binary to use for qemu-img commands')
124flags.DEFINE_bool('start_guests_on_host_boot', False,
125 'Whether to restart guests when the host reboots')
12668
12769
128def get_connection(read_only):70def get_connection(read_only):
129 # These are loaded late so that there's no need to install these71 """Retrieve a libvirt connection object."""
130 # libraries when not using libvirt.
131 # Cheetah is separate because the unit tests want to load Cheetah,
132 # but not libvirt.
133 global libvirt
134 global libxml2
135 if libvirt is None:72 if libvirt is None:
136 libvirt = __import__('libvirt')73 raise ImportError(_("Unable to import libvirt"))
137 if libxml2 is None:74 if libxml2 is None:
138 libxml2 = __import__('libxml2')75 raise ImportError(_("Unable to import libxml2"))
139 _late_load_cheetah()76 if Template is None:
77 raise ImportError(_("Unable to import Cheetah.Template"))
78
140 return LibvirtConnection(read_only)79 return LibvirtConnection(read_only)
14180
14281
143def _late_load_cheetah():
144 global Template
145 if Template is None:
146 t = __import__('Cheetah.Template', globals(), locals(),
147 ['Template'], -1)
148 Template = t.Template
149
150
151def _strip_dev(mount_path):82def _strip_dev(mount_path):
152 return re.sub(r'^/dev/', '', mount_path)83 return re.sub(r'^/dev/', '', mount_path)
15384
@@ -896,7 +827,7 @@
896 nets.append(net_info)827 nets.append(net_info)
897828
898 if have_injected_networks:829 if have_injected_networks:
899 net = str(Template(ifc_template,830 net = str(Template.Template(ifc_template,
900 searchList=[{'interfaces': nets,831 searchList=[{'interfaces': nets,
901 'use_ipv6': FLAGS.use_ipv6}]))832 'use_ipv6': FLAGS.use_ipv6}]))
902833
@@ -1035,7 +966,7 @@
1035 LOG.debug(_('instance %s: starting toXML method'), instance['name'])966 LOG.debug(_('instance %s: starting toXML method'), instance['name'])
1036 xml_info = self._prepare_xml_info(instance, rescue, network_info,967 xml_info = self._prepare_xml_info(instance, rescue, network_info,
1037 block_device_mapping)968 block_device_mapping)
1038 xml = str(Template(self.libvirt_xml, searchList=[xml_info]))969 xml = str(Template.Template(self.libvirt_xml, searchList=[xml_info]))
1039 LOG.debug(_('instance %s: finished toXML method'), instance['name'])970 LOG.debug(_('instance %s: finished toXML method'), instance['name'])
1040 return xml971 return xml
1041972
@@ -1439,7 +1370,7 @@
14391370
1440 LOG.info(_('Instance launched has CPU info:\n%s') % cpu_info)1371 LOG.info(_('Instance launched has CPU info:\n%s') % cpu_info)
1441 dic = utils.loads(cpu_info)1372 dic = utils.loads(cpu_info)
1442 xml = str(Template(self.cpuinfo_xml, searchList=dic))1373 xml = str(Template.Template(self.cpuinfo_xml, searchList=dic))
1443 LOG.info(_('to xml...\n:%s ' % xml))1374 LOG.info(_('to xml...\n:%s ' % xml))
14441375
1445 u = "http://libvirt.org/html/libvirt-libvirt.html#virCPUCompareResult"1376 u = "http://libvirt.org/html/libvirt-libvirt.html#virCPUCompareResult"
14461377
=== modified file 'nova/virt/libvirt/firewall.py'
--- nova/virt/libvirt/firewall.py 2011-06-27 21:48:03 +0000
+++ nova/virt/libvirt/firewall.py 2011-07-08 00:31:40 +0000
@@ -32,11 +32,7 @@
32FLAGS = flags.FLAGS32FLAGS = flags.FLAGS
3333
3434
35try:35libvirt = utils.optional_import("libvirt")
36 import libvirt
37except ImportError:
38 LOG.warn(_("Libvirt module could not be loaded. NWFilterFirewall will "
39 "not work correctly."))
4036
4137
42class FirewallDriver(object):38class FirewallDriver(object):
4339
=== modified file 'tools/pip-requires'
--- tools/pip-requires 2011-06-30 18:11:03 +0000
+++ tools/pip-requires 2011-07-08 00:31:40 +0000
@@ -33,3 +33,4 @@
33nosexcover33nosexcover
34GitPython34GitPython
35paramiko35paramiko
36unittest2