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

The nova.network.model.Network class uses names
'should_create_{bridge,vlan}' not 'should_provide_{bridge,vlan}'

The bridge_interface attribute should always be set, even if
to None, since None is a valid value.

The vlan attribute is compulsory if should_create_vlan is
set.

Closes-bug: 1612281
Change-Id: I245f560156d596be14ef9181bfb881be9680c166
This commit is contained in:
Daniel P. Berrange 2016-08-11 16:11:01 +01:00 committed by Matt Riedemann
parent a14d5ff5ba
commit 26399c7005
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 oslo_log import log as logging
from nova import exception from nova import exception
from nova.i18n import _
from nova.network import model from nova.network import model
@ -200,6 +201,7 @@ def _nova_to_osvif_network(network):
netobj = objects.network.Network( netobj = objects.network.Network(
id=network['id'], id=network['id'],
bridge_interface=network.get_meta("bridge_interface"),
subnets=_nova_to_osvif_subnets(network['subnets'])) subnets=_nova_to_osvif_subnets(network['subnets']))
if network["bridge"] is not None: 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: if network.get_meta("multi_host") is not None:
netobj.multi_host = network.get_meta("multi_host") 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 = \ netobj.should_provide_bridge = \
network.get_meta("should_provide_bridge") network.get_meta("should_create_bridge")
if network.get_meta("bridge_interface") is not None: if network.get_meta("should_create_vlan") is not None:
netobj.bridge_interface = network.get_meta("bridge_interface") netobj.should_provide_vlan = network.get_meta("should_create_vlan")
if network.get_meta("should_provide_vlan") is not None: if network.get_meta("vlan") is None:
netobj.should_provide_vlan = network.get_meta("should_provide_vlan") raise exception.NovaException(_("Missing vlan number in %s") %
if network.get_meta("vlan") is not None: network)
netobj.vlan = network.get_meta("vlan") netobj.vlan = network.get_meta("vlan")
return netobj return netobj

View File

@ -326,6 +326,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
expect = osv_objects.network.Network( expect = osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915", id="b82c1929-051e-481d-8110-4669916c7915",
bridge="br0", bridge="br0",
bridge_interface=None,
subnets=osv_objects.subnet.SubnetList( subnets=osv_objects.subnet.SubnetList(
objects=[ objects=[
osv_objects.subnet.Subnet( osv_objects.subnet.Subnet(
@ -348,8 +349,8 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
id="b82c1929-051e-481d-8110-4669916c7915", id="b82c1929-051e-481d-8110-4669916c7915",
bridge="br0", bridge="br0",
multi_host=True, multi_host=True,
should_provide_bridge=True, should_create_bridge=True,
should_provide_vlan=True, should_create_vlan=True,
bridge_interface="eth0", bridge_interface="eth0",
vlan=1729, vlan=1729,
subnets=[ subnets=[
@ -397,6 +398,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
expect = osv_objects.network.Network( expect = osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915", id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net", label="Demo Net",
subnets=osv_objects.subnet.SubnetList( subnets=osv_objects.subnet.SubnetList(
objects=[ objects=[
@ -415,6 +417,22 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
self.assertObjEqual(expect, actual) 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): def test_nova_to_osvif_vif_linux_bridge(self):
vif = model.VIF( vif = model.VIF(
id="dc065497-3c8d-4f44-8fb4-e1d33c16a536", id="dc065497-3c8d-4f44-8fb4-e1d33c16a536",
@ -441,6 +459,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
vif_name="nicdc065497-3c", vif_name="nicdc065497-3c",
network=osv_objects.network.Network( network=osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915", id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net", label="Demo Net",
subnets=osv_objects.subnet.SubnetList( subnets=osv_objects.subnet.SubnetList(
objects=[]))) objects=[])))
@ -475,6 +494,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
vif_name="nicdc065497-3c", vif_name="nicdc065497-3c",
network=osv_objects.network.Network( network=osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915", id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net", label="Demo Net",
subnets=osv_objects.subnet.SubnetList( subnets=osv_objects.subnet.SubnetList(
objects=[]))) objects=[])))
@ -510,6 +530,7 @@ class OSVIFUtilTestCase(test.NoDBTestCase):
vif_name="nicdc065497-3c", vif_name="nicdc065497-3c",
network=osv_objects.network.Network( network=osv_objects.network.Network(
id="b82c1929-051e-481d-8110-4669916c7915", id="b82c1929-051e-481d-8110-4669916c7915",
bridge_interface=None,
label="Demo Net", label="Demo Net",
subnets=osv_objects.subnet.SubnetList( subnets=osv_objects.subnet.SubnetList(
objects=[]))) objects=[])))