N1Kv: Fix failing network and port creates

Due to the change in name of an attribute from "profile_id" to "profile"
in Neutron attribute extensions for networks and ports, network and port
creations fail from the dashboard since dashboard is still using
"n1kv:profile_id" rather than "n1kv:profile".

Change-Id: I3a0508eda6b7b977d4f5bc5304d0ef13bd4092f2
Closes-Bug: 1474618
This commit is contained in:
Saksham Varma 2015-07-15 11:14:02 -07:00
parent 61520479bb
commit b93e868925
2 changed files with 69 additions and 21 deletions

View File

@ -660,7 +660,7 @@ def network_create(request, **kwargs):
LOG.debug("network_create(): kwargs = %s" % kwargs)
# In the case network profiles are being used, profile id is needed.
if 'net_profile_id' in kwargs:
kwargs['n1kv:profile_id'] = kwargs.pop('net_profile_id')
kwargs['n1kv:profile'] = kwargs.pop('net_profile_id')
if 'tenant_id' not in kwargs:
kwargs['tenant_id'] = request.user.project_id
body = {'network': kwargs}
@ -764,7 +764,7 @@ def port_create(request, network_id, **kwargs):
LOG.debug("port_create(): netid=%s, kwargs=%s" % (network_id, kwargs))
# In the case policy profiles are being used, profile id is needed.
if 'policy_profile_id' in kwargs:
kwargs['n1kv:profile_id'] = kwargs.pop('policy_profile_id')
kwargs['n1kv:profile'] = kwargs.pop('policy_profile_id')
kwargs = unescape_port_kwargs(**kwargs)
body = {'port': {'network_id': network_id}}
if 'tenant_id' not in kwargs:

View File

@ -52,18 +52,41 @@ class NeutronApiTests(test.APITestCase):
ret_val = api.neutron.network_get(self.request, network_id)
self.assertIsInstance(ret_val, api.neutron.Network)
def test_network_create(self):
def _test_network_create(self, with_n1kv=False):
network = {'network': self.api_networks.first()}
neutronclient = self.stub_neutronclient()
form_data = {'network': {'name': 'net1',
'tenant_id': self.request.user.project_id}}
neutronclient.create_network(body=form_data).AndReturn(network)
self.mox.ReplayAll()
ret_val = api.neutron.network_create(self.request, name='net1')
neutronclient = self.stub_neutronclient()
if with_n1kv:
n1kv_profile = 'n1kv:profile'
test_net_profile = 'test_net_profile'
network['network'][n1kv_profile] = test_net_profile
form_data['network'][n1kv_profile] = test_net_profile
neutronclient.create_network(body=form_data).AndReturn(network)
self.mox.ReplayAll()
ret_val = api.neutron.network_create(
self.request,
name='net1',
net_profile_id=test_net_profile)
# assert that when 'net_profile_id' is passed as a param to
# network_create function, 'n1kv:profile' is appended as a key to
# the returned network dictionary with value TEST_NET_PROFILE
self.assertEqual(test_net_profile, ret_val[n1kv_profile])
# also assert that 'net_profile_id' isn't there in the returned
# network dictionary
self.assertNotIn('net_profile_id', [k for k, _ in ret_val.items()])
else:
neutronclient.create_network(body=form_data).AndReturn(network)
self.mox.ReplayAll()
ret_val = api.neutron.network_create(self.request, name='net1')
self.assertIsInstance(ret_val, api.neutron.Network)
def test_network_create(self):
self._test_network_create()
def test_network_create_with_net_profile(self):
self._test_network_create(with_n1kv=True)
def test_network_update(self):
network = {'network': self.api_networks.first()}
network_id = self.api_networks.first()['id']
@ -171,21 +194,46 @@ class NeutronApiTests(test.APITestCase):
ret_val = api.neutron.port_get(self.request, port_id)
self.assertIsInstance(ret_val, api.neutron.Port)
def test_port_create(self):
port_data = self.api_ports.first()
params = {'network_id': port_data['network_id'],
'tenant_id': port_data['tenant_id'],
'name': port_data['name'],
'device_id': port_data['device_id']}
def _test_port_create(self, with_n1kv=False):
port = {'port': self.api_ports.first()}
params = {'network_id': port['port']['network_id'],
'tenant_id': port['port']['tenant_id'],
'name': port['port']['name'],
'device_id': port['port']['device_id']}
neutronclient = self.stub_neutronclient()
neutronclient.create_port(body={'port': params})\
.AndReturn({'port': port_data})
self.mox.ReplayAll()
ret_val = api.neutron.port_create(self.request, **params)
if with_n1kv:
n1kv_profile = 'n1kv:profile'
test_policy_profile = 'test_policy_profile'
port['port'][n1kv_profile] = test_policy_profile
body = {k: v for (k, v) in params.items()}
body[n1kv_profile] = port['port'][n1kv_profile]
neutronclient.create_port(body={'port': body}).AndReturn(port)
self.mox.ReplayAll()
ret_val = api.neutron.port_create(
self.request,
policy_profile_id=test_policy_profile,
**params)
# assert that when 'policy_profile_id' is passed as a param to
# port_create function, 'n1kv:profile' is appended as a key to the
# returned port dictionary with value TEST_POLICY_PROFILE
self.assertEqual(test_policy_profile, ret_val[n1kv_profile])
# also assert that 'policy_profile_id' isn't there in the returned
# port dictionary
self.assertNotIn('policy_profile_id',
[k for k, _ in ret_val.items()])
else:
neutronclient.create_port(body={'port': params}).AndReturn(port)
self.mox.ReplayAll()
ret_val = api.neutron.port_create(self.request, **params)
self.assertIsInstance(ret_val, api.neutron.Port)
self.assertEqual(api.neutron.Port(port_data).id, ret_val.id)
self.assertEqual(api.neutron.Port(port['port']).id, ret_val.id)
def test_port_create(self):
self._test_port_create()
def test_port_create_with_policy_profile(self):
self._test_port_create(with_n1kv=True)
def test_port_update(self):
port_data = self.api_ports.first()