Use c-style string interpolation for log messages in kolla-build

TrivialFix

Change-Id: I4b01402f8feb029563a90d4941c8d829a05794e0
This commit is contained in:
Michal Rostecki 2015-12-23 16:36:13 +01:00
parent 8eca1155f6
commit d7095790a2

View File

@ -74,9 +74,9 @@ class WorkerThread(Thread):
# an 'error' status # an 'error' status
for child in image['children']: for child in image['children']:
self.queue.put(child) self.queue.put(child)
LOG.debug('{}:Added image to queue'.format(child['name'])) LOG.debug('%s:Added image to queue', child['name'])
self.queue.task_done() self.queue.task_done()
LOG.debug('{}:Processed'.format(image['name'])) LOG.debug('%s:Processed', image['name'])
def run(self): def run(self):
"""Executes tasks until the queue is empty""" """Executes tasks until the queue is empty"""
@ -100,17 +100,16 @@ class WorkerThread(Thread):
dest_archive = os.path.join(image['path'], source['name'] + '-archive') dest_archive = os.path.join(image['path'], source['name'] + '-archive')
if source.get('type') == 'url': if source.get('type') == 'url':
LOG.debug("{}:Getting archive from {}".format(image['name'], LOG.debug("%s:Getting archive from %s", image['name'],
source['source'])) source['source'])
r = requests.get(source['source']) r = requests.get(source['source'])
if r.status_code == 200: if r.status_code == 200:
with open(dest_archive, 'wb') as f: with open(dest_archive, 'wb') as f:
f.write(r.content) f.write(r.content)
else: else:
LOG.error( LOG.error('%s:Failed to download archive: status_code %s',
'{}:Failed to download archive: status_code {}'.format( image['name'], r.status_code)
image['name'], r.status_code))
image['status'] = "error" image['status'] = "error"
return return
@ -118,16 +117,15 @@ class WorkerThread(Thread):
clone_dir = '{}-{}'.format(dest_archive, clone_dir = '{}-{}'.format(dest_archive,
source['reference'].replace('/', '-')) source['reference'].replace('/', '-'))
try: try:
LOG.debug("{}:Cloning from {}".format(image['name'], LOG.debug("%s:Cloning from %s", image['name'],
source['source'])) source['source'])
git.Git().clone(source['source'], clone_dir) git.Git().clone(source['source'], clone_dir)
LOG.debug("{}:Git checkout by reference {}".format( LOG.debug("%s:Git checkout by reference %s",
image['name'], source['reference'])) image['name'], source['reference'])
git.Git(clone_dir).checkout(source['reference']) git.Git(clone_dir).checkout(source['reference'])
except Exception as e: except Exception as e:
LOG.error("{}:Failed to get source from git".format( LOG.error("%s:Failed to get source from git", image['name'])
image['name'])) LOG.error("%s:Error:%s", image['name'], str(e))
LOG.error("{}:Error:{}".format(image['name'], str(e)))
# clean-up clone folder to retry # clean-up clone folder to retry
shutil.rmtree(clone_dir) shutil.rmtree(clone_dir)
image['status'] = "error" image['status'] = "error"
@ -137,8 +135,8 @@ class WorkerThread(Thread):
tar.add(clone_dir, arcname=os.path.basename(clone_dir)) tar.add(clone_dir, arcname=os.path.basename(clone_dir))
else: else:
LOG.error("{}:Wrong source type '{}'".format(image['name'], LOG.error("%s:Wrong source type '%s'", image['name'],
source.get('type'))) source.get('type'))
image['status'] = "error" image['status'] = "error"
return return
@ -148,20 +146,20 @@ class WorkerThread(Thread):
return dest_archive return dest_archive
def builder(self, image): def builder(self, image):
LOG.debug('{}:Processing'.format(image['name'])) LOG.debug('%s:Processing', image['name'])
if image['status'] == 'unmatched': if image['status'] == 'unmatched':
return return
if (image['parent'] is not None and if (image['parent'] is not None and
image['parent']['status'] in ['error', 'parent_error', image['parent']['status'] in ['error', 'parent_error',
'connection_error']): 'connection_error']):
LOG.error('{}:Parent image error\'d with message "{}"'.format( LOG.error('%s:Parent image error\'d with message "%s"',
image['name'], image['parent']['status'])) image['name'], image['parent']['status'])
image['status'] = "parent_error" image['status'] = "parent_error"
return return
image['status'] = "building" image['status'] = "building"
LOG.info('{}:Building'.format(image['name'])) LOG.info('%s:Building', image['name'])
if 'source' in image and 'source' in image['source']: if 'source' in image and 'source' in image['source']:
self.process_source(image, image['source']) self.process_source(image, image['source'])
@ -184,11 +182,11 @@ class WorkerThread(Thread):
os.mkdir(plugins_path) os.mkdir(plugins_path)
except OSError as e: except OSError as e:
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
LOG.info('Directory {} already exist. Skipping.'.format( LOG.info('Directory %s already exist. Skipping.',
plugins_path)) plugins_path)
else: else:
LOG.error('Failed to create directory {}: {}'.format( LOG.error('Failed to create directory %s: %s',
plugins_path, e)) plugins_path, e)
image['status'] = "error" image['status'] = "error"
return return
with tarfile.open(os.path.join(image['path'], 'plugins-archive'), with tarfile.open(os.path.join(image['path'], 'plugins-archive'),
@ -211,20 +209,20 @@ class WorkerThread(Thread):
image['logs'] = image['logs'] + stream['stream'] image['logs'] = image['logs'] + stream['stream']
for line in stream['stream'].split('\n'): for line in stream['stream'].split('\n'):
if line: if line:
LOG.info('{}:{}'.format(image['name'], line)) LOG.info('%s:%s', image['name'], line)
if 'errorDetail' in stream: if 'errorDetail' in stream:
image['status'] = "error" image['status'] = "error"
LOG.error('{}:Error\'d with the following message'.format( LOG.error('%s:Error\'d with the following message',
image['name'])) image['name'])
for line in stream['errorDetail']['message'].split('\n'): for line in stream['errorDetail']['message'].split('\n'):
if line: if line:
LOG.error('{}:{}'.format(image['name'], line)) LOG.error('%s:%s', image['name'], line)
return return
image['status'] = "built" image['status'] = "built"
LOG.info('{}:Built'.format(image['name'])) LOG.info('%s:Built', image['name'])
def get_kolla_version(): def get_kolla_version():
@ -412,7 +410,7 @@ class KollaWorker(object):
self.temp_dir = tempfile.mkdtemp(prefix='kolla-' + ts) self.temp_dir = tempfile.mkdtemp(prefix='kolla-' + ts)
self.working_dir = os.path.join(self.temp_dir, 'docker') self.working_dir = os.path.join(self.temp_dir, 'docker')
shutil.copytree(self.images_dir, self.working_dir) shutil.copytree(self.images_dir, self.working_dir)
LOG.debug('Created working dir: {}'.format(self.working_dir)) LOG.debug('Created working dir: %s', self.working_dir)
def set_time(self): def set_time(self):
for root, dirs, files in os.walk(self.working_dir): for root, dirs, files in os.walk(self.working_dir):
@ -455,9 +453,9 @@ class KollaWorker(object):
for root, dirs, names in os.walk(path): for root, dirs, names in os.walk(path):
if filename in names: if filename in names:
self.docker_build_paths.append(root) self.docker_build_paths.append(root)
LOG.debug('Found {}'.format(root.split(self.working_dir)[1])) LOG.debug('Found %s', root.split(self.working_dir)[1])
LOG.debug('Found {} Dockerfiles'.format(len(self.docker_build_paths))) LOG.debug('Found %d Dockerfiles', len(self.docker_build_paths))
def cleanup(self): def cleanup(self):
"""Remove temp files""" """Remove temp files"""
@ -477,12 +475,12 @@ class KollaWorker(object):
profile profile
).split(',') ).split(',')
except six.moves.configparser.NoSectionError: except six.moves.configparser.NoSectionError:
LOG.error('No [profiles] section found in {}'.format( LOG.error('No [profiles] section found in %s',
find_config_file('kolla-build.conf'))) find_config_file('kolla-build.conf'))
except six.moves.configparser.NoOptionError: except six.moves.configparser.NoOptionError:
LOG.error('No profile named "{}" found in {}'.format( LOG.error('No profile named "%s" found in %s',
self.profile, self.profile,
find_config_file('kolla-build.conf'))) find_config_file('kolla-build.conf'))
if filter_: if filter_:
patterns = re.compile(r"|".join(filter_).join('()')) patterns = re.compile(r"|".join(filter_).join('()'))
@ -495,7 +493,7 @@ class KollaWorker(object):
image['parent']['status'] != 'matched'): image['parent']['status'] != 'matched'):
image = image['parent'] image = image['parent']
image['status'] = 'matched' image['status'] = 'matched'
LOG.debug('{}:Matched regex'.format(image['name'])) LOG.debug('%s:Matched regex', image['name'])
else: else:
image['status'] = 'unmatched' image['status'] = 'unmatched'
else: else:
@ -508,11 +506,10 @@ class KollaWorker(object):
# to help us debug and it will be extra helpful in the gate. # to help us debug and it will be extra helpful in the gate.
for image in self.images: for image in self.images:
if image['status'] == 'error': if image['status'] == 'error':
LOG.debug("{}:Failed with the following logs".format( LOG.debug("%s:Failed with the following logs", image['name'])
image['name']))
for line in image['logs'].split('\n'): for line in image['logs'].split('\n'):
if line: if line:
LOG.debug("{}:{}".format(image['name'], ''.join(line))) LOG.debug("%s:%s", image['name'], ''.join(line))
self.get_image_statuses() self.get_image_statuses()
@ -526,8 +523,7 @@ class KollaWorker(object):
LOG.info("Images that failed to build") LOG.info("Images that failed to build")
LOG.info("===========================") LOG.info("===========================")
for name, status in six.iteritems(self.image_statuses_bad): for name, status in six.iteritems(self.image_statuses_bad):
LOG.error('{}\r\t\t\t Failed with status: {}'.format( LOG.error('{}\r\t\t\t Failed with status: %s', name, status)
name, status))
if self.image_statuses_unmatched: if self.image_statuses_unmatched:
LOG.debug("Images not matched for build by regex") LOG.debug("Images not matched for build by regex")
@ -566,7 +562,7 @@ class KollaWorker(object):
installation['reference'] = \ installation['reference'] = \
self.source_location.get(section, 'reference') self.source_location.get(section, 'reference')
except six.moves.configparser.NoSectionError: except six.moves.configparser.NoSectionError:
LOG.debug('{}:No source location found'.format(section)) LOG.debug('%s:No source location found', section)
return installation return installation
for path in self.docker_build_paths: for path in self.docker_build_paths:
@ -626,7 +622,7 @@ class KollaWorker(object):
for image in self.images: for image in self.images:
if image['parent'] is None: if image['parent'] is None:
queue.put(image) queue.put(image)
LOG.debug('{}:Added image to queue'.format(image['name'])) LOG.debug('%s:Added image to queue', image['name'])
return queue return queue
@ -642,7 +638,7 @@ def push_image(image):
if 'stream' in stream: if 'stream' in stream:
image['push_logs'] = image['logs'] + stream['stream'] image['push_logs'] = image['logs'] + stream['stream']
LOG.info('{}'.format(stream['stream'])) LOG.info('%s', stream['stream'])
elif 'errorDetail' in stream: elif 'errorDetail' in stream:
image['status'] = "error" image['status'] = "error"
LOG.error(stream['errorDetail']['message']) LOG.error(stream['errorDetail']['message'])
@ -661,7 +657,7 @@ def main():
kolla.create_dockerfiles() kolla.create_dockerfiles()
if config['template_only']: if config['template_only']:
LOG.info('Dockerfiles are generated in {}'.format(kolla.working_dir)) LOG.info('Dockerfiles are generated in %s', kolla.working_dir)
return return
# We set the atime and mtime to 0 epoch to preserve allow the Docker cache # We set the atime and mtime to 0 epoch to preserve allow the Docker cache