Browse Source

Include add subnet action on admin networks panel

Currently users can only add and delete networks on admin networks panel.

This patch adds the add subnet action to the admin networks panel so it
is consistent with the project networks panel.

Change-Id: I84e2d51baa4d2adb81ca3fd36e35063a69097326
Closes-bug: #1710723
Ying Zuo 1 year ago
parent
commit
a4aed76ab9

+ 11
- 3
openstack_dashboard/dashboards/admin/networks/subnets/tests.py View File

@@ -22,6 +22,7 @@ from horizon.workflows import views
22 22
 from openstack_dashboard import api
23 23
 from openstack_dashboard.dashboards.project.networks import tests
24 24
 from openstack_dashboard.test import helpers as test
25
+from openstack_dashboard.usage import quotas
25 26
 
26 27
 DETAIL_URL = 'horizon:admin:networks:subnets:detail'
27 28
 
@@ -308,7 +309,8 @@ class NetworkSubnetTests(test.BaseAdminViewTests):
308 309
                                       'port_list',
309 310
                                       'is_extension_supported',
310 311
                                       'show_network_ip_availability',
311
-                                      'list_dhcp_agent_hosting_networks',)})
312
+                                      'list_dhcp_agent_hosting_networks',),
313
+                        quotas: ('tenant_quota_usages',)})
312 314
     def test_subnet_delete_with_mac_learning(self):
313 315
         self._test_subnet_delete(mac_learning=True)
314 316
 
@@ -390,7 +392,8 @@ class NetworkSubnetTests(test.BaseAdminViewTests):
390 392
                                       'port_list',
391 393
                                       'is_extension_supported',
392 394
                                       'show_network_ip_availability',
393
-                                      'list_dhcp_agent_hosting_networks',)})
395
+                                      'list_dhcp_agent_hosting_networks',),
396
+                        quotas: ('tenant_quota_usages',)})
394 397
     def test_network_detail_ip_availability_exception(self):
395 398
         self._test_network_detail_ip_availability_exception()
396 399
 
@@ -399,13 +402,15 @@ class NetworkSubnetTests(test.BaseAdminViewTests):
399 402
                                       'port_list',
400 403
                                       'is_extension_supported',
401 404
                                       'show_network_ip_availability',
402
-                                      'list_dhcp_agent_hosting_networks',)})
405
+                                      'list_dhcp_agent_hosting_networks',),
406
+                        quotas: ('tenant_quota_usages',)})
403 407
     def test_network_detail_ip_availability_exception_with_mac_learning(self):
404 408
         self._test_network_detail_ip_availability_exception(mac_learning=True)
405 409
 
406 410
     def _test_network_detail_ip_availability_exception(self,
407 411
                                                        mac_learning=False):
408 412
         network_id = self.networks.first().id
413
+        quota_data = self.quota_usages.first()
409 414
         api.neutron.is_extension_supported(
410 415
             IsA(http.HttpRequest),
411 416
             'network-ip-availability').AndReturn(True)
@@ -426,6 +431,9 @@ class NetworkSubnetTests(test.BaseAdminViewTests):
426 431
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
427 432
                                            'dhcp_agent_scheduler')\
428 433
             .MultipleTimes().AndReturn(True)
434
+        quotas.tenant_quota_usages(
435
+            IsA(http.HttpRequest), targets=('subnets',)) \
436
+            .MultipleTimes().AndReturn(quota_data)
429 437
         self.mox.ReplayAll()
430 438
         from django.utils.http import urlunquote
431 439
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',

+ 5
- 1
openstack_dashboard/dashboards/admin/networks/tables.py View File

@@ -79,6 +79,10 @@ class EditNetwork(policy.PolicyTargetMixin, tables.LinkAction):
79 79
     policy_rules = (("network", "update_network"),)
80 80
 
81 81
 
82
+class CreateSubnet(project_tables.CreateSubnet):
83
+    url = "horizon:admin:networks:createsubnet"
84
+
85
+
82 86
 DISPLAY_CHOICES = (
83 87
     ("up", pgettext_lazy("Admin state of a Network", u"UP")),
84 88
     ("down", pgettext_lazy("Admin state of a Network", u"DOWN")),
@@ -119,7 +123,7 @@ class NetworksTable(tables.DataTable):
119 123
         verbose_name = _("Networks")
120 124
         table_actions = (CreateNetwork, DeleteNetwork,
121 125
                          AdminNetworksFilterAction)
122
-        row_actions = (EditNetwork, DeleteNetwork)
126
+        row_actions = (EditNetwork, CreateSubnet, DeleteNetwork)
123 127
 
124 128
     def __init__(self, request, data=None, needs_form_wrapper=None, **kwargs):
125 129
         super(NetworksTable, self).__init__(

+ 45
- 11
openstack_dashboard/dashboards/admin/networks/tests.py View File

@@ -34,9 +34,11 @@ class NetworkTests(test.BaseAdminViewTests):
34 34
     @test.create_stubs({api.neutron: ('network_list',
35 35
                                       'list_dhcp_agent_hosting_networks',
36 36
                                       'is_extension_supported'),
37
-                        api.keystone: ('tenant_list',)})
37
+                        api.keystone: ('tenant_list',),
38
+                        usage.quotas: ('tenant_quota_usages',)})
38 39
     def test_index(self):
39 40
         tenants = self.tenants.list()
41
+        quota_data = self.quota_usages.first()
40 42
         api.neutron.network_list(IsA(http.HttpRequest)) \
41 43
             .AndReturn(self.networks.list())
42 44
         api.keystone.tenant_list(IsA(http.HttpRequest))\
@@ -52,6 +54,9 @@ class NetworkTests(test.BaseAdminViewTests):
52 54
         api.neutron.is_extension_supported(
53 55
             IsA(http.HttpRequest),
54 56
             'dhcp_agent_scheduler').AndReturn(True)
57
+        usage.quotas.tenant_quota_usages(
58
+            IsA(http.HttpRequest), targets=('subnets', )) \
59
+            .MultipleTimes().AndReturn(quota_data)
55 60
         self.mox.ReplayAll()
56 61
 
57 62
         res = self.client.get(INDEX_URL)
@@ -82,7 +87,8 @@ class NetworkTests(test.BaseAdminViewTests):
82 87
                                       'port_list',
83 88
                                       'show_network_ip_availability',
84 89
                                       'list_dhcp_agent_hosting_networks',
85
-                                      'is_extension_supported')})
90
+                                      'is_extension_supported'),
91
+                        usage.quotas: ('tenant_quota_usages',)})
86 92
     def test_network_detail_subnets_tab(self):
87 93
         self._test_network_detail_subnets_tab()
88 94
 
@@ -91,14 +97,17 @@ class NetworkTests(test.BaseAdminViewTests):
91 97
                                       'port_list',
92 98
                                       'is_extension_supported',
93 99
                                       'show_network_ip_availability',
94
-                                      'list_dhcp_agent_hosting_networks',)})
100
+                                      'list_dhcp_agent_hosting_networks',),
101
+                        usage.quotas: ('tenant_quota_usages',)})
95 102
     def test_network_detail_subnets_tab_with_mac_learning(self):
96 103
         self._test_network_detail_subnets_tab(mac_learning=True)
97 104
 
98 105
     @test.create_stubs({api.neutron: ('network_get',
99
-                                      'is_extension_supported')})
106
+                                      'is_extension_supported'),
107
+                        usage.quotas: ('tenant_quota_usages',)})
100 108
     def test_network_detail_new(self, mac_learning=False):
101 109
         network_id = self.networks.first().id
110
+        quota_data = self.quota_usages.first()
102 111
         api.neutron.network_get(IsA(http.HttpRequest), network_id) \
103 112
             .MultipleTimes().AndReturn(self.networks.first())
104 113
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
@@ -111,6 +120,9 @@ class NetworkTests(test.BaseAdminViewTests):
111 120
         api.neutron.is_extension_supported(
112 121
             IsA(http.HttpRequest),
113 122
             'dhcp_agent_scheduler').AndReturn(True)
123
+        usage.quotas.tenant_quota_usages(
124
+            IsA(http.HttpRequest), targets=('subnets',)) \
125
+            .MultipleTimes().AndReturn(quota_data)
114 126
         self.mox.ReplayAll()
115 127
         url = urlunquote(reverse('horizon:admin:networks:detail',
116 128
                                  args=[network_id]))
@@ -125,6 +137,7 @@ class NetworkTests(test.BaseAdminViewTests):
125 137
     def _test_network_detail_subnets_tab(self, mac_learning=False):
126 138
         network_id = self.networks.first().id
127 139
         ip_availability = self.ip_availability.get()
140
+        quota_data = self.quota_usages.first()
128 141
         api.neutron.show_network_ip_availability(IsA(http.HttpRequest),
129 142
                                                  network_id).\
130 143
             MultipleTimes().AndReturn(ip_availability)
@@ -145,6 +158,9 @@ class NetworkTests(test.BaseAdminViewTests):
145 158
         api.neutron.is_extension_supported(
146 159
             IsA(http.HttpRequest),
147 160
             'dhcp_agent_scheduler').AndReturn(True)
161
+        usage.quotas.tenant_quota_usages(
162
+            IsA(http.HttpRequest), targets=('subnets',)) \
163
+            .MultipleTimes().AndReturn(quota_data)
148 164
         self.mox.ReplayAll()
149 165
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
150 166
                          args=[network_id]))
@@ -179,6 +195,9 @@ class NetworkTests(test.BaseAdminViewTests):
179 195
         api.neutron.is_extension_supported(
180 196
             IsA(http.HttpRequest),
181 197
             'dhcp_agent_scheduler').AndReturn(True)
198
+        usage.quotas.tenant_quota_usages(
199
+            IsA(http.HttpRequest), targets=('subnets',)) \
200
+            .MultipleTimes().AndReturn(quota_data)
182 201
 
183 202
         self.mox.ReplayAll()
184 203
         url = reverse('horizon:admin:networks:ports_tab',
@@ -193,9 +212,11 @@ class NetworkTests(test.BaseAdminViewTests):
193 212
                                       'subnet_list',
194 213
                                       'port_list',
195 214
                                       'is_extension_supported',
196
-                                      'list_dhcp_agent_hosting_networks',)})
215
+                                      'list_dhcp_agent_hosting_networks',),
216
+                        usage.quotas: ('tenant_quota_usages',)})
197 217
     def test_network_detail_agents_tab(self, mac_learning=False):
198 218
         network_id = self.networks.first().id
219
+        quota_data = self.quota_usages.first()
199 220
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
200 221
                                            'network-ip-availability') \
201 222
             .AndReturn(True)
@@ -214,6 +235,9 @@ class NetworkTests(test.BaseAdminViewTests):
214 235
         api.neutron.is_extension_supported(
215 236
             IsA(http.HttpRequest),
216 237
             'dhcp_agent_scheduler').AndReturn(True)
238
+        usage.quotas.tenant_quota_usages(
239
+            IsA(http.HttpRequest), targets=('subnets', )) \
240
+            .MultipleTimes().AndReturn(quota_data)
217 241
         self.mox.ReplayAll()
218 242
         url = reverse('horizon:admin:networks:agents_tab', args=[network_id])
219 243
         res = self.client.get(urlunquote(url))
@@ -277,7 +301,8 @@ class NetworkTests(test.BaseAdminViewTests):
277 301
                                       'subnet_list',
278 302
                                       'port_list',
279 303
                                       'list_dhcp_agent_hosting_networks',
280
-                                      'is_extension_supported')})
304
+                                      'is_extension_supported'),
305
+                        usage.quotas: ('tenant_quota_usages',)})
281 306
     def test_network_detail_subnets_tab_subnet_exception(self):
282 307
         self._test_network_detail_subnets_tab_subnet_exception()
283 308
 
@@ -285,7 +310,8 @@ class NetworkTests(test.BaseAdminViewTests):
285 310
                                       'subnet_list',
286 311
                                       'port_list',
287 312
                                       'is_extension_supported',
288
-                                      'list_dhcp_agent_hosting_networks',)})
313
+                                      'list_dhcp_agent_hosting_networks',),
314
+                        usage.quotas: ('tenant_quota_usages',)})
289 315
     def test_network_detail_subnets_tab_subnet_exception_w_mac_learning(self):
290 316
         self._test_network_detail_subnets_tab_subnet_exception(
291 317
             mac_learning=True)
@@ -293,6 +319,7 @@ class NetworkTests(test.BaseAdminViewTests):
293 319
     def _test_network_detail_subnets_tab_subnet_exception(self,
294 320
                                                           mac_learning=False):
295 321
         network_id = self.networks.first().id
322
+        quota_data = self.quota_usages.first()
296 323
         api.neutron.network_get(IsA(http.HttpRequest), network_id).\
297 324
             AndReturn(self.networks.first())
298 325
         api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id).\
@@ -309,7 +336,9 @@ class NetworkTests(test.BaseAdminViewTests):
309 336
         api.neutron.is_extension_supported(
310 337
             IsA(http.HttpRequest),
311 338
             'dhcp_agent_scheduler').AndReturn(True)
312
-
339
+        usage.quotas.tenant_quota_usages(
340
+            IsA(http.HttpRequest), targets=('subnets',)) \
341
+            .MultipleTimes().AndReturn(quota_data)
313 342
         self.mox.ReplayAll()
314 343
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
315 344
                          args=[network_id]))
@@ -324,7 +353,8 @@ class NetworkTests(test.BaseAdminViewTests):
324 353
                                       'port_list',
325 354
                                       'is_extension_supported',
326 355
                                       'show_network_ip_availability',
327
-                                      'list_dhcp_agent_hosting_networks',)})
356
+                                      'list_dhcp_agent_hosting_networks',),
357
+                        usage.quotas: ('tenant_quota_usages',)})
328 358
     def test_network_detail_port_exception(self):
329 359
         self._test_network_detail_subnets_tab_port_exception()
330 360
 
@@ -333,7 +363,8 @@ class NetworkTests(test.BaseAdminViewTests):
333 363
                                       'port_list',
334 364
                                       'is_extension_supported',
335 365
                                       'show_network_ip_availability',
336
-                                      'list_dhcp_agent_hosting_networks',)})
366
+                                      'list_dhcp_agent_hosting_networks',),
367
+                        usage.quotas: ('tenant_quota_usages',)})
337 368
     def test_network_detail_subnets_tab_port_exception_with_mac_learning(self):
338 369
         self._test_network_detail_subnets_tab_port_exception(mac_learning=True)
339 370
 
@@ -341,6 +372,7 @@ class NetworkTests(test.BaseAdminViewTests):
341 372
                                                         mac_learning=False):
342 373
         network_id = self.networks.first().id
343 374
         ip_availability = self.ip_availability.get()
375
+        quota_data = self.quota_usages.first()
344 376
         api.neutron.show_network_ip_availability(IsA(http.HttpRequest),
345 377
                                                  network_id). \
346 378
             MultipleTimes().AndReturn(ip_availability)
@@ -360,7 +392,9 @@ class NetworkTests(test.BaseAdminViewTests):
360 392
         api.neutron.is_extension_supported(IsA(http.HttpRequest),
361 393
                                            'dhcp_agent_scheduler')\
362 394
             .AndReturn(True)
363
-
395
+        usage.quotas.tenant_quota_usages(
396
+            IsA(http.HttpRequest), targets=('subnets',)) \
397
+            .MultipleTimes().AndReturn(quota_data)
364 398
         self.mox.ReplayAll()
365 399
         url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
366 400
                          args=[network_id]))

Loading…
Cancel
Save