LOGGER -> logger.
While logger may be a global variable, it is not constant. Let the linters complain!
This commit is contained in:
parent
a8473db87f
commit
09cc4ba4c1
4 changed files with 35 additions and 35 deletions
|
@ -9,7 +9,7 @@ from buildman.server import BuilderServer
|
||||||
|
|
||||||
from trollius import SSLContext
|
from trollius import SSLContext
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
BUILD_MANAGERS = {
|
BUILD_MANAGERS = {
|
||||||
'enterprise': EnterpriseManager
|
'enterprise': EnterpriseManager
|
||||||
|
@ -17,22 +17,22 @@ BUILD_MANAGERS = {
|
||||||
|
|
||||||
def run_build_manager():
|
def run_build_manager():
|
||||||
if not features.BUILD_SUPPORT:
|
if not features.BUILD_SUPPORT:
|
||||||
LOGGER.debug('Building is disabled. Please enable the feature flag')
|
logger.debug('Building is disabled. Please enable the feature flag')
|
||||||
return
|
return
|
||||||
|
|
||||||
build_manager_config = app.config.get('BUILD_MANAGER')
|
build_manager_config = app.config.get('BUILD_MANAGER')
|
||||||
if build_manager_config is None:
|
if build_manager_config is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
LOGGER.debug('Asking to start build manager with lifecycle "%s"', build_manager_config[0])
|
logger.debug('Asking to start build manager with lifecycle "%s"', build_manager_config[0])
|
||||||
manager_klass = BUILD_MANAGERS.get(build_manager_config[0])
|
manager_klass = BUILD_MANAGERS.get(build_manager_config[0])
|
||||||
if manager_klass is None:
|
if manager_klass is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
LOGGER.debug('Starting build manager with lifecycle "%s"', build_manager_config[0])
|
logger.debug('Starting build manager with lifecycle "%s"', build_manager_config[0])
|
||||||
ssl_context = None
|
ssl_context = None
|
||||||
if os.environ.get('SSL_CONFIG'):
|
if os.environ.get('SSL_CONFIG'):
|
||||||
LOGGER.debug('Loading SSL cert and key')
|
logger.debug('Loading SSL cert and key')
|
||||||
ssl_context = SSLContext()
|
ssl_context = SSLContext()
|
||||||
ssl_context.load_cert_chain(os.environ.get('SSL_CONFIG') + '/ssl.cert',
|
ssl_context.load_cert_chain(os.environ.get('SSL_CONFIG') + '/ssl.cert',
|
||||||
os.environ.get('SSL_CONFIG') + '/ssl.key')
|
os.environ.get('SSL_CONFIG') + '/ssl.key')
|
||||||
|
|
|
@ -20,7 +20,7 @@ HEARTBEAT_DELTA = datetime.timedelta(seconds=30)
|
||||||
HEARTBEAT_TIMEOUT = 10
|
HEARTBEAT_TIMEOUT = 10
|
||||||
INITIAL_TIMEOUT = 25
|
INITIAL_TIMEOUT = 25
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class ComponentStatus(object):
|
class ComponentStatus(object):
|
||||||
""" ComponentStatus represents the possible states of a component. """
|
""" ComponentStatus represents the possible states of a component. """
|
||||||
|
@ -51,7 +51,7 @@ class BuildComponent(BaseComponent):
|
||||||
self.join(self.builder_realm)
|
self.join(self.builder_realm)
|
||||||
|
|
||||||
def onJoin(self, details):
|
def onJoin(self, details):
|
||||||
LOGGER.debug('Registering methods and listeners for component %s', self.builder_realm)
|
logger.debug('Registering methods and listeners for component %s', self.builder_realm)
|
||||||
yield From(self.register(self._on_ready, u'io.quay.buildworker.ready'))
|
yield From(self.register(self._on_ready, u'io.quay.buildworker.ready'))
|
||||||
yield From(self.register(self._ping, u'io.quay.buildworker.ping'))
|
yield From(self.register(self._ping, u'io.quay.buildworker.ping'))
|
||||||
yield From(self.subscribe(self._on_heartbeat, 'io.quay.builder.heartbeat'))
|
yield From(self.subscribe(self._on_heartbeat, 'io.quay.builder.heartbeat'))
|
||||||
|
@ -75,7 +75,7 @@ class BuildComponent(BaseComponent):
|
||||||
buildpack_url = self.user_files.get_file_url(build_job.repo_build().resource_key,
|
buildpack_url = self.user_files.get_file_url(build_job.repo_build().resource_key,
|
||||||
requires_cors=False)
|
requires_cors=False)
|
||||||
|
|
||||||
LOGGER.debug('Retreiving build package: %s', buildpack_url)
|
logger.debug('Retreiving build package: %s', buildpack_url)
|
||||||
buildpack = None
|
buildpack = None
|
||||||
try:
|
try:
|
||||||
buildpack = BuildPackage.from_url(buildpack_url)
|
buildpack = BuildPackage.from_url(buildpack_url)
|
||||||
|
@ -85,7 +85,7 @@ class BuildComponent(BaseComponent):
|
||||||
|
|
||||||
# Extract the base image information from the Dockerfile.
|
# Extract the base image information from the Dockerfile.
|
||||||
parsed_dockerfile = None
|
parsed_dockerfile = None
|
||||||
LOGGER.debug('Parsing dockerfile')
|
logger.debug('Parsing dockerfile')
|
||||||
|
|
||||||
build_config = build_job.build_config()
|
build_config = build_job.build_config()
|
||||||
try:
|
try:
|
||||||
|
@ -143,8 +143,8 @@ class BuildComponent(BaseComponent):
|
||||||
}
|
}
|
||||||
|
|
||||||
# Invoke the build.
|
# Invoke the build.
|
||||||
LOGGER.debug('Invoking build: %s', self.builder_realm)
|
logger.debug('Invoking build: %s', self.builder_realm)
|
||||||
LOGGER.debug('With Arguments: %s', build_arguments)
|
logger.debug('With Arguments: %s', build_arguments)
|
||||||
|
|
||||||
return (self
|
return (self
|
||||||
.call("io.quay.builder.build", **build_arguments)
|
.call("io.quay.builder.build", **build_arguments)
|
||||||
|
@ -217,7 +217,7 @@ class BuildComponent(BaseComponent):
|
||||||
# the pull/push progress, as well as the current step index.
|
# the pull/push progress, as well as the current step index.
|
||||||
with self._build_status as status_dict:
|
with self._build_status as status_dict:
|
||||||
if self._build_status.set_phase(phase):
|
if self._build_status.set_phase(phase):
|
||||||
LOGGER.debug('Build %s has entered a new phase: %s', self.builder_realm, phase)
|
logger.debug('Build %s has entered a new phase: %s', self.builder_realm, phase)
|
||||||
|
|
||||||
BuildComponent._process_pushpull_status(status_dict, phase, docker_data, self._image_info)
|
BuildComponent._process_pushpull_status(status_dict, phase, docker_data, self._image_info)
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ class BuildComponent(BaseComponent):
|
||||||
})
|
})
|
||||||
|
|
||||||
build_id = self._current_job.repo_build().uuid
|
build_id = self._current_job.repo_build().uuid
|
||||||
LOGGER.warning('Build %s failed with message: %s', build_id, error_message)
|
logger.warning('Build %s failed with message: %s', build_id, error_message)
|
||||||
|
|
||||||
# Mark that the build has finished (in an error state)
|
# Mark that the build has finished (in an error state)
|
||||||
self._build_finished(BuildJobResult.ERROR)
|
self._build_finished(BuildJobResult.ERROR)
|
||||||
|
@ -283,11 +283,11 @@ class BuildComponent(BaseComponent):
|
||||||
|
|
||||||
def _on_ready(self, token):
|
def _on_ready(self, token):
|
||||||
if self._component_status != 'waiting':
|
if self._component_status != 'waiting':
|
||||||
LOGGER.warning('Build component (token "%s") is already connected', self.expected_token)
|
logger.warning('Build component (token "%s") is already connected', self.expected_token)
|
||||||
return
|
return
|
||||||
|
|
||||||
if token != self.expected_token:
|
if token != self.expected_token:
|
||||||
LOGGER.warning('Builder token mismatch. Expected: "%s". Found: "%s"', self.expected_token, token)
|
logger.warning('Builder token mismatch. Expected: "%s". Found: "%s"', self.expected_token, token)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._set_status(ComponentStatus.RUNNING)
|
self._set_status(ComponentStatus.RUNNING)
|
||||||
|
@ -295,7 +295,7 @@ class BuildComponent(BaseComponent):
|
||||||
# Start the heartbeat check and updating loop.
|
# Start the heartbeat check and updating loop.
|
||||||
loop = trollius.get_event_loop()
|
loop = trollius.get_event_loop()
|
||||||
loop.create_task(self._heartbeat())
|
loop.create_task(self._heartbeat())
|
||||||
LOGGER.debug('Build worker %s is connected and ready', self.builder_realm)
|
logger.debug('Build worker %s is connected and ready', self.builder_realm)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _set_status(self, phase):
|
def _set_status(self, phase):
|
||||||
|
@ -332,7 +332,7 @@ class BuildComponent(BaseComponent):
|
||||||
self.parent_manager.job_heartbeat(current_job)
|
self.parent_manager.job_heartbeat(current_job)
|
||||||
|
|
||||||
# Check the heartbeat from the worker.
|
# Check the heartbeat from the worker.
|
||||||
LOGGER.debug('Checking heartbeat on realm %s', self.builder_realm)
|
logger.debug('Checking heartbeat on realm %s', self.builder_realm)
|
||||||
if self._last_heartbeat and self._last_heartbeat < datetime.datetime.now() - HEARTBEAT_DELTA:
|
if self._last_heartbeat and self._last_heartbeat < datetime.datetime.now() - HEARTBEAT_DELTA:
|
||||||
self._timeout()
|
self._timeout()
|
||||||
return
|
return
|
||||||
|
@ -341,7 +341,7 @@ class BuildComponent(BaseComponent):
|
||||||
|
|
||||||
def _timeout(self):
|
def _timeout(self):
|
||||||
self._set_status(ComponentStatus.TIMED_OUT)
|
self._set_status(ComponentStatus.TIMED_OUT)
|
||||||
LOGGER.warning('Build component with realm %s has timed out', self.builder_realm)
|
logger.warning('Build component with realm %s has timed out', self.builder_realm)
|
||||||
self._dispose(timed_out=True)
|
self._dispose(timed_out=True)
|
||||||
|
|
||||||
def _dispose(self, timed_out=False):
|
def _dispose(self, timed_out=False):
|
||||||
|
|
|
@ -8,7 +8,7 @@ from buildman.manager.basemanager import BaseManager
|
||||||
from trollius.coroutines import From
|
from trollius.coroutines import From
|
||||||
|
|
||||||
REGISTRATION_REALM = 'registration'
|
REGISTRATION_REALM = 'registration'
|
||||||
LOGGER = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class DynamicRegistrationComponent(BaseComponent):
|
class DynamicRegistrationComponent(BaseComponent):
|
||||||
""" Component session that handles dynamic registration of the builder components. """
|
""" Component session that handles dynamic registration of the builder components. """
|
||||||
|
@ -17,12 +17,12 @@ class DynamicRegistrationComponent(BaseComponent):
|
||||||
self.join(REGISTRATION_REALM)
|
self.join(REGISTRATION_REALM)
|
||||||
|
|
||||||
def onJoin(self, details):
|
def onJoin(self, details):
|
||||||
LOGGER.debug('Registering registration method')
|
logger.debug('Registering registration method')
|
||||||
yield From(self.register(self._worker_register, u'io.quay.buildworker.register'))
|
yield From(self.register(self._worker_register, u'io.quay.buildworker.register'))
|
||||||
|
|
||||||
def _worker_register(self):
|
def _worker_register(self):
|
||||||
realm = self.parent_manager.add_build_component()
|
realm = self.parent_manager.add_build_component()
|
||||||
LOGGER.debug('Registering new build component+worker with realm %s', realm)
|
logger.debug('Registering new build component+worker with realm %s', realm)
|
||||||
return realm
|
return realm
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ from datetime import datetime, timedelta
|
||||||
from buildman.jobutil.buildjob import BuildJob, BuildJobLoadException
|
from buildman.jobutil.buildjob import BuildJob, BuildJobLoadException
|
||||||
from data.queue import WorkQueue
|
from data.queue import WorkQueue
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
WORK_CHECK_TIMEOUT = 10
|
WORK_CHECK_TIMEOUT = 10
|
||||||
TIMEOUT_PERIOD_MINUTES = 20
|
TIMEOUT_PERIOD_MINUTES = 20
|
||||||
|
@ -68,14 +68,14 @@ class BuilderServer(object):
|
||||||
self._controller_app = controller_app
|
self._controller_app = controller_app
|
||||||
|
|
||||||
def run(self, host, ssl=None):
|
def run(self, host, ssl=None):
|
||||||
LOGGER.debug('Initializing the lifecycle manager')
|
logger.debug('Initializing the lifecycle manager')
|
||||||
self._lifecycle_manager.initialize()
|
self._lifecycle_manager.initialize()
|
||||||
|
|
||||||
LOGGER.debug('Initializing all members of the event loop')
|
logger.debug('Initializing all members of the event loop')
|
||||||
loop = trollius.get_event_loop()
|
loop = trollius.get_event_loop()
|
||||||
trollius.Task(self._initialize(loop, host, ssl))
|
trollius.Task(self._initialize(loop, host, ssl))
|
||||||
|
|
||||||
LOGGER.debug('Starting server on port %s, with controller on port %s', WEBSOCKET_PORT,
|
logger.debug('Starting server on port %s, with controller on port %s', WEBSOCKET_PORT,
|
||||||
CONTROLLER_PORT)
|
CONTROLLER_PORT)
|
||||||
try:
|
try:
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
|
@ -85,17 +85,17 @@ class BuilderServer(object):
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
LOGGER.debug('Requested server shutdown')
|
logger.debug('Requested server shutdown')
|
||||||
self._current_status = 'shutting_down'
|
self._current_status = 'shutting_down'
|
||||||
self._lifecycle_manager.shutdown()
|
self._lifecycle_manager.shutdown()
|
||||||
self._shutdown_event.wait()
|
self._shutdown_event.wait()
|
||||||
LOGGER.debug('Shutting down server')
|
logger.debug('Shutting down server')
|
||||||
|
|
||||||
def _register_component(self, realm, component_klass, **kwargs):
|
def _register_component(self, realm, component_klass, **kwargs):
|
||||||
""" Registers a component with the server. The component_klass must derive from
|
""" Registers a component with the server. The component_klass must derive from
|
||||||
BaseComponent.
|
BaseComponent.
|
||||||
"""
|
"""
|
||||||
LOGGER.debug('Registering component with realm %s', realm)
|
logger.debug('Registering component with realm %s', realm)
|
||||||
|
|
||||||
component = component_klass(types.ComponentConfig(realm=realm), realm=realm, **kwargs)
|
component = component_klass(types.ComponentConfig(realm=realm), realm=realm, **kwargs)
|
||||||
component.server = self
|
component.server = self
|
||||||
|
@ -109,7 +109,7 @@ class BuilderServer(object):
|
||||||
return component
|
return component
|
||||||
|
|
||||||
def _unregister_component(self, component):
|
def _unregister_component(self, component):
|
||||||
LOGGER.debug('Unregistering component with realm %s and token %s',
|
logger.debug('Unregistering component with realm %s and token %s',
|
||||||
component.builder_realm, component.expected_token)
|
component.builder_realm, component.expected_token)
|
||||||
|
|
||||||
self._current_components.remove(component)
|
self._current_components.remove(component)
|
||||||
|
@ -137,25 +137,25 @@ class BuilderServer(object):
|
||||||
@trollius.coroutine
|
@trollius.coroutine
|
||||||
def _work_checker(self):
|
def _work_checker(self):
|
||||||
while self._current_status == 'running':
|
while self._current_status == 'running':
|
||||||
LOGGER.debug('Checking for more work')
|
logger.debug('Checking for more work')
|
||||||
job_item = self._queue.get(processing_time=self._lifecycle_manager.setup_time())
|
job_item = self._queue.get(processing_time=self._lifecycle_manager.setup_time())
|
||||||
if job_item is None:
|
if job_item is None:
|
||||||
LOGGER.debug('No additional work found. Going to sleep for %s seconds', WORK_CHECK_TIMEOUT)
|
logger.debug('No additional work found. Going to sleep for %s seconds', WORK_CHECK_TIMEOUT)
|
||||||
yield From(trollius.sleep(WORK_CHECK_TIMEOUT))
|
yield From(trollius.sleep(WORK_CHECK_TIMEOUT))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
build_job = BuildJob(job_item)
|
build_job = BuildJob(job_item)
|
||||||
except BuildJobLoadException as irbe:
|
except BuildJobLoadException as irbe:
|
||||||
LOGGER.exception(irbe)
|
logger.exception(irbe)
|
||||||
self._queue.incomplete(job_item, restore_retry=False)
|
self._queue.incomplete(job_item, restore_retry=False)
|
||||||
|
|
||||||
LOGGER.debug('Build job found. Checking for an avaliable worker.')
|
logger.debug('Build job found. Checking for an avaliable worker.')
|
||||||
if self._lifecycle_manager.schedule(build_job, self._loop):
|
if self._lifecycle_manager.schedule(build_job, self._loop):
|
||||||
self._job_count = self._job_count + 1
|
self._job_count = self._job_count + 1
|
||||||
LOGGER.debug('Build job scheduled. Running: %s', self._job_count)
|
logger.debug('Build job scheduled. Running: %s', self._job_count)
|
||||||
else:
|
else:
|
||||||
LOGGER.debug('All workers are busy. Requeuing.')
|
logger.debug('All workers are busy. Requeuing.')
|
||||||
self._queue.incomplete(job_item, restore_retry=True, retry_after=0)
|
self._queue.incomplete(job_item, restore_retry=True, retry_after=0)
|
||||||
|
|
||||||
yield From(trollius.sleep(WORK_CHECK_TIMEOUT))
|
yield From(trollius.sleep(WORK_CHECK_TIMEOUT))
|
||||||
|
|
Reference in a new issue