summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2018-05-14 09:18:40 +0900
committerAkihiro Motoki <amotoki@gmail.com>2018-05-14 11:28:31 +0900
commit5e012b45fc028f5a7ec4333be247acf03f9c3eac (patch)
tree16ded4c6c826c2d57400cf7acf574a97659f4c18
parent26fb8f259f088b32e68992617eca667c53910dab (diff)
Convert admin.networks tests into mock
Notes
Notes (review): Code-Review+2: Ivan Kolodyazhny <e0ne@e0ne.info> Workflow+1: Ivan Kolodyazhny <e0ne@e0ne.info> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 17 May 2018 10:16:39 +0000 Reviewed-on: https://review.openstack.org/568163 Project: openstack/horizon Branch: refs/heads/master
-rw-r--r--openstack_dashboard/dashboards/admin/networks/tests.py1073
1 files changed, 559 insertions, 514 deletions
diff --git a/openstack_dashboard/dashboards/admin/networks/tests.py b/openstack_dashboard/dashboards/admin/networks/tests.py
index 68c3b64..1cb64b9 100644
--- a/openstack_dashboard/dashboards/admin/networks/tests.py
+++ b/openstack_dashboard/dashboards/admin/networks/tests.py
@@ -12,12 +12,12 @@
12# License for the specific language governing permissions and limitations 12# License for the specific language governing permissions and limitations
13# under the License. 13# under the License.
14 14
15import collections
15 16
16from django import http
17from django.urls import reverse 17from django.urls import reverse
18from django.utils.http import urlunquote 18from django.utils.http import urlunquote
19 19
20from mox3.mox import IsA 20import mock
21 21
22from horizon import forms 22from horizon import forms
23 23
@@ -32,9 +32,20 @@ INDEX_URL = reverse('horizon:admin:networks:index')
32 32
33class NetworkTests(test.BaseAdminViewTests): 33class NetworkTests(test.BaseAdminViewTests):
34 34
35 use_mox = True 35 def _stub_is_extension_supported(self, features):
36 self._features = features
37 self._feature_call_counts = collections.defaultdict(int)
36 38
37 @test.create_stubs({api.neutron: ('network_list', 39 def fake_extension_supported(request, alias):
40 self._feature_call_counts[alias] += 1
41 return self._features[alias]
42
43 self.mock_is_extension_supported.side_effect = fake_extension_supported
44
45 def _check_is_extension_supported(self, expected_count):
46 self.assertEqual(expected_count, self._feature_call_counts)
47
48 @test.create_mocks({api.neutron: ('network_list',
38 'list_dhcp_agent_hosting_networks', 49 'list_dhcp_agent_hosting_networks',
39 'is_extension_supported'), 50 'is_extension_supported'),
40 api.keystone: ('tenant_list',), 51 api.keystone: ('tenant_list',),
@@ -42,28 +53,15 @@ class NetworkTests(test.BaseAdminViewTests):
42 def test_index(self): 53 def test_index(self):
43 tenants = self.tenants.list() 54 tenants = self.tenants.list()
44 quota_data = self.quota_usages.first() 55 quota_data = self.quota_usages.first()
45 api.neutron.network_list(IsA(http.HttpRequest)) \ 56
46 .AndReturn(self.networks.list()) 57 self.mock_network_list.return_value = self.networks.list()
47 api.keystone.tenant_list(IsA(http.HttpRequest))\ 58 self.mock_tenant_list.return_value = [tenants, False]
48 .AndReturn([tenants, False]) 59 self._stub_is_extension_supported(
49 api.neutron.is_extension_supported( 60 {'network_availability_zone': True,
50 IsA(http.HttpRequest), 61 'dhcp_agent_scheduler': True})
51 'network_availability_zone').AndReturn(True) 62 self.mock_tenant_quota_usages.return_value = quota_data
52 for network in self.networks.list(): 63 self.mock_list_dhcp_agent_hosting_networks.return_value = \
53 usage.quotas.tenant_quota_usages( 64 self.agents.list()
54 IsA(http.HttpRequest), tenant_id=network.tenant_id,
55 targets=('subnet', )).AndReturn(quota_data)
56 api.neutron.list_dhcp_agent_hosting_networks(IsA(http.HttpRequest),
57 network.id)\
58 .AndReturn(self.agents.list())
59 api.neutron.is_extension_supported(
60 IsA(http.HttpRequest),
61 'dhcp_agent_scheduler').AndReturn(True)
62
63 api.neutron.is_extension_supported(
64 IsA(http.HttpRequest),
65 'dhcp_agent_scheduler').AndReturn(True)
66 self.mox.ReplayAll()
67 65
68 res = self.client.get(INDEX_URL) 66 res = self.client.get(INDEX_URL)
69 67
@@ -71,19 +69,30 @@ class NetworkTests(test.BaseAdminViewTests):
71 networks = res.context['networks_table'].data 69 networks = res.context['networks_table'].data
72 self.assertItemsEqual(networks, self.networks.list()) 70 self.assertItemsEqual(networks, self.networks.list())
73 71
74 @test.create_stubs({api.neutron: ('network_list', 72 self.mock_network_list.assert_called_once_with(test.IsHttpRequest())
73 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
74 self._check_is_extension_supported(
75 {'network_availability_zone': 1,
76 'dhcp_agent_scheduler': len(self.networks.list()) + 1})
77 self.mock_tenant_quota_usages.assert_has_calls(
78 [mock.call(test.IsHttpRequest(), tenant_id=network.tenant_id,
79 targets=('subnet', ))
80 for network in self.networks.list()])
81 self.assertEqual(len(self.networks.list()),
82 self.mock_tenant_quota_usages.call_count)
83 self.mock_list_dhcp_agent_hosting_networks.assert_has_calls(
84 [mock.call(test.IsHttpRequest(), network.id)
85 for network in self.networks.list()])
86 self.assertEqual(len(self.networks.list()),
87 self.mock_list_dhcp_agent_hosting_networks.call_count)
88
89 @test.create_mocks({api.neutron: ('network_list',
75 'is_extension_supported',)}) 90 'is_extension_supported',)})
76 def test_index_network_list_exception(self): 91 def test_index_network_list_exception(self):
77 api.neutron.network_list(IsA(http.HttpRequest)) \ 92 self.mock_network_list.side_effect = self.exceptions.neutron
78 .AndRaise(self.exceptions.neutron) 93 self._stub_is_extension_supported(
79 api.neutron.is_extension_supported( 94 {'network_availability_zone': True,
80 IsA(http.HttpRequest), 95 'dhcp_agent_scheduler': True})
81 'network_availability_zone').AndReturn(True)
82 api.neutron.is_extension_supported(
83 IsA(http.HttpRequest),
84 'dhcp_agent_scheduler').AndReturn(True)
85
86 self.mox.ReplayAll()
87 96
88 res = self.client.get(INDEX_URL) 97 res = self.client.get(INDEX_URL)
89 98
@@ -91,51 +100,26 @@ class NetworkTests(test.BaseAdminViewTests):
91 self.assertEqual(len(res.context['networks_table'].data), 0) 100 self.assertEqual(len(res.context['networks_table'].data), 0)
92 self.assertMessageCount(res, error=1) 101 self.assertMessageCount(res, error=1)
93 102
94 @test.create_stubs({api.neutron: ('network_get', 103 self.mock_network_list.assert_called_once_with(test.IsHttpRequest())
95 'subnet_list', 104 self._check_is_extension_supported(
96 'port_list', 105 {'network_availability_zone': 1,
97 'show_network_ip_availability', 106 'dhcp_agent_scheduler': 1})
98 'list_dhcp_agent_hosting_networks',
99 'is_extension_supported'),
100 usage.quotas: ('tenant_quota_usages',)})
101 def test_network_detail_subnets_tab(self):
102 self._test_network_detail_subnets_tab()
103
104 @test.create_stubs({api.neutron: ('network_get',
105 'subnet_list',
106 'port_list',
107 'is_extension_supported',
108 'show_network_ip_availability',
109 'list_dhcp_agent_hosting_networks',),
110 usage.quotas: ('tenant_quota_usages',)})
111 def test_network_detail_subnets_tab_with_mac_learning(self):
112 self._test_network_detail_subnets_tab(mac_learning=True)
113 107
114 @test.create_stubs({api.neutron: ('network_get', 108 @test.create_mocks({api.neutron: ('network_get',
115 'is_extension_supported'), 109 'is_extension_supported'),
116 usage.quotas: ('tenant_quota_usages',)}) 110 usage.quotas: ('tenant_quota_usages',)})
117 def test_network_detail_new(self, mac_learning=False): 111 def test_network_detail_new(self, mac_learning=False):
118 network = self.networks.first() 112 network = self.networks.first()
119 quota_data = self.quota_usages.first() 113 quota_data = self.quota_usages.first()
120 api.neutron.network_get(IsA(http.HttpRequest), network.id) \ 114
121 .MultipleTimes().AndReturn(self.networks.first()) 115 self.mock_network_get.return_value = network
122 api.neutron.is_extension_supported(IsA(http.HttpRequest), 116 self.mock_tenant_quota_usages.return_value = quota_data
123 'network-ip-availability') \ 117 self._stub_is_extension_supported(
124 .AndReturn(True) 118 {'network-ip-availability': True,
125 api.neutron.is_extension_supported(IsA(http.HttpRequest), 119 'network_availability_zone': True,
126 'mac-learning') \ 120 'mac-learning': mac_learning,
127 .AndReturn(mac_learning) 121 'dhcp_agent_scheduler': True})
128 122
129 api.neutron.is_extension_supported(
130 IsA(http.HttpRequest),
131 'network_availability_zone').AndReturn(True)
132 api.neutron.is_extension_supported(
133 IsA(http.HttpRequest),
134 'dhcp_agent_scheduler').AndReturn(True)
135 usage.quotas.tenant_quota_usages(
136 IsA(http.HttpRequest), tenant_id=network.tenant_id,
137 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
138 self.mox.ReplayAll()
139 url = urlunquote(reverse('horizon:admin:networks:detail', 123 url = urlunquote(reverse('horizon:admin:networks:detail',
140 args=[network.id])) 124 args=[network.id]))
141 125
@@ -146,37 +130,44 @@ class NetworkTests(test.BaseAdminViewTests):
146 network.status_label) 130 network.status_label)
147 self.assertTemplateUsed(res, 'horizon/common/_detail.html') 131 self.assertTemplateUsed(res, 'horizon/common/_detail.html')
148 132
133 self.assert_mock_multiple_calls_with_same_arguments(
134 self.mock_network_get, 2,
135 mock.call(test.IsHttpRequest(), network.id))
136 self.mock_tenant_quota_usages.assert_called_once_with(
137 test.IsHttpRequest(), tenant_id=network.tenant_id,
138 targets=('subnet',))
139 self._check_is_extension_supported(
140 {'network-ip-availability': 1,
141 'network_availability_zone': 1,
142 'mac-learning': 1,
143 'dhcp_agent_scheduler': 1})
144
145 def test_network_detail_subnets_tab(self):
146 self._test_network_detail_subnets_tab()
147
148 def test_network_detail_subnets_tab_with_mac_learning(self):
149 self._test_network_detail_subnets_tab(mac_learning=True)
150
151 @test.create_mocks({api.neutron: ('network_get',
152 'subnet_list',
153 'show_network_ip_availability',
154 'is_extension_supported'),
155 usage.quotas: ('tenant_quota_usages',)})
149 def _test_network_detail_subnets_tab(self, mac_learning=False): 156 def _test_network_detail_subnets_tab(self, mac_learning=False):
150 network = self.networks.first() 157 network = self.networks.first()
151 ip_availability = self.ip_availability.get() 158 ip_availability = self.ip_availability.get()
152 quota_data = self.quota_usages.first() 159 quota_data = self.quota_usages.first()
153 api.neutron.show_network_ip_availability(IsA(http.HttpRequest), 160
154 network.id).\ 161 self.mock_show_network_ip_availability.return_value = ip_availability
155 MultipleTimes().AndReturn(ip_availability) 162 self.mock_network_get.return_value = network
156 api.neutron.network_get(IsA(http.HttpRequest), network.id)\ 163 self.mock_subnet_list.return_value = [self.subnets.first()]
157 .MultipleTimes().AndReturn(self.networks.first()) 164 self._stub_is_extension_supported(
158 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network.id)\ 165 {'network-ip-availability': True,
159 .AndReturn([self.subnets.first()]) 166 'mac-learning': mac_learning,
160 api.neutron.is_extension_supported( 167 'network_availability_zone': True,
161 IsA(http.HttpRequest), 168 'dhcp_agent_scheduler': True})
162 'network-ip-availability').AndReturn(True) 169 self.mock_tenant_quota_usages.return_value = quota_data
163 api.neutron.is_extension_supported(IsA(http.HttpRequest), 170
164 'mac-learning')\
165 .AndReturn(mac_learning)
166
167 api.neutron.is_extension_supported(
168 IsA(http.HttpRequest),
169 'network-ip-availability').AndReturn(True)
170 api.neutron.is_extension_supported(
171 IsA(http.HttpRequest),
172 'network_availability_zone').AndReturn(True)
173 api.neutron.is_extension_supported(
174 IsA(http.HttpRequest),
175 'dhcp_agent_scheduler').AndReturn(True)
176 usage.quotas.tenant_quota_usages(
177 IsA(http.HttpRequest), tenant_id=network.tenant_id,
178 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
179 self.mox.ReplayAll()
180 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 171 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
181 args=[network.id])) 172 args=[network.id]))
182 res = self.client.get(url) 173 res = self.client.get(url)
@@ -185,39 +176,40 @@ class NetworkTests(test.BaseAdminViewTests):
185 subnets = res.context['subnets_table'].data 176 subnets = res.context['subnets_table'].data
186 self.assertItemsEqual(subnets, [self.subnets.first()]) 177 self.assertItemsEqual(subnets, [self.subnets.first()])
187 178
188 @test.create_stubs({api.neutron: ('network_get', 179 self.mock_show_network_ip_availability.assert_called_once_with(
189 'subnet_list', 180 test.IsHttpRequest(), network.id)
181 self.assert_mock_multiple_calls_with_same_arguments(
182 self.mock_network_get, 2,
183 mock.call(test.IsHttpRequest(), network.id))
184 self.mock_subnet_list.assert_called_once_with(test.IsHttpRequest(),
185 network_id=network.id)
186 self._check_is_extension_supported(
187 {'network-ip-availability': 2,
188 'mac-learning': 1,
189 'network_availability_zone': 1,
190 'dhcp_agent_scheduler': 1})
191 self.assert_mock_multiple_calls_with_same_arguments(
192 self.mock_tenant_quota_usages, 3,
193 mock.call(test.IsHttpRequest(), tenant_id=network.tenant_id,
194 targets=('subnet',)))
195
196 @test.create_mocks({api.neutron: ('network_get',
190 'port_list', 197 'port_list',
191 'is_extension_supported', 198 'is_extension_supported'),
192 'list_dhcp_agent_hosting_networks',),
193 usage.quotas: ('tenant_quota_usages',)}) 199 usage.quotas: ('tenant_quota_usages',)})
194 def test_network_detail_ports_tab(self, mac_learning=False): 200 def test_network_detail_ports_tab(self, mac_learning=False):
195 network = self.networks.first() 201 network = self.networks.first()
196 api.neutron.network_get(IsA(http.HttpRequest), network.id)\
197 .MultipleTimes().AndReturn(self.networks.first())
198 api.neutron.port_list(IsA(http.HttpRequest), network_id=network.id)\
199 .AndReturn([self.ports.first()])
200 quota_data = self.neutron_quota_usages.first() 202 quota_data = self.neutron_quota_usages.first()
201 usage.quotas.tenant_quota_usages( 203
202 IsA(http.HttpRequest), tenant_id=network.tenant_id, 204 self.mock_network_get.return_value = network
203 targets=('port',)).MultipleTimes().AndReturn(quota_data) 205 self.mock_port_list.return_value = [self.ports.first()]
204 api.neutron.is_extension_supported( 206 self.mock_tenant_quota_usages.return_value = quota_data
205 IsA(http.HttpRequest), 207 self._stub_is_extension_supported(
206 'network-ip-availability').AndReturn(True) 208 {'network-ip-availability': True,
207 api.neutron.is_extension_supported(IsA(http.HttpRequest), 209 'mac-learning': mac_learning,
208 'mac-learning')\ 210 'network_availability_zone': True,
209 .AndReturn(mac_learning) 211 'dhcp_agent_scheduler': True})
210 api.neutron.is_extension_supported( 212
211 IsA(http.HttpRequest),
212 'network_availability_zone').AndReturn(True)
213 api.neutron.is_extension_supported(
214 IsA(http.HttpRequest),
215 'dhcp_agent_scheduler').AndReturn(True)
216 usage.quotas.tenant_quota_usages(
217 IsA(http.HttpRequest), tenant_id=network.tenant_id,
218 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
219
220 self.mox.ReplayAll()
221 url = reverse('horizon:admin:networks:ports_tab', 213 url = reverse('horizon:admin:networks:ports_tab',
222 args=[network.id]) 214 args=[network.id])
223 res = self.client.get(urlunquote(url)) 215 res = self.client.get(urlunquote(url))
@@ -226,40 +218,44 @@ class NetworkTests(test.BaseAdminViewTests):
226 ports = res.context['ports_table'].data 218 ports = res.context['ports_table'].data
227 self.assertItemsEqual(ports, [self.ports.first()]) 219 self.assertItemsEqual(ports, [self.ports.first()])
228 220
229 @test.create_stubs({api.neutron: ('network_get', 221 self.assert_mock_multiple_calls_with_same_arguments(
230 'subnet_list', 222 self.mock_network_get, 2,
231 'port_list', 223 mock.call(test.IsHttpRequest(), network.id))
224 self.mock_port_list.assert_called_once_with(test.IsHttpRequest(),
225 network_id=network.id)
226 self.assertEqual(3, self.mock_tenant_quota_usages.call_count)
227 self.mock_tenant_quota_usages.assert_has_calls([
228 mock.call(test.IsHttpRequest(), tenant_id=network.tenant_id,
229 targets=('subnet',)),
230 mock.call(test.IsHttpRequest(), tenant_id=network.tenant_id,
231 targets=('port',)),
232 mock.call(test.IsHttpRequest(), tenant_id=network.tenant_id,
233 targets=('port',)),
234 ])
235 self._check_is_extension_supported(
236 {'network-ip-availability': 1,
237 'mac-learning': 1,
238 'network_availability_zone': 1,
239 'dhcp_agent_scheduler': 1})
240
241 @test.create_mocks({api.neutron: ('network_get',
232 'is_extension_supported', 242 'is_extension_supported',
233 'list_dhcp_agent_hosting_networks',), 243 'list_dhcp_agent_hosting_networks',),
234 usage.quotas: ('tenant_quota_usages',)}) 244 usage.quotas: ('tenant_quota_usages',)})
235 def test_network_detail_agents_tab(self, mac_learning=False): 245 def test_network_detail_agents_tab(self, mac_learning=False):
236 network = self.networks.first() 246 network = self.networks.first()
237 quota_data = self.quota_usages.first() 247 quota_data = self.quota_usages.first()
238 api.neutron.is_extension_supported(IsA(http.HttpRequest), 248
239 'network-ip-availability') \ 249 self._stub_is_extension_supported(
240 .AndReturn(True) 250 {'network-ip-availability': True,
241 251 'mac-learning': mac_learning,
242 api.neutron.is_extension_supported(IsA(http.HttpRequest), 252 'network_availability_zone': True,
243 'mac-learning')\ 253 'dhcp_agent_scheduler': True})
244 .AndReturn(mac_learning) 254 self.mock_list_dhcp_agent_hosting_networks.return_value = \
245 api.neutron.list_dhcp_agent_hosting_networks(IsA(http.HttpRequest), 255 self.agents.list()
246 network.id)\ 256 self.mock_network_get.return_value = network
247 .AndReturn(self.agents.list()) 257 self.mock_tenant_quota_usages.return_value = quota_data
248 api.neutron.network_get(IsA(http.HttpRequest), network.id)\ 258
249 .MultipleTimes().AndReturn(self.networks.first())
250 api.neutron.is_extension_supported(
251 IsA(http.HttpRequest),
252 'dhcp_agent_scheduler').AndReturn(True)
253 api.neutron.is_extension_supported(
254 IsA(http.HttpRequest),
255 'network_availability_zone').AndReturn(True)
256 api.neutron.is_extension_supported(
257 IsA(http.HttpRequest),
258 'dhcp_agent_scheduler').AndReturn(True)
259 usage.quotas.tenant_quota_usages(
260 IsA(http.HttpRequest), tenant_id=network.tenant_id,
261 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
262 self.mox.ReplayAll()
263 url = reverse('horizon:admin:networks:agents_tab', args=[network.id]) 259 url = reverse('horizon:admin:networks:agents_tab', args=[network.id])
264 res = self.client.get(urlunquote(url)) 260 res = self.client.get(urlunquote(url))
265 261
@@ -269,47 +265,41 @@ class NetworkTests(test.BaseAdminViewTests):
269 265
270 self.assertItemsEqual(result_agents, expected_agents) 266 self.assertItemsEqual(result_agents, expected_agents)
271 267
272 @test.create_stubs({api.neutron: ('network_get', 268 self._check_is_extension_supported(
273 'subnet_list', 269 {'network-ip-availability': 1,
274 'port_list', 270 'mac-learning': 1,
275 'is_extension_supported', 271 'network_availability_zone': 1,
276 'show_network_ip_availability', 272 'dhcp_agent_scheduler': 2})
277 'list_dhcp_agent_hosting_networks',)}) 273 self.mock_list_dhcp_agent_hosting_networks.assert_called_once_with(
274 test.IsHttpRequest(), network.id)
275 self.mock_network_get.assert_called_once_with(
276 test.IsHttpRequest(), network.id)
277 self.mock_tenant_quota_usages.assert_called_once_with(
278 test.IsHttpRequest(), tenant_id=network.tenant_id,
279 targets=('subnet',))
280
278 def test_network_detail_subnets_tab_network_exception(self): 281 def test_network_detail_subnets_tab_network_exception(self):
279 self._test_network_detail_subnets_tab_network_exception() 282 self._test_network_detail_subnets_tab_network_exception()
280 283
281 @test.create_stubs({api.neutron: ('network_get',
282 'subnet_list',
283 'port_list',
284 'is_extension_supported',
285 'show_network_ip_availability',
286 'list_dhcp_agent_hosting_networks',)})
287 def test_network_detail_network_exception_with_mac_learning(self): 284 def test_network_detail_network_exception_with_mac_learning(self):
288 self._test_network_detail_subnets_tab_network_exception( 285 self._test_network_detail_subnets_tab_network_exception(
289 mac_learning=True) 286 mac_learning=True)
290 287
288 @test.create_mocks({api.neutron: ('network_get',
289 'subnet_list',
290 'is_extension_supported',
291 'show_network_ip_availability')})
291 def _test_network_detail_subnets_tab_network_exception(self, 292 def _test_network_detail_subnets_tab_network_exception(self,
292 mac_learning=False): 293 mac_learning=False):
293 network_id = self.networks.first().id 294 network_id = self.networks.first().id
294 ip_availability = self.ip_availability.get() 295 ip_availability = self.ip_availability.get()
295 api.neutron.show_network_ip_availability(IsA(http.HttpRequest), 296
296 network_id).\ 297 self.mock_show_network_ip_availability.return_value = ip_availability
297 MultipleTimes().AndReturn(ip_availability) 298 self.mock_network_get.side_effect = self.exceptions.neutron
298 api.neutron.network_get(IsA(http.HttpRequest), network_id)\ 299 self.mock_subnet_list.return_value = [self.subnets.first()]
299 .AndRaise(self.exceptions.neutron) 300 self._stub_is_extension_supported(
300 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network_id)\ 301 {'network-ip-availability': True,
301 .AndReturn([self.subnets.first()]) 302 'mac-learning': mac_learning})
302 api.neutron.is_extension_supported(
303 IsA(http.HttpRequest),
304 'network-ip-availability').AndReturn(True)
305 api.neutron.is_extension_supported(IsA(http.HttpRequest),
306 'mac-learning')\
307 .AndReturn(mac_learning)
308 api.neutron.is_extension_supported(
309 IsA(http.HttpRequest),
310 'network-ip-availability').AndReturn(True)
311
312 self.mox.ReplayAll()
313 303
314 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 304 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
315 args=[network_id])) 305 args=[network_id]))
@@ -318,52 +308,44 @@ class NetworkTests(test.BaseAdminViewTests):
318 redir_url = INDEX_URL 308 redir_url = INDEX_URL
319 self.assertRedirectsNoFollow(res, redir_url) 309 self.assertRedirectsNoFollow(res, redir_url)
320 310
321 @test.create_stubs({api.neutron: ('network_get', 311 self.mock_show_network_ip_availability.assert_called_once_with(
322 'subnet_list', 312 test.IsHttpRequest(), network_id)
323 'port_list', 313 self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),
324 'list_dhcp_agent_hosting_networks', 314 network_id)
325 'is_extension_supported'), 315 self.mock_subnet_list.assert_called_once_with(test.IsHttpRequest(),
326 usage.quotas: ('tenant_quota_usages',)}) 316 network_id=network_id)
317 self._check_is_extension_supported(
318 {'network-ip-availability': 2,
319 'mac-learning': 1})
320
327 def test_network_detail_subnets_tab_subnet_exception(self): 321 def test_network_detail_subnets_tab_subnet_exception(self):
328 self._test_network_detail_subnets_tab_subnet_exception() 322 self._test_network_detail_subnets_tab_subnet_exception()
329 323
330 @test.create_stubs({api.neutron: ('network_get',
331 'subnet_list',
332 'port_list',
333 'is_extension_supported',
334 'list_dhcp_agent_hosting_networks',),
335 usage.quotas: ('tenant_quota_usages',)})
336 def test_network_detail_subnets_tab_subnet_exception_w_mac_learning(self): 324 def test_network_detail_subnets_tab_subnet_exception_w_mac_learning(self):
337 self._test_network_detail_subnets_tab_subnet_exception( 325 self._test_network_detail_subnets_tab_subnet_exception(
338 mac_learning=True) 326 mac_learning=True)
339 327
328 @test.create_mocks({api.neutron: ('network_get',
329 'subnet_list',
330 'show_network_ip_availability',
331 'is_extension_supported'),
332 usage.quotas: ('tenant_quota_usages',)})
340 def _test_network_detail_subnets_tab_subnet_exception(self, 333 def _test_network_detail_subnets_tab_subnet_exception(self,
341 mac_learning=False): 334 mac_learning=False):
342 network = self.networks.first() 335 network = self.networks.first()
343 quota_data = self.quota_usages.first() 336 quota_data = self.quota_usages.first()
344 api.neutron.network_get(IsA(http.HttpRequest), network.id)\ 337
345 .MultipleTimes().AndReturn(self.networks.first()) 338 self.mock_show_network_ip_availability.return_value = \
346 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network.id).\ 339 self.ip_availability.get()
347 AndRaise(self.exceptions.neutron) 340 self.mock_network_get.return_value = network
348 api.neutron.is_extension_supported( 341 self.mock_subnet_list.side_effect = self.exceptions.neutron
349 IsA(http.HttpRequest), 342 self._stub_is_extension_supported(
350 'network-ip-availability').AndReturn(True) 343 {'network-ip-availability': True,
351 api.neutron.is_extension_supported(IsA(http.HttpRequest), 344 'mac-learning': mac_learning,
352 'mac-learning')\ 345 'dhcp_agent_scheduler': True,
353 .AndReturn(mac_learning) 346 'network_availability_zone': True})
354 api.neutron.is_extension_supported( 347 self.mock_tenant_quota_usages.return_value = quota_data
355 IsA(http.HttpRequest), 348
356 'dhcp_agent_scheduler').AndReturn(True)
357 api.neutron.is_extension_supported(
358 IsA(http.HttpRequest),
359 'network_availability_zone').AndReturn(True)
360 api.neutron.is_extension_supported(
361 IsA(http.HttpRequest),
362 'dhcp_agent_scheduler').AndReturn(True)
363 usage.quotas.tenant_quota_usages(
364 IsA(http.HttpRequest), tenant_id=network.tenant_id,
365 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
366 self.mox.ReplayAll()
367 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 349 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
368 args=[network.id])) 350 args=[network.id]))
369 res = self.client.get(url) 351 res = self.client.get(url)
@@ -372,57 +354,50 @@ class NetworkTests(test.BaseAdminViewTests):
372 subnets = res.context['subnets_table'].data 354 subnets = res.context['subnets_table'].data
373 self.assertEqual(len(subnets), 0) 355 self.assertEqual(len(subnets), 0)
374 356
375 @test.create_stubs({api.neutron: ('network_get', 357 self.mock_show_network_ip_availability.assert_called_once_with(
376 'subnet_list', 358 test.IsHttpRequest(), network.id)
377 'port_list', 359 self.assert_mock_multiple_calls_with_same_arguments(
378 'is_extension_supported', 360 self.mock_network_get, 2,
379 'show_network_ip_availability', 361 mock.call(test.IsHttpRequest(), network.id))
380 'list_dhcp_agent_hosting_networks',), 362 self.mock_subnet_list.assert_called_once_with(test.IsHttpRequest(),
381 usage.quotas: ('tenant_quota_usages',)}) 363 network_id=network.id)
364 self.assert_mock_multiple_calls_with_same_arguments(
365 self.mock_tenant_quota_usages, 3,
366 mock.call(test.IsHttpRequest(), tenant_id=network.tenant_id,
367 targets=('subnet',)))
368 self._stub_is_extension_supported(
369 {'network-ip-availability': 1,
370 'mac-learning': 1,
371 'dhcp_agent_scheduler': 2,
372 'network_availability_zone': 1})
373
382 def test_network_detail_port_exception(self): 374 def test_network_detail_port_exception(self):
383 self._test_network_detail_subnets_tab_port_exception() 375 self._test_network_detail_subnets_tab_port_exception()
384 376
385 @test.create_stubs({api.neutron: ('network_get',
386 'subnet_list',
387 'port_list',
388 'is_extension_supported',
389 'show_network_ip_availability',
390 'list_dhcp_agent_hosting_networks',),
391 usage.quotas: ('tenant_quota_usages',)})
392 def test_network_detail_subnets_tab_port_exception_with_mac_learning(self): 377 def test_network_detail_subnets_tab_port_exception_with_mac_learning(self):
393 self._test_network_detail_subnets_tab_port_exception(mac_learning=True) 378 self._test_network_detail_subnets_tab_port_exception(mac_learning=True)
394 379
380 @test.create_mocks({api.neutron: ('network_get',
381 'subnet_list',
382 'is_extension_supported',
383 'show_network_ip_availability'),
384 usage.quotas: ('tenant_quota_usages',)})
395 def _test_network_detail_subnets_tab_port_exception(self, 385 def _test_network_detail_subnets_tab_port_exception(self,
396 mac_learning=False): 386 mac_learning=False):
397 network = self.networks.first() 387 network = self.networks.first()
398 ip_availability = self.ip_availability.get() 388 ip_availability = self.ip_availability.get()
399 quota_data = self.quota_usages.first() 389 quota_data = self.quota_usages.first()
400 api.neutron.show_network_ip_availability(IsA(http.HttpRequest), 390
401 network.id). \ 391 self.mock_show_network_ip_availability.return_value = ip_availability
402 MultipleTimes().AndReturn(ip_availability) 392 self.mock_network_get.return_value = network
403 api.neutron.network_get(IsA(http.HttpRequest), network.id)\ 393 self.mock_subnet_list.return_value = [self.subnets.first()]
404 .MultipleTimes().AndReturn(self.networks.first()) 394 self._stub_is_extension_supported(
405 api.neutron.subnet_list(IsA(http.HttpRequest), network_id=network.id).\ 395 {'network-ip-availability': True,
406 AndReturn([self.subnets.first()]) 396 'mac-learning': mac_learning,
407 api.neutron.is_extension_supported( 397 'network_availability_zone': True,
408 IsA(http.HttpRequest), 398 'dhcp_agent_scheduler': True})
409 'network-ip-availability').AndReturn(True) 399 self.mock_tenant_quota_usages.return_value = quota_data
410 api.neutron.is_extension_supported(IsA(http.HttpRequest), 400
411 'mac-learning')\
412 .AndReturn(mac_learning)
413 api.neutron.is_extension_supported(
414 IsA(http.HttpRequest),
415 'network-ip-availability').AndReturn(True)
416 api.neutron.is_extension_supported(
417 IsA(http.HttpRequest),
418 'network_availability_zone').AndReturn(True)
419 api.neutron.is_extension_supported(IsA(http.HttpRequest),
420 'dhcp_agent_scheduler')\
421 .AndReturn(True)
422 usage.quotas.tenant_quota_usages(
423 IsA(http.HttpRequest), tenant_id=network.tenant_id,
424 targets=('subnet',)).MultipleTimes().AndReturn(quota_data)
425 self.mox.ReplayAll()
426 url = urlunquote(reverse('horizon:admin:networks:subnets_tab', 401 url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
427 args=[network.id])) 402 args=[network.id]))
428 res = self.client.get(url) 403 res = self.client.get(url)
@@ -431,22 +406,45 @@ class NetworkTests(test.BaseAdminViewTests):
431 subnets = res.context['subnets_table'].data 406 subnets = res.context['subnets_table'].data
432 self.assertItemsEqual(subnets, [self.subnets.first()]) 407 self.assertItemsEqual(subnets, [self.subnets.first()])
433 408
434 @test.create_stubs({api.neutron: ('is_extension_supported',), 409 self.mock_show_network_ip_availability.assert_called_once_with(
410 test.IsHttpRequest(), network.id)
411 self.assert_mock_multiple_calls_with_same_arguments(
412 self.mock_network_get, 2,
413 mock.call(test.IsHttpRequest(), network.id))
414 self.mock_subnet_list.assert_called_once_with(test.IsHttpRequest(),
415 network_id=network.id)
416 self._check_is_extension_supported(
417 {'network-ip-availability': 2,
418 'mac-learning': 1,
419 'network_availability_zone': 1,
420 'dhcp_agent_scheduler': 1})
421 self.assert_mock_multiple_calls_with_same_arguments(
422 self.mock_tenant_quota_usages, 3,
423 mock.call(test.IsHttpRequest(), tenant_id=network.tenant_id,
424 targets=('subnet',)))
425
426 @test.create_mocks({api.neutron: ('is_extension_supported',),
435 api.keystone: ('tenant_list',)}) 427 api.keystone: ('tenant_list',)})
436 def test_network_create_get(self): 428 def test_network_create_get(self):
437 tenants = self.tenants.list() 429 tenants = self.tenants.list()
438 api.keystone.tenant_list(IsA( 430 self.mock_tenant_list.return_value = [tenants, False]
439 http.HttpRequest)).AndReturn([tenants, False]) 431 self._stub_is_extension_supported(
440 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 432 {'provider': True,
441 AndReturn(True) 433 'network_availability_zone': False,
442 self.mox.ReplayAll() 434 'subnet_allocation': False})
443 435
444 url = reverse('horizon:admin:networks:create') 436 url = reverse('horizon:admin:networks:create')
445 res = self.client.get(url) 437 res = self.client.get(url)
446 438
447 self.assertTemplateUsed(res, 'horizon/common/_workflow_base.html') 439 self.assertTemplateUsed(res, 'horizon/common/_workflow_base.html')
448 440
449 @test.create_stubs({api.neutron: ('network_create', 441 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
442 self._check_is_extension_supported(
443 {'provider': 1,
444 'network_availability_zone': 2,
445 'subnet_allocation': 1})
446
447 @test.create_mocks({api.neutron: ('network_create',
450 'is_extension_supported', 448 'is_extension_supported',
451 'subnetpool_list'), 449 'subnetpool_list'),
452 api.keystone: ('tenant_list',)}) 450 api.keystone: ('tenant_list',)})
@@ -455,29 +453,13 @@ class NetworkTests(test.BaseAdminViewTests):
455 tenant_id = self.tenants.first().id 453 tenant_id = self.tenants.first().id
456 network = self.networks.first() 454 network = self.networks.first()
457 455
458 api.keystone.tenant_list(IsA(http.HttpRequest))\ 456 self.mock_tenant_list.return_value = [tenants, False]
459 .AndReturn([tenants, False]) 457 self._stub_is_extension_supported(
460 params = {'name': network.name, 458 {'provider': True,
461 'tenant_id': tenant_id, 459 'network_availability_zone': False,
462 'admin_state_up': network.admin_state_up, 460 'subnet_allocation': True})
463 'router:external': True, 461 self.mock_subnetpool_list.return_value = self.subnetpools.list()
464 'shared': True, 462 self.mock_network_create.return_value = network
465 'provider:network_type': 'local',
466 'with_subnet': False}
467 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
468 MultipleTimes().AndReturn(True)
469 api.neutron.is_extension_supported(IsA(http.HttpRequest),
470 'network_availability_zone').\
471 MultipleTimes().AndReturn(False)
472 api.neutron.is_extension_supported(IsA(http.HttpRequest),
473 'subnet_allocation').\
474 MultipleTimes().AndReturn(True)
475 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
476 AndReturn(self.subnetpools.list())
477 api.neutron.network_create(IsA(http.HttpRequest), **params)\
478 .AndReturn(network)
479
480 self.mox.ReplayAll()
481 463
482 form_data = {'tenant_id': tenant_id, 464 form_data = {'tenant_id': tenant_id,
483 'name': network.name, 465 'name': network.name,
@@ -491,7 +473,22 @@ class NetworkTests(test.BaseAdminViewTests):
491 self.assertNoFormErrors(res) 473 self.assertNoFormErrors(res)
492 self.assertRedirectsNoFollow(res, INDEX_URL) 474 self.assertRedirectsNoFollow(res, INDEX_URL)
493 475
494 @test.create_stubs({api.neutron: ('network_create', 476 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
477 self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest())
478 params = {'name': network.name,
479 'tenant_id': tenant_id,
480 'admin_state_up': network.admin_state_up,
481 'router:external': True,
482 'shared': True,
483 'provider:network_type': 'local'}
484 self.mock_network_create.assert_called_once_with(test.IsHttpRequest(),
485 **params)
486 self._check_is_extension_supported(
487 {'provider': 3,
488 'network_availability_zone': 2,
489 'subnet_allocation': 1})
490
491 @test.create_mocks({api.neutron: ('network_create',
495 'is_extension_supported', 492 'is_extension_supported',
496 'list_availability_zones', 493 'list_availability_zones',
497 'subnetpool_list'), 494 'subnetpool_list'),
@@ -501,33 +498,15 @@ class NetworkTests(test.BaseAdminViewTests):
501 tenant_id = self.tenants.first().id 498 tenant_id = self.tenants.first().id
502 network = self.networks.first() 499 network = self.networks.first()
503 500
504 api.keystone.tenant_list(IsA(http.HttpRequest))\ 501 self.mock_tenant_list.return_value = [tenants, False]
505 .AndReturn([tenants, False]) 502 self._stub_is_extension_supported(
506 params = {'name': network.name, 503 {'provider': True,
507 'tenant_id': tenant_id, 504 'network_availability_zone': True,
508 'admin_state_up': network.admin_state_up, 505 'subnet_allocation': True})
509 'router:external': True, 506 self.mock_list_availability_zones.return_value = \
510 'shared': True, 507 self.neutron_availability_zones.list()
511 'provider:network_type': 'local', 508 self.mock_subnetpool_list.return_value = self.subnetpools.list()
512 'with_subnet': False, 509 self.mock_network_create.return_value = network
513 'az_hints': ['nova']}
514 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
515 MultipleTimes().AndReturn(True)
516 api.neutron.is_extension_supported(IsA(http.HttpRequest),
517 'network_availability_zone').\
518 MultipleTimes().AndReturn(True)
519 api.neutron.list_availability_zones(IsA(http.HttpRequest),
520 "network", "available")\
521 .AndReturn(self.neutron_availability_zones.list())
522 api.neutron.is_extension_supported(IsA(http.HttpRequest),
523 'subnet_allocation').\
524 MultipleTimes().AndReturn(True)
525 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
526 AndReturn(self.subnetpools.list())
527 api.neutron.network_create(IsA(http.HttpRequest), **params)\
528 .AndReturn(network)
529
530 self.mox.ReplayAll()
531 510
532 form_data = {'tenant_id': tenant_id, 511 form_data = {'tenant_id': tenant_id,
533 'name': network.name, 512 'name': network.name,
@@ -535,14 +514,33 @@ class NetworkTests(test.BaseAdminViewTests):
535 'external': True, 514 'external': True,
536 'shared': True, 515 'shared': True,
537 'network_type': 'local', 516 'network_type': 'local',
538 'availability_zone_hints': ['nova']} 517 'az_hints': ['nova']}
539 url = reverse('horizon:admin:networks:create') 518 url = reverse('horizon:admin:networks:create')
540 res = self.client.post(url, form_data) 519 res = self.client.post(url, form_data)
541 520
542 self.assertNoFormErrors(res) 521 self.assertNoFormErrors(res)
543 self.assertRedirectsNoFollow(res, INDEX_URL) 522 self.assertRedirectsNoFollow(res, INDEX_URL)
544 523
545 @test.create_stubs({api.neutron: ('network_create', 524 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
525 self._stub_is_extension_supported(
526 {'provider': 1,
527 'network_availability_zone': 1,
528 'subnet_allocation': 1})
529 self.assert_mock_multiple_calls_with_same_arguments(
530 self.mock_list_availability_zones, 2,
531 mock.call(test.IsHttpRequest(), "network", "available"))
532 self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest())
533 params = {'name': network.name,
534 'tenant_id': tenant_id,
535 'admin_state_up': network.admin_state_up,
536 'router:external': True,
537 'shared': True,
538 'provider:network_type': 'local',
539 'availability_zone_hints': ['nova']}
540 self.mock_network_create.assert_called_once_with(test.IsHttpRequest(),
541 **params)
542
543 @test.create_mocks({api.neutron: ('network_create',
546 'subnet_create', 544 'subnet_create',
547 'is_extension_supported', 545 'is_extension_supported',
548 'subnetpool_list'), 546 'subnetpool_list'),
@@ -552,30 +550,15 @@ class NetworkTests(test.BaseAdminViewTests):
552 tenant_id = self.tenants.first().id 550 tenant_id = self.tenants.first().id
553 network = self.networks.first() 551 network = self.networks.first()
554 subnet = self.subnets.first() 552 subnet = self.subnets.first()
555 params = {'name': network.name, 553
556 'tenant_id': tenant_id, 554 self._stub_is_extension_supported(
557 'admin_state_up': network.admin_state_up, 555 {'provider': True,
558 'router:external': True, 556 'network_availability_zone': False,
559 'shared': True, 557 'subnet_allocation': True})
560 'provider:network_type': 'local', 558 self.mock_tenant_list.return_value = [tenants, False]
561 'with_subnet': True} 559 self.mock_subnetpool_list.return_value = self.subnetpools.list()
562 560 self.mock_network_create.return_value = network
563 api.keystone.tenant_list(IsA(http.HttpRequest))\ 561 self.mock_subnet_create.return_value = subnet
564 .AndReturn([tenants, False])
565
566 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
567 MultipleTimes().AndReturn(True)
568 api.neutron.is_extension_supported(IsA(http.HttpRequest),
569 'network_availability_zone').\
570 MultipleTimes().AndReturn(False)
571 api.neutron.is_extension_supported(IsA(http.HttpRequest),
572 'subnet_allocation').\
573 MultipleTimes().AndReturn(True)
574 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
575 AndReturn(self.subnetpools.list())
576 api.neutron.network_create(IsA(http.HttpRequest), **params)\
577 .AndReturn(network)
578 self.mox.ReplayAll()
579 562
580 form_data = {'tenant_id': tenant_id, 563 form_data = {'tenant_id': tenant_id,
581 'name': network.name, 564 'name': network.name,
@@ -591,7 +574,30 @@ class NetworkTests(test.BaseAdminViewTests):
591 self.assertNoFormErrors(res) 574 self.assertNoFormErrors(res)
592 self.assertRedirectsNoFollow(res, INDEX_URL) 575 self.assertRedirectsNoFollow(res, INDEX_URL)
593 576
594 @test.create_stubs({api.neutron: ('network_create', 577 self._check_is_extension_supported(
578 {'provider': 3,
579 'network_availability_zone': 2,
580 'subnet_allocation': 1})
581 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
582 self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest())
583 params = {'name': network.name,
584 'tenant_id': tenant_id,
585 'admin_state_up': network.admin_state_up,
586 'router:external': True,
587 'shared': True,
588 'provider:network_type': 'local'}
589 self.mock_network_create.assert_called_once_with(test.IsHttpRequest(),
590 **params)
591 subnet_params = {'name': subnet.name,
592 'network_id': subnet.network_id,
593 'cidr': subnet.cidr,
594 'enable_dhcp': subnet.enable_dhcp,
595 'gateway_ip': subnet.gateway_ip,
596 'ip_version': subnet.ip_version}
597 self.mock_subnet_create.assert_called_once_with(test.IsHttpRequest(),
598 **subnet_params)
599
600 @test.create_mocks({api.neutron: ('network_create',
595 'is_extension_supported', 601 'is_extension_supported',
596 'subnetpool_list'), 602 'subnetpool_list'),
597 api.keystone: ('tenant_list',)}) 603 api.keystone: ('tenant_list',)})
@@ -600,28 +606,13 @@ class NetworkTests(test.BaseAdminViewTests):
600 tenant_id = self.tenants.first().id 606 tenant_id = self.tenants.first().id
601 network = self.networks.first() 607 network = self.networks.first()
602 608
603 api.keystone.tenant_list(IsA(http.HttpRequest)).AndReturn([tenants, 609 self.mock_tenant_list.return_value = [tenants, False]
604 False]) 610 self._stub_is_extension_supported(
605 params = {'name': network.name, 611 {'provider': True,
606 'tenant_id': tenant_id, 612 'network_availability_zone': False,
607 'admin_state_up': network.admin_state_up, 613 'subnet_allocation': True})
608 'router:external': True, 614 self.mock_subnetpool_list.return_value = self.subnetpools.list()
609 'shared': False, 615 self.mock_network_create.side_effect = self.exceptions.neutron
610 'provider:network_type': 'local',
611 'with_subnet': False}
612 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
613 MultipleTimes().AndReturn(True)
614 api.neutron.is_extension_supported(IsA(http.HttpRequest),
615 'network_availability_zone').\
616 MultipleTimes().AndReturn(False)
617 api.neutron.is_extension_supported(IsA(http.HttpRequest),
618 'subnet_allocation').\
619 MultipleTimes().AndReturn(True)
620 api.neutron.subnetpool_list(IsA(http.HttpRequest)).\
621 AndReturn(self.subnetpools.list())
622 api.neutron.network_create(IsA(http.HttpRequest),
623 **params).AndRaise(self.exceptions.neutron)
624 self.mox.ReplayAll()
625 616
626 form_data = {'tenant_id': tenant_id, 617 form_data = {'tenant_id': tenant_id,
627 'name': network.name, 618 'name': network.name,
@@ -635,22 +626,33 @@ class NetworkTests(test.BaseAdminViewTests):
635 self.assertNoFormErrors(res) 626 self.assertNoFormErrors(res)
636 self.assertRedirectsNoFollow(res, INDEX_URL) 627 self.assertRedirectsNoFollow(res, INDEX_URL)
637 628
638 @test.create_stubs({api.neutron: ('is_extension_supported',), 629 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
630 self._check_is_extension_supported(
631 {'provider': 3,
632 'network_availability_zone': 2,
633 'subnet_allocation': 1})
634 self.mock_subnetpool_list.assert_called_once_with(test.IsHttpRequest())
635 params = {'name': network.name,
636 'tenant_id': tenant_id,
637 'admin_state_up': network.admin_state_up,
638 'router:external': True,
639 'shared': False,
640 'provider:network_type': 'local'}
641 self.mock_network_create.assert_called_once_with(test.IsHttpRequest(),
642 **params)
643
644 @test.create_mocks({api.neutron: ('is_extension_supported',),
639 api.keystone: ('tenant_list',)}) 645 api.keystone: ('tenant_list',)})
640 def test_network_create_vlan_segmentation_id_invalid(self): 646 def test_network_create_vlan_segmentation_id_invalid(self):
641 tenants = self.tenants.list() 647 tenants = self.tenants.list()
642 tenant_id = self.tenants.first().id 648 tenant_id = self.tenants.first().id
643 network = self.networks.first() 649 network = self.networks.first()
644 api.keystone.tenant_list(
645 IsA(http.HttpRequest)
646 ).MultipleTimes().AndReturn([tenants, False])
647 api.neutron.is_extension_supported(IsA(http.HttpRequest),
648 'network_availability_zone').\
649 MultipleTimes().AndReturn(False)
650 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider')\
651 .MultipleTimes().AndReturn(True)
652 650
653 self.mox.ReplayAll() 651 self.mock_tenant_list.return_value = [tenants, False]
652 self._stub_is_extension_supported(
653 {'network_availability_zone': False,
654 'subnet_allocation': False,
655 'provider': True})
654 656
655 form_data = {'tenant_id': tenant_id, 657 form_data = {'tenant_id': tenant_id,
656 'name': network.name, 658 'name': network.name,
@@ -666,23 +668,24 @@ class NetworkTests(test.BaseAdminViewTests):
666 self.assertFormErrors(res, 1) 668 self.assertFormErrors(res, 1)
667 self.assertContains(res, "1 through 4094") 669 self.assertContains(res, "1 through 4094")
668 670
669 @test.create_stubs({api.neutron: ('is_extension_supported',), 671 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
672 self._check_is_extension_supported(
673 {'network_availability_zone': 2,
674 'subnet_allocation': 1,
675 'provider': 2})
676
677 @test.create_mocks({api.neutron: ('is_extension_supported',),
670 api.keystone: ('tenant_list',)}) 678 api.keystone: ('tenant_list',)})
671 def test_network_create_gre_segmentation_id_invalid(self): 679 def test_network_create_gre_segmentation_id_invalid(self):
672 tenants = self.tenants.list() 680 tenants = self.tenants.list()
673 tenant_id = self.tenants.first().id 681 tenant_id = self.tenants.first().id
674 network = self.networks.first() 682 network = self.networks.first()
675 683
676 api.keystone.tenant_list( 684 self.mock_tenant_list.return_value = [tenants, False]
677 IsA(http.HttpRequest) 685 self._stub_is_extension_supported(
678 ).MultipleTimes().AndReturn([tenants, False]) 686 {'network_availability_zone': False,
679 687 'subnet_allocation': False,
680 api.neutron.is_extension_supported(IsA(http.HttpRequest), 688 'provider': True})
681 'network_availability_zone').\
682 MultipleTimes().AndReturn(False)
683 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\
684 MultipleTimes().AndReturn(True)
685 self.mox.ReplayAll()
686 689
687 form_data = {'tenant_id': tenant_id, 690 form_data = {'tenant_id': tenant_id,
688 'name': network.name, 691 'name': network.name,
@@ -698,7 +701,13 @@ class NetworkTests(test.BaseAdminViewTests):
698 self.assertFormErrors(res, 1) 701 self.assertFormErrors(res, 1)
699 self.assertContains(res, "1 through %s" % ((2 ** 32) - 1)) 702 self.assertContains(res, "1 through %s" % ((2 ** 32) - 1))
700 703
701 @test.create_stubs({api.neutron: ('is_extension_supported',), 704 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
705 self._check_is_extension_supported(
706 {'network_availability_zone': 2,
707 'subnet_allocation': 1,
708 'provider': 2})
709
710 @test.create_mocks({api.neutron: ('is_extension_supported',),
702 api.keystone: ('tenant_list',)}) 711 api.keystone: ('tenant_list',)})
703 @test.update_settings( 712 @test.update_settings(
704 OPENSTACK_NEUTRON_NETWORK={ 713 OPENSTACK_NEUTRON_NETWORK={
@@ -707,17 +716,12 @@ class NetworkTests(test.BaseAdminViewTests):
707 tenants = self.tenants.list() 716 tenants = self.tenants.list()
708 tenant_id = self.tenants.first().id 717 tenant_id = self.tenants.first().id
709 network = self.networks.first() 718 network = self.networks.first()
710 api.keystone.tenant_list(
711 IsA(http.HttpRequest)
712 ).MultipleTimes().AndReturn([tenants, False])
713
714 api.neutron.is_extension_supported(IsA(http.HttpRequest),
715 'network_availability_zone').\
716 MultipleTimes().AndReturn(False)
717 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider')\
718 .MultipleTimes().AndReturn(True)
719 719
720 self.mox.ReplayAll() 720 self.mock_tenant_list.return_value = [tenants, False]
721 self._stub_is_extension_supported(
722 {'network_availability_zone': False,
723 'subnet_allocation': False,
724 'provider': True})
721 725
722 form_data = {'tenant_id': tenant_id, 726 form_data = {'tenant_id': tenant_id,
723 'name': network.name, 727 'name': network.name,
@@ -733,7 +737,13 @@ class NetworkTests(test.BaseAdminViewTests):
733 self.assertFormErrors(res, 1) 737 self.assertFormErrors(res, 1)
734 self.assertContains(res, "10 through 20") 738 self.assertContains(res, "10 through 20")
735 739
736 @test.create_stubs({api.neutron: ('is_extension_supported',), 740 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
741 self._check_is_extension_supported(
742 {'network_availability_zone': 2,
743 'subnet_allocation': 1,
744 'provider': 2})
745
746 @test.create_mocks({api.neutron: ('is_extension_supported',),
737 api.keystone: ('tenant_list',)}) 747 api.keystone: ('tenant_list',)})
738 @test.update_settings( 748 @test.update_settings(
739 OPENSTACK_NEUTRON_NETWORK={ 749 OPENSTACK_NEUTRON_NETWORK={
@@ -741,11 +751,11 @@ class NetworkTests(test.BaseAdminViewTests):
741 def test_network_create_no_provider_types(self): 751 def test_network_create_no_provider_types(self):
742 tenants = self.tenants.list() 752 tenants = self.tenants.list()
743 753
744 api.keystone.tenant_list(IsA(http.HttpRequest)).AndReturn([tenants, 754 self.mock_tenant_list.return_value = [tenants, False]
745 False]) 755 self._stub_is_extension_supported(
746 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 756 {'network_availability_zone': False,
747 AndReturn(True) 757 'subnet_allocation': False,
748 self.mox.ReplayAll() 758 'provider': True})
749 759
750 url = reverse('horizon:admin:networks:create') 760 url = reverse('horizon:admin:networks:create')
751 res = self.client.get(url) 761 res = self.client.get(url)
@@ -756,18 +766,25 @@ class NetworkTests(test.BaseAdminViewTests):
756 '<input type="hidden" name="network_type" id="id_network_type" />', 766 '<input type="hidden" name="network_type" id="id_network_type" />',
757 html=True) 767 html=True)
758 768
759 @test.create_stubs({api.neutron: ('is_extension_supported',), 769 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
770 self._check_is_extension_supported(
771 {'network_availability_zone': 2,
772 'subnet_allocation': 1,
773 'provider': 1})
774
775 @test.create_mocks({api.neutron: ('is_extension_supported',),
760 api.keystone: ('tenant_list',)}) 776 api.keystone: ('tenant_list',)})
761 @test.update_settings( 777 @test.update_settings(
762 OPENSTACK_NEUTRON_NETWORK={ 778 OPENSTACK_NEUTRON_NETWORK={
763 'supported_provider_types': ['local', 'flat', 'gre']}) 779 'supported_provider_types': ['local', 'flat', 'gre']})
764 def test_network_create_unsupported_provider_types(self): 780 def test_network_create_unsupported_provider_types(self):
765 tenants = self.tenants.list() 781 tenants = self.tenants.list()
766 api.keystone.tenant_list(IsA(http.HttpRequest)).AndReturn([tenants, 782
767 False]) 783 self.mock_tenant_list.return_value = [tenants, False]
768 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 784 self._stub_is_extension_supported(
769 AndReturn(True) 785 {'network_availability_zone': False,
770 self.mox.ReplayAll() 786 'subnet_allocation': False,
787 'provider': True})
771 788
772 url = reverse('horizon:admin:networks:create') 789 url = reverse('horizon:admin:networks:create')
773 res = self.client.get(url) 790 res = self.client.get(url)
@@ -778,26 +795,30 @@ class NetworkTests(test.BaseAdminViewTests):
778 ('flat', 'Flat'), 795 ('flat', 'Flat'),
779 ('gre', 'GRE')]) 796 ('gre', 'GRE')])
780 797
781 @test.create_stubs({api.neutron: ('network_get',)}) 798 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
799 self._check_is_extension_supported(
800 {'network_availability_zone': 2,
801 'subnet_allocation': 1,
802 'provider': 1})
803
804 @test.create_mocks({api.neutron: ('network_get',)})
782 def test_network_update_get(self): 805 def test_network_update_get(self):
783 network = self.networks.first() 806 network = self.networks.first()
784 api.neutron.network_get(IsA(http.HttpRequest), network.id, 807 self.mock_network_get.return_value = network
785 expand_subnet=False).AndReturn(network)
786
787 self.mox.ReplayAll()
788 808
789 url = reverse('horizon:admin:networks:update', args=[network.id]) 809 url = reverse('horizon:admin:networks:update', args=[network.id])
790 res = self.client.get(url) 810 res = self.client.get(url)
791 811
792 self.assertTemplateUsed(res, 'admin/networks/update.html') 812 self.assertTemplateUsed(res, 'admin/networks/update.html')
793 813
794 @test.create_stubs({api.neutron: ('network_get',)}) 814 self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),
815 network.id,
816 expand_subnet=False)
817
818 @test.create_mocks({api.neutron: ('network_get',)})
795 def test_network_update_get_exception(self): 819 def test_network_update_get_exception(self):
796 network = self.networks.first() 820 network = self.networks.first()
797 api.neutron.network_get(IsA(http.HttpRequest), network.id)\ 821 self.mock_network_get.side_effect = self.exceptions.neutron
798 .AndRaise(self.exceptions.neutron)
799
800 self.mox.ReplayAll()
801 822
802 url = reverse('horizon:admin:networks:update', args=[network.id]) 823 url = reverse('horizon:admin:networks:update', args=[network.id])
803 res = self.client.get(url) 824 res = self.client.get(url)
@@ -805,20 +826,17 @@ class NetworkTests(test.BaseAdminViewTests):
805 redir_url = INDEX_URL 826 redir_url = INDEX_URL
806 self.assertRedirectsNoFollow(res, redir_url) 827 self.assertRedirectsNoFollow(res, redir_url)
807 828
808 @test.create_stubs({api.neutron: ('network_update', 829 self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),
830 network.id,
831 expand_subnet=False)
832
833 @test.create_mocks({api.neutron: ('network_update',
809 'network_get',)}) 834 'network_get',)})
810 def test_network_update_post(self): 835 def test_network_update_post(self):
811 network = self.networks.first() 836 network = self.networks.first()
812 params = {'name': network.name, 837
813 'shared': True, 838 self.mock_network_update.return_value = network
814 'admin_state_up': network.admin_state_up, 839 self.mock_network_get.return_value = network
815 'router:external': True}
816 api.neutron.network_update(IsA(http.HttpRequest), network.id,
817 **params)\
818 .AndReturn(network)
819 api.neutron.network_get(IsA(http.HttpRequest), network.id,
820 expand_subnet=False).AndReturn(network)
821 self.mox.ReplayAll()
822 840
823 form_data = {'network_id': network.id, 841 form_data = {'network_id': network.id,
824 'name': network.name, 842 'name': network.name,
@@ -831,7 +849,18 @@ class NetworkTests(test.BaseAdminViewTests):
831 849
832 self.assertRedirectsNoFollow(res, INDEX_URL) 850 self.assertRedirectsNoFollow(res, INDEX_URL)
833 851
834 @test.create_stubs({api.neutron: ('network_update', 852 params = {'name': network.name,
853 'shared': True,
854 'admin_state_up': network.admin_state_up,
855 'router:external': True}
856 self.mock_network_update.assert_called_once_with(test.IsHttpRequest(),
857 network.id,
858 **params)
859 self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),
860 network.id,
861 expand_subnet=False)
862
863 @test.create_mocks({api.neutron: ('network_update',
835 'network_get',)}) 864 'network_get',)})
836 def test_network_update_post_exception(self): 865 def test_network_update_post_exception(self):
837 network = self.networks.first() 866 network = self.networks.first()
@@ -839,12 +868,8 @@ class NetworkTests(test.BaseAdminViewTests):
839 'shared': False, 868 'shared': False,
840 'admin_state_up': network.admin_state_up, 869 'admin_state_up': network.admin_state_up,
841 'router:external': False} 870 'router:external': False}
842 api.neutron.network_update(IsA(http.HttpRequest), network.id, 871 self.mock_network_update.side_effect = self.exceptions.neutron
843 **params)\ 872 self.mock_network_get.return_value = network
844 .AndRaise(self.exceptions.neutron)
845 api.neutron.network_get(IsA(http.HttpRequest), network.id,
846 expand_subnet=False).AndReturn(network)
847 self.mox.ReplayAll()
848 873
849 form_data = {'network_id': network.id, 874 form_data = {'network_id': network.id,
850 'name': network.name, 875 'name': network.name,
@@ -857,7 +882,14 @@ class NetworkTests(test.BaseAdminViewTests):
857 882
858 self.assertRedirectsNoFollow(res, INDEX_URL) 883 self.assertRedirectsNoFollow(res, INDEX_URL)
859 884
860 @test.create_stubs({api.neutron: ('network_list', 885 self.mock_network_update.assert_called_once_with(test.IsHttpRequest(),
886 network.id,
887 **params)
888 self.mock_network_get.assert_called_once_with(test.IsHttpRequest(),
889 network.id,
890 expand_subnet=False)
891
892 @test.create_mocks({api.neutron: ('network_list',
861 'network_delete', 893 'network_delete',
862 'list_dhcp_agent_hosting_networks', 894 'list_dhcp_agent_hosting_networks',
863 'is_extension_supported'), 895 'is_extension_supported'),
@@ -865,32 +897,32 @@ class NetworkTests(test.BaseAdminViewTests):
865 def test_delete_network(self): 897 def test_delete_network(self):
866 tenants = self.tenants.list() 898 tenants = self.tenants.list()
867 network = self.networks.first() 899 network = self.networks.first()
868 api.neutron.list_dhcp_agent_hosting_networks(IsA(http.HttpRequest), 900
869 network.id).\ 901 self.mock_list_dhcp_agent_hosting_networks.return_value = \
870 AndReturn(self.agents.list()) 902 self.agents.list()
871 api.neutron.is_extension_supported( 903 self._stub_is_extension_supported(
872 IsA(http.HttpRequest), 904 {'network_availability_zone': True,
873 'network_availability_zone').AndReturn(True) 905 'dhcp_agent_scheduler': True})
874 api.neutron.is_extension_supported( 906 self.mock_tenant_list.return_value = [tenants, False]
875 IsA(http.HttpRequest), 907 self.mock_network_list.return_value = [network]
876 'dhcp_agent_scheduler').AndReturn(True) 908 self.mock_network_delete.return_value = None
877 api.neutron.is_extension_supported(
878 IsA(http.HttpRequest),
879 'dhcp_agent_scheduler').AndReturn(True)
880 api.keystone.tenant_list(IsA(http.HttpRequest))\
881 .AndReturn([tenants, False])
882 api.neutron.network_list(IsA(http.HttpRequest))\
883 .AndReturn([network])
884 api.neutron.network_delete(IsA(http.HttpRequest), network.id)
885
886 self.mox.ReplayAll()
887 909
888 form_data = {'action': 'networks__delete__%s' % network.id} 910 form_data = {'action': 'networks__delete__%s' % network.id}
889 res = self.client.post(INDEX_URL, form_data) 911 res = self.client.post(INDEX_URL, form_data)
890 912
891 self.assertRedirectsNoFollow(res, INDEX_URL) 913 self.assertRedirectsNoFollow(res, INDEX_URL)
892 914
893 @test.create_stubs({api.neutron: ('network_list', 915 self.mock_list_dhcp_agent_hosting_networks.assert_called_once_with(
916 test.IsHttpRequest(), network.id)
917 self._check_is_extension_supported(
918 {'network_availability_zone': 1,
919 'dhcp_agent_scheduler': 2})
920 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
921 self.mock_network_list.assert_called_once_with(test.IsHttpRequest())
922 self.mock_network_delete.assert_called_once_with(test.IsHttpRequest(),
923 network.id)
924
925 @test.create_mocks({api.neutron: ('network_list',
894 'network_delete', 926 'network_delete',
895 'list_dhcp_agent_hosting_networks', 927 'list_dhcp_agent_hosting_networks',
896 'is_extension_supported'), 928 'is_extension_supported'),
@@ -898,59 +930,55 @@ class NetworkTests(test.BaseAdminViewTests):
898 def test_delete_network_exception(self): 930 def test_delete_network_exception(self):
899 tenants = self.tenants.list() 931 tenants = self.tenants.list()
900 network = self.networks.first() 932 network = self.networks.first()
901 api.neutron.list_dhcp_agent_hosting_networks(IsA(http.HttpRequest), 933
902 network.id).\ 934 self.mock_list_dhcp_agent_hosting_networks.return_value = \
903 AndReturn(self.agents.list()) 935 self.agents.list()
904 api.neutron.is_extension_supported( 936 self._stub_is_extension_supported(
905 IsA(http.HttpRequest), 937 {'network_availability_zone': True,
906 'network_availability_zone').AndReturn(True) 938 'dhcp_agent_scheduler': True})
907 api.neutron.is_extension_supported( 939 self.mock_tenant_list.return_value = [tenants, False]
908 IsA(http.HttpRequest), 940 self.mock_network_list.return_value = [network]
909 'dhcp_agent_scheduler').AndReturn(True) 941 self.mock_network_delete.side_effect = self.exceptions.neutron
910 api.neutron.is_extension_supported(
911 IsA(http.HttpRequest),
912 'dhcp_agent_scheduler').AndReturn(True)
913 api.keystone.tenant_list(IsA(http.HttpRequest))\
914 .AndReturn([tenants, False])
915 api.neutron.network_list(IsA(http.HttpRequest))\
916 .AndReturn([network])
917 api.neutron.network_delete(IsA(http.HttpRequest), network.id)\
918 .AndRaise(self.exceptions.neutron)
919
920 self.mox.ReplayAll()
921 942
922 form_data = {'action': 'networks__delete__%s' % network.id} 943 form_data = {'action': 'networks__delete__%s' % network.id}
923 res = self.client.post(INDEX_URL, form_data) 944 res = self.client.post(INDEX_URL, form_data)
924 945
925 self.assertRedirectsNoFollow(res, INDEX_URL) 946 self.assertRedirectsNoFollow(res, INDEX_URL)
926 947
927 @test.create_stubs({api.neutron: ('is_extension_supported',)}) 948 self.mock_list_dhcp_agent_hosting_networks.assert_called_once_with(
949 test.IsHttpRequest(), network.id)
950 self._check_is_extension_supported(
951 {'network_availability_zone': 1,
952 'dhcp_agent_scheduler': 2})
953 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
954 self.mock_network_list.assert_called_once_with(test.IsHttpRequest())
955 self.mock_network_delete.assert_called_once_with(test.IsHttpRequest(),
956 network.id)
957
958 @test.create_mocks({api.neutron: ('is_extension_supported',)})
928 @test.update_settings(FILTER_DATA_FIRST={'admin.networks': True}) 959 @test.update_settings(FILTER_DATA_FIRST={'admin.networks': True})
929 def test_networks_list_with_admin_filter_first(self): 960 def test_networks_list_with_admin_filter_first(self):
930 api.neutron.is_extension_supported( 961 self._stub_is_extension_supported(
931 IsA(http.HttpRequest), 962 {'network_availability_zone': True,
932 'network_availability_zone').AndReturn(True) 963 'dhcp_agent_scheduler': True})
933 api.neutron.is_extension_supported( 964
934 IsA(http.HttpRequest),
935 'dhcp_agent_scheduler').AndReturn(True)
936 self.mox.ReplayAll()
937 res = self.client.get(reverse('horizon:admin:networks:index')) 965 res = self.client.get(reverse('horizon:admin:networks:index'))
938 self.assertTemplateUsed(res, INDEX_TEMPLATE) 966 self.assertTemplateUsed(res, INDEX_TEMPLATE)
939 networks = res.context['networks_table'].data 967 networks = res.context['networks_table'].data
940 self.assertItemsEqual(networks, []) 968 self.assertItemsEqual(networks, [])
941 969
942 @test.create_stubs({api.keystone: ('tenant_list',), 970 self._check_is_extension_supported(
971 {'network_availability_zone': 1,
972 'dhcp_agent_scheduler': 1})
973
974 @test.create_mocks({api.keystone: ('tenant_list',),
943 api.neutron: ('is_extension_supported',)}) 975 api.neutron: ('is_extension_supported',)})
944 def test_networks_list_with_non_exist_tenant_filter(self): 976 def test_networks_list_with_non_exist_tenant_filter(self):
945 api.neutron.is_extension_supported( 977 self._stub_is_extension_supported(
946 IsA(http.HttpRequest), 978 {'network_availability_zone': True,
947 'network_availability_zone').AndReturn(True) 979 'dhcp_agent_scheduler': True})
948 api.neutron.is_extension_supported( 980 self.mock_tenant_list.return_value = [self.tenants.list(), False]
949 IsA(http.HttpRequest), 981
950 'dhcp_agent_scheduler').AndReturn(True)
951 api.keystone.tenant_list(IsA(http.HttpRequest))\
952 .AndReturn([self.tenants.list(), False])
953 self.mox.ReplayAll()
954 self.client.post( 982 self.client.post(
955 reverse('horizon:admin:networks:index'), 983 reverse('horizon:admin:networks:index'),
956 data={'networks__filter_admin_networks__q_field': 'project', 984 data={'networks__filter_admin_networks__q_field': 'project',
@@ -960,33 +988,44 @@ class NetworkTests(test.BaseAdminViewTests):
960 networks = res.context['networks_table'].data 988 networks = res.context['networks_table'].data
961 self.assertItemsEqual(networks, []) 989 self.assertItemsEqual(networks, [])
962 990
963 @test.create_stubs({api.neutron: ('is_extension_supported',), 991 self._check_is_extension_supported(
992 {'network_availability_zone': 2,
993 'dhcp_agent_scheduler': 2})
994 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
995
996 @test.create_mocks({api.neutron: ('is_extension_supported',),
964 api.keystone: ('tenant_list',)}) 997 api.keystone: ('tenant_list',)})
965 def test_network_create_without_physical_networks(self): 998 def test_network_create_without_physical_networks(self):
966 tenants = self.tenants.list() 999 tenants = self.tenants.list()
967 api.keystone.tenant_list(IsA(http.HttpRequest)).AndReturn([tenants, 1000 self.mock_tenant_list.return_value = [tenants, False]
968 False]) 1001 self._stub_is_extension_supported(
969 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 1002 {'provider': True,
970 AndReturn(True) 1003 'network_availability_zone': False,
971 self.mox.ReplayAll() 1004 'subnet_allocation': False})
972 1005
973 url = reverse('horizon:admin:networks:create') 1006 url = reverse('horizon:admin:networks:create')
974 res = self.client.get(url) 1007 res = self.client.get(url)
975 physical_network = res.context['form'].fields['physical_network'] 1008 physical_network = res.context['form'].fields['physical_network']
976 self.assertEqual(type(physical_network), forms.CharField) 1009 self.assertEqual(type(physical_network), forms.CharField)
977 1010
978 @test.create_stubs({api.neutron: ('is_extension_supported',), 1011 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
1012 self._check_is_extension_supported(
1013 {'provider': 1,
1014 'network_availability_zone': 2,
1015 'subnet_allocation': 1})
1016
1017 @test.create_mocks({api.neutron: ('is_extension_supported',),
979 api.keystone: ('tenant_list',)}) 1018 api.keystone: ('tenant_list',)})
980 @test.update_settings( 1019 @test.update_settings(
981 OPENSTACK_NEUTRON_NETWORK={ 1020 OPENSTACK_NEUTRON_NETWORK={
982 'physical_networks': ['default', 'test']}) 1021 'physical_networks': ['default', 'test']})
983 def test_network_create_with_physical_networks(self): 1022 def test_network_create_with_physical_networks(self):
984 tenants = self.tenants.list() 1023 tenants = self.tenants.list()
985 api.keystone.tenant_list(IsA(http.HttpRequest)).AndReturn([tenants, 1024 self.mock_tenant_list.return_value = [tenants, False]
986 False]) 1025 self._stub_is_extension_supported(
987 api.neutron.is_extension_supported(IsA(http.HttpRequest), 'provider').\ 1026 {'provider': True,
988 AndReturn(True) 1027 'network_availability_zone': False,
989 self.mox.ReplayAll() 1028 'subnet_allocation': False})
990 1029
991 url = reverse('horizon:admin:networks:create') 1030 url = reverse('horizon:admin:networks:create')
992 res = self.client.get(url) 1031 res = self.client.get(url)
@@ -994,3 +1033,9 @@ class NetworkTests(test.BaseAdminViewTests):
994 self.assertEqual(type(physical_network), forms.ThemableChoiceField) 1033 self.assertEqual(type(physical_network), forms.ThemableChoiceField)
995 self.assertListEqual(list(physical_network.choices), 1034 self.assertListEqual(list(physical_network.choices),
996 [('default', 'default'), ('test', 'test')]) 1035 [('default', 'default'), ('test', 'test')])
1036
1037 self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
1038 self._check_is_extension_supported(
1039 {'provider': 1,
1040 'network_availability_zone': 2,
1041 'subnet_allocation': 1})