Show subnet detail with prefix_delegation subnetpool properly

Subnet pool ID 'prefix_delegation' is a special subnet pool in Neutron
and there is no real subnet pool with ID 'prefix_delegation',
so we need to skip subnetpool_get() call
if a subnet has 'prefix_delegation' subnet pool.

This commit also adds unit tests which covers subnet pool operations
in the subnet detail view.

Change-Id: I3227a92084ee79b60d2b10262ed94a034e396306
Closes-Bug: #1702466
(cherry picked from commit 5de6b3eb14)
This commit is contained in:
Akihiro Motoki 2017-10-07 16:02:50 +00:00
parent 39d863ec23
commit d60ea82bfc
2 changed files with 53 additions and 2 deletions

View File

@ -34,8 +34,7 @@ form_data_subnet = net_tests.form_data_subnet
class NetworkSubnetTests(test.TestCase):
@test.create_stubs({api.neutron: ('network_get',
'subnet_get',
'is_extension_supported')})
'subnet_get',)})
def test_subnet_detail(self):
network = self.networks.first()
subnet = self.subnets.first()
@ -65,6 +64,55 @@ class NetworkSubnetTests(test.TestCase):
self.assertRedirectsNoFollow(res, NETWORKS_INDEX_URL)
@test.create_stubs({api.neutron: ('network_get',
'subnet_get', 'subnetpool_get',
'is_extension_supported')})
def test_subnet_detail_with_subnetpool(self):
network = self.networks.first()
subnet = self.subnets.first()
subnetpool = self.subnetpools.first()
subnet.subnetpool_id = subnetpool.id
api.neutron.network_get(IsA(http.HttpRequest), network.id)\
.MultipleTimes().AndReturn(network)
api.neutron.subnet_get(IsA(http.HttpRequest), subnet.id)\
.AndReturn(subnet)
api.neutron.is_extension_supported(
IsA(http.HttpRequest), 'subnet_allocation').AndReturn(True)
api.neutron.subnetpool_get(IsA(http.HttpRequest), subnetpool.id)\
.AndReturn(subnetpool)
self.mox.ReplayAll()
url = reverse(DETAIL_URL, args=[subnet.id])
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
self.assertEqual(subnet.id, res.context['subnet'].id)
self.assertEqual(subnetpool.id, res.context['subnet'].subnetpool_id)
self.assertEqual(subnetpool.name,
res.context['subnet'].subnetpool_name)
@test.create_stubs({api.neutron: ('network_get',
'subnet_get')})
def test_subnet_detail_with_subnetpool_prefixdelegation(self):
network = self.networks.first()
subnet = self.subnets.first()
subnet.subnetpool_id = 'prefix_delegation'
api.neutron.network_get(IsA(http.HttpRequest), network.id)\
.MultipleTimes().AndReturn(network)
api.neutron.subnet_get(IsA(http.HttpRequest), subnet.id)\
.AndReturn(subnet)
self.mox.ReplayAll()
url = reverse(DETAIL_URL, args=[subnet.id])
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
self.assertEqual(subnet.id, res.context['subnet'].id)
self.assertEqual('prefix_delegation',
res.context['subnet'].subnetpool_id)
@test.create_stubs({api.neutron: ('network_get',
'is_extension_supported',
'subnetpool_list')})

View File

@ -123,6 +123,9 @@ class DetailView(tabs.TabView):
if ('subnetpool_id' in subnet and
subnet.subnetpool_id and
# subnetpool_id = prefix_delegation is a special subnetpool
# and we cannot retrieve such subnet pool.
subnet.subnetpool_id != 'prefix_delegation' and
api.neutron.is_extension_supported(self.request,
'subnet_allocation')):
subnetpool = api.neutron.subnetpool_get(self.request,