| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import testtools |
| 16 |
from uuid import UUID |
| 17 |
|
| 18 |
from dateutil import parser |
| 19 |
from tempest import config |
| 20 |
from tempest.lib.common.utils import data_utils |
| 21 |
from tempest.lib import decorators |
| 22 |
from tempest.lib import exceptions |
| 23 |
|
| 24 |
from octavia_tempest_plugin.common import constants as const |
| 25 |
from octavia_tempest_plugin.tests import test_base |
| 26 |
from octavia_tempest_plugin.tests import waiters |
| 27 |
|
| 28 |
CONF = config.CONF |
| 29 |
|
| 30 |
|
| 31 |
class HealthMonitorScenarioTest(test_base.LoadBalancerBaseTest): |
| 32 |
|
| 33 |
@classmethod |
| 34 |
def resource_setup(cls): |
| 35 |
"""Setup resources needed by the tests.""" |
| 36 |
super(HealthMonitorScenarioTest, cls).resource_setup() |
| 37 |
|
| 38 |
lb_name = data_utils.rand_name("lb_member_lb1_hm") |
| 39 |
lb_kwargs = {const.PROVIDER: CONF.load_balancer.provider, |
| 40 |
const.NAME: lb_name} |
| 41 |
|
| 42 |
cls._setup_lb_network_kwargs(lb_kwargs) |
| 43 |
|
| 44 |
lb = cls.mem_lb_client.create_loadbalancer(**lb_kwargs) |
| 45 |
cls.lb_id = lb[const.ID] |
| 46 |
cls.addClassResourceCleanup( |
| 47 |
cls.mem_lb_client.cleanup_loadbalancer, |
| 48 |
cls.lb_id, cascade=True) |
| 49 |
|
| 50 |
waiters.wait_for_status(cls.mem_lb_client.show_loadbalancer, |
| 51 |
cls.lb_id, const.PROVISIONING_STATUS, |
| 52 |
const.ACTIVE, |
| 53 |
CONF.load_balancer.lb_build_interval, |
| 54 |
CONF.load_balancer.lb_build_timeout) |
| 55 |
|
| 56 |
@decorators.idempotent_id('4c2058f9-b8e2-4a5b-a2f3-3bd58a29f63b') |
| 57 |
def test_LC_HTTP_healthmonitor_CRUD(self): |
| 58 |
self._test_healthmonitor_CRUD( |
| 59 |
const.HTTP, const.LB_ALGORITHM_LEAST_CONNECTIONS, |
| 60 |
const.HEALTH_MONITOR_HTTP) |
| 61 |
|
| 62 |
@decorators.idempotent_id('08681eac-e907-4f71-8799-4b8fdf23914a') |
| 63 |
def test_LC_HTTPS_healthmonitor_CRUD(self): |
| 64 |
self._test_healthmonitor_CRUD( |
| 65 |
const.HTTPS, const.LB_ALGORITHM_LEAST_CONNECTIONS, |
| 66 |
const.HEALTH_MONITOR_HTTPS) |
| 67 |
|
| 68 |
@decorators.idempotent_id('74611ffb-45f8-4cf5-a28c-7cc37879a27b') |
| 69 |
def test_LC_PING_healthmonitor_CRUD(self): |
| 70 |
self._test_healthmonitor_CRUD( |
| 71 |
const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS, |
| 72 |
const.HEALTH_MONITOR_PING) |
| 73 |
|
| 74 |
@decorators.idempotent_id('cacec696-10f4-430d-bc9e-2c5f235a3324') |
| 75 |
def test_LC_TCP_healthmonitor_CRUD(self): |
| 76 |
self._test_healthmonitor_CRUD( |
| 77 |
const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS, |
| 78 |
const.HEALTH_MONITOR_TCP) |
| 79 |
|
| 80 |
@decorators.idempotent_id('6becafb2-1e15-4977-bb29-b08f5728d028') |
| 81 |
def test_LC_TLS_healthmonitor_CRUD(self): |
| 82 |
self._test_healthmonitor_CRUD( |
| 83 |
const.TCP, const.LB_ALGORITHM_LEAST_CONNECTIONS, |
| 84 |
const.HEALTH_MONITOR_TLS_HELLO) |
| 85 |
|
| 86 |
@decorators.idempotent_id('fe43ee90-093d-4175-837e-92f803958ef1') |
| 87 |
def test_LC_UDP_healthmonitor_CRUD(self): |
| 88 |
self._test_healthmonitor_CRUD( |
| 89 |
const.UDP, const.LB_ALGORITHM_LEAST_CONNECTIONS, |
| 90 |
const.HEALTH_MONITOR_UDP_CONNECT) |
| 91 |
|
| 92 |
@decorators.idempotent_id('a51e09aa-6e44-4c67-a9e4-df70d0e08f96') |
| 93 |
def test_RR_HTTP_healthmonitor_CRUD(self): |
| 94 |
self._test_healthmonitor_CRUD( |
| 95 |
const.HTTP, const.LB_ALGORITHM_ROUND_ROBIN, |
| 96 |
const.HEALTH_MONITOR_HTTP) |
| 97 |
|
| 98 |
@decorators.idempotent_id('fef9eabc-9d1e-4ad2-ae3e-05afc8c84c48') |
| 99 |
def test_RR_HTTPS_healthmonitor_CRUD(self): |
| 100 |
self._test_healthmonitor_CRUD( |
| 101 |
const.HTTPS, const.LB_ALGORITHM_ROUND_ROBIN, |
| 102 |
const.HEALTH_MONITOR_HTTPS) |
| 103 |
|
| 104 |
@decorators.idempotent_id('de01b73d-dba0-4426-9e20-9be3a34cfc44') |
| 105 |
def test_RR_PING_healthmonitor_CRUD(self): |
| 106 |
self._test_healthmonitor_CRUD( |
| 107 |
const.TCP, const.LB_ALGORITHM_ROUND_ROBIN, |
| 108 |
const.HEALTH_MONITOR_PING) |
| 109 |
|
| 110 |
@decorators.idempotent_id('141a121a-8918-4f9c-a070-eaf8ec29008d') |
| 111 |
def test_RR_TCP_healthmonitor_CRUD(self): |
| 112 |
self._test_healthmonitor_CRUD( |
| 113 |
const.TCP, const.LB_ALGORITHM_ROUND_ROBIN, |
| 114 |
const.HEALTH_MONITOR_TCP) |
| 115 |
|
| 116 |
@decorators.idempotent_id('de80d87a-5479-41c6-8c6b-518cc64ec62d') |
| 117 |
def test_RR_TLS_healthmonitor_CRUD(self): |
| 118 |
self._test_healthmonitor_CRUD( |
| 119 |
const.TCP, const.LB_ALGORITHM_ROUND_ROBIN, |
| 120 |
const.HEALTH_MONITOR_TLS_HELLO) |
| 121 |
|
| 122 |
@decorators.idempotent_id('265d7359-f0a5-4083-92a8-07cb1787fe36') |
| 123 |
def test_RR_UDP_healthmonitor_CRUD(self): |
| 124 |
self._test_healthmonitor_CRUD( |
| 125 |
const.UDP, const.LB_ALGORITHM_ROUND_ROBIN, |
| 126 |
const.HEALTH_MONITOR_UDP_CONNECT) |
| 127 |
|
| 128 |
@decorators.idempotent_id('20a2905f-2b53-4395-9a7f-1ded67ef4408') |
| 129 |
def test_SI_HTTP_healthmonitor_CRUD(self): |
| 130 |
self._test_healthmonitor_CRUD( |
| 131 |
const.HTTP, const.LB_ALGORITHM_SOURCE_IP, |
| 132 |
const.HEALTH_MONITOR_HTTP) |
| 133 |
|
| 134 |
@decorators.idempotent_id('8a8cc776-b68f-4761-9bf9-cae566cdc155') |
| 135 |
def test_SI_HTTPS_healthmonitor_CRUD(self): |
| 136 |
self._test_healthmonitor_CRUD( |
| 137 |
const.HTTPS, const.LB_ALGORITHM_SOURCE_IP, |
| 138 |
const.HEALTH_MONITOR_HTTPS) |
| 139 |
|
| 140 |
@decorators.idempotent_id('296a445c-5cc8-47a7-ae26-8d548f9712c3') |
| 141 |
def test_SI_PING_healthmonitor_CRUD(self): |
| 142 |
self._test_healthmonitor_CRUD( |
| 143 |
const.TCP, const.LB_ALGORITHM_SOURCE_IP, |
| 144 |
const.HEALTH_MONITOR_PING) |
| 145 |
|
| 146 |
@decorators.idempotent_id('94be34b1-4dc6-492b-a777-0587626a785f') |
| 147 |
def test_SI_TCP_healthmonitor_CRUD(self): |
| 148 |
self._test_healthmonitor_CRUD( |
| 149 |
const.TCP, const.LB_ALGORITHM_SOURCE_IP, |
| 150 |
const.HEALTH_MONITOR_TCP) |
| 151 |
|
| 152 |
@decorators.idempotent_id('0de0e021-fd3c-4f7c-b959-67d758394fd2') |
| 153 |
def test_SI_TLS_healthmonitor_CRUD(self): |
| 154 |
self._test_healthmonitor_CRUD( |
| 155 |
const.TCP, const.LB_ALGORITHM_SOURCE_IP, |
| 156 |
const.HEALTH_MONITOR_TLS_HELLO) |
| 157 |
|
| 158 |
@decorators.idempotent_id('3c79750a-aba6-4838-acbe-bc937ccf2118') |
| 159 |
def test_SI_UDP_healthmonitor_CRUD(self): |
| 160 |
self._test_healthmonitor_CRUD( |
| 161 |
const.UDP, const.LB_ALGORITHM_SOURCE_IP, |
| 162 |
const.HEALTH_MONITOR_UDP_CONNECT) |
| 163 |
|
| 164 |
@decorators.idempotent_id('d5e0d1b6-7cce-4592-abce-0ac6bee18818') |
| 165 |
def test_SIP_HTTP_healthmonitor_CRUD(self): |
| 166 |
try: |
| 167 |
self._test_healthmonitor_CRUD( |
| 168 |
const.HTTP, const.LB_ALGORITHM_SOURCE_IP_PORT, |
| 169 |
const.HEALTH_MONITOR_HTTP) |
| 170 |
except exceptions.NotImplemented as e: |
| 171 |
message = ("The configured provider driver '{driver}' " |
| 172 |
"does not support a feature required for this " |
| 173 |
"test.".format(driver=CONF.load_balancer.provider)) |
| 174 |
if hasattr(e, 'resp_body'): |
| 175 |
message = e.resp_body.get('faultstring', message) |
| 176 |
raise testtools.TestCase.skipException(message) |
| 177 |
|
| 178 |
@decorators.idempotent_id('e188daac-6db9-4dc2-8ecb-b47932e1984a') |
| 179 |
def test_SIP_HTTPS_healthmonitor_CRUD(self): |
| 180 |
try: |
| 181 |
self._test_healthmonitor_CRUD( |
| 182 |
const.HTTPS, const.LB_ALGORITHM_SOURCE_IP_PORT, |
| 183 |
const.HEALTH_MONITOR_HTTPS) |
| 184 |
except exceptions.NotImplemented as e: |
| 185 |
message = ("The configured provider driver '{driver}' " |
| 186 |
"does not support a feature required for this " |
| 187 |
"test.".format(driver=CONF.load_balancer.provider)) |
| 188 |
if hasattr(e, 'resp_body'): |
| 189 |
message = e.resp_body.get('faultstring', message) |
| 190 |
raise testtools.TestCase.skipException(message) |
| 191 |
|
| 192 |
@decorators.idempotent_id('f9458ffd-5af7-402b-9c15-c061bf2eb9ba') |
| 193 |
def test_SIP_PING_healthmonitor_CRUD(self): |
| 194 |
try: |
| 195 |
self._test_healthmonitor_CRUD( |
| 196 |
const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT, |
| 197 |
const.HEALTH_MONITOR_PING) |
| 198 |
except exceptions.NotImplemented as e: |
| 199 |
message = ("The configured provider driver '{driver}' " |
| 200 |
"does not support a feature required for this " |
| 201 |
"test.".format(driver=CONF.load_balancer.provider)) |
| 202 |
if hasattr(e, 'resp_body'): |
| 203 |
message = e.resp_body.get('faultstring', message) |
| 204 |
raise testtools.TestCase.skipException(message) |
| 205 |
|
| 206 |
@decorators.idempotent_id('b4cbe603-0a14-4778-b38c-f330053c86b6') |
| 207 |
def test_SIP_TCP_healthmonitor_CRUD(self): |
| 208 |
try: |
| 209 |
self._test_healthmonitor_CRUD( |
| 210 |
const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT, |
| 211 |
const.HEALTH_MONITOR_TCP) |
| 212 |
except exceptions.NotImplemented as e: |
| 213 |
message = ("The configured provider driver '{driver}' " |
| 214 |
"does not support a feature required for this " |
| 215 |
"test.".format(driver=CONF.load_balancer.provider)) |
| 216 |
if hasattr(e, 'resp_body'): |
| 217 |
message = e.resp_body.get('faultstring', message) |
| 218 |
raise testtools.TestCase.skipException(message) |
| 219 |
|
| 220 |
@decorators.idempotent_id('57714d4c-d584-4345-9ceb-becc3ae37b7f') |
| 221 |
def test_SIP_TLS_healthmonitor_CRUD(self): |
| 222 |
try: |
| 223 |
self._test_healthmonitor_CRUD( |
| 224 |
const.TCP, const.LB_ALGORITHM_SOURCE_IP_PORT, |
| 225 |
const.HEALTH_MONITOR_TLS_HELLO) |
| 226 |
except exceptions.NotImplemented as e: |
| 227 |
message = ("The configured provider driver '{driver}' " |
| 228 |
"does not support a feature required for this " |
| 229 |
"test.".format(driver=CONF.load_balancer.provider)) |
| 230 |
if hasattr(e, 'resp_body'): |
| 231 |
message = e.resp_body.get('faultstring', message) |
| 232 |
raise testtools.TestCase.skipException(message) |
| 233 |
|
| 234 |
@decorators.idempotent_id('cc4abf84-361b-409b-b859-9a860d539deb') |
| 235 |
def test_SIP_UDP_healthmonitor_CRUD(self): |
| 236 |
try: |
| 237 |
self._test_healthmonitor_CRUD( |
| 238 |
const.UDP, const.LB_ALGORITHM_SOURCE_IP_PORT, |
| 239 |
const.HEALTH_MONITOR_UDP_CONNECT) |
| 240 |
except exceptions.NotImplemented as e: |
| 241 |
message = ("The configured provider driver '{driver}' " |
| 242 |
"does not support a feature required for this " |
| 243 |
"test.".format(driver=CONF.load_balancer.provider)) |
| 244 |
if hasattr(e, 'resp_body'): |
| 245 |
message = e.resp_body.get('faultstring', message) |
| 246 |
raise testtools.TestCase.skipException(message) |
| 247 |
|
| 248 |
def _test_healthmonitor_CRUD(self, pool_protocol, pool_algorithm, hm_type): |
| 249 |
"""Tests healthmonitor create, read, update, delete, and member status |
| 250 |
|
| 251 |
* Create a fully populated healthmonitor. |
| 252 |
* Show healthmonitor details. |
| 253 |
* Update the healthmonitor. |
| 254 |
* Delete the healthmonitor. |
| 255 |
""" |
| 256 |
if (pool_algorithm == const.LB_ALGORITHM_SOURCE_IP_PORT and not |
| 257 |
self.mem_listener_client.is_version_supported( |
| 258 |
self.api_version, '2.13')): |
| 259 |
raise testtools.TestCase.skipException( |
| 260 |
'Skipping this test as load balancing algorithm ' |
| 261 |
'SOURCE_IP_PORT requires API version 2.13 or newer.') |
| 262 |
|
| 263 |
pool_name = data_utils.rand_name("lb_member_pool1_hm") |
| 264 |
pool_kwargs = { |
| 265 |
const.NAME: pool_name, |
| 266 |
const.PROTOCOL: pool_protocol, |
| 267 |
const.LB_ALGORITHM: pool_algorithm, |
| 268 |
const.LOADBALANCER_ID: self.lb_id, |
| 269 |
} |
| 270 |
pool = self.mem_pool_client.create_pool(**pool_kwargs) |
| 271 |
|
| 272 |
self.addClassResourceCleanup( |
| 273 |
self.mem_pool_client.cleanup_pool, |
| 274 |
pool[const.ID], |
| 275 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 276 |
|
| 277 |
waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 278 |
self.lb_id, const.PROVISIONING_STATUS, |
| 279 |
const.ACTIVE, |
| 280 |
CONF.load_balancer.build_interval, |
| 281 |
CONF.load_balancer.build_timeout) |
| 282 |
|
| 283 |
|
| 284 |
hm_name = data_utils.rand_name("lb_member_hm1-CRUD") |
| 285 |
delay = 3 if hm_type == const.HEALTH_MONITOR_UDP_CONNECT else 2 |
| 286 |
hm_kwargs = { |
| 287 |
const.POOL_ID: pool[const.ID], |
| 288 |
const.NAME: hm_name, |
| 289 |
const.TYPE: hm_type, |
| 290 |
const.DELAY: delay, |
| 291 |
const.TIMEOUT: 2, |
| 292 |
const.MAX_RETRIES: 2, |
| 293 |
const.MAX_RETRIES_DOWN: 2, |
| 294 |
const.ADMIN_STATE_UP: True, |
| 295 |
} |
| 296 |
if hm_type == const.HEALTH_MONITOR_HTTP: |
| 297 |
hm_kwargs.update({const.HTTP_METHOD: const.GET, |
| 298 |
const.URL_PATH: '/', |
| 299 |
const.EXPECTED_CODES: '200'}) |
| 300 |
|
| 301 |
hm = self.mem_healthmonitor_client.create_healthmonitor(**hm_kwargs) |
| 302 |
|
| 303 |
self.addClassResourceCleanup( |
| 304 |
self.mem_healthmonitor_client.cleanup_healthmonitor, |
| 305 |
hm[const.ID], |
| 306 |
lb_client=self.mem_lb_client, lb_id=self.lb_id) |
| 307 |
|
| 308 |
waiters.wait_for_status( |
| 309 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 310 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 311 |
CONF.load_balancer.build_interval, |
| 312 |
CONF.load_balancer.build_timeout) |
| 313 |
hm = waiters.wait_for_status( |
| 314 |
self.mem_healthmonitor_client.show_healthmonitor, |
| 315 |
hm[const.ID], const.PROVISIONING_STATUS, |
| 316 |
const.ACTIVE, |
| 317 |
CONF.load_balancer.build_interval, |
| 318 |
CONF.load_balancer.build_timeout) |
| 319 |
|
| 320 |
parser.parse(hm[const.CREATED_AT]) |
| 321 |
parser.parse(hm[const.UPDATED_AT]) |
| 322 |
UUID(hm[const.ID]) |
| 323 |
self.assertEqual(const.ONLINE, hm[const.OPERATING_STATUS]) |
| 324 |
|
| 325 |
equal_items = [const.NAME, const.TYPE, const.DELAY, const.TIMEOUT, |
| 326 |
const.MAX_RETRIES, const.MAX_RETRIES_DOWN, |
| 327 |
const.ADMIN_STATE_UP] |
| 328 |
if hm_type == const.HEALTH_MONITOR_HTTP: |
| 329 |
equal_items = equal_items + [const.HTTP_METHOD, const.URL_PATH, |
| 330 |
const.EXPECTED_CODES] |
| 331 |
|
| 332 |
for item in equal_items: |
| 333 |
self.assertEqual(hm_kwargs[item], hm[item]) |
| 334 |
|
| 335 |
|
| 336 |
new_name = data_utils.rand_name("lb_member_hm1-update") |
| 337 |
hm_update_kwargs = { |
| 338 |
const.NAME: new_name, |
| 339 |
const.DELAY: hm_kwargs[const.DELAY] + 1, |
| 340 |
const.TIMEOUT: hm_kwargs[const.TIMEOUT] + 1, |
| 341 |
const.MAX_RETRIES: hm_kwargs[const.MAX_RETRIES] + 1, |
| 342 |
const.MAX_RETRIES_DOWN: hm_kwargs[const.MAX_RETRIES_DOWN] + 1, |
| 343 |
const.ADMIN_STATE_UP: not hm_kwargs[const.ADMIN_STATE_UP], |
| 344 |
} |
| 345 |
if hm_type == const.HEALTH_MONITOR_HTTP: |
| 346 |
hm_update_kwargs.update({const.HTTP_METHOD: const.POST, |
| 347 |
const.URL_PATH: '/test', |
| 348 |
const.EXPECTED_CODES: '201,202'}) |
| 349 |
|
| 350 |
hm = self.mem_healthmonitor_client.update_healthmonitor( |
| 351 |
hm[const.ID], **hm_update_kwargs) |
| 352 |
|
| 353 |
waiters.wait_for_status( |
| 354 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 355 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 356 |
CONF.load_balancer.build_interval, |
| 357 |
CONF.load_balancer.build_timeout) |
| 358 |
hm = waiters.wait_for_status( |
| 359 |
self.mem_healthmonitor_client.show_healthmonitor, |
| 360 |
hm[const.ID], const.PROVISIONING_STATUS, |
| 361 |
const.ACTIVE, |
| 362 |
CONF.load_balancer.build_interval, |
| 363 |
CONF.load_balancer.build_timeout) |
| 364 |
|
| 365 |
|
| 366 |
equal_items = [const.NAME, const.DELAY, const.TIMEOUT, |
| 367 |
const.MAX_RETRIES, const.MAX_RETRIES_DOWN, |
| 368 |
const.ADMIN_STATE_UP] |
| 369 |
if hm_type == const.HEALTH_MONITOR_HTTP: |
| 370 |
equal_items = equal_items + [const.HTTP_METHOD, const.URL_PATH, |
| 371 |
const.EXPECTED_CODES] |
| 372 |
|
| 373 |
for item in equal_items: |
| 374 |
self.assertEqual(hm_update_kwargs[item], hm[item]) |
| 375 |
|
| 376 |
|
| 377 |
equal_items = [const.TYPE] |
| 378 |
for item in equal_items: |
| 379 |
self.assertEqual(hm_kwargs[item], hm[item]) |
| 380 |
|
| 381 |
|
| 382 |
self.mem_healthmonitor_client.delete_healthmonitor(hm[const.ID]) |
| 383 |
|
| 384 |
waiters.wait_for_deleted_status_or_not_found( |
| 385 |
self.mem_healthmonitor_client.show_healthmonitor, hm[const.ID], |
| 386 |
const.PROVISIONING_STATUS, |
| 387 |
CONF.load_balancer.check_interval, |
| 388 |
CONF.load_balancer.check_timeout) |
| 389 |
|
| 390 |
waiters.wait_for_status( |
| 391 |
self.mem_lb_client.show_loadbalancer, self.lb_id, |
| 392 |
const.PROVISIONING_STATUS, const.ACTIVE, |
| 393 |
CONF.load_balancer.check_interval, |
| 394 |
CONF.load_balancer.check_timeout) |