Fix fetching dvportgroup name
With suds, there is no attribute 'name' on the managed object reference. The attributes of dvportgroup has to be fetched separately. Change-Id: I78368974a1fcded5179377e7413fd24868c3db75
This commit is contained in:
parent
2dbeafe1d4
commit
3a453dff48
@ -324,3 +324,13 @@ class DvsManager(object):
|
||||
instanceUuid=True)
|
||||
if vm_refs:
|
||||
return vm_refs[0].value
|
||||
|
||||
def get_portgroup_info(self, pg_moref):
|
||||
"""Get portgroup information."""
|
||||
# Expand the properties to collect on need basis.
|
||||
properties = ['name']
|
||||
pg_info = self._session.invoke_api(vim_util,
|
||||
'get_object_properties_dict',
|
||||
self._session.vim,
|
||||
pg_moref, properties)
|
||||
return pg_info
|
||||
|
@ -151,9 +151,10 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
if net_data.get(pnet.NETWORK_TYPE) == c_utils.NetworkTypes.PORTGROUP:
|
||||
net_id = net_data.get(pnet.PHYSICAL_NETWORK)
|
||||
dvpg_moref = self._dvs._net_id_to_moref(net_id)
|
||||
if dvpg_moref.name != net_data.get('name'):
|
||||
err_msg = (_("Portgroup name %s(dvpg)s must match network "
|
||||
"name %(network)s"), {'dvpg': dvpg_moref.name,
|
||||
pg_info = self._dvs.get_portgroup_info(dvpg_moref)
|
||||
if pg_info.get('name') != net_data.get('name'):
|
||||
err_msg = (_("Portgroup name %(dvpg)s must match network "
|
||||
"name %(network)s") % {'dvpg': pg_info.get('name'),
|
||||
'network': net_data.get('name')})
|
||||
raise n_exc.InvalidInput(error_message=err_msg)
|
||||
dvs_id = dvpg_moref.value
|
||||
|
@ -197,19 +197,25 @@ class NeutronSimpleDvsTest(test_plugin.NeutronDbPluginV2TestCase):
|
||||
def test_create_and_delete_dvs_network_flat(self):
|
||||
self._create_and_delete_dvs_network()
|
||||
|
||||
@mock.patch.object(dvs.DvsManager, 'get_portgroup_info')
|
||||
@mock.patch.object(dvs.DvsManager, '_net_id_to_moref')
|
||||
def test_create_and_delete_dvs_network_portgroup(self, fake_get_moref):
|
||||
fake_get_moref.return_value.name = 'fake-name'
|
||||
def test_create_and_delete_dvs_network_portgroup(self, fake_get_moref,
|
||||
fake_pg_info):
|
||||
fake_pg_info.return_value = {'name': 'fake-name'}
|
||||
self._create_and_delete_dvs_network(network_type='portgroup')
|
||||
self.assertTrue(fake_get_moref.call_count)
|
||||
self.assertTrue(fake_pg_info.call_count)
|
||||
|
||||
@mock.patch.object(dvs.DvsManager, 'get_portgroup_info')
|
||||
@mock.patch.object(dvs.DvsManager, '_net_id_to_moref')
|
||||
def test_create_and_delete_dvs_network_portgroup_vlan(self,
|
||||
fake_get_moref):
|
||||
fake_get_moref.return_value.name = 'fake-name'
|
||||
fake_get_moref,
|
||||
fake_pg_info):
|
||||
fake_pg_info.return_value = {'name': 'fake-name'}
|
||||
self._create_and_delete_dvs_network(network_type='portgroup',
|
||||
vlan_tag=7)
|
||||
self.assertTrue(fake_get_moref.call_count)
|
||||
self.assertTrue(fake_pg_info.call_count)
|
||||
|
||||
def test_create_and_delete_dvs_port(self):
|
||||
params = {'provider:network_type': 'vlan',
|
||||
@ -297,10 +303,12 @@ class NeutronSimpleDvsTest(test_plugin.NeutronDbPluginV2TestCase):
|
||||
{'network': {'port_security_enabled': True}})
|
||||
self.assertEqual(True, updated_net['port_security_enabled'])
|
||||
|
||||
@mock.patch.object(dvs.DvsManager, 'get_portgroup_info')
|
||||
@mock.patch.object(dvs.DvsManager, '_net_id_to_moref')
|
||||
def test_create_and_delete_portgroup_network_invalid_name(self,
|
||||
fake_get_moref):
|
||||
fake_get_moref.return_value.name = 'fake-different-name'
|
||||
fake_get_moref,
|
||||
fake_pg_info):
|
||||
fake_pg_info.return_value = {'name': 'fake-different-name'}
|
||||
data = {'network': {'provider:network_type': 'portgroup',
|
||||
'name': 'fake-name',
|
||||
'admin_state_up': True}}
|
||||
|
Loading…
Reference in New Issue
Block a user