VMware: Fix ensure_vlan_bridge to work properly with existing DVS

With Nova Flat Network, if the DVS exists, we should not try to
worry about virtual switches or port groups. We should just return
the network_ref

ensure_vlan_bridge was also missing the return of network_ref at
tne end of the method, added that as well since that return value
is needed/used in virt/vmwareapi/vmops.py#L191

Fixes LP# 1194018

Change-Id: I78c71e4c15f1aa87378ae2eb0448c047c6a2a666
This commit is contained in:
Davanum Srinivas
2013-08-25 22:40:30 -04:00
committed by Gerrit Code Review
parent db6721b5f8
commit 3a5e4fae13
2 changed files with 46 additions and 22 deletions

View File

@@ -17,6 +17,7 @@
from nova.network import model as network_model
from nova import test
from nova.tests import matchers
from nova.virt.vmwareapi import network_util
from nova.virt.vmwareapi import vif
@@ -62,6 +63,7 @@ class VMwareVifTestCase(test.TestCase):
self.cluster).AndReturn(True)
network_util.create_port_group(self.session, 'fa0', 'vmnet0', 3,
self.cluster)
network_util.get_network_with_the_name('fake', 'fa0', None)
self.mox.ReplayAll()
vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=True)
@@ -83,9 +85,29 @@ class VMwareVifTestCase(test.TestCase):
self.cluster).AndReturn(True)
network_util.create_port_group(self.session, 'fa0', 'vmnet0', 0,
self.cluster)
network_util.get_network_with_the_name('fake', 'fa0', None)
self.mox.ReplayAll()
vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
# Flat network mode with DVS
def test_ensure_vlan_bridge_with_existing_dvs(self):
network_ref = {'dvpg': 'dvportgroup-2062',
'type': 'DistributedVirtualPortgroup'}
self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
self.mox.StubOutWithMock(network_util,
'get_vswitch_for_vlan_interface')
self.mox.StubOutWithMock(network_util,
'check_if_vlan_interface_exists')
self.mox.StubOutWithMock(network_util, 'create_port_group')
network_util.get_network_with_the_name(self.session, 'fa0',
self.cluster).AndReturn(network_ref)
self.mox.ReplayAll()
ref = vif.ensure_vlan_bridge(self.session,
self.vif,
create_vlan=False)
self.assertThat(ref, matchers.DictMatches(network_ref))
def test_get_network_ref_neutron(self):
self.mox.StubOutWithMock(vif, 'get_neutron_network')
vif.get_neutron_network(self.session, 'fa0', self.cluster, self.vif)

View File

@@ -46,6 +46,9 @@ def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
network_ref = network_util.get_network_with_the_name(session, bridge,
cluster)
if network_ref and network_ref['type'] == 'DistributedVirtualPortgroup':
return network_ref
# Get the vSwitch associated with the Physical Adapter
vswitch_associated = network_util.get_vswitch_for_vlan_interface(
session, vlan_interface, cluster)
@@ -57,35 +60,34 @@ def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
if not network_util.check_if_vlan_interface_exists(session,
vlan_interface, cluster):
raise exception.NetworkAdapterNotFound(adapter=vlan_interface)
if create_vlan:
if network_ref is None:
if network_ref is None:
# Create a port group on the vSwitch associated with the
# vlan_interface corresponding physical network adapter on the ESX
# host.
network_util.create_port_group(session, bridge,
vswitch_associated, vlan_num,
network_util.create_port_group(session, bridge,
vswitch_associated,
vlan_num if create_vlan else 0,
cluster)
else:
# Get the vlan id and vswitch corresponding to the port group
_get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)
network_ref = network_util.get_network_with_the_name(session,
bridge,
cluster)
elif create_vlan:
# Get the vlan id and vswitch corresponding to the port group
_get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)
# Check if the vswitch associated is proper
if pg_vswitch != vswitch_associated:
raise exception.InvalidVLANPortGroup(
bridge=bridge, expected=vswitch_associated,
actual=pg_vswitch)
# Check if the vswitch associated is proper
if pg_vswitch != vswitch_associated:
raise exception.InvalidVLANPortGroup(
bridge=bridge, expected=vswitch_associated,
actual=pg_vswitch)
# Check if the vlan id is proper for the port group
if pg_vlanid != vlan_num:
raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
pgroup=pg_vlanid)
else:
if network_ref is None:
network_util.create_port_group(session, bridge,
vswitch_associated, 0,
cluster)
# Check if the vlan id is proper for the port group
if pg_vlanid != vlan_num:
raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
pgroup=pg_vlanid)
return network_ref
def get_neutron_network(session, network_name, cluster, vif):