From 7fe40bb559ab23bb689adfe19aba4a9dc758feed Mon Sep 17 00:00:00 2001
From: Zhenguo Niu <niuzhenguo@huawei.com>
Date: Fri, 19 Feb 2016 11:30:46 +0800
Subject: [PATCH] Replace all the 'self.log' calls with global LOG

Change-Id: Iae917e1139c8c95a1bad5466df8a607656b9de5c
---
 ironic_python_agent/agent.py             | 17 +++++++++--------
 ironic_python_agent/extensions/base.py   |  1 -
 ironic_python_agent/ironic_api_client.py | 13 +++++--------
 3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/ironic_python_agent/agent.py b/ironic_python_agent/agent.py
index 897a84f91..fc0238fa9 100644
--- a/ironic_python_agent/agent.py
+++ b/ironic_python_agent/agent.py
@@ -32,6 +32,9 @@ from ironic_python_agent import inspector
 from ironic_python_agent import ironic_api_client
 
 
+LOG = log.getLogger(__name__)
+
+
 def _time():
     """Wraps time.time() for simpler testing."""
     return time.time()
@@ -73,7 +76,6 @@ class IronicPythonAgentHeartbeater(threading.Thread):
         self.agent = agent
         self.api = ironic_api_client.APIClient(agent.api_url,
                                                agent.driver_name)
-        self.log = log.getLogger(__name__)
         self.error_delay = self.initial_delay
         self.reader = None
         self.writer = None
@@ -81,7 +83,7 @@ class IronicPythonAgentHeartbeater(threading.Thread):
     def run(self):
         """Start the heartbeat thread."""
         # The first heartbeat happens immediately
-        self.log.info('starting heartbeater')
+        LOG.info('starting heartbeater')
         interval = 0
         self.agent.set_agent_advertise_addr()
 
@@ -100,7 +102,7 @@ class IronicPythonAgentHeartbeater(threading.Thread):
                     self.max_jitter_multiplier)
                 interval = self.agent.heartbeat_timeout * interval_multiplier
                 log_msg = 'sleeping before next heartbeat, interval: {0}'
-                self.log.info(log_msg.format(interval))
+                LOG.info(log_msg.format(interval))
         finally:
             os.close(self.reader)
             os.close(self.writer)
@@ -115,9 +117,9 @@ class IronicPythonAgentHeartbeater(threading.Thread):
                 advertise_address=self.agent.advertise_address
             )
             self.error_delay = self.initial_delay
-            self.log.info('heartbeat successful')
+            LOG.info('heartbeat successful')
         except Exception:
-            self.log.exception('error sending heartbeat')
+            LOG.exception('error sending heartbeat')
             self.error_delay = min(self.error_delay * self.backoff_factor,
                                    self.max_delay)
 
@@ -127,7 +129,7 @@ class IronicPythonAgentHeartbeater(threading.Thread):
     def stop(self):
         """Stop the heartbeat thread."""
         if self.writer is not None:
-            self.log.info('stopping heartbeater')
+            LOG.info('stopping heartbeater')
             os.write(self.writer, 'a')
             return self.join()
 
@@ -156,7 +158,6 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
         self.api = app.VersionSelectorApplication(self)
         self.heartbeater = IronicPythonAgentHeartbeater(self)
         self.heartbeat_timeout = None
-        self.log = log.getLogger(__name__)
         self.started_at = None
         self.node = None
         # lookup timeout in seconds
@@ -308,7 +309,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
         try:
             wsgi.serve_forever()
         except BaseException:
-            self.log.exception('shutting down')
+            LOG.exception('shutting down')
 
         if not self.standalone:
             self.heartbeater.stop()
diff --git a/ironic_python_agent/extensions/base.py b/ironic_python_agent/extensions/base.py
index 6f7de8e74..88e2f9278 100644
--- a/ironic_python_agent/extensions/base.py
+++ b/ironic_python_agent/extensions/base.py
@@ -182,7 +182,6 @@ class BaseAgentExtension(object):
     def __init__(self, agent=None):
         super(BaseAgentExtension, self).__init__()
         self.agent = agent
-        self.log = log.getLogger(__name__)
         self.command_map = dict(
             (v.command_name, v)
             for k, v in inspect.getmembers(self)
diff --git a/ironic_python_agent/ironic_api_client.py b/ironic_python_agent/ironic_api_client.py
index 4be6849ec..5017776ca 100644
--- a/ironic_python_agent/ironic_api_client.py
+++ b/ironic_python_agent/ironic_api_client.py
@@ -42,7 +42,6 @@ class APIClient(object):
         self.session.mount(self.api_url, adapter)
 
         self.encoder = encoding.RESTJSONEncoder()
-        self.log = log.getLogger(__name__)
 
     def _request(self, method, path, data=None):
         request_url = '{api_url}{path}'.format(api_url=self.api_url, path=path)
@@ -114,28 +113,26 @@ class APIClient(object):
         try:
             response = self._request('POST', path, data=data)
         except Exception as e:
-            self.log.warning('POST failed: %s' % str(e))
+            LOG.warning('POST failed: %s' % str(e))
             return False
 
         if response.status_code != requests.codes.OK:
-            self.log.warning('Invalid status code: %s' % response.status_code)
+            LOG.warning('Invalid status code: %s' % response.status_code)
             return False
 
         try:
             content = json.loads(response.content)
         except Exception as e:
-            self.log.warning('Error decoding response: %s' % str(e))
+            LOG.warning('Error decoding response: %s' % str(e))
             return False
 
         # Check for valid response data
         if 'node' not in content or 'uuid' not in content['node']:
-            self.log.warning('Got invalid node data from the API: %s' %
-                             content)
+            LOG.warning('Got invalid node data from the API: %s' % content)
             return False
 
         if 'heartbeat_timeout' not in content:
-            self.log.warning('Got invalid heartbeat from the API: %s' %
-                             content)
+            LOG.warning('Got invalid heartbeat from the API: %s' % content)
             return False
 
         # Got valid content