Merge "Pass all logging messages as strings"
This commit is contained in:
commit
e8dcb431fe
|
@ -22,7 +22,7 @@ from setuptools import setup
|
|||
def find_requires():
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
requirements = []
|
||||
with open(u'{0}/requirements.txt'.format(dir_path), 'r') as reqs:
|
||||
with open('{0}/requirements.txt'.format(dir_path), 'r') as reqs:
|
||||
requirements = reqs.readlines()
|
||||
return requirements
|
||||
|
||||
|
|
|
@ -122,33 +122,33 @@ class SupervisorClient(object):
|
|||
def start_all_services(self):
|
||||
"""Stops all processes
|
||||
"""
|
||||
logger.info(u'Start all services')
|
||||
logger.info('Start all services')
|
||||
self.supervisor.startAllProcesses()
|
||||
|
||||
def stop_all_services(self):
|
||||
"""Stops all processes
|
||||
"""
|
||||
logger.info(u'Stop all services')
|
||||
logger.info('Stop all services')
|
||||
self.supervisor.stopAllProcesses()
|
||||
|
||||
def restart_and_wait(self):
|
||||
"""Restart supervisor and wait untill it will be available
|
||||
"""
|
||||
logger.info(u'Restart supervisor')
|
||||
logger.info('Restart supervisor')
|
||||
self.supervisor.restart()
|
||||
|
||||
all_processes = utils.wait_for_true(
|
||||
lambda: self.get_all_processes_safely() is not None,
|
||||
timeout=self.config.supervisor['restart_timeout'])
|
||||
|
||||
logger.debug(u'List of supervisor processes %s', all_processes)
|
||||
logger.debug('List of supervisor processes %s', all_processes)
|
||||
|
||||
def start(self, service_name):
|
||||
"""Start the process under supervisor
|
||||
|
||||
:param str service_name: name of supervisor's process
|
||||
"""
|
||||
logger.debug(u'Start supervisor process %s', service_name)
|
||||
logger.debug('Start supervisor process %s', service_name)
|
||||
self.supervisor.startProcess(service_name)
|
||||
|
||||
def get_all_processes_safely(self):
|
||||
|
@ -174,7 +174,7 @@ class SupervisorClient(object):
|
|||
`autostart` - run the service on supervisor start
|
||||
"""
|
||||
logger.info(
|
||||
u'Generate supervisor configs for services %s', services)
|
||||
'Generate supervisor configs for services %s', services)
|
||||
|
||||
for service in services:
|
||||
self.generate_config(
|
||||
|
|
|
@ -119,7 +119,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
def save_db(self):
|
||||
"""Saves postgresql database into the file
|
||||
"""
|
||||
logger.debug(u'Backup database')
|
||||
logger.debug('Backup database')
|
||||
pg_dump_path = os.path.join(self.working_directory, 'pg_dump_all.sql')
|
||||
pg_dump_files = utils.VersionedFile(pg_dump_path)
|
||||
pg_dump_tmp_path = pg_dump_files.next_file_name()
|
||||
|
@ -137,7 +137,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
valid_dumps[self.config.keep_db_backups_count:])
|
||||
else:
|
||||
raise errors.DatabaseDumpError(
|
||||
u'Failed to make database dump, there '
|
||||
'Failed to make database dump, there '
|
||||
'are no valid database backup '
|
||||
'files, {0}'.format(pg_dump_path))
|
||||
|
||||
|
@ -159,7 +159,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
|
||||
self.exec_cmd_in_container(
|
||||
container_name,
|
||||
u"su postgres -c 'pg_dumpall --clean' > {0}".format(
|
||||
"su postgres -c 'pg_dumpall --clean' > {0}".format(
|
||||
pg_dump_tmp_path))
|
||||
except (errors.ExecutedErrorNonZeroExitCode,
|
||||
errors.CannotFindContainerError) as exc:
|
||||
|
@ -169,7 +169,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
return False
|
||||
|
||||
logger.debug(
|
||||
u'Failed to make database dump, '
|
||||
'Failed to make database dump, '
|
||||
'will be used dump from previous run: %s', exc)
|
||||
|
||||
return True
|
||||
|
@ -203,41 +203,41 @@ class DockerUpgrader(UpgradeEngine):
|
|||
# contain at least one file (default.json)
|
||||
if len(configs) < 1:
|
||||
raise errors.WrongCobblerConfigsError(
|
||||
u'Cannot find json files in directory {0}'.format(
|
||||
'Cannot find json files in directory {0}'.format(
|
||||
self.cobbler_config_path))
|
||||
|
||||
for config in configs:
|
||||
if not utils.check_file_is_valid_json(config):
|
||||
raise errors.WrongCobblerConfigsError(
|
||||
u'Invalid json config {0}'.format(config))
|
||||
'Invalid json config {0}'.format(config))
|
||||
|
||||
def upload_images(self):
|
||||
"""Uploads images to docker
|
||||
"""
|
||||
logger.info(u'Start image uploading')
|
||||
logger.info('Start image uploading')
|
||||
|
||||
if not os.path.exists(self.config.images):
|
||||
logger.warn(u'Cannot find docker images "%s"', self.config.images)
|
||||
logger.warn('Cannot find docker images "%s"', self.config.images)
|
||||
return
|
||||
|
||||
# NOTE(eli): docker-py binding
|
||||
# doesn't have equal call for
|
||||
# image importing which equals to
|
||||
# `docker load`
|
||||
utils.exec_cmd(u'docker load -i "{0}"'.format(self.config.images))
|
||||
utils.exec_cmd('docker load -i "{0}"'.format(self.config.images))
|
||||
|
||||
def create_and_start_new_containers(self):
|
||||
"""Create containers in the right order
|
||||
"""
|
||||
logger.info(u'Started containers creation')
|
||||
logger.info('Started containers creation')
|
||||
graph = self.build_dependencies_graph(self.new_release_containers)
|
||||
logger.debug(u'Built dependencies graph %s', graph)
|
||||
logger.debug('Built dependencies graph %s', graph)
|
||||
containers_to_creation = utils.topological_sorting(graph)
|
||||
logger.debug(u'Resolved creation order %s', containers_to_creation)
|
||||
logger.debug('Resolved creation order %s', containers_to_creation)
|
||||
|
||||
for container_id in containers_to_creation:
|
||||
container = self.container_by_id(container_id)
|
||||
logger.debug(u'Start container %s', container)
|
||||
logger.debug('Start container %s', container)
|
||||
|
||||
links = self.get_container_links(container)
|
||||
|
||||
|
@ -367,7 +367,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
params = {
|
||||
'config_name': container['id'],
|
||||
'service_name': self.make_service_name(container['id']),
|
||||
'command': u'docker start -a {0}'.format(
|
||||
'command': 'docker start -a {0}'.format(
|
||||
container['container_name']),
|
||||
'autostart': autostart
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
containers)
|
||||
|
||||
for container in containers_to_stop:
|
||||
logger.debug(u'Stop container: %s', container)
|
||||
logger.debug('Stop container: %s', container)
|
||||
|
||||
self.stop_container(container['Id'])
|
||||
|
||||
|
@ -448,7 +448,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
|
||||
:param container_id: container id
|
||||
"""
|
||||
logger.debug(u'Stop container: %s', container_id)
|
||||
logger.debug('Stop container: %s', container_id)
|
||||
|
||||
try:
|
||||
self.docker_client.stop(
|
||||
|
@ -460,7 +460,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
# Here we just want to make sure that
|
||||
# container was stopped.
|
||||
logger.warn(
|
||||
u'Couldn\'t stop ctonainer, try '
|
||||
'Couldn\'t stop ctonainer, try '
|
||||
'to stop it again: %s', container_id)
|
||||
self.docker_client.stop(
|
||||
container_id, self.config.docker['stop_container_timeout'])
|
||||
|
@ -471,7 +471,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
:param container: container name
|
||||
:param params: dict of arguments for container starting
|
||||
"""
|
||||
logger.debug(u'Start container "%s": %s', container['Id'], params)
|
||||
logger.debug('Start container "%s": %s', container['Id'], params)
|
||||
self.docker_client.start(container['Id'], **params)
|
||||
|
||||
def create_container(self, image_name, **params):
|
||||
|
@ -491,7 +491,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
new_params = deepcopy(params)
|
||||
new_params['ports'] = self.get_ports(new_params)
|
||||
|
||||
logger.debug(u'Create container from image %s: %s',
|
||||
logger.debug('Create container from image %s: %s',
|
||||
image_name, new_params)
|
||||
|
||||
def func_create():
|
||||
|
@ -531,7 +531,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
if version is None:
|
||||
version = self.config.new_version
|
||||
|
||||
return u'{0}{1}-{2}'.format(
|
||||
return '{0}{1}-{2}'.format(
|
||||
self.config.container_prefix, version, container_id)
|
||||
|
||||
def make_image_name(self, image_id):
|
||||
|
@ -540,7 +540,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
:param image_id: image id from config file
|
||||
:returns: full name
|
||||
"""
|
||||
return u'{0}{1}_{2}'.format(
|
||||
return '{0}{1}_{2}'.format(
|
||||
self.config.image_prefix,
|
||||
image_id,
|
||||
self.config.new_version)
|
||||
|
@ -587,7 +587,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
|
||||
for container in found_containers:
|
||||
self.stop_container(container['Id'])
|
||||
logger.debug(u'Delete container %s', container)
|
||||
logger.debug('Delete container %s', container)
|
||||
|
||||
# TODO(eli): refactor it and make retries
|
||||
# as a decorator
|
||||
|
@ -603,7 +603,7 @@ class DockerUpgrader(UpgradeEngine):
|
|||
|
||||
def _get_containers_by_name(self, container_name):
|
||||
return filter(
|
||||
lambda c: u'/{0}'.format(container_name) in c['Names'],
|
||||
lambda c: '/{0}'.format(container_name) in c['Names'],
|
||||
self.docker_client.containers(all=True))
|
||||
|
||||
def _delete_containers_for_image(self, image):
|
||||
|
@ -620,10 +620,10 @@ class DockerUpgrader(UpgradeEngine):
|
|||
all_containers)
|
||||
|
||||
for container in containers:
|
||||
logger.debug(u'Try to stop container %s which '
|
||||
logger.debug('Try to stop container %s which '
|
||||
'depends on image %s', container['Id'], image)
|
||||
self.docker_client.stop(container['Id'])
|
||||
logger.debug(u'Delete container %s which '
|
||||
logger.debug('Delete container %s which '
|
||||
'depends on image %s', container['Id'], image)
|
||||
self.docker_client.remove_container(container['Id'])
|
||||
|
||||
|
@ -645,4 +645,4 @@ class DockerInitializer(DockerUpgrader):
|
|||
self.supervisor.restart_and_wait()
|
||||
|
||||
def rollback(self):
|
||||
logger.warn(u"DockerInitializer doesn't support rollback")
|
||||
logger.warn("DockerInitializer doesn't support rollback")
|
||||
|
|
|
@ -55,7 +55,7 @@ class MoveKeysHook(PreUpgradeHookBase):
|
|||
if not utils.file_exists(self.dst_path):
|
||||
os.makedirs(self.dst_path)
|
||||
|
||||
container_name = u'{0}{1}-astute'.format(
|
||||
container_name = '{0}{1}-astute'.format(
|
||||
self.config.container_prefix, self.config.from_version)
|
||||
try:
|
||||
utils.exec_cmd('docker cp {0}:{1} {2}'.format(
|
||||
|
|
|
@ -48,13 +48,13 @@ def exec_cmd(cmd):
|
|||
|
||||
:param cmd: shell command
|
||||
"""
|
||||
logger.debug(u'Execute command "%s"', cmd)
|
||||
logger.debug('Execute command "%s"', cmd)
|
||||
child = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=True)
|
||||
|
||||
logger.debug(u'Stdout and stderr of command "%s":', cmd)
|
||||
logger.debug('Stdout and stderr of command "%s":', cmd)
|
||||
for line in child.stdout:
|
||||
logger.debug(line.rstrip())
|
||||
|
||||
|
@ -82,13 +82,13 @@ def exec_cmd_iterator(cmd):
|
|||
:returns: generator where yeach item
|
||||
is line from stdout
|
||||
"""
|
||||
logger.debug(u'Execute command "%s"', cmd)
|
||||
logger.debug('Execute command "%s"', cmd)
|
||||
child = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=True)
|
||||
|
||||
logger.debug(u'Stdout and stderr of command "%s":', cmd)
|
||||
logger.debug('Stdout and stderr of command "%s":', cmd)
|
||||
for line in child.stdout:
|
||||
logger.debug(line.rstrip())
|
||||
yield line
|
||||
|
@ -108,10 +108,10 @@ def _wait_and_check_exit_code(cmd, child):
|
|||
|
||||
if exit_code != 0:
|
||||
raise errors.ExecutedErrorNonZeroExitCode(
|
||||
u'Shell command executed with "{0}" '
|
||||
'Shell command executed with "{0}" '
|
||||
'exit code: {1} '.format(exit_code, cmd))
|
||||
|
||||
logger.debug(u'Command "%s" successfully executed', cmd)
|
||||
logger.debug('Command "%s" successfully executed', cmd)
|
||||
|
||||
|
||||
def get_request(url):
|
||||
|
@ -155,7 +155,7 @@ def topological_sorting(dep_graph):
|
|||
|
||||
if cyclic:
|
||||
raise errors.CyclicDependenciesError(
|
||||
u'Cyclic dependencies error {0}'.format(graph))
|
||||
'Cyclic dependencies error {0}'.format(graph))
|
||||
|
||||
return sorted_nodes
|
||||
|
||||
|
@ -215,7 +215,7 @@ def symlink(source, destination, overwrite=True):
|
|||
:param overwrite: overwrite a destination if True
|
||||
"""
|
||||
logger.debug(
|
||||
u'Symlinking "%s" -> "%s" [overwrite=%d]',
|
||||
'Symlinking "%s" -> "%s" [overwrite=%d]',
|
||||
source, destination, overwrite)
|
||||
|
||||
if overwrite or not os.path.exists(destination):
|
||||
|
@ -234,7 +234,7 @@ def symlink_if_src_exists(source, destination, overwrite=True):
|
|||
"""
|
||||
if not os.path.exists(source):
|
||||
logger.debug(
|
||||
u'Skip creating symlink, because "%s" does not exists', source)
|
||||
'Skip creating symlink, because "%s" does not exists', source)
|
||||
return
|
||||
symlink(source, destination, overwrite=overwrite)
|
||||
|
||||
|
@ -247,7 +247,7 @@ def hardlink(source, destination, overwrite=True):
|
|||
:param overwrite: overwrite a destination if True
|
||||
"""
|
||||
logger.debug(
|
||||
u'Creating hardlink "%s" -> "%s" [overwrite=%d]',
|
||||
'Creating hardlink "%s" -> "%s" [overwrite=%d]',
|
||||
source, destination, overwrite)
|
||||
|
||||
if overwrite or not os.path.exists(destination):
|
||||
|
@ -263,7 +263,7 @@ def remove_if_exists(path):
|
|||
:param path: path to file for removal
|
||||
"""
|
||||
if os.path.exists(path):
|
||||
logger.debug(u'Remove file "%s"', path)
|
||||
logger.debug('Remove file "%s"', path)
|
||||
os.remove(path)
|
||||
|
||||
|
||||
|
@ -277,7 +277,7 @@ def file_contains_lines(file_path, patterns):
|
|||
False if file doesn't match one or more patterns
|
||||
"""
|
||||
logger.debug(
|
||||
u'Check if file "%s" matches to pattern "%s"', file_path, patterns)
|
||||
'Check if file "%s" matches to pattern "%s"', file_path, patterns)
|
||||
|
||||
regexps = [re.compile(pattern) for pattern in patterns]
|
||||
|
||||
|
@ -351,7 +351,7 @@ def copy_file(source, destination, overwrite=True):
|
|||
:param overwrite: overwrite destination if True
|
||||
"""
|
||||
logger.debug(
|
||||
u'Copying "%s" -> "%s" [overwrite=%d]',
|
||||
'Copying "%s" -> "%s" [overwrite=%d]',
|
||||
source, destination, overwrite)
|
||||
|
||||
# tranform destinatio to path/to/file, not path/to/dir
|
||||
|
@ -375,7 +375,7 @@ def copy_dir(source, destination, overwrite=True, symlinks=True):
|
|||
:param symlinks: resolve symlinks if True
|
||||
"""
|
||||
logger.debug(
|
||||
u'Copying "%s" -> "%s" [overwrite=%d symlinks=%d]',
|
||||
'Copying "%s" -> "%s" [overwrite=%d symlinks=%d]',
|
||||
source, destination, overwrite, symlinks)
|
||||
|
||||
if overwrite or not os.path.lexists(destination):
|
||||
|
@ -393,7 +393,7 @@ def remove(path, ignore_errors=True):
|
|||
:param path: a file or directory to remove
|
||||
:param ignore_errors: ignore some errors and non existense if True
|
||||
"""
|
||||
logger.debug(u'Removing "%s"', path)
|
||||
logger.debug('Removing "%s"', path)
|
||||
|
||||
if ignore_errors and not os.path.lexists(path):
|
||||
return
|
||||
|
@ -410,7 +410,7 @@ def rmtree(source, ignore_errors=True):
|
|||
:param str source: path to directory
|
||||
:param bool ignore_errors: ignores error if True
|
||||
"""
|
||||
logger.debug(u'Removing %s', source)
|
||||
logger.debug('Removing %s', source)
|
||||
if os.path.exists(source):
|
||||
shutil.rmtree(source, ignore_errors=ignore_errors)
|
||||
|
||||
|
@ -424,7 +424,7 @@ def rename(source, destination, overwrite=True):
|
|||
:param str destination: rename to
|
||||
"""
|
||||
logger.debug(
|
||||
u'Renaming "%s" -> "%s" [overwrite=%d]',
|
||||
'Renaming "%s" -> "%s" [overwrite=%d]',
|
||||
source, destination, overwrite)
|
||||
|
||||
if overwrite or not os.path.exists(destination):
|
||||
|
|
|
@ -65,7 +65,7 @@ class VersionFile(object):
|
|||
* creates new version yaml file
|
||||
* and creates symlink to /etc/fuel/version.yaml
|
||||
"""
|
||||
logger.info(u'Switch version file to new version')
|
||||
logger.info('Switch version file to new version')
|
||||
|
||||
utils.create_dir_if_not_exists(os.path.dirname(
|
||||
self.dst_new_version_file))
|
||||
|
@ -81,5 +81,5 @@ class VersionFile(object):
|
|||
def switch_to_previous(self):
|
||||
"""Switch version file symlink to previous version
|
||||
"""
|
||||
logger.info(u'Switch current version file to previous version')
|
||||
logger.info('Switch current version file to previous version')
|
||||
utils.symlink(self.previous_version_file, self.current_version_file)
|
||||
|
|
Loading…
Reference in New Issue