summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2012-10-10 13:47:26 +0200
committerNikola Dipanov <ndipanov@redhat.com>2012-10-10 15:01:37 +0200
commitc1e5e3352a71cc61ba9e7dba0d9048d8b766e2c0 (patch)
treef61f5321c88c0ec83495ed93e81258bafdef5ddc /nova
parent76596a79a3d39c9daa2e48a52298b17f06a653fc (diff)
downloadnova-c1e5e3352a71cc61ba9e7dba0d9048d8b766e2c0.tar.gz
nova-c1e5e3352a71cc61ba9e7dba0d9048d8b766e2c0.tar.xz
nova-c1e5e3352a71cc61ba9e7dba0d9048d8b766e2c0.zip
Fixes test_libvirtr spawn_with_network_info test
This patch fixes the LibvirtConnTestCase.test_spawn_with_network_info test case that was reported as bug 1053572. The new implementation of the test makes no assumptions about the raised exceptions, and exercises the LibvirtDriver.spawn method completely. The test has the network_info faked and the libvirt connection mocked out. In addition. it also fixes the fake_network.FakeVIFDriver class used in this test to return a LibvirtConfigGuestInterface instance with fake values instead of just a dict. Also fixes some docstring inaccuracies in the nova.libvirt.vif module that may have lead to the FakeVIFDrivers wrong implementation before. Fixes bug 1053572 Change-Id: Ie5b69a2269ab099267231329eae21bd308fef835
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(':', '')