Skip to content

Commit 373d826

Browse files
committed
Fixing handling of health monitors properly
1 parent c8ca1e9 commit 373d826

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

04-lbaas-upgrade/lbaas_upgrade.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def _translate_pool(self, p_res):
327327
)
328328

329329
def create_health_monitor(hm_obj):
330+
print(" Creating health monitor res for {}".format(p_res.name))
330331
hm_res_values = dict()
331332
attr_name_lst = [
332333
'created_at', 'updated_at', 'action', 'status',
@@ -350,12 +351,15 @@ def create_health_monitor(hm_obj):
350351
hm_res_values['properties_data_encrypted'] = 0
351352

352353
hm_res_pd = dict()
353-
# TODO: session persistance
354354
hm_res_pd["delay"] = hm_obj.delay
355355
hm_res_pd["type"] = hm_obj.type
356356
hm_res_pd["max_retries"] = hm_obj.max_retries
357357
hm_res_pd["timeout"] = hm_obj.timeout
358-
hm_res_pd["pool"] = hm_obj.pool
358+
hm_res_pd["pool"] = p_res.nova_instance
359+
if hm_obj.type == 'HTTP' or hm_obj.type == 'HTTPS':
360+
hm_res_pd['http_method'] = hm_obj.http_method
361+
hm_res_pd['expected_codes'] = hm_obj.expected_codes
362+
hm_res_pd['url_path'] = hm_obj.url_path
359363
hm_res_values['properties_data'] = hm_res_pd
360364

361365
hm_res = Resource.create(hctxt(), hm_res_values)
@@ -369,20 +373,16 @@ def delete_health_monitor(hm_res_name, hm_res):
369373

370374
if 'monitors' in p_properties:
371375
p_obj = self.lbaasv2_data.get_pool(p_res.nova_instance)
376+
372377
# this is the only used hm after the data migration
373378
active_hm_id = p_obj.healthmonitor_id
379+
if not active_hm_id:
380+
return
374381

375-
for mon in p_properties['monitors']:
376-
if isinstance(mon, str):
377-
hm_obj = self.lbaasv2_data.get_health_monitor(
378-
p_obj.healthmonitor_id)
379-
if hm_obj.id == active_hm_id:
380-
create_health_monitor(hm_obj)
381-
elif isinstance(mon, dict) and 'get_resource' in mon:
382-
hm_res_name = mon['get_resource']
383-
hm_res = self.res_dict['HealthMonitor'][hm_res_name]
384-
if hm_res.nova_instance != active_hm_id:
385-
delete_health_monitor(hm_res_name, hm_res)
382+
hm_res_name = self.get_resource_name('HealthMonitor', active_hm_id)
383+
if not hm_res_name:
384+
hm_obj = self.lbaasv2_data.get_health_monitor(active_hm_id)
385+
create_health_monitor(hm_obj)
386386

387387
def _handle_no_lb_case(self, p_res):
388388
def respective_lb_res_exists():
@@ -563,20 +563,27 @@ def _finalize_and_save(self):
563563
res.update_and_save(
564564
{'properties_data': res.properties_data})
565565

566-
if res_type == 'LoadBalancer':
566+
if res_type == 'Pool':
567+
res.update_and_save(
568+
{'rsrc_metadata': {}})
569+
elif res_type == 'LoadBalancer':
567570
res.update_and_save(
568571
{'nova_instance': self._lb_id[res_name]})
569572
elif res_type == 'HealthMonitor' and not res.nova_instance:
570573
res.update_and_save(
571574
{'nova_instance': None})
572575

573576
def get_resource_prop_name(self, res_type, nova_instance):
577+
if res_type not in self.res_dict:
578+
return None
574579
for res_name, res in self.res_dict[res_type].items():
575580
if res.nova_instance == nova_instance:
576581
return res.name
577582
return None
578583

579584
def get_resource_name(self, res_type, nova_instance):
585+
if res_type not in self.res_dict:
586+
return None
580587
for res_name, res in self.res_dict[res_type].items():
581588
if res.nova_instance == nova_instance:
582589
return res_name
@@ -628,14 +635,17 @@ def create_health_monitor(hm_res_name):
628635
t_hm_res_p['type'] = hm_res_p['type']
629636
t_hm_res_p['max_retries'] = hm_res_p['max_retries']
630637
t_hm_res_p['timeout'] = hm_res_p['timeout']
631-
#TODO: test again!
632638
t_hm_res_p['pool'] = {
633639
'get_resource':
634640
self.res_handler.get_resource_name(
635641
'Pool',
636642
hm_res_p['pool']
637643
)
638644
}
645+
if hm_res_p['type'] == 'HTTP' or hm_res_p['type'] == 'HTTPS':
646+
t_hm_res_p['http_method'] = hm_res_p['http_method']
647+
t_hm_res_p['expected_codes'] = hm_res_p['expected_codes']
648+
t_hm_res_p['url_path'] = hm_res_p['url_path']
639649
self.resources[hm_res_name] = dict()
640650
self.resources[hm_res_name]['properties'] = t_hm_res_p
641651
self.resources[hm_res_name]['type'] = (

0 commit comments

Comments
 (0)