Merge "network: fix handling of linux-bridge in os-vif conversion"

This commit is contained in:
Jenkins 2016-08-12 03:00:07 +00:00 committed by Gerrit Code Review
commit 3f642cff8e
2 changed files with 32 additions and 9 deletions

View File

@ -26,6 +26,7 @@ from oslo_config import cfg
from oslo_log import log as logging
from nova import exception
from nova.i18n import _
from nova.network import model
@ -200,6 +201,7 @@ def _nova_to_osvif_network(network):
netobj = objects.network.Network(
id=network['id'],
bridge_interface=network.get_meta("bridge_interface"),
subnets=_nova_to_osvif_subnets(network['subnets']))
if network["bridge"] is not None:
@ -209,14 +211,14 @@ def _nova_to_osvif_network(network):
if network.get_meta("multi_host") is not None:
netobj.multi_host = network.get_meta("multi_host")
if network.get_meta("should_provide_bridge") is not None:
if network.get_meta("should_create_bridge") is not None:
netobj.should_provide_bridge = \
network.get_meta("should_provide_bridge")
if network.get_meta("bridge_interface") is not None:
netobj.bridge_interface = network.get_meta("bridge_interface")
if network.get_meta("should_provide_vlan") is not None:
netobj.should_provide_vlan = network.get_meta("should_provide_vlan")
if network.get_meta("vlan") is not None:
network.get_meta("should_create_bridge")
if network.get_meta("should_create_vlan") is not None:
netobj.should_provide_vlan = network.get_meta("should_create_vlan")
if network.get_meta("vlan") is None:
raise exception.NovaException(_("Missing vlan number in %s") %
network)
netobj.vlan = network.get_meta("vlan")
return netobj

View File

@ -326,6 +326,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
expect = osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915",
bridge="br0",
bridge_interface=None,
subnets=osv_objects.subnet.SubnetList(
objects=[
osv_objects.subnet.Subnet(
@ -348,8 +349,8 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
id="b82c1929-051e-481d-8110-4669916c7915",
bridge="br0",
multi_host=True,
should_provide_bridge=True,
should_provide_vlan=True,
should_create_bridge=True,
should_create_vlan=True,
bridge_interface="eth0",
vlan=1729,
subnets=[
@ -397,6 +398,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
expect = osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net",
subnets=osv_objects.subnet.SubnetList(
objects=[
@ -415,6 +417,22 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
self.assertObjEqual(expect, actual)
def test_nova_to_osvif_network_labeled_no_vlan(self):
network = model.Network(
id="b82c1929-051e-481d-8110-4669916c7915",
label="Demo Net",
should_create_vlan=True,
subnets=[
model.Subnet(cidr="192.168.1.0/24",
gateway=model.IP(
address="192.168.1.254",
type='gateway')),
])
self.assertRaises(exception.NovaException,
os_vif_util._nova_to_osvif_network,
network)
def test_nova_to_osvif_vif_linux_bridge(self):
vif = model.VIF(
id="dc065497-3c8d-4f44-8fb4-e1d33c16a536",
@ -441,6 +459,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
vif_name="nicdc065497-3c",
network=osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net",
subnets=osv_objects.subnet.SubnetList(
objects=[])))
@ -475,6 +494,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
vif_name="nicdc065497-3c",
network=osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net",
subnets=osv_objects.subnet.SubnetList(
objects=[])))
@ -510,6 +530,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
vif_name="nicdc065497-3c",
network=osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net",
subnets=osv_objects.subnet.SubnetList(
objects=[])))