Merge "Show external networks"

This commit is contained in:
Jenkins 2015-09-30 17:38:54 +00:00 committed by Gerrit Code Review
commit a23a7e0b6c
5 changed files with 52 additions and 49 deletions

View File

@ -170,6 +170,11 @@ class APIDictWrapper(object):
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self._apidict)
def __cmp__(self, other):
if hasattr(other, '_apidict'):
return cmp(self._apidict, other._apidict)
return cmp(self._apidict, other)
def to_dict(self):
return self._apidict

View File

@ -635,13 +635,13 @@ def network_get(request, network_id, expand_subnet=True, **params):
LOG.debug("network_get(): netid=%s, params=%s" % (network_id, params))
network = neutronclient(request).show_network(network_id,
**params).get('network')
# Since the number of subnets per network must be small,
# call subnet_get() for each subnet instead of calling
# subnet_list() once.
if expand_subnet:
network['subnets'] = [subnet_get(request, sid)
for sid in network['subnets']]
if request.user.tenant_id == network['tenant_id'] or network['shared']:
# Since the number of subnets per network must be small,
# call subnet_get() for each subnet instead of calling
# subnet_list() once.
network['subnets'] = [subnet_get(request, sid)
for sid in network['subnets']]
return Network(network)

View File

@ -175,6 +175,8 @@ class NetworksTable(tables.DataTable):
verbose_name=_("Subnets Associated"),)
shared = tables.Column("shared", verbose_name=_("Shared"),
filters=(filters.yesno, filters.capfirst))
external = tables.Column("router:external", verbose_name=_("External"),
filters=(filters.yesno, filters.capfirst))
status = tables.Column("status", verbose_name=_("Status"),
display_choices=STATUS_DISPLAY_CHOICES)
admin_state = tables.Column("admin_state",

View File

@ -99,7 +99,31 @@ def _str_host_routes(host_routes):
for route in host_routes])
class NetworkTests(test.TestCase):
class NetworkStubMixin(object):
def _stub_net_list(self):
all_networks = self.networks.list()
api.neutron.network_list(
IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False).AndReturn([
network for network in all_networks
if network['tenant_id'] == self.tenant.id
])
api.neutron.network_list(
IsA(http.HttpRequest),
shared=True).AndReturn([
network for network in all_networks
if network.get('shared')
])
api.neutron.network_list(
IsA(http.HttpRequest),
**{'router:external': True}).AndReturn([
network for network in all_networks
if network.get('router:external')
])
class NetworkTests(test.TestCase, NetworkStubMixin):
@test.create_stubs({api.neutron: ('network_list',),
quotas: ('tenant_quota_usages',)})
@ -107,13 +131,7 @@ class NetworkTests(test.TestCase):
quota_data = self.quota_usages.first()
quota_data['networks']['available'] = 5
quota_data['subnets']['available'] = 5
api.neutron.network_list(
IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False).AndReturn(self.networks.list())
api.neutron.network_list(
IsA(http.HttpRequest),
shared=True).AndReturn([])
self._stub_net_list()
quotas.tenant_quota_usages(
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(quota_data)
@ -830,13 +848,7 @@ class NetworkTests(test.TestCase):
network.id,
expand_subnet=False)\
.AndReturn(network)
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=network.tenant_id,
shared=False)\
.AndReturn([network])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True)\
.AndReturn([])
self._stub_net_list()
api.neutron.network_delete(IsA(http.HttpRequest), network.id)
self.mox.ReplayAll()
@ -857,12 +869,7 @@ class NetworkTests(test.TestCase):
network.id,
expand_subnet=False)\
.AndReturn(network)
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=network.tenant_id,
shared=False)\
.AndReturn([network])
api.neutron.network_list(IsA(http.HttpRequest), shared=True)\
.AndReturn([])
self._stub_net_list()
api.neutron.subnet_delete(IsA(http.HttpRequest), subnet_id)
api.neutron.network_delete(IsA(http.HttpRequest), network.id)
@ -885,13 +892,7 @@ class NetworkTests(test.TestCase):
network.id,
expand_subnet=False)\
.AndReturn(network)
api.neutron.network_list(IsA(http.HttpRequest),
tenant_id=network.tenant_id,
shared=False)\
.AndReturn([network])
api.neutron.network_list(IsA(http.HttpRequest),
shared=True)\
.AndReturn([])
self._stub_net_list()
api.neutron.subnet_delete(IsA(http.HttpRequest), subnet_id)
api.neutron.network_delete(IsA(http.HttpRequest), network.id)\
.AndRaise(self.exceptions.neutron)
@ -2137,7 +2138,7 @@ class NetworkPortTests(test.TestCase):
self.assertRedirectsNoFollow(res, redir_url)
class NetworkViewTests(test.TestCase):
class NetworkViewTests(test.TestCase, NetworkStubMixin):
def _test_create_button_shown_when_quota_disabled(
self, expected_string):
@ -2148,13 +2149,7 @@ class NetworkViewTests(test.TestCase):
quota_data['networks'].pop('available')
quota_data['subnets'].pop('available')
api.neutron.network_list(
IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False).AndReturn(self.networks.list())
api.neutron.network_list(
IsA(http.HttpRequest),
shared=True).AndReturn([])
self._stub_net_list()
quotas.tenant_quota_usages(
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(quota_data)
@ -2177,13 +2172,7 @@ class NetworkViewTests(test.TestCase):
quota_data['networks']['available'] = network_quota
quota_data['subnets']['available'] = subnet_quota
api.neutron.network_list(
IsA(http.HttpRequest),
tenant_id=self.tenant.id,
shared=False).AndReturn(self.networks.list())
api.neutron.network_list(
IsA(http.HttpRequest),
shared=True).AndReturn([])
self._stub_net_list()
quotas.tenant_quota_usages(
IsA(http.HttpRequest)) \
.MultipleTimes().AndReturn(quota_data)

View File

@ -49,6 +49,13 @@ class IndexView(tables.DataTableView):
tenant_id = self.request.user.tenant_id
networks = api.neutron.network_list_for_tenant(self.request,
tenant_id)
# List Public networks
for network in api.neutron.network_list(
self.request, **{'router:external': True}
):
if network not in networks:
networks.append(network)
except Exception:
networks = []
msg = _('Network list can not be retrieved.')