summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/fake_network.py18
-rw-r--r--nova/tests/test_libvirt.py41
-rw-r--r--nova/virt/libvirt/vif.py2
3 files changed, 42 insertions, 19 deletions
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py
index add6ecf4b..ff22278c5 100644
--- a/nova/tests/fake_network.py
+++ b/nova/tests/fake_network.py
@@ -26,6 +26,7 @@ from nova.network import manager as network_manager
from nova.network import model as network_model
from nova.network import nova_ipam_lib
from nova import utils
+from nova.virt.libvirt import config as libvirt_config
HOST = "testhost"
@@ -51,15 +52,14 @@ class FakeVIFDriver(object):
def setattr(self, key, val):
self.__setattr__(key, val)
- def plug(self, instance, network, mapping):
- return {
- 'id': 'fake',
- 'bridge_name': 'fake',
- 'mac_address': 'fake',
- 'ip_address': 'fake',
- 'dhcp_server': 'fake',
- 'extra_params': 'fake',
- }
+ def plug(self, instance, vif):
+ conf = libvirt_config.LibvirtConfigGuestInterface()
+
+ for attr, val in conf.__dict__.iteritems():
+ if val is None:
+ setattr(conf, attr, 'fake')
+
+ return conf
class FakeModel(dict):
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 91cf8df7c..05873bd79 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -1985,19 +1985,45 @@ class LibvirtConnTestCase(test.TestCase):
def test_spawn_with_network_info(self):
# Preparing mocks
- def fake_none(self, instance):
+ def fake_none(*args, **kwargs):
return
+ def fake_getLibVersion():
+ return 9007
+
+ def fake_getCapabilities():
+ return """
+ <capabilities>
+ <host>
+ <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
+ <cpu>
+ <arch>x86_64</arch>
+ <model>Penryn</model>
+ <vendor>Intel</vendor>
+ <topology sockets='1' cores='2' threads='1'/>
+ <feature name='xtpr'/>
+ </cpu>
+ </host>
+ </capabilities>
+ """
+
# _fake_network_info must be called before create_fake_libvirt_mock(),
# as _fake_network_info calls importutils.import_class() and
# create_fake_libvirt_mock() mocks importutils.import_class().
network_info = _fake_network_info(self.stubs, 1)
- self.create_fake_libvirt_mock()
+ self.create_fake_libvirt_mock(getLibVersion=fake_getLibVersion,
+ getCapabilities=fake_getCapabilities)
instance_ref = self.test_instance
instance_ref['image_ref'] = 123456 # we send an int to test sha1 call
instance = db.instance_create(self.context, instance_ref)
+ # Mock out the get_info method of the LibvirtDriver so that the polling
+ # in the spawn method of the LibvirtDriver returns immediately
+ self.mox.StubOutWithMock(libvirt_driver.LibvirtDriver, 'get_info')
+ libvirt_driver.LibvirtDriver.get_info(instance
+ ).AndReturn({'state': power_state.RUNNING})
+
# Start test
self.mox.ReplayAll()
conn = libvirt_driver.LibvirtDriver(False)
@@ -2007,15 +2033,12 @@ class LibvirtConnTestCase(test.TestCase):
self.stubs.Set(conn.firewall_driver,
'prepare_instance_filter',
fake_none)
+ self.stubs.Set(imagebackend.Image,
+ 'cache',
+ fake_none)
- try:
- conn.spawn(self.context, instance, None, [], 'herp',
+ conn.spawn(self.context, instance, None, [], 'herp',
network_info=network_info)
- except Exception, e:
- # assert that no exception is raised due to sha1 receiving an int
- self.assertEqual(-1, unicode(e).find('must be string or buffer'
- ', not int'))
- self.assertNotIn('Unexpected method call', unicode(e))
path = os.path.join(FLAGS.instances_path, instance.name)
if os.path.isdir(path):
diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py
index ea0834d87..b4eee39b3 100644
--- a/nova/virt/libvirt/vif.py
+++ b/nova/virt/libvirt/vif.py
@@ -52,7 +52,7 @@ class LibvirtBridgeDriver(vif.VIFDriver):
"""VIF driver for Linux bridge."""
def _get_configurations(self, instance, network, mapping):
- """Get a dictionary of VIF configurations for bridge type."""
+ """Get VIF configurations for bridge type."""
mac_id = mapping['mac'].replace(':', '')