Debian Codegraph @

octavia_tempest_plugin/tests/api/v2/test_healthmonitor.py

raw symbols SCIP
1 # Copyright 2018 GoDaddy
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import testtools
16 import time
17 from uuid import UUID
18
19 from dateutil import parser
20 from oslo_log import log as logging
21 from tempest import config
22 from tempest.lib.common.utils import data_utils
23 from tempest.lib import decorators
24 from tempest.lib import exceptions
25
26 from octavia_tempest_plugin.common import constants as const
27 from octavia_tempest_plugin.tests import test_base
28 from octavia_tempest_plugin.tests import waiters
29
30 CONF = config.CONF
31 LOG = logging.getLogger(__name__)
32
33
34 class HealthMonitorAPITest(test_base.LoadBalancerBaseTest):
35 """Test the healthmonitor object API."""
36 @classmethod
37 def resource_setup(cls):
38 """Setup resources needed by the tests."""
39 super(HealthMonitorAPITest, cls).resource_setup()
40
41 lb_name = data_utils.rand_name("lb_member_lb1_hm")
42 lb_kwargs = {const.PROVIDER: CONF.load_balancer.provider,
43 const.NAME: lb_name}
44
45 cls._setup_lb_network_kwargs(lb_kwargs)
46
47 lb = cls.mem_lb_client.create_loadbalancer(**lb_kwargs)
48 cls.lb_id = lb[const.ID]
49 cls.addClassResourceCleanup(
50 cls.mem_lb_client.cleanup_loadbalancer,
51 cls.lb_id, cascade=True)
52
53 waiters.wait_for_status(cls.mem_lb_client.show_loadbalancer,
54 cls.lb_id, const.PROVISIONING_STATUS,
55 const.ACTIVE,
56 CONF.load_balancer.lb_build_interval,
57 CONF.load_balancer.lb_build_timeout)
58
59 @decorators.idempotent_id('bc3fc817-3368-4e1e-bb6d-52c4de3fb10c')
60 def test_LC_HTTP_healthmonitor_create(self):
61 self._test_healthmonitor_create(
62 const.HTTP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
63 const.HEALTH_MONITOR_HTTP)
64
65 @decorators.idempotent_id('18fcd6b8-9fc3-4858-83f6-d8800052b655')
66 def test_LC_HTTPS_healthmonitor_create(self):
67 self._test_healthmonitor_create(
68 const.HTTPS, const.LB_ALGORITHM_LEAST_CONNECTIONS,
69 const.HEALTH_MONITOR_HTTPS)
70
71 @decorators.idempotent_id('5b0446f2-374e-4e74-9865-72e16a19c587')
72 def test_LC_PING_healthmonitor_create(self):
73 self._test_healthmonitor_create(
74 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
75 const.HEALTH_MONITOR_PING)
76
77 @decorators.idempotent_id('46c4e159-84d2-4876-9298-ac85561d3bd0')
78 def test_LC_TCP_healthmonitor_create(self):
79 self._test_healthmonitor_create(
80 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
81 const.HEALTH_MONITOR_TCP)
82
83 @decorators.idempotent_id('a15f7319-2d3b-4ec8-9d70-e77a55045145')
84 def test_LC_TLS_healthmonitor_create(self):
85 self._test_healthmonitor_create(
86 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
87 const.HEALTH_MONITOR_TLS_HELLO)
88
89 @decorators.idempotent_id('f609b2c2-391d-4bc9-9793-9a4bc30ab00b')
90 def test_LC_UDP_healthmonitor_create(self):
91 self._test_healthmonitor_create(
92 const.UDP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
93 const.HEALTH_MONITOR_UDP_CONNECT)
94
95 @decorators.idempotent_id('4f20473f-ab02-4426-8d15-cf34b3c72558')
96 def test_RR_HTTP_healthmonitor_create(self):
97 self._test_healthmonitor_create(
98 const.HTTP, const.LB_ALGORITHM_ROUND_ROBIN,
99 const.HEALTH_MONITOR_HTTP)
100
101 @decorators.idempotent_id('abfff805-5491-4aef-9952-45b553cbebbb')
102 def test_RR_HTTPS_healthmonitor_create(self):
103 self._test_healthmonitor_create(
104 const.HTTPS, const.LB_ALGORITHM_ROUND_ROBIN,
105 const.HEALTH_MONITOR_HTTPS)
106
107 @decorators.idempotent_id('ac64228e-dc4c-4116-b610-5783a85a87f1')
108 def test_RR_PING_healthmonitor_create(self):
109 self._test_healthmonitor_create(
110 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
111 const.HEALTH_MONITOR_PING)
112
113 @decorators.idempotent_id('e3ac7193-1dc9-41df-a4e2-7d40ca70a678')
114 def test_RR_TCP_healthmonitor_create(self):
115 self._test_healthmonitor_create(
116 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
117 const.HEALTH_MONITOR_TCP)
118
119 @decorators.idempotent_id('54952a9a-b3ef-4b36-a586-9adcd63dfc49')
120 def test_RR_TLS_healthmonitor_create(self):
121 self._test_healthmonitor_create(
122 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
123 const.HEALTH_MONITOR_TLS_HELLO)
124
125 @decorators.idempotent_id('9af20b3c-fc42-4365-a4e9-cecbdddf90c0')
126 def test_RR_UDP_healthmonitor_create(self):
127 self._test_healthmonitor_create(
128 const.UDP, const.LB_ALGORITHM_ROUND_ROBIN,
129 const.HEALTH_MONITOR_UDP_CONNECT)
130
131 @decorators.idempotent_id('35b076a4-dfb1-4557-9eac-a33982f73856')
132 def test_SI_HTTP_healthmonitor_create(self):
133 self._test_healthmonitor_create(
134 const.HTTP, const.LB_ALGORITHM_SOURCE_IP,
135 const.HEALTH_MONITOR_HTTP)
136
137 @decorators.idempotent_id('965804cb-d6a1-4fdd-99dc-948829e0c046')
138 def test_SI_HTTPS_healthmonitor_create(self):
139 self._test_healthmonitor_create(
140 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP,
141 const.HEALTH_MONITOR_HTTPS)
142
143 @decorators.idempotent_id('eb86eab1-4cdf-40fc-b633-679d7fb64806')
144 def test_SI_PING_healthmonitor_create(self):
145 self._test_healthmonitor_create(
146 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
147 const.HEALTH_MONITOR_PING)
148
149 @decorators.idempotent_id('6bdab976-b6ad-4c83-87ab-0d184e80eb2c')
150 def test_SI_TCP_healthmonitor_create(self):
151 self._test_healthmonitor_create(
152 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
153 const.HEALTH_MONITOR_TCP)
154
155 @decorators.idempotent_id('4f8111dd-4f03-4740-ae4b-b13b731f45a0')
156 def test_SI_TLS_healthmonitor_create(self):
157 self._test_healthmonitor_create(
158 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
159 const.HEALTH_MONITOR_TLS_HELLO)
160
161 @decorators.idempotent_id('d98365ca-56ba-450d-955f-d1c06c329960')
162 def test_SI_UDP_healthmonitor_create(self):
163 self._test_healthmonitor_create(
164 const.UDP, const.LB_ALGORITHM_SOURCE_IP,
165 const.HEALTH_MONITOR_UDP_CONNECT)
166
167 @decorators.idempotent_id('acab47f5-3006-4e84-a55f-e9dfe33113d2')
168 def test_SIP_HTTP_healthmonitor_create(self):
169 self._test_healthmonitor_create(
170 const.HTTP, const.LB_ALGORITHM_SOURCE_IP_PORT,
171 const.HEALTH_MONITOR_HTTP)
172
173 @decorators.idempotent_id('ca42a541-3280-4496-8604-9ce64e1992d6')
174 def test_SIP_HTTPS_healthmonitor_create(self):
175 self._test_healthmonitor_create(
176 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP_PORT,
177 const.HEALTH_MONITOR_HTTPS)
178
179 @decorators.idempotent_id('78c8e5fc-3ba0-44d0-ac4a-93a90fb59c3f')
180 def test_SIP_PING_healthmonitor_create(self):
181 self._test_healthmonitor_create(
182 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
183 const.HEALTH_MONITOR_PING)
184
185 @decorators.idempotent_id('d5b50306-a3bd-4293-96ed-17a2897d57cc')
186 def test_SIP_TCP_healthmonitor_create(self):
187 self._test_healthmonitor_create(
188 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
189 const.HEALTH_MONITOR_TCP)
190
191 @decorators.idempotent_id('204556df-185e-4305-b1b7-e8d345d645e4')
192 def test_SIP_TLS_healthmonitor_create(self):
193 self._test_healthmonitor_create(
194 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
195 const.HEALTH_MONITOR_TLS_HELLO)
196
197 @decorators.idempotent_id('2de53a00-c631-4985-abc1-89070ac2515f')
198 def test_SIP_UDP_healthmonitor_create(self):
199 self._test_healthmonitor_create(
200 const.UDP, const.LB_ALGORITHM_SOURCE_IP_PORT,
201 const.HEALTH_MONITOR_UDP_CONNECT)
202
203 def _test_healthmonitor_create(self, pool_protocol, pool_algorithm,
204 hm_type):
205 """Tests healthmonitor create and basic show APIs.
206
207 * Create a clean pool to use for the healthmonitor.
208 * Tests that users without the loadbalancer member role cannot
209 create healthmonitors.
210 * Create a fully populated healthmonitor.
211 * Show healthmonitor details.
212 * Validate the show reflects the requested values.
213 """
214 if (pool_algorithm == const.LB_ALGORITHM_SOURCE_IP_PORT and not
215 self.mem_listener_client.is_version_supported(
216 self.api_version, '2.13')):
217 raise testtools.TestCase.skipException(
218 'Skipping this test as load balancing algorithm '
219 'SOURCE_IP_PORT requires API version 2.13 or newer.')
220
221 pool_name = data_utils.rand_name("lb_member_pool1_hm-create")
222 pool_kwargs = {
223 const.NAME: pool_name,
224 const.PROTOCOL: pool_protocol,
225 const.LB_ALGORITHM: pool_algorithm,
226 const.LOADBALANCER_ID: self.lb_id,
227 }
228
229 # This is a special case as the reference driver does not support
230 # SOURCE-IP-PORT. Since it runs with not_implemented_is_error, we must
231 # handle this test case special.
232 try:
233 pool = self.mem_pool_client.create_pool(**pool_kwargs)
234 except exceptions.NotImplemented as e:
235 if pool_algorithm != const.LB_ALGORITHM_SOURCE_IP_PORT:
236 raise
237 message = ("The configured provider driver '{driver}' "
238 "does not support a feature required for this "
239 "test.".format(driver=CONF.load_balancer.provider))
240 if hasattr(e, 'resp_body'):
241 message = e.resp_body.get('faultstring', message)
242 raise testtools.TestCase.skipException(message)
243
244 self.addCleanup(
245 self.mem_pool_client.cleanup_pool, pool[const.ID],
246 lb_client=self.mem_lb_client, lb_id=self.lb_id)
247
248 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
249 self.lb_id, const.PROVISIONING_STATUS,
250 const.ACTIVE,
251 CONF.load_balancer.build_interval,
252 CONF.load_balancer.build_timeout)
253
254 hm_name = data_utils.rand_name("lb_member_hm1-create")
255 delay = 3 if hm_type == const.HEALTH_MONITOR_UDP_CONNECT else 2
256 hm_kwargs = {
257 const.POOL_ID: pool[const.ID],
258 const.NAME: hm_name,
259 const.TYPE: hm_type,
260 const.DELAY: delay,
261 const.TIMEOUT: 3,
262 const.MAX_RETRIES: 4,
263 const.MAX_RETRIES_DOWN: 5,
264 const.ADMIN_STATE_UP: True,
265 }
266 if hm_type == const.HEALTH_MONITOR_HTTP:
267 hm_kwargs.update({const.HTTP_METHOD: const.GET,
268 const.URL_PATH: '/',
269 const.EXPECTED_CODES: '200-204'})
270
271 if self.mem_listener_client.is_version_supported(
272 self.api_version, '2.5'):
273 hw_tags = ["Hello", "World"]
274 hm_kwargs.update({
275 const.TAGS: hw_tags
276 })
277
278 # Test that a user without the loadbalancer role cannot
279 # create a healthmonitor
280 expected_allowed = ['os_admin', 'os_roles_lb_admin',
281 'os_roles_lb_member']
282 self.check_create_RBAC_enforcement(
283 'HealthMonitorClient', 'create_healthmonitor',
284 expected_allowed,
285 status_method=self.mem_lb_client.show_loadbalancer,
286 obj_id=self.lb_id, **hm_kwargs)
287
288 hm = self.mem_healthmonitor_client.create_healthmonitor(**hm_kwargs)
289 self.addCleanup(
290 self.mem_healthmonitor_client.cleanup_healthmonitor,
291 hm[const.ID],
292 lb_client=self.mem_lb_client, lb_id=self.lb_id)
293
294 waiters.wait_for_status(
295 self.mem_lb_client.show_loadbalancer, self.lb_id,
296 const.PROVISIONING_STATUS, const.ACTIVE,
297 CONF.load_balancer.build_interval,
298 CONF.load_balancer.build_timeout)
299 hm = waiters.wait_for_status(
300 self.mem_healthmonitor_client.show_healthmonitor,
301 hm[const.ID], const.PROVISIONING_STATUS,
302 const.ACTIVE,
303 CONF.load_balancer.build_interval,
304 CONF.load_balancer.build_timeout)
305
306 parser.parse(hm[const.CREATED_AT])
307 parser.parse(hm[const.UPDATED_AT])
308 UUID(hm[const.ID])
309
310 # Healthmonitors are always ONLINE
311 self.assertEqual(const.ONLINE, hm[const.OPERATING_STATUS])
312
313 equal_items = [const.NAME, const.TYPE, const.DELAY, const.TIMEOUT,
314 const.MAX_RETRIES, const.MAX_RETRIES_DOWN,
315 const.ADMIN_STATE_UP]
316 if hm_type == const.HEALTH_MONITOR_HTTP:
317 equal_items = equal_items + [const.HTTP_METHOD, const.URL_PATH,
318 const.EXPECTED_CODES]
319
320 for item in equal_items:
321 self.assertEqual(hm_kwargs[item], hm[item])
322
323 if self.mem_listener_client.is_version_supported(
324 self.api_version, '2.5'):
325 self.assertCountEqual(hm_kwargs[const.TAGS], hm[const.TAGS])
326
327 # Helper functions for test healthmonitor list
328 def _filter_hms_by_pool_id(self, hms, pool_ids):
329 return [hm for hm in hms
330 if hm[const.POOLS][0][const.ID] in pool_ids]
331
332 def _filter_hms_by_index(self, hms, indexes):
333 return [hm for i, hm in enumerate(hms) if i not in indexes]
334
335 @decorators.idempotent_id('9e4b1298-b6a0-46c7-b8e4-afcd31f904d3')
336 def test_LC_HTTP_healthmonitor_list(self):
337 self._test_healthmonitor_list(const.HTTP,
338 const.LB_ALGORITHM_LEAST_CONNECTIONS,
339 const.HEALTH_MONITOR_HTTP)
340
341 @decorators.idempotent_id('7488b1e1-12b5-4a42-9d78-9e08060ec7b1')
342 def test_LC_HTTPS_healthmonitor_list(self):
343 self._test_healthmonitor_list(const.HTTPS,
344 const.LB_ALGORITHM_LEAST_CONNECTIONS,
345 const.HEALTH_MONITOR_HTTPS)
346
347 @decorators.idempotent_id('1f93483c-29ae-4ac1-a588-9ce9bd837232')
348 def test_LC_PING_healthmonitor_list(self):
349 self._test_healthmonitor_list(const.TCP,
350 const.LB_ALGORITHM_LEAST_CONNECTIONS,
351 const.HEALTH_MONITOR_PING)
352
353 @decorators.idempotent_id('49ccd27c-3a4c-41e5-bcb0-d4f03ecc3e79')
354 def test_LC_TCP_healthmonitor_list(self):
355 self._test_healthmonitor_list(const.TCP,
356 const.LB_ALGORITHM_LEAST_CONNECTIONS,
357 const.HEALTH_MONITOR_TCP)
358
359 @decorators.idempotent_id('60a254dc-4764-45f2-a183-8102063462e0')
360 def test_LC_TLS_healthmonitor_list(self):
361 self._test_healthmonitor_list(const.TCP,
362 const.LB_ALGORITHM_LEAST_CONNECTIONS,
363 const.HEALTH_MONITOR_TLS_HELLO)
364
365 @decorators.idempotent_id('6637d37d-76aa-455a-ba73-8f1a12edcedd')
366 def test_LC_UDP_healthmonitor_list(self):
367 self._test_healthmonitor_list(const.UDP,
368 const.LB_ALGORITHM_LEAST_CONNECTIONS,
369 const.HEALTH_MONITOR_UDP_CONNECT)
370
371 @decorators.idempotent_id('c9a9f20c-3680-4ae8-b657-33c687258fea')
372 def test_RR_HTTP_healthmonitor_list(self):
373 self._test_healthmonitor_list(const.HTTP,
374 const.LB_ALGORITHM_ROUND_ROBIN,
375 const.HEALTH_MONITOR_HTTP)
376
377 @decorators.idempotent_id('93c0d03a-eb32-457b-a5af-96c03a891c06')
378 def test_RR_HTTPS_healthmonitor_list(self):
379 self._test_healthmonitor_list(const.HTTPS,
380 const.LB_ALGORITHM_ROUND_ROBIN,
381 const.HEALTH_MONITOR_HTTPS)
382
383 @decorators.idempotent_id('2ef2944f-dd56-40a5-9100-4e1b86c623af')
384 def test_RR_PING_healthmonitor_list(self):
385 self._test_healthmonitor_list(const.TCP,
386 const.LB_ALGORITHM_ROUND_ROBIN,
387 const.HEALTH_MONITOR_PING)
388
389 @decorators.idempotent_id('5912534f-20b3-45b7-9907-9247bf05cd13')
390 def test_RR_TCP_healthmonitor_list(self):
391 self._test_healthmonitor_list(const.TCP,
392 const.LB_ALGORITHM_ROUND_ROBIN,
393 const.HEALTH_MONITOR_TCP)
394
395 @decorators.idempotent_id('5d169fe7-16f3-4f70-8b1e-72aeeec4fd61')
396 def test_RR_TLS_healthmonitor_list(self):
397 self._test_healthmonitor_list(const.TCP,
398 const.LB_ALGORITHM_ROUND_ROBIN,
399 const.HEALTH_MONITOR_TLS_HELLO)
400
401 @decorators.idempotent_id('3f81050e-4218-46fa-8d85-09807b8cdded')
402 def test_RR_UDP_healthmonitor_list(self):
403 self._test_healthmonitor_list(const.UDP,
404 const.LB_ALGORITHM_ROUND_ROBIN,
405 const.HEALTH_MONITOR_UDP_CONNECT)
406
407 @decorators.idempotent_id('2df98839-7b2a-46c4-9da7-34e3d1c33851')
408 def test_SI_HTTP_healthmonitor_list(self):
409 self._test_healthmonitor_list(const.HTTP,
410 const.LB_ALGORITHM_SOURCE_IP,
411 const.HEALTH_MONITOR_HTTP)
412
413 @decorators.idempotent_id('1ce28897-917c-4e7a-89bb-cc2aabd67037')
414 def test_SI_HTTPS_healthmonitor_list(self):
415 self._test_healthmonitor_list(const.HTTPS,
416 const.LB_ALGORITHM_SOURCE_IP,
417 const.HEALTH_MONITOR_HTTPS)
418
419 @decorators.idempotent_id('e8418eaa-73a5-4d56-8ca5-314dd2141dc9')
420 def test_SI_PING_healthmonitor_list(self):
421 self._test_healthmonitor_list(const.TCP,
422 const.LB_ALGORITHM_SOURCE_IP,
423 const.HEALTH_MONITOR_PING)
424
425 @decorators.idempotent_id('25203919-a039-43a4-84db-15279cbd2ec7')
426 def test_SI_TCP_healthmonitor_list(self):
427 self._test_healthmonitor_list(const.TCP,
428 const.LB_ALGORITHM_SOURCE_IP,
429 const.HEALTH_MONITOR_TCP)
430
431 @decorators.idempotent_id('4f84c05e-d4a7-4998-98cd-bc74024309f4')
432 def test_SI_TLS_healthmonitor_list(self):
433 self._test_healthmonitor_list(const.TCP,
434 const.LB_ALGORITHM_SOURCE_IP,
435 const.HEALTH_MONITOR_TLS_HELLO)
436
437 @decorators.idempotent_id('4cb10c86-a875-4a9e-be8f-c0afc8aa5633')
438 def test_SI_UDP_healthmonitor_list(self):
439 self._test_healthmonitor_list(const.UDP,
440 const.LB_ALGORITHM_SOURCE_IP,
441 const.HEALTH_MONITOR_UDP_CONNECT)
442
443 @decorators.idempotent_id('45bdd757-3132-4ede-8584-c46bc2f8f19e')
444 def test_SIP_HTTP_healthmonitor_list(self):
445 self._test_healthmonitor_list(const.HTTP,
446 const.LB_ALGORITHM_SOURCE_IP_PORT,
447 const.HEALTH_MONITOR_HTTP)
448
449 @decorators.idempotent_id('300db789-b231-45be-863d-f4d6116660d3')
450 def test_SIP_HTTPS_healthmonitor_list(self):
451 self._test_healthmonitor_list(const.HTTPS,
452 const.LB_ALGORITHM_SOURCE_IP_PORT,
453 const.HEALTH_MONITOR_HTTPS)
454
455 @decorators.idempotent_id('a1d534ba-ada9-4d7c-8e17-6e520a27c110')
456 def test_SIP_PING_healthmonitor_list(self):
457 self._test_healthmonitor_list(const.TCP,
458 const.LB_ALGORITHM_SOURCE_IP_PORT,
459 const.HEALTH_MONITOR_PING)
460
461 @decorators.idempotent_id('12c29b89-bbbc-46b0-89c5-beb42fc52181')
462 def test_SIP_TCP_healthmonitor_list(self):
463 self._test_healthmonitor_list(const.TCP,
464 const.LB_ALGORITHM_SOURCE_IP_PORT,
465 const.HEALTH_MONITOR_TCP)
466
467 @decorators.idempotent_id('a3b01b12-f4cb-4b2a-9f62-af24834ce19b')
468 def test_SIP_TLS_healthmonitor_list(self):
469 self._test_healthmonitor_list(const.TCP,
470 const.LB_ALGORITHM_SOURCE_IP_PORT,
471 const.HEALTH_MONITOR_TLS_HELLO)
472
473 @decorators.idempotent_id('571e139b-08ae-4e8c-b25c-0e0bb9d198af')
474 def test_SIP_UDP_healthmonitor_list(self):
475 self._test_healthmonitor_list(const.UDP,
476 const.LB_ALGORITHM_SOURCE_IP_PORT,
477 const.HEALTH_MONITOR_UDP_CONNECT)
478
479 def _test_healthmonitor_list(self, pool_protocol, pool_algorithm, hm_type):
480 """Tests healthmonitor list API and field filtering.
481
482 * Create three clean pools to use for the healthmonitors.
483 * Create three healthmonitors.
484 * Validates that other accounts cannot list the healthmonitors.
485 * List the healthmonitors using the default sort order.
486 * List the healthmonitors using descending sort order.
487 * List the healthmonitors using ascending sort order.
488 * List the healthmonitors returning one field at a time.
489 * List the healthmonitors returning two fields.
490 * List the healthmonitors filtering to one of the three.
491 * List the healthmonitors filtered, one field, and sorted.
492 """
493 # IDs of health monitors created in the test
494 test_ids = []
495
496 if (pool_algorithm == const.LB_ALGORITHM_SOURCE_IP_PORT and not
497 self.mem_listener_client.is_version_supported(
498 self.api_version, '2.13')):
499 raise testtools.TestCase.skipException(
500 'Skipping this test as load balancing algorithm '
501 'SOURCE_IP_PORT requires API version 2.13 or newer.')
502
503 # Get a list of pre-existing HMs to filter from test data
504 pretest_hms = self.mem_healthmonitor_client.list_healthmonitors()
505 # Store their IDs for easy access
506 pretest_hm_ids = [hm['id'] for hm in pretest_hms]
507
508 pool1_name = data_utils.rand_name("lb_member_pool1_hm-list")
509 pool1_kwargs = {
510 const.NAME: pool1_name,
511 const.PROTOCOL: pool_protocol,
512 const.LB_ALGORITHM: pool_algorithm,
513 const.LOADBALANCER_ID: self.lb_id,
514 }
515
516 # This is a special case as the reference driver does not support
517 # SOURCE-IP-PORT. Since it runs with not_implemented_is_error, we must
518 # handle this test case special.
519 try:
520 pool1 = self.mem_pool_client.create_pool(**pool1_kwargs)
521 except exceptions.NotImplemented as e:
522 if pool_algorithm != const.LB_ALGORITHM_SOURCE_IP_PORT:
523 raise
524 message = ("The configured provider driver '{driver}' "
525 "does not support a feature required for this "
526 "test.".format(driver=CONF.load_balancer.provider))
527 if hasattr(e, 'resp_body'):
528 message = e.resp_body.get('faultstring', message)
529 raise testtools.TestCase.skipException(message)
530
531 pool1_id = pool1[const.ID]
532 self.addCleanup(
533 self.mem_pool_client.cleanup_pool, pool1_id,
534 lb_client=self.mem_lb_client, lb_id=self.lb_id)
535
536 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
537 self.lb_id, const.PROVISIONING_STATUS,
538 const.ACTIVE,
539 CONF.load_balancer.build_interval,
540 CONF.load_balancer.build_timeout)
541
542 pool2_name = data_utils.rand_name("lb_member_pool2_hm-list")
543 pool2_kwargs = {
544 const.NAME: pool2_name,
545 const.PROTOCOL: pool_protocol,
546 const.LB_ALGORITHM: pool_algorithm,
547 const.LOADBALANCER_ID: self.lb_id,
548 }
549
550 pool2 = self.mem_pool_client.create_pool(**pool2_kwargs)
551 pool2_id = pool2[const.ID]
552 self.addCleanup(
553 self.mem_pool_client.cleanup_pool, pool2_id,
554 lb_client=self.mem_lb_client, lb_id=self.lb_id)
555
556 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
557 self.lb_id, const.PROVISIONING_STATUS,
558 const.ACTIVE,
559 CONF.load_balancer.build_interval,
560 CONF.load_balancer.build_timeout)
561
562 pool3_name = data_utils.rand_name("lb_member_pool3_hm-list")
563 pool3_kwargs = {
564 const.NAME: pool3_name,
565 const.PROTOCOL: pool_protocol,
566 const.LB_ALGORITHM: pool_algorithm,
567 const.LOADBALANCER_ID: self.lb_id,
568 }
569
570 pool3 = self.mem_pool_client.create_pool(**pool3_kwargs)
571 pool3_id = pool3[const.ID]
572 self.addCleanup(
573 self.mem_pool_client.cleanup_pool, pool3_id,
574 lb_client=self.mem_lb_client, lb_id=self.lb_id)
575
576 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
577 self.lb_id, const.PROVISIONING_STATUS,
578 const.ACTIVE,
579 CONF.load_balancer.build_interval,
580 CONF.load_balancer.build_timeout)
581
582 hm1_name = data_utils.rand_name("lb_member_hm2-list")
583 delay = 3 if hm_type == const.HEALTH_MONITOR_UDP_CONNECT else 2
584 hm1_kwargs = {
585 const.POOL_ID: pool1_id,
586 const.NAME: hm1_name,
587 const.TYPE: hm_type,
588 const.DELAY: delay,
589 const.TIMEOUT: 3,
590 const.MAX_RETRIES: 2,
591 const.MAX_RETRIES_DOWN: 5,
592 const.ADMIN_STATE_UP: True,
593 }
594 if hm_type == const.HEALTH_MONITOR_HTTP:
595 hm1_kwargs.update({const.HTTP_METHOD: const.GET,
596 const.URL_PATH: '/B',
597 const.EXPECTED_CODES: '200-204'})
598
599 if self.mem_healthmonitor_client.is_version_supported(
600 self.api_version, '2.5'):
601 hm1_tags = ["English", "Mathematics",
602 "Marketing", "Creativity"]
603 hm1_kwargs.update({const.TAGS: hm1_tags})
604
605 hm1 = self.mem_healthmonitor_client.create_healthmonitor(
606 **hm1_kwargs)
607 self.addCleanup(
608 self.mem_healthmonitor_client.cleanup_healthmonitor,
609 hm1[const.ID],
610 lb_client=self.mem_lb_client, lb_id=self.lb_id)
611 hm1 = waiters.wait_for_status(
612 self.mem_healthmonitor_client.show_healthmonitor, hm1[const.ID],
613 const.PROVISIONING_STATUS, const.ACTIVE,
614 CONF.load_balancer.build_interval,
615 CONF.load_balancer.build_timeout)
616 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
617 self.lb_id,
618 const.PROVISIONING_STATUS,
619 const.ACTIVE,
620 CONF.load_balancer.build_interval,
621 CONF.load_balancer.build_timeout)
622 test_ids.append(hm1[const.ID])
623 # Time resolution for created_at is only to the second, and we need to
624 # ensure that each object has a distinct creation time. Delaying one
625 # second is both a simple and a reliable way to accomplish this.
626 time.sleep(1)
627
628 hm2_name = data_utils.rand_name("lb_member_hm1-list")
629 hm2_kwargs = {
630 const.POOL_ID: pool2_id,
631 const.NAME: hm2_name,
632 const.TYPE: hm_type,
633 const.DELAY: delay,
634 const.TIMEOUT: 3,
635 const.MAX_RETRIES: 1,
636 const.MAX_RETRIES_DOWN: 5,
637 const.ADMIN_STATE_UP: True,
638 }
639 if hm_type == const.HEALTH_MONITOR_HTTP:
640 hm2_kwargs.update({const.HTTP_METHOD: const.GET,
641 const.URL_PATH: '/A',
642 const.EXPECTED_CODES: '200-204'})
643
644 if self.mem_listener_client.is_version_supported(
645 self.api_version, '2.5'):
646 hm2_tags = ["English", "Spanish",
647 "Soft_skills", "Creativity"]
648 hm2_kwargs.update({const.TAGS: hm2_tags})
649
650 hm2 = self.mem_healthmonitor_client.create_healthmonitor(
651 **hm2_kwargs)
652 self.addCleanup(
653 self.mem_healthmonitor_client.cleanup_healthmonitor,
654 hm2[const.ID],
655 lb_client=self.mem_lb_client, lb_id=self.lb_id)
656 hm2 = waiters.wait_for_status(
657 self.mem_healthmonitor_client.show_healthmonitor, hm2[const.ID],
658 const.PROVISIONING_STATUS, const.ACTIVE,
659 CONF.load_balancer.build_interval,
660 CONF.load_balancer.build_timeout)
661 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
662 self.lb_id,
663 const.PROVISIONING_STATUS,
664 const.ACTIVE,
665 CONF.load_balancer.build_interval,
666 CONF.load_balancer.build_timeout)
667 test_ids.append(hm2[const.ID])
668 # Time resolution for created_at is only to the second, and we need to
669 # ensure that each object has a distinct creation time. Delaying one
670 # second is both a simple and a reliable way to accomplish this.
671 time.sleep(1)
672
673 hm3_name = data_utils.rand_name("lb_member_hm3-list")
674 hm3_kwargs = {
675 const.POOL_ID: pool3_id,
676 const.NAME: hm3_name,
677 const.TYPE: hm_type,
678 const.DELAY: delay,
679 const.TIMEOUT: 3,
680 const.MAX_RETRIES: 3,
681 const.MAX_RETRIES_DOWN: 5,
682 const.ADMIN_STATE_UP: False,
683 }
684 if hm_type == const.HEALTH_MONITOR_HTTP:
685 hm3_kwargs.update({const.HTTP_METHOD: const.GET,
686 const.URL_PATH: '/C',
687 const.EXPECTED_CODES: '200-204'})
688
689 if self.mem_listener_client.is_version_supported(
690 self.api_version, '2.5'):
691 hm3_tags = ["English", "Project_management",
692 "Communication", "Creativity"]
693 hm3_kwargs.update({const.TAGS: hm3_tags})
694
695 hm3 = self.mem_healthmonitor_client.create_healthmonitor(
696 **hm3_kwargs)
697 self.addCleanup(
698 self.mem_healthmonitor_client.cleanup_healthmonitor,
699 hm3[const.ID],
700 lb_client=self.mem_lb_client, lb_id=self.lb_id)
701 hm3 = waiters.wait_for_status(
702 self.mem_healthmonitor_client.show_healthmonitor, hm3[const.ID],
703 const.PROVISIONING_STATUS, const.ACTIVE,
704 CONF.load_balancer.build_interval,
705 CONF.load_balancer.build_timeout)
706 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
707 self.lb_id,
708 const.PROVISIONING_STATUS,
709 const.ACTIVE,
710 CONF.load_balancer.build_interval,
711 CONF.load_balancer.build_timeout)
712 test_ids.append(hm3[const.ID])
713
714 # Test that a different users cannot see the lb_member healthmonitors
715 expected_allowed = []
716 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
717 expected_allowed = ['os_primary', 'os_roles_lb_member2']
718 if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES:
719 expected_allowed = ['os_primary', 'os_roles_lb_member2',
720 'os_roles_lb_observer',
721 'os_roles_lb_global_observer']
722 if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
723 expected_allowed = ['os_roles_lb_observer', 'os_roles_lb_member2']
724 if expected_allowed:
725 self.check_list_RBAC_enforcement_count(
726 'HealthMonitorClient', 'list_healthmonitors',
727 expected_allowed, 0)
728
729 # Test credentials that should see these healthmonitors can see them.
730 expected_allowed = []
731 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
732 expected_allowed = ['os_admin', 'os_roles_lb_member']
733 if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES:
734 expected_allowed = ['os_admin', 'os_roles_lb_admin',
735 'os_roles_lb_member']
736 if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
737 expected_allowed = ['os_admin', 'os_roles_lb_admin',
738 'os_roles_lb_member',
739 'os_roles_lb_global_observer']
740 if expected_allowed:
741 self.check_list_IDs_RBAC_enforcement(
742 'HealthMonitorClient', 'list_healthmonitors',
743 expected_allowed, test_ids)
744
745 # Test that users without the lb member role cannot list healthmonitors
746 # Note: non-owners can still call this API, they will just get the list
747 # of health monitors for their project (zero). The above tests
748 # are intended to cover the cross project use case.
749 expected_allowed = []
750 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
751 expected_allowed = ['os_admin', 'os_primary', 'os_roles_lb_admin',
752 'os_roles_lb_member', 'os_roles_lb_member2']
753 # Note: os_admin is here because it evaluaties to "project_admin"
754 # in oslo_policy and since keystone considers "project_admin"
755 # a superscope of "project_reader". This means it can read
756 # objects in the "admin" credential's project.
757 if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES:
758 expected_allowed = ['os_admin', 'os_primary', 'os_roles_lb_admin',
759 'os_roles_lb_observer',
760 'os_roles_lb_global_observer',
761 'os_roles_lb_member', 'os_roles_lb_member2']
762 if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
763 expected_allowed = ['os_admin', 'os_roles_lb_admin',
764 'os_roles_lb_observer',
765 'os_roles_lb_global_observer',
766 'os_roles_lb_member', 'os_roles_lb_member2']
767 if expected_allowed:
768 self.check_list_RBAC_enforcement(
769 'HealthMonitorClient', 'list_healthmonitors',
770 expected_allowed)
771
772 # Check the default sort order, created_at
773 hms = self.mem_healthmonitor_client.list_healthmonitors()
774 hms = self._filter_hms_by_pool_id(hms, (pool1_id, pool2_id, pool3_id))
775 if hm_type == const.HEALTH_MONITOR_HTTP:
776 self.assertEqual(hm1[const.URL_PATH],
777 hms[0][const.URL_PATH])
778 self.assertEqual(hm2[const.URL_PATH],
779 hms[1][const.URL_PATH])
780 self.assertEqual(hm3[const.URL_PATH],
781 hms[2][const.URL_PATH])
782 else:
783 self.assertEqual(hm1[const.MAX_RETRIES],
784 hms[0][const.MAX_RETRIES])
785 self.assertEqual(hm2[const.MAX_RETRIES],
786 hms[1][const.MAX_RETRIES])
787 self.assertEqual(hm3[const.MAX_RETRIES],
788 hms[2][const.MAX_RETRIES])
789
790 # Test sort descending by description
791 if hm_type == const.HEALTH_MONITOR_HTTP:
792 hms = self.mem_healthmonitor_client.list_healthmonitors(
793 query_params='{sort}={url_path}:{desc}'
794 .format(sort=const.SORT,
795 url_path=const.URL_PATH, desc=const.DESC))
796 hms = self._filter_hms_by_pool_id(hms,
797 (pool1_id, pool2_id, pool3_id))
798 self.assertEqual(hm1[const.URL_PATH],
799 hms[1][const.URL_PATH])
800 self.assertEqual(hm2[const.URL_PATH],
801 hms[2][const.URL_PATH])
802 self.assertEqual(hm3[const.URL_PATH],
803 hms[0][const.URL_PATH])
804 else:
805 hms = self.mem_healthmonitor_client.list_healthmonitors(
806 query_params='{sort}={url_path}:{desc}'
807 .format(sort=const.SORT,
808 url_path=const.MAX_RETRIES,
809 desc=const.DESC))
810 hms = self._filter_hms_by_pool_id(hms,
811 (pool1_id, pool2_id, pool3_id))
812 self.assertEqual(hm1[const.MAX_RETRIES],
813 hms[1][const.MAX_RETRIES])
814 self.assertEqual(hm2[const.MAX_RETRIES],
815 hms[2][const.MAX_RETRIES])
816 self.assertEqual(hm3[const.MAX_RETRIES],
817 hms[0][const.MAX_RETRIES])
818
819 # Test sort ascending by description
820 if hm_type == const.HEALTH_MONITOR_HTTP:
821 hms = self.mem_healthmonitor_client.list_healthmonitors(
822 query_params='{sort}={url_path}:{asc}'
823 .format(sort=const.SORT,
824 url_path=const.URL_PATH, asc=const.ASC))
825 hms = self._filter_hms_by_pool_id(hms,
826 (pool1_id, pool2_id, pool3_id))
827 self.assertEqual(hm1[const.URL_PATH],
828 hms[1][const.URL_PATH])
829 self.assertEqual(hm2[const.URL_PATH],
830 hms[0][const.URL_PATH])
831 self.assertEqual(hm3[const.URL_PATH],
832 hms[2][const.URL_PATH])
833 else:
834 hms = self.mem_healthmonitor_client.list_healthmonitors(
835 query_params='{sort}={url_path}:{asc}'
836 .format(sort=const.SORT,
837 url_path=const.MAX_RETRIES,
838 asc=const.ASC))
839 hms = self._filter_hms_by_pool_id(hms,
840 (pool1_id, pool2_id, pool3_id))
841 self.assertEqual(hm1[const.MAX_RETRIES],
842 hms[1][const.MAX_RETRIES])
843 self.assertEqual(hm2[const.MAX_RETRIES],
844 hms[0][const.MAX_RETRIES])
845 self.assertEqual(hm3[const.MAX_RETRIES],
846 hms[2][const.MAX_RETRIES])
847
848 # Determine indexes of pretest HMs in default sort
849 pretest_hm_indexes = []
850 hms = self.mem_healthmonitor_client.list_healthmonitors()
851 for i, hm in enumerate(hms):
852 if hm['id'] in pretest_hm_ids:
853 pretest_hm_indexes.append(i)
854
855 # Test fields
856 for field in const.SHOW_HEALTHMONITOR_RESPONSE_FIELDS:
857 hms = self.mem_healthmonitor_client.list_healthmonitors(
858 query_params='{fields}={field}'
859 .format(fields=const.FIELDS, field=field))
860 hms = self._filter_hms_by_index(hms, pretest_hm_indexes)
861 self.assertEqual(1, len(hms[0]))
862 self.assertEqual(hm1[field], hms[0][field])
863 self.assertEqual(hm2[field], hms[1][field])
864 self.assertEqual(hm3[field], hms[2][field])
865
866 # Test multiple fields at the same time
867 hms = self.mem_healthmonitor_client.list_healthmonitors(
868 query_params='{fields}={admin}&'
869 '{fields}={created}&'
870 '{fields}={pools}'.format(
871 fields=const.FIELDS,
872 admin=const.ADMIN_STATE_UP,
873 created=const.CREATED_AT,
874 pools=const.POOLS))
875 hms = self._filter_hms_by_pool_id(hms, (pool1_id, pool2_id, pool3_id))
876 self.assertEqual(3, len(hms[0]))
877 self.assertTrue(hms[0][const.ADMIN_STATE_UP])
878 parser.parse(hms[0][const.CREATED_AT])
879 self.assertTrue(hms[1][const.ADMIN_STATE_UP])
880 parser.parse(hms[1][const.CREATED_AT])
881 self.assertFalse(hms[2][const.ADMIN_STATE_UP])
882 parser.parse(hms[2][const.CREATED_AT])
883
884 # Test filtering
885 hms = self.mem_healthmonitor_client.list_healthmonitors(
886 query_params='{name}={hm_name}'.format(
887 name=const.NAME,
888 hm_name=hm2[const.NAME]))
889 self.assertEqual(1, len(hms))
890 self.assertEqual(hm2[const.NAME],
891 hms[0][const.NAME])
892
893 # Test combined params
894 hms = self.mem_healthmonitor_client.list_healthmonitors(
895 query_params='{admin}={true}&'
896 '{fields}={name}&{fields}={pools}&'
897 '{sort}={name}:{desc}'.format(
898 admin=const.ADMIN_STATE_UP,
899 true=const.ADMIN_STATE_UP_TRUE,
900 fields=const.FIELDS, name=const.NAME,
901 pools=const.POOLS, sort=const.SORT,
902 desc=const.DESC))
903 hms = self._filter_hms_by_pool_id(hms, (pool1_id, pool2_id, pool3_id))
904 # Should get two healthmonitors
905 self.assertEqual(2, len(hms))
906 # healthmonitors should have two fields
907 self.assertEqual(2, len(hms[0]))
908 # Should be in descending order
909 self.assertEqual(hm2[const.NAME],
910 hms[1][const.NAME])
911 self.assertEqual(hm1[const.NAME],
912 hms[0][const.NAME])
913
914 # Creating a list of 3 healthmonitors, each one contains different tags
915 if self.mem_healthmonitor_client.is_version_supported(
916 self.api_version, '2.5'):
917 list_of_hms = [hm1, hm2, hm3]
918 test_list = []
919 for hm in list_of_hms:
920
921 # If tags "English" and "Creativity" are in the HM's tags
922 # and "Spanish" is not, add the HM to the list
923 if "English" in hm[const.TAGS] and "Creativity" in (
924 hm[const.TAGS]) and "Spanish" not in (
925 hm[const.TAGS]):
926 test_list.append(hm[const.NAME])
927
928 # Tests if only the first and the third ones have those tags
929 self.assertEqual(
930 test_list, [hm1[const.NAME], hm3[const.NAME]])
931
932 # Tests that filtering by an empty tag will return an empty list
933 self.assertTrue(not any(["" in hm[const.TAGS]
934 for hm in list_of_hms]))
935
936 @decorators.idempotent_id('358afb0b-6259-46be-a0b3-b11e5e202624')
937 def test_LC_HTTP_healthmonitor_show(self):
938 self._test_healthmonitor_show(
939 const.HTTP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
940 const.HEALTH_MONITOR_HTTP)
941
942 @decorators.idempotent_id('c2476eea-8ae1-40ed-be55-0125f9399bd4')
943 def test_LC_HTTPS_healthmonitor_show(self):
944 self._test_healthmonitor_show(
945 const.HTTPS, const.LB_ALGORITHM_LEAST_CONNECTIONS,
946 const.HEALTH_MONITOR_HTTPS)
947
948 @decorators.idempotent_id('1489251c-0704-4735-bf62-801b5277c5c9')
949 def test_LC_PING_healthmonitor_show(self):
950 self._test_healthmonitor_show(
951 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
952 const.HEALTH_MONITOR_PING)
953
954 @decorators.idempotent_id('c761f90e-7b9c-400b-b540-e7c14f65d0a8')
955 def test_LC_TCP_healthmonitor_show(self):
956 self._test_healthmonitor_show(
957 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
958 const.HEALTH_MONITOR_TCP)
959
960 @decorators.idempotent_id('8ed512d7-9fd7-4932-bf5f-090498b384bb')
961 def test_LC_TLS_healthmonitor_show(self):
962 self._test_healthmonitor_show(
963 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
964 const.HEALTH_MONITOR_TLS_HELLO)
965
966 @decorators.idempotent_id('a3a9be7e-83d6-42cb-b603-f14a464b8268')
967 def test_LC_UDP_healthmonitor_show(self):
968 self._test_healthmonitor_show(
969 const.UDP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
970 const.HEALTH_MONITOR_UDP_CONNECT)
971
972 @decorators.idempotent_id('284e8d3b-7b2d-4697-9e41-580b3423c0b4')
973 def test_RR_HTTP_healthmonitor_show(self):
974 self._test_healthmonitor_show(
975 const.HTTP, const.LB_ALGORITHM_ROUND_ROBIN,
976 const.HEALTH_MONITOR_HTTP)
977
978 @decorators.idempotent_id('eeb4967b-ce46-4717-a750-3e740223a804')
979 def test_RR_HTTPS_healthmonitor_show(self):
980 self._test_healthmonitor_show(
981 const.HTTPS, const.LB_ALGORITHM_ROUND_ROBIN,
982 const.HEALTH_MONITOR_HTTPS)
983
984 @decorators.idempotent_id('799ada1b-c082-42c5-b6ea-477f10fc88ce')
985 def test_RR_PING_healthmonitor_show(self):
986 self._test_healthmonitor_show(
987 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
988 const.HEALTH_MONITOR_PING)
989
990 @decorators.idempotent_id('d2eae7f4-43b4-4696-93ed-a30f95c978fe')
991 def test_RR_TCP_healthmonitor_show(self):
992 self._test_healthmonitor_show(
993 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
994 const.HEALTH_MONITOR_TCP)
995
996 @decorators.idempotent_id('5ce6eecc-d425-47cd-809f-aab5c56e1a9d')
997 def test_RR_TLS_healthmonitor_show(self):
998 self._test_healthmonitor_show(
999 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
1000 const.HEALTH_MONITOR_TLS_HELLO)
1001
1002 @decorators.idempotent_id('a6a46e6a-a063-46bf-972c-86d0305fb766')
1003 def test_RR_UDP_healthmonitor_show(self):
1004 self._test_healthmonitor_show(
1005 const.UDP, const.LB_ALGORITHM_ROUND_ROBIN,
1006 const.HEALTH_MONITOR_UDP_CONNECT)
1007
1008 @decorators.idempotent_id('54d693ba-1ba4-4388-b020-c29dc3184522')
1009 def test_SI_HTTP_healthmonitor_show(self):
1010 self._test_healthmonitor_show(
1011 const.HTTP, const.LB_ALGORITHM_SOURCE_IP,
1012 const.HEALTH_MONITOR_HTTP)
1013
1014 @decorators.idempotent_id('2638718e-b345-4868-b527-9bed575e27d6')
1015 def test_SI_HTTPS_healthmonitor_show(self):
1016 self._test_healthmonitor_show(
1017 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP,
1018 const.HEALTH_MONITOR_HTTPS)
1019
1020 @decorators.idempotent_id('124a5ca1-5eae-4ed0-8528-7a499e9ad7a2')
1021 def test_SI_PING_healthmonitor_show(self):
1022 self._test_healthmonitor_show(
1023 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1024 const.HEALTH_MONITOR_PING)
1025
1026 @decorators.idempotent_id('098ae671-1791-455a-a5a8-ada8c592a2dd')
1027 def test_SI_TCP_healthmonitor_show(self):
1028 self._test_healthmonitor_show(
1029 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1030 const.HEALTH_MONITOR_TCP)
1031
1032 @decorators.idempotent_id('eef8f780-b557-447f-9f61-b1f3e6daec77')
1033 def test_SI_TLS_healthmonitor_show(self):
1034 self._test_healthmonitor_show(
1035 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1036 const.HEALTH_MONITOR_TLS_HELLO)
1037
1038 @decorators.idempotent_id('9b6d9c45-4696-4f6a-8816-594b03e3ee5b')
1039 def test_SI_UDP_healthmonitor_show(self):
1040 self._test_healthmonitor_show(
1041 const.UDP, const.LB_ALGORITHM_SOURCE_IP,
1042 const.HEALTH_MONITOR_UDP_CONNECT)
1043
1044 @decorators.idempotent_id('5653ea25-c7e0-4c72-8b2a-19dd97dd5a69')
1045 def test_SIP_HTTP_healthmonitor_show(self):
1046 self._test_healthmonitor_show(
1047 const.HTTP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1048 const.HEALTH_MONITOR_HTTP)
1049
1050 @decorators.idempotent_id('fff4472d-b4de-4b8b-9748-476ffc7c8e13')
1051 def test_SIP_HTTPS_healthmonitor_show(self):
1052 self._test_healthmonitor_show(
1053 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP_PORT,
1054 const.HEALTH_MONITOR_HTTPS)
1055
1056 @decorators.idempotent_id('1af98ebe-3f3c-4e5f-8f72-ecbd9b25c69f')
1057 def test_SIP_PING_healthmonitor_show(self):
1058 self._test_healthmonitor_show(
1059 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1060 const.HEALTH_MONITOR_PING)
1061
1062 @decorators.idempotent_id('40169a7d-84ac-4362-b8d7-64b9b807ce7e')
1063 def test_SIP_TCP_healthmonitor_show(self):
1064 self._test_healthmonitor_show(
1065 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1066 const.HEALTH_MONITOR_TCP)
1067
1068 @decorators.idempotent_id('15146c2e-e1c1-48ac-a7d8-3a1b4de590b2')
1069 def test_SIP_TLS_healthmonitor_show(self):
1070 self._test_healthmonitor_show(
1071 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1072 const.HEALTH_MONITOR_TLS_HELLO)
1073
1074 @decorators.idempotent_id('008042da-3734-4bbb-b8b2-f4ad9e2dab21')
1075 def test_SIP_UDP_healthmonitor_show(self):
1076 self._test_healthmonitor_show(
1077 const.UDP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1078 const.HEALTH_MONITOR_UDP_CONNECT)
1079
1080 def _test_healthmonitor_show(self, pool_protocol, pool_algorithm, hm_type):
1081 """Tests healthmonitor show API.
1082
1083 * Create a clean pool to use for the healthmonitor.
1084 * Create a fully populated healthmonitor.
1085 * Show healthmonitor details.
1086 * Validate the show reflects the requested values.
1087 * Validates that other accounts cannot see the healthmonitor.
1088 """
1089 if (pool_algorithm == const.LB_ALGORITHM_SOURCE_IP_PORT and not
1090 self.mem_listener_client.is_version_supported(
1091 self.api_version, '2.13')):
1092 raise testtools.TestCase.skipException(
1093 'Skipping this test as load balancing algorithm '
1094 'SOURCE_IP_PORT requires API version 2.13 or newer.')
1095
1096 pool_name = data_utils.rand_name("lb_member_pool1_hm-show")
1097 pool_kwargs = {
1098 const.NAME: pool_name,
1099 const.PROTOCOL: pool_protocol,
1100 const.LB_ALGORITHM: pool_algorithm,
1101 const.LOADBALANCER_ID: self.lb_id,
1102 }
1103
1104 # This is a special case as the reference driver does not support
1105 # SOURCE-IP-PORT. Since it runs with not_implemented_is_error, we must
1106 # handle this test case special.
1107 try:
1108 pool = self.mem_pool_client.create_pool(**pool_kwargs)
1109 except exceptions.NotImplemented as e:
1110 if pool_algorithm != const.LB_ALGORITHM_SOURCE_IP_PORT:
1111 raise
1112 message = ("The configured provider driver '{driver}' "
1113 "does not support a feature required for this "
1114 "test.".format(driver=CONF.load_balancer.provider))
1115 if hasattr(e, 'resp_body'):
1116 message = e.resp_body.get('faultstring', message)
1117 raise testtools.TestCase.skipException(message)
1118
1119 self.addCleanup(
1120 self.mem_pool_client.cleanup_pool, pool[const.ID],
1121 lb_client=self.mem_lb_client, lb_id=self.lb_id)
1122
1123 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
1124 self.lb_id, const.PROVISIONING_STATUS,
1125 const.ACTIVE,
1126 CONF.load_balancer.build_interval,
1127 CONF.load_balancer.build_timeout)
1128
1129 hm_name = data_utils.rand_name("lb_member_hm1-show")
1130 delay = 3 if hm_type == const.HEALTH_MONITOR_UDP_CONNECT else 2
1131 hm_kwargs = {
1132 const.POOL_ID: pool[const.ID],
1133 const.NAME: hm_name,
1134 const.TYPE: hm_type,
1135 const.DELAY: delay,
1136 const.TIMEOUT: 3,
1137 const.MAX_RETRIES: 4,
1138 const.MAX_RETRIES_DOWN: 5,
1139 const.ADMIN_STATE_UP: True,
1140 }
1141 if hm_type == const.HEALTH_MONITOR_HTTP:
1142 hm_kwargs.update({const.HTTP_METHOD: const.GET,
1143 const.URL_PATH: '/',
1144 const.EXPECTED_CODES: '200-204'})
1145
1146 hm = self.mem_healthmonitor_client.create_healthmonitor(**hm_kwargs)
1147 self.addCleanup(
1148 self.mem_healthmonitor_client.cleanup_healthmonitor,
1149 hm[const.ID],
1150 lb_client=self.mem_lb_client, lb_id=self.lb_id)
1151
1152 waiters.wait_for_status(
1153 self.mem_lb_client.show_loadbalancer, self.lb_id,
1154 const.PROVISIONING_STATUS, const.ACTIVE,
1155 CONF.load_balancer.build_interval,
1156 CONF.load_balancer.build_timeout)
1157 hm = waiters.wait_for_status(
1158 self.mem_healthmonitor_client.show_healthmonitor,
1159 hm[const.ID], const.PROVISIONING_STATUS,
1160 const.ACTIVE,
1161 CONF.load_balancer.build_interval,
1162 CONF.load_balancer.build_timeout)
1163
1164 parser.parse(hm[const.CREATED_AT])
1165 parser.parse(hm[const.UPDATED_AT])
1166 UUID(hm[const.ID])
1167
1168 # Healthmonitors are always ONLINE
1169 self.assertEqual(const.ONLINE, hm[const.OPERATING_STATUS])
1170
1171 equal_items = [const.NAME, const.TYPE, const.DELAY, const.TIMEOUT,
1172 const.MAX_RETRIES, const.MAX_RETRIES_DOWN,
1173 const.ADMIN_STATE_UP]
1174 if hm_type == const.HEALTH_MONITOR_HTTP:
1175 equal_items = equal_items + [const.HTTP_METHOD, const.URL_PATH,
1176 const.EXPECTED_CODES]
1177
1178 for item in equal_items:
1179 self.assertEqual(hm_kwargs[item], hm[item])
1180
1181 # Test that the appropriate users can see or not see the health
1182 # monitors based on the API RBAC.
1183 expected_allowed = []
1184 if CONF.load_balancer.RBAC_test_type == const.OWNERADMIN:
1185 expected_allowed = ['os_admin', 'os_roles_lb_admin',
1186 'os_roles_lb_member']
1187 if CONF.load_balancer.RBAC_test_type == const.KEYSTONE_DEFAULT_ROLES:
1188 expected_allowed = ['os_admin', 'os_roles_lb_admin',
1189 'os_roles_lb_member']
1190 if CONF.load_balancer.RBAC_test_type == const.ADVANCED:
1191 expected_allowed = ['os_admin', 'os_roles_lb_admin',
1192 'os_roles_lb_global_observer',
1193 'os_roles_lb_member']
1194 if expected_allowed:
1195 self.check_show_RBAC_enforcement(
1196 'HealthMonitorClient', 'show_healthmonitor',
1197 expected_allowed, hm[const.ID])
1198
1199 @decorators.idempotent_id('2417164b-ec03-4488-afd2-60b096dc0077')
1200 def test_LC_HTTP_healthmonitor_update(self):
1201 self._test_healthmonitor_update(
1202 const.HTTP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1203 const.HEALTH_MONITOR_HTTP)
1204
1205 @decorators.idempotent_id('5d88aa1e-2db9-43f8-bb9b-4673c2060835')
1206 def test_LC_HTTPS_healthmonitor_update(self):
1207 self._test_healthmonitor_update(
1208 const.HTTPS, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1209 const.HEALTH_MONITOR_HTTPS)
1210
1211 @decorators.idempotent_id('61908142-9768-44aa-9a4b-b3904560a0dc')
1212 def test_LC_PING_healthmonitor_update(self):
1213 self._test_healthmonitor_update(
1214 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1215 const.HEALTH_MONITOR_PING)
1216
1217 @decorators.idempotent_id('649bdfa3-1009-4f88-bc92-c3e3141c493e')
1218 def test_LC_TCP_healthmonitor_update(self):
1219 self._test_healthmonitor_update(
1220 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1221 const.HEALTH_MONITOR_TCP)
1222
1223 @decorators.idempotent_id('365fffd3-0817-4907-aab1-7da60736ba60')
1224 def test_LC_TLS_healthmonitor_update(self):
1225 self._test_healthmonitor_update(
1226 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1227 const.HEALTH_MONITOR_TLS_HELLO)
1228
1229 @decorators.idempotent_id('df29f696-a321-4626-acb2-6f66105e1661')
1230 def test_LC_UDP_healthmonitor_update(self):
1231 self._test_healthmonitor_update(
1232 const.UDP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1233 const.HEALTH_MONITOR_UDP_CONNECT)
1234
1235 @decorators.idempotent_id('fa584b2c-f179-4c4e-ad2e-ff51fd1c5973')
1236 def test_RR_HTTP_healthmonitor_update(self):
1237 self._test_healthmonitor_update(
1238 const.HTTP, const.LB_ALGORITHM_ROUND_ROBIN,
1239 const.HEALTH_MONITOR_HTTP)
1240
1241 @decorators.idempotent_id('b927836a-2770-46ff-92de-3031c5240da6')
1242 def test_RR_HTTPS_healthmonitor_update(self):
1243 self._test_healthmonitor_update(
1244 const.HTTPS, const.LB_ALGORITHM_ROUND_ROBIN,
1245 const.HEALTH_MONITOR_HTTPS)
1246
1247 @decorators.idempotent_id('cdd559b1-5c7b-492f-9c8d-c1da6e8d7b3b')
1248 def test_RR_PING_healthmonitor_update(self):
1249 self._test_healthmonitor_update(
1250 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
1251 const.HEALTH_MONITOR_PING)
1252
1253 @decorators.idempotent_id('1b9c310e-cffe-4f6a-b1af-021f751fc2a9')
1254 def test_RR_TCP_healthmonitor_update(self):
1255 self._test_healthmonitor_update(
1256 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
1257 const.HEALTH_MONITOR_TCP)
1258
1259 @decorators.idempotent_id('4b3c9a67-f884-43a3-8f42-bac68be7060b')
1260 def test_RR_TLS_healthmonitor_update(self):
1261 self._test_healthmonitor_update(
1262 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
1263 const.HEALTH_MONITOR_TLS_HELLO)
1264
1265 @decorators.idempotent_id('805e2976-962a-4bb0-a9cc-97270a42c376')
1266 def test_RR_UDP_healthmonitor_update(self):
1267 self._test_healthmonitor_update(
1268 const.UDP, const.LB_ALGORITHM_ROUND_ROBIN,
1269 const.HEALTH_MONITOR_UDP_CONNECT)
1270
1271 @decorators.idempotent_id('654e4ce3-b579-4595-b1a1-6762f64b2408')
1272 def test_SI_HTTP_healthmonitor_update(self):
1273 self._test_healthmonitor_update(
1274 const.HTTP, const.LB_ALGORITHM_SOURCE_IP,
1275 const.HEALTH_MONITOR_HTTP)
1276
1277 @decorators.idempotent_id('879ef60a-4621-45aa-a520-b57da3b1fddc')
1278 def test_SI_HTTPS_healthmonitor_update(self):
1279 self._test_healthmonitor_update(
1280 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP,
1281 const.HEALTH_MONITOR_HTTPS)
1282
1283 @decorators.idempotent_id('66e83157-53c3-4eac-a7f0-e3dc4f51de06')
1284 def test_SI_PING_healthmonitor_update(self):
1285 self._test_healthmonitor_update(
1286 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1287 const.HEALTH_MONITOR_PING)
1288
1289 @decorators.idempotent_id('ce475c4c-d01a-4cde-be71-555c84f2b8da')
1290 def test_SI_TCP_healthmonitor_update(self):
1291 self._test_healthmonitor_update(
1292 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1293 const.HEALTH_MONITOR_TCP)
1294
1295 @decorators.idempotent_id('b292478f-5c26-462e-b222-103be3b115d3')
1296 def test_SI_TLS_healthmonitor_update(self):
1297 self._test_healthmonitor_update(
1298 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1299 const.HEALTH_MONITOR_TLS_HELLO)
1300
1301 @decorators.idempotent_id('49ccc552-752b-4f84-9900-65908cb13add')
1302 def test_SI_UDP_healthmonitor_update(self):
1303 self._test_healthmonitor_update(
1304 const.UDP, const.LB_ALGORITHM_SOURCE_IP,
1305 const.HEALTH_MONITOR_UDP_CONNECT)
1306
1307 @decorators.idempotent_id('d141d8d1-fa12-49cb-9d6d-413998aa2dc5')
1308 def test_SIP_HTTP_healthmonitor_update(self):
1309 self._test_healthmonitor_update(
1310 const.HTTP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1311 const.HEALTH_MONITOR_HTTP)
1312
1313 @decorators.idempotent_id('9a1bbbbb-c640-48cb-bd1a-e3d3fd2602af')
1314 def test_SIP_HTTPS_healthmonitor_update(self):
1315 self._test_healthmonitor_update(
1316 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP_PORT,
1317 const.HEALTH_MONITOR_HTTPS)
1318
1319 @decorators.idempotent_id('3f573e31-49b9-45d0-bb00-8483f48ae422')
1320 def test_SIP_PING_healthmonitor_update(self):
1321 self._test_healthmonitor_update(
1322 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1323 const.HEALTH_MONITOR_PING)
1324
1325 @decorators.idempotent_id('1a6922fd-9e8c-4836-9a6a-087f09249a49')
1326 def test_SIP_TCP_healthmonitor_update(self):
1327 self._test_healthmonitor_update(
1328 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1329 const.HEALTH_MONITOR_TCP)
1330
1331 @decorators.idempotent_id('e9468e81-dbff-4e88-8d4b-e2a54835c2d8')
1332 def test_SIP_TLS_healthmonitor_update(self):
1333 self._test_healthmonitor_update(
1334 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1335 const.HEALTH_MONITOR_TLS_HELLO)
1336
1337 @decorators.idempotent_id('64379cb2-b789-4fe6-ae3a-e62b907c6365')
1338 def test_SIP_UDP_healthmonitor_update(self):
1339 self._test_healthmonitor_update(
1340 const.UDP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1341 const.HEALTH_MONITOR_UDP_CONNECT)
1342
1343 def _test_healthmonitor_update(self, pool_protocol, pool_algorithm,
1344 hm_type):
1345 """Tests healthmonitor update and show APIs.
1346
1347 * Create a clean pool to use for the healthmonitor.
1348 * Create a fully populated healthmonitor.
1349 * Show healthmonitor details.
1350 * Validate the show reflects the initial values.
1351 * Validates that other accounts cannot update the healthmonitor.
1352 * Update the healthmonitor details.
1353 * Show healthmonitor details.
1354 * Validate the show reflects the updated values.
1355 """
1356 if (pool_algorithm == const.LB_ALGORITHM_SOURCE_IP_PORT and not
1357 self.mem_listener_client.is_version_supported(
1358 self.api_version, '2.13')):
1359 raise testtools.TestCase.skipException(
1360 'Skipping this test as load balancing algorithm '
1361 'SOURCE_IP_PORT requires API version 2.13 or newer.')
1362
1363 pool_name = data_utils.rand_name("lb_member_pool1_hm-update")
1364 pool_kwargs = {
1365 const.NAME: pool_name,
1366 const.PROTOCOL: pool_protocol,
1367 const.LB_ALGORITHM: pool_algorithm,
1368 const.LOADBALANCER_ID: self.lb_id,
1369 }
1370
1371 # This is a special case as the reference driver does not support
1372 # SOURCE-IP-PORT. Since it runs with not_implemented_is_error, we must
1373 # handle this test case special.
1374 try:
1375 pool = self.mem_pool_client.create_pool(**pool_kwargs)
1376 except exceptions.NotImplemented as e:
1377 if pool_algorithm != const.LB_ALGORITHM_SOURCE_IP_PORT:
1378 raise
1379 message = ("The configured provider driver '{driver}' "
1380 "does not support a feature required for this "
1381 "test.".format(driver=CONF.load_balancer.provider))
1382 if hasattr(e, 'resp_body'):
1383 message = e.resp_body.get('faultstring', message)
1384 raise testtools.TestCase.skipException(message)
1385
1386 self.addCleanup(
1387 self.mem_pool_client.cleanup_pool, pool[const.ID],
1388 lb_client=self.mem_lb_client, lb_id=self.lb_id)
1389
1390 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
1391 self.lb_id, const.PROVISIONING_STATUS,
1392 const.ACTIVE,
1393 CONF.load_balancer.build_interval,
1394 CONF.load_balancer.build_timeout)
1395
1396 hm_name = data_utils.rand_name("lb_member_hm1-update")
1397 delay = 3 if hm_type == const.HEALTH_MONITOR_UDP_CONNECT else 2
1398 hm_kwargs = {
1399 const.POOL_ID: pool[const.ID],
1400 const.NAME: hm_name,
1401 const.TYPE: hm_type,
1402 const.DELAY: delay,
1403 const.TIMEOUT: 3,
1404 const.MAX_RETRIES: 4,
1405 const.MAX_RETRIES_DOWN: 5,
1406 const.ADMIN_STATE_UP: False,
1407 }
1408 if hm_type == const.HEALTH_MONITOR_HTTP:
1409 hm_kwargs.update({const.HTTP_METHOD: const.GET,
1410 const.URL_PATH: '/',
1411 const.EXPECTED_CODES: '200-204'})
1412
1413 if self.mem_listener_client.is_version_supported(
1414 self.api_version, '2.5'):
1415 hw_tags = ["Hello", "World"]
1416 hm_kwargs.update({
1417 const.TAGS: hw_tags
1418 })
1419
1420 hm = self.mem_healthmonitor_client.create_healthmonitor(**hm_kwargs)
1421 self.addCleanup(
1422 self.mem_healthmonitor_client.cleanup_healthmonitor,
1423 hm[const.ID],
1424 lb_client=self.mem_lb_client, lb_id=self.lb_id)
1425
1426 waiters.wait_for_status(
1427 self.mem_lb_client.show_loadbalancer, self.lb_id,
1428 const.PROVISIONING_STATUS, const.ACTIVE,
1429 CONF.load_balancer.build_interval,
1430 CONF.load_balancer.build_timeout)
1431 hm = waiters.wait_for_status(
1432 self.mem_healthmonitor_client.show_healthmonitor,
1433 hm[const.ID], const.PROVISIONING_STATUS,
1434 const.ACTIVE,
1435 CONF.load_balancer.build_interval,
1436 CONF.load_balancer.build_timeout)
1437
1438 parser.parse(hm[const.CREATED_AT])
1439 parser.parse(hm[const.UPDATED_AT])
1440 UUID(hm[const.ID])
1441
1442 # Healthmonitors are ONLINE if admin_state_up = True, else OFFLINE
1443 if hm_kwargs[const.ADMIN_STATE_UP]:
1444 self.assertEqual(const.ONLINE, hm[const.OPERATING_STATUS])
1445 else:
1446 self.assertEqual(const.OFFLINE, hm[const.OPERATING_STATUS])
1447
1448 equal_items = [const.NAME, const.TYPE, const.DELAY, const.TIMEOUT,
1449 const.MAX_RETRIES, const.MAX_RETRIES_DOWN,
1450 const.ADMIN_STATE_UP]
1451 if hm_type == const.HEALTH_MONITOR_HTTP:
1452 equal_items = equal_items + [const.HTTP_METHOD, const.URL_PATH,
1453 const.EXPECTED_CODES]
1454
1455 for item in equal_items:
1456 self.assertEqual(hm_kwargs[item], hm[item])
1457
1458 if self.mem_listener_client.is_version_supported(
1459 self.api_version, '2.5'):
1460 self.assertCountEqual(hm_kwargs[const.TAGS], hm[const.TAGS])
1461
1462 # Test that a user, without the loadbalancer member role, cannot
1463 # update this healthmonitor.
1464 expected_allowed = ['os_admin', 'os_roles_lb_admin',
1465 'os_roles_lb_member']
1466 self.check_update_RBAC_enforcement(
1467 'HealthMonitorClient', 'update_healthmonitor',
1468 expected_allowed, None, None, hm[const.ID],
1469 admin_state_up=True)
1470
1471 # Assert we didn't go into PENDING_*
1472 hm_check = self.mem_healthmonitor_client.show_healthmonitor(
1473 hm[const.ID])
1474 self.assertEqual(const.ACTIVE,
1475 hm_check[const.PROVISIONING_STATUS])
1476 self.assertFalse(hm_check[const.ADMIN_STATE_UP])
1477
1478 new_name = data_utils.rand_name("lb_member_hm1-UPDATED")
1479 hm_update_kwargs = {
1480 const.NAME: new_name,
1481 const.DELAY: hm_kwargs[const.DELAY] + 1,
1482 const.TIMEOUT: hm_kwargs[const.TIMEOUT] + 1,
1483 const.MAX_RETRIES: hm_kwargs[const.MAX_RETRIES] + 1,
1484 const.MAX_RETRIES_DOWN: hm_kwargs[const.MAX_RETRIES_DOWN] + 1,
1485 const.ADMIN_STATE_UP: not hm_kwargs[const.ADMIN_STATE_UP],
1486 }
1487 if hm_type == const.HEALTH_MONITOR_HTTP:
1488 hm_update_kwargs.update({const.HTTP_METHOD: const.POST,
1489 const.URL_PATH: '/test',
1490 const.EXPECTED_CODES: '201,202'})
1491
1492 if self.mem_listener_client.is_version_supported(
1493 self.api_version, '2.5'):
1494 hw_new_tags = ["Hola", "Mundo"]
1495 hm_update_kwargs.update({
1496 const.TAGS: hw_new_tags
1497 })
1498
1499 hm = self.mem_healthmonitor_client.update_healthmonitor(
1500 hm[const.ID], **hm_update_kwargs)
1501
1502 waiters.wait_for_status(
1503 self.mem_lb_client.show_loadbalancer, self.lb_id,
1504 const.PROVISIONING_STATUS, const.ACTIVE,
1505 CONF.load_balancer.build_interval,
1506 CONF.load_balancer.build_timeout)
1507 hm = waiters.wait_for_status(
1508 self.mem_healthmonitor_client.show_healthmonitor,
1509 hm[const.ID], const.PROVISIONING_STATUS,
1510 const.ACTIVE,
1511 CONF.load_balancer.build_interval,
1512 CONF.load_balancer.build_timeout)
1513
1514 # Healthmonitors are ONLINE if admin_state_up = True, else OFFLINE
1515 if hm_update_kwargs[const.ADMIN_STATE_UP]:
1516 self.assertEqual(const.ONLINE, hm[const.OPERATING_STATUS])
1517 else:
1518 self.assertEqual(const.OFFLINE, hm[const.OPERATING_STATUS])
1519
1520 # Test changed items
1521 equal_items = [const.NAME, const.DELAY, const.TIMEOUT,
1522 const.MAX_RETRIES, const.MAX_RETRIES_DOWN,
1523 const.ADMIN_STATE_UP]
1524 if hm_type == const.HEALTH_MONITOR_HTTP:
1525 equal_items = equal_items + [const.HTTP_METHOD, const.URL_PATH,
1526 const.EXPECTED_CODES]
1527
1528 if self.mem_listener_client.is_version_supported(
1529 self.api_version, '2.5'):
1530 self.assertCountEqual(hm_update_kwargs[const.TAGS], hm[const.TAGS])
1531
1532 for item in equal_items:
1533 self.assertEqual(hm_update_kwargs[item], hm[item])
1534
1535 # Test unchanged items
1536 equal_items = [const.TYPE]
1537 for item in equal_items:
1538 self.assertEqual(hm_kwargs[item], hm[item])
1539
1540 @decorators.idempotent_id('76b3d116-0190-4de8-a58e-8e450a46a621')
1541 def test_LC_HTTP_healthmonitor_delete(self):
1542 self._test_healthmonitor_delete(
1543 const.HTTP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1544 const.HEALTH_MONITOR_HTTP)
1545
1546 @decorators.idempotent_id('8e277e7f-49ea-4fcf-98e6-12566cc33846')
1547 def test_LC_HTTPS_healthmonitor_delete(self):
1548 self._test_healthmonitor_delete(
1549 const.HTTPS, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1550 const.HEALTH_MONITOR_HTTPS)
1551
1552 @decorators.idempotent_id('c6646a25-b46d-4541-82de-75ee2beef052')
1553 def test_LC_PING_healthmonitor_delete(self):
1554 self._test_healthmonitor_delete(
1555 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1556 const.HEALTH_MONITOR_PING)
1557
1558 @decorators.idempotent_id('5cfacffe-63f2-4aa3-856a-9fa3dafa2d33')
1559 def test_LC_TCP_healthmonitor_delete(self):
1560 self._test_healthmonitor_delete(
1561 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1562 const.HEALTH_MONITOR_TCP)
1563
1564 @decorators.idempotent_id('a4055e48-7740-4ff5-b6e2-9e69b1d40dce')
1565 def test_LC_TLS_healthmonitor_delete(self):
1566 self._test_healthmonitor_delete(
1567 const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1568 const.HEALTH_MONITOR_TLS_HELLO)
1569
1570 @decorators.idempotent_id('369bd443-54ec-4071-a279-5ac1ed38c52d')
1571 def test_LC_UDP_healthmonitor_delete(self):
1572 self._test_healthmonitor_delete(
1573 const.UDP, const.LB_ALGORITHM_LEAST_CONNECTIONS,
1574 const.HEALTH_MONITOR_UDP_CONNECT)
1575
1576 @decorators.idempotent_id('a7bab4ac-340c-4776-ab9d-9fcb66869432')
1577 def test_RR_HTTP_healthmonitor_delete(self):
1578 self._test_healthmonitor_delete(
1579 const.HTTP, const.LB_ALGORITHM_ROUND_ROBIN,
1580 const.HEALTH_MONITOR_HTTP)
1581
1582 @decorators.idempotent_id('2991664a-9138-4c10-8e30-2cb6a82bb5b4')
1583 def test_RR_HTTPS_healthmonitor_delete(self):
1584 self._test_healthmonitor_delete(
1585 const.HTTPS, const.LB_ALGORITHM_ROUND_ROBIN,
1586 const.HEALTH_MONITOR_HTTPS)
1587
1588 @decorators.idempotent_id('31f7c2c2-9174-4538-8dce-35128bc47ce7')
1589 def test_RR_PING_healthmonitor_delete(self):
1590 self._test_healthmonitor_delete(
1591 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
1592 const.HEALTH_MONITOR_PING)
1593
1594 @decorators.idempotent_id('56e0cd28-3e74-498c-b55b-21078a758d1f')
1595 def test_RR_TCP_healthmonitor_delete(self):
1596 self._test_healthmonitor_delete(
1597 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
1598 const.HEALTH_MONITOR_TCP)
1599
1600 @decorators.idempotent_id('e22a02e2-411a-46d5-9a3a-20ff37cbc835')
1601 def test_RR_TLS_healthmonitor_delete(self):
1602 self._test_healthmonitor_delete(
1603 const.TCP, const.LB_ALGORITHM_ROUND_ROBIN,
1604 const.HEALTH_MONITOR_TLS_HELLO)
1605
1606 @decorators.idempotent_id('9221a59f-3f0f-41e8-b65c-cdbcca1a2eca')
1607 def test_RR_UDP_healthmonitor_delete(self):
1608 self._test_healthmonitor_delete(
1609 const.UDP, const.LB_ALGORITHM_ROUND_ROBIN,
1610 const.HEALTH_MONITOR_UDP_CONNECT)
1611
1612 @decorators.idempotent_id('717e447f-d5c8-485a-923b-da83e560273b')
1613 def test_SI_HTTP_healthmonitor_delete(self):
1614 self._test_healthmonitor_delete(
1615 const.HTTP, const.LB_ALGORITHM_SOURCE_IP,
1616 const.HEALTH_MONITOR_HTTP)
1617
1618 @decorators.idempotent_id('2e177a95-4ec8-4847-bd35-706b6452406a')
1619 def test_SI_HTTPS_healthmonitor_delete(self):
1620 self._test_healthmonitor_delete(
1621 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP,
1622 const.HEALTH_MONITOR_HTTPS)
1623
1624 @decorators.idempotent_id('17127700-dc5f-4546-a6e6-c0b851704836')
1625 def test_SI_PING_healthmonitor_delete(self):
1626 self._test_healthmonitor_delete(
1627 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1628 const.HEALTH_MONITOR_PING)
1629
1630 @decorators.idempotent_id('0b1699c2-ff3e-47b6-a1ad-7128465d1233')
1631 def test_SI_TCP_healthmonitor_delete(self):
1632 self._test_healthmonitor_delete(
1633 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1634 const.HEALTH_MONITOR_TCP)
1635
1636 @decorators.idempotent_id('4ad99064-9015-40b3-8d5b-6cc99e2cc8b9')
1637 def test_SI_TLS_healthmonitor_delete(self):
1638 self._test_healthmonitor_delete(
1639 const.TCP, const.LB_ALGORITHM_SOURCE_IP,
1640 const.HEALTH_MONITOR_TLS_HELLO)
1641
1642 @decorators.idempotent_id('a17825ff-e774-4230-9c53-b53bfc355d61')
1643 def test_SI_UDP_healthmonitor_delete(self):
1644 self._test_healthmonitor_delete(
1645 const.UDP, const.LB_ALGORITHM_SOURCE_IP,
1646 const.HEALTH_MONITOR_UDP_CONNECT)
1647
1648 @decorators.idempotent_id('142022cc-9be3-4695-9acf-a7576e4b3268')
1649 def test_SIP_HTTP_healthmonitor_delete(self):
1650 self._test_healthmonitor_delete(
1651 const.HTTP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1652 const.HEALTH_MONITOR_HTTP)
1653
1654 @decorators.idempotent_id('dfd994b2-511b-433f-95f7-0786f1857090')
1655 def test_SIP_HTTPS_healthmonitor_delete(self):
1656 self._test_healthmonitor_delete(
1657 const.HTTPS, const.LB_ALGORITHM_SOURCE_IP_PORT,
1658 const.HEALTH_MONITOR_HTTPS)
1659
1660 @decorators.idempotent_id('0d08ffc0-6e6a-470d-abed-5c101a828401')
1661 def test_SIP_PING_healthmonitor_delete(self):
1662 self._test_healthmonitor_delete(
1663 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1664 const.HEALTH_MONITOR_PING)
1665
1666 @decorators.idempotent_id('ccf4a10c-2e72-4dbf-bc2f-134156eac3e2')
1667 def test_SIP_TCP_healthmonitor_delete(self):
1668 self._test_healthmonitor_delete(
1669 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1670 const.HEALTH_MONITOR_TCP)
1671
1672 @decorators.idempotent_id('aaacc11e-98cd-4322-a7db-7c720eafd2b2')
1673 def test_SIP_TLS_healthmonitor_delete(self):
1674 self._test_healthmonitor_delete(
1675 const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1676 const.HEALTH_MONITOR_TLS_HELLO)
1677
1678 @decorators.idempotent_id('559eccf4-eb7c-4d23-9dc8-741cc1601fc7')
1679 def test_SIP_UDP_healthmonitor_delete(self):
1680 self._test_healthmonitor_delete(
1681 const.UDP, const.LB_ALGORITHM_SOURCE_IP_PORT,
1682 const.HEALTH_MONITOR_UDP_CONNECT)
1683
1684 def _test_healthmonitor_delete(self, pool_protocol, pool_algorithm,
1685 hm_type):
1686 """Tests healthmonitor create and delete APIs.
1687
1688 * Create a clean pool to use for the healthmonitor.
1689 * Creates a healthmonitor.
1690 * Validates that other accounts cannot delete the healthmonitor
1691 * Deletes the healthmonitor.
1692 * Validates the healthmonitor is in the DELETED state.
1693 """
1694 if (pool_algorithm == const.LB_ALGORITHM_SOURCE_IP_PORT and not
1695 self.mem_listener_client.is_version_supported(
1696 self.api_version, '2.13')):
1697 raise testtools.TestCase.skipException(
1698 'Skipping this test as load balancing algorithm '
1699 'SOURCE_IP_PORT requires API version 2.13 or newer.')
1700
1701 pool_name = data_utils.rand_name("lb_member_pool1_hm-delete")
1702 pool_kwargs = {
1703 const.NAME: pool_name,
1704 const.PROTOCOL: pool_protocol,
1705 const.LB_ALGORITHM: pool_algorithm,
1706 const.LOADBALANCER_ID: self.lb_id,
1707 }
1708
1709 # This is a special case as the reference driver does not support
1710 # SOURCE-IP-PORT. Since it runs with not_implemented_is_error, we must
1711 # handle this test case special.
1712 try:
1713 pool = self.mem_pool_client.create_pool(**pool_kwargs)
1714 except exceptions.NotImplemented as e:
1715 if pool_algorithm != const.LB_ALGORITHM_SOURCE_IP_PORT:
1716 raise
1717 message = ("The configured provider driver '{driver}' "
1718 "does not support a feature required for this "
1719 "test.".format(driver=CONF.load_balancer.provider))
1720 if hasattr(e, 'resp_body'):
1721 message = e.resp_body.get('faultstring', message)
1722 raise testtools.TestCase.skipException(message)
1723
1724 self.addCleanup(
1725 self.mem_pool_client.cleanup_pool, pool[const.ID],
1726 lb_client=self.mem_lb_client, lb_id=self.lb_id)
1727
1728 waiters.wait_for_status(self.mem_lb_client.show_loadbalancer,
1729 self.lb_id, const.PROVISIONING_STATUS,
1730 const.ACTIVE,
1731 CONF.load_balancer.build_interval,
1732 CONF.load_balancer.build_timeout)
1733
1734 hm_name = data_utils.rand_name("lb_member_hm1-delete")
1735 delay = 3 if hm_type == const.HEALTH_MONITOR_UDP_CONNECT else 2
1736 hm_kwargs = {
1737 const.POOL_ID: pool[const.ID],
1738 const.NAME: hm_name,
1739 const.TYPE: hm_type,
1740 const.DELAY: delay,
1741 const.TIMEOUT: 3,
1742 const.MAX_RETRIES: 4,
1743 }
1744 hm = self.mem_healthmonitor_client.create_healthmonitor(**hm_kwargs)
1745 self.addCleanup(
1746 self.mem_healthmonitor_client.cleanup_healthmonitor,
1747 hm[const.ID],
1748 lb_client=self.mem_lb_client, lb_id=self.lb_id)
1749
1750 waiters.wait_for_status(
1751 self.mem_lb_client.show_loadbalancer,
1752 self.lb_id, const.PROVISIONING_STATUS,
1753 const.ACTIVE,
1754 CONF.load_balancer.build_interval,
1755 CONF.load_balancer.build_timeout)
1756
1757 # Test that a user without the loadbalancer role cannot delete this
1758 # healthmonitor.
1759 expected_allowed = ['os_admin', 'os_roles_lb_admin',
1760 'os_roles_lb_member']
1761 self.check_delete_RBAC_enforcement(
1762 'HealthMonitorClient', 'delete_healthmonitor',
1763 expected_allowed, None, None, hm[const.ID])
1764
1765 self.mem_healthmonitor_client.delete_healthmonitor(hm[const.ID])
1766
1767 waiters.wait_for_deleted_status_or_not_found(
1768 self.mem_healthmonitor_client.show_healthmonitor, hm[const.ID],
1769 const.PROVISIONING_STATUS,
1770 CONF.load_balancer.check_interval,
1771 CONF.load_balancer.check_timeout)
1772
1773 waiters.wait_for_status(
1774 self.mem_lb_client.show_loadbalancer,
1775 self.lb_id, const.PROVISIONING_STATUS,
1776 const.ACTIVE,
1777 CONF.load_balancer.check_interval,
1778 CONF.load_balancer.check_timeout)