Replace all the 'self.log' calls with global LOG
Change-Id: Iae917e1139c8c95a1bad5466df8a607656b9de5c
This commit is contained in:
parent
3bcda73ca0
commit
7fe40bb559
ironic_python_agent
@ -32,6 +32,9 @@ from ironic_python_agent import inspector
|
|||||||
from ironic_python_agent import ironic_api_client
|
from ironic_python_agent import ironic_api_client
|
||||||
|
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _time():
|
def _time():
|
||||||
"""Wraps time.time() for simpler testing."""
|
"""Wraps time.time() for simpler testing."""
|
||||||
return time.time()
|
return time.time()
|
||||||
@ -73,7 +76,6 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|||||||
self.agent = agent
|
self.agent = agent
|
||||||
self.api = ironic_api_client.APIClient(agent.api_url,
|
self.api = ironic_api_client.APIClient(agent.api_url,
|
||||||
agent.driver_name)
|
agent.driver_name)
|
||||||
self.log = log.getLogger(__name__)
|
|
||||||
self.error_delay = self.initial_delay
|
self.error_delay = self.initial_delay
|
||||||
self.reader = None
|
self.reader = None
|
||||||
self.writer = None
|
self.writer = None
|
||||||
@ -81,7 +83,7 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
"""Start the heartbeat thread."""
|
"""Start the heartbeat thread."""
|
||||||
# The first heartbeat happens immediately
|
# The first heartbeat happens immediately
|
||||||
self.log.info('starting heartbeater')
|
LOG.info('starting heartbeater')
|
||||||
interval = 0
|
interval = 0
|
||||||
self.agent.set_agent_advertise_addr()
|
self.agent.set_agent_advertise_addr()
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|||||||
self.max_jitter_multiplier)
|
self.max_jitter_multiplier)
|
||||||
interval = self.agent.heartbeat_timeout * interval_multiplier
|
interval = self.agent.heartbeat_timeout * interval_multiplier
|
||||||
log_msg = 'sleeping before next heartbeat, interval: {0}'
|
log_msg = 'sleeping before next heartbeat, interval: {0}'
|
||||||
self.log.info(log_msg.format(interval))
|
LOG.info(log_msg.format(interval))
|
||||||
finally:
|
finally:
|
||||||
os.close(self.reader)
|
os.close(self.reader)
|
||||||
os.close(self.writer)
|
os.close(self.writer)
|
||||||
@ -115,9 +117,9 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|||||||
advertise_address=self.agent.advertise_address
|
advertise_address=self.agent.advertise_address
|
||||||
)
|
)
|
||||||
self.error_delay = self.initial_delay
|
self.error_delay = self.initial_delay
|
||||||
self.log.info('heartbeat successful')
|
LOG.info('heartbeat successful')
|
||||||
except Exception:
|
except Exception:
|
||||||
self.log.exception('error sending heartbeat')
|
LOG.exception('error sending heartbeat')
|
||||||
self.error_delay = min(self.error_delay * self.backoff_factor,
|
self.error_delay = min(self.error_delay * self.backoff_factor,
|
||||||
self.max_delay)
|
self.max_delay)
|
||||||
|
|
||||||
@ -127,7 +129,7 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stop the heartbeat thread."""
|
"""Stop the heartbeat thread."""
|
||||||
if self.writer is not None:
|
if self.writer is not None:
|
||||||
self.log.info('stopping heartbeater')
|
LOG.info('stopping heartbeater')
|
||||||
os.write(self.writer, 'a')
|
os.write(self.writer, 'a')
|
||||||
return self.join()
|
return self.join()
|
||||||
|
|
||||||
@ -156,7 +158,6 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|||||||
self.api = app.VersionSelectorApplication(self)
|
self.api = app.VersionSelectorApplication(self)
|
||||||
self.heartbeater = IronicPythonAgentHeartbeater(self)
|
self.heartbeater = IronicPythonAgentHeartbeater(self)
|
||||||
self.heartbeat_timeout = None
|
self.heartbeat_timeout = None
|
||||||
self.log = log.getLogger(__name__)
|
|
||||||
self.started_at = None
|
self.started_at = None
|
||||||
self.node = None
|
self.node = None
|
||||||
# lookup timeout in seconds
|
# lookup timeout in seconds
|
||||||
@ -308,7 +309,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|||||||
try:
|
try:
|
||||||
wsgi.serve_forever()
|
wsgi.serve_forever()
|
||||||
except BaseException:
|
except BaseException:
|
||||||
self.log.exception('shutting down')
|
LOG.exception('shutting down')
|
||||||
|
|
||||||
if not self.standalone:
|
if not self.standalone:
|
||||||
self.heartbeater.stop()
|
self.heartbeater.stop()
|
||||||
|
@ -182,7 +182,6 @@ class BaseAgentExtension(object):
|
|||||||
def __init__(self, agent=None):
|
def __init__(self, agent=None):
|
||||||
super(BaseAgentExtension, self).__init__()
|
super(BaseAgentExtension, self).__init__()
|
||||||
self.agent = agent
|
self.agent = agent
|
||||||
self.log = log.getLogger(__name__)
|
|
||||||
self.command_map = dict(
|
self.command_map = dict(
|
||||||
(v.command_name, v)
|
(v.command_name, v)
|
||||||
for k, v in inspect.getmembers(self)
|
for k, v in inspect.getmembers(self)
|
||||||
|
@ -42,7 +42,6 @@ class APIClient(object):
|
|||||||
self.session.mount(self.api_url, adapter)
|
self.session.mount(self.api_url, adapter)
|
||||||
|
|
||||||
self.encoder = encoding.RESTJSONEncoder()
|
self.encoder = encoding.RESTJSONEncoder()
|
||||||
self.log = log.getLogger(__name__)
|
|
||||||
|
|
||||||
def _request(self, method, path, data=None):
|
def _request(self, method, path, data=None):
|
||||||
request_url = '{api_url}{path}'.format(api_url=self.api_url, path=path)
|
request_url = '{api_url}{path}'.format(api_url=self.api_url, path=path)
|
||||||
@ -114,28 +113,26 @@ class APIClient(object):
|
|||||||
try:
|
try:
|
||||||
response = self._request('POST', path, data=data)
|
response = self._request('POST', path, data=data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.warning('POST failed: %s' % str(e))
|
LOG.warning('POST failed: %s' % str(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if response.status_code != requests.codes.OK:
|
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
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content = json.loads(response.content)
|
content = json.loads(response.content)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.warning('Error decoding response: %s' % str(e))
|
LOG.warning('Error decoding response: %s' % str(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Check for valid response data
|
# Check for valid response data
|
||||||
if 'node' not in content or 'uuid' not in content['node']:
|
if 'node' not in content or 'uuid' not in content['node']:
|
||||||
self.log.warning('Got invalid node data from the API: %s' %
|
LOG.warning('Got invalid node data from the API: %s' % content)
|
||||||
content)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if 'heartbeat_timeout' not in content:
|
if 'heartbeat_timeout' not in content:
|
||||||
self.log.warning('Got invalid heartbeat from the API: %s' %
|
LOG.warning('Got invalid heartbeat from the API: %s' % content)
|
||||||
content)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Got valid content
|
# Got valid content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user