summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2013-02-08 16:59:32 +0000
committerDaniel P. Berrange <berrange@redhat.com>2013-02-13 11:14:57 +0000
commit99ddc0d2ad7f2f9c27deaac08559eb794845afc3 (patch)
treeaca6302f4c82f126b42242d625b861b96b40efbb /nova/tests
parentd980805880c681881504e269e03130e4452630ab (diff)
Allow VIF model to be chosen per image
This allows for an image in glance to be annotated with a property describing the required VIF model eg # glance image-update \ --property vif_model=e1000 \ f16-x86_64-openstack-sda Valid model values vary per the libvirt_type setting: qemu/kvm: 'virtio', 'ne2k_pci', 'pcnet', 'rtl8139', 'e1000' xen: 'netfront', 'ne2k_pci', 'pcnet', 'rtl8139', 'e1000' Requesting an unsupported VIF model will cause the guest instance to fail to launch. DocImpact Blueprint: libvirt-custom-hardware Change-Id: Idbee0c61cffdb43db5668fb88869a5d30278593f Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/fake_network.py2
-rw-r--r--nova/tests/test_libvirt_vif.py44
2 files changed, 43 insertions, 3 deletions
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py
index 883466cd6..d7f43829a 100644
--- a/nova/tests/fake_network.py
+++ b/nova/tests/fake_network.py
@@ -53,7 +53,7 @@ class FakeVIFDriver(object):
def setattr(self, key, val):
self.__setattr__(key, val)
- def get_config(self, instance, network, mapping):
+ def get_config(self, instance, network, mapping, image_meta):
conf = libvirt_config.LibvirtConfigGuestInterface()
for attr, val in conf.__dict__.iteritems():
diff --git a/nova/tests/test_libvirt_vif.py b/nova/tests/test_libvirt_vif.py
index 916b961da..749fda33a 100644
--- a/nova/tests/test_libvirt_vif.py
+++ b/nova/tests/test_libvirt_vif.py
@@ -171,7 +171,7 @@ class LibvirtVifTestCase(test.TestCase):
self.stubs.Set(utils, 'execute', fake_execute)
- def _get_instance_xml(self, driver, net, mapping):
+ def _get_instance_xml(self, driver, net, mapping, image_meta=None):
conf = vconfig.LibvirtConfigGuest()
conf.virt_type = "qemu"
conf.name = "fake-name"
@@ -179,7 +179,7 @@ class LibvirtVifTestCase(test.TestCase):
conf.memory = 100 * 1024
conf.vcpus = 4
- nic = driver.get_config(self.instance, net, mapping)
+ nic = driver.get_config(self.instance, net, mapping, image_meta)
conf.add_device(nic)
return conf.to_xml()
@@ -269,6 +269,46 @@ class LibvirtVifTestCase(test.TestCase):
ret = node.findall("driver")
self.assertEqual(len(ret), 0)
+ def test_model_kvm_custom(self):
+ self.flags(libvirt_use_virtio_for_bridges=True,
+ libvirt_type='kvm')
+
+ def get_connection():
+ return fakelibvirt.Connection("qemu:///session",
+ False)
+ d = vif.LibvirtGenericVIFDriver(get_connection)
+ image_meta = {'properties': {'vif_model': 'e1000'}}
+ xml = self._get_instance_xml(d,
+ self.net_bridge,
+ self.mapping_bridge,
+ image_meta)
+
+ doc = etree.fromstring(xml)
+ ret = doc.findall('./devices/interface')
+ self.assertEqual(len(ret), 1)
+ node = ret[0]
+
+ model = node.find("model").get("type")
+ self.assertEqual(model, "e1000")
+ ret = node.findall("driver")
+ self.assertEqual(len(ret), 0)
+
+ def test_model_kvm_bogus(self):
+ self.flags(libvirt_use_virtio_for_bridges=True,
+ libvirt_type='kvm')
+
+ def get_connection():
+ return fakelibvirt.Connection("qemu:///session",
+ False)
+ d = vif.LibvirtGenericVIFDriver(get_connection)
+ image_meta = {'properties': {'vif_model': 'acme'}}
+ self.assertRaises(exception.UnsupportedHardware,
+ self._get_instance_xml,
+ d,
+ self.net_bridge,
+ self.mapping_bridge,
+ image_meta)
+
def test_model_qemu(self):
self.flags(libvirt_use_virtio_for_bridges=True,
libvirt_type='qemu')