From 425bb1d66320f1d624ac38d613e293fa25475693 Mon Sep 17 00:00:00 2001 From: suzhengwei Date: Thu, 4 Jun 2020 11:22:35 +0800 Subject: [PATCH] repeated parsing It repeatedly uses 'node_state_tag.get('uname')' to parse the hostname. But the hostname doesn't change in the loop. Change-Id: Icac10015698378a1901c664f37f11b4529bf03e1 --- .../hostmonitor/host_handler/handle_host.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/masakarimonitors/hostmonitor/host_handler/handle_host.py b/masakarimonitors/hostmonitor/host_handler/handle_host.py index 98c6e55..3d6b0e7 100644 --- a/masakarimonitors/hostmonitor/host_handler/handle_host.py +++ b/masakarimonitors/hostmonitor/host_handler/handle_host.py @@ -282,28 +282,26 @@ class HandleHost(driver.DriverBase): # Check if host status changed. for node_state_tag in node_state_tag_list: - + hostname = node_state_tag.get('uname') # hostmonitor doesn't monitor itself. - if node_state_tag.get('uname') == self.my_hostname: + if hostname == self.my_hostname: continue # Get current status and old status. current_status = node_state_tag.get('crmd') - old_status = self.status_holder.get_host_status( - node_state_tag.get('uname')) + old_status = self.status_holder.get_host_status(hostname) # If old_status is None, This is first get of host status. if old_status is None: msg = ("Recognized '%s' as a new member of cluster." " Host status is '%s'.") \ - % (node_state_tag.get('uname'), current_status) + % (hostname, current_status) LOG.info("%s", msg) self.status_holder.set_host_status(node_state_tag) continue # Output host status. - msg = ("'%s' is '%s'.") % (node_state_tag.get('uname'), - current_status) + msg = ("'%s' is '%s'.") % (hostname, current_status) LOG.info("%s", msg) # If host status changed, send a notification. @@ -316,8 +314,7 @@ class HandleHost(driver.DriverBase): % current_status LOG.info("%s", msg) else: - event = self._make_event(node_state_tag.get('uname'), - current_status) + event = self._make_event(hostname, current_status) # Send a notification. self.notifier.send_notification(