Several stylistic fixes for upgarde system

* use unicode strings
* removed bin helpers which were used for development,
  use python setup.py instead
* import os module instead single path method
* fix imports order in utils.py file

Related to blueprint fuel-upgrade

Change-Id: Id9a906b05463c6bcb3abc51206e448264a920b40
This commit is contained in:
Evgeniy L 2014-03-24 18:06:06 +04:00
parent 4d81ad1c98
commit 1a090d52c7
9 changed files with 21 additions and 79 deletions

View File

@ -1,28 +0,0 @@
#!/usr/bin/env python
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import sys
sys.path[:0] = [os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))]
from fuel_update_downloader.cli import main
if __name__ == '__main__':
main()

View File

@ -24,7 +24,7 @@ from fuel_update_downloader import errors
def handle_exception(exc):
if isinstance(exc, errors.FuelUpgradeException):
sys.stderr.write(str(exc) + "\n")
sys.stderr.write(exc.message + "\n")
sys.exit(-1)
else:
traceback.print_exc(exc)

View File

@ -53,7 +53,7 @@ class Downloader(object):
free_space = calculate_free_space(self.dst_path)
if free_space < self.required_free_space:
raise errors.NotEnoughFreeSpace(
'Not enough free space, path - "{0}", '
u'Not enough free space, path - "{0}", '
'free space - "{1}", '
'required free space - "{2}"'.format(
self.dst_path, free_space, self.required_free_space))
@ -66,6 +66,6 @@ class Downloader(object):
calculated_checksum = calculate_md5sum(self.dst_path)
if calculated_checksum != self.checksum:
raise errors.WrongChecksum(
'File "{0}" has wrong checkum, actual '
u'File "{0}" has wrong checkum, actual '
'checksum "{1}" expected checksum "{2}"'.format(
self.dst_path, calculated_checksum, self.checksum))

View File

@ -22,7 +22,7 @@ from setuptools import setup
def find_requires():
dir_path = os.path.dirname(os.path.realpath(__file__))
requirements = []
with open('{0}/requirements.txt'.format(dir_path), 'r') as reqs:
with open(u'{0}/requirements.txt'.format(dir_path), 'r') as reqs:
requirements = reqs.readlines()
return requirements

View File

@ -1,28 +0,0 @@
#!/usr/bin/env python
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import sys
sys.path[:0] = [os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))]
from fuel_upgrade.cli import main
if __name__ == '__main__':
main()

View File

@ -14,16 +14,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from fuel_upgrade.logger import configure_logger
# TODO(eli): move to config
logger = configure_logger('/tmp/file.log')
import argparse
import sys
import traceback
from fuel_upgrade.logger import configure_logger
# TODO(eli): move to config
logger = configure_logger('/tmp/file.log')
from fuel_upgrade import errors
from fuel_upgrade.upgrade import PuppetUpgrader
from fuel_upgrade.upgrade import Upgrade
@ -31,8 +29,7 @@ from fuel_upgrade.upgrade import Upgrade
def handle_exception(exc):
if isinstance(exc, errors.FuelUpgradeException):
err_msg = str(exc)
logger.error(err_msg)
logger.error(exc.message)
sys.exit(-1)
else:
traceback.print_exc(exc)

View File

@ -15,10 +15,9 @@
# under the License.
import logging
import os
import traceback
from os import path
from fuel_upgrade.utils import exec_cmd
logger = logging.getLogger(__name__)
@ -33,8 +32,10 @@ class PuppetUpgrader(object):
puppet_modules_dir = 'puppet_modules'
def __init__(self, update_path):
puppet_modules_path = path.join(update_path, self.puppet_modules_dir)
self.puppet_cmd = 'puppet apply --debug --modulepath={0} -e '.format(
puppet_modules_path = os.path.join(
update_path, self.puppet_modules_dir)
self.puppet_cmd = u'puppet apply --debug --modulepath={0} -e '.format(
puppet_modules_path)
def upgrade(self):
@ -58,7 +59,7 @@ class Upgrade(object):
disable_rollback=False):
logger.debug(
'Create Upgrade object with update path "{0}", '
u'Create Upgrade object with update path "{0}", '
'working directory "{1}", '
'upgrade engine "{2}", '
'disable rollback is "{3}"'.format(
@ -78,7 +79,7 @@ class Upgrade(object):
self.upgrade()
self.after_upgrade()
except Exception as exc:
logger.error('Upgrade failed: {0}'.format(exc))
logger.error(u'Upgrade failed: {0}'.format(exc))
logger.error(traceback.format_exc())
if not self.disable_rollback:
self.rollback()

View File

@ -30,13 +30,13 @@ def exec_cmd(cmd):
:param cmd: shell command
:raises: ExecutedErrorNonZeroExitCode
"""
logger.debug('Execute command "{0}"'.format(cmd))
logger.debug(u'Execute command "{0}"'.format(cmd))
child = subprocess.Popen(
cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)
logger.debug('Stdout and stderr of command "{0}":'.format(cmd))
logger.debug(u'Stdout and stderr of command "{0}":'.format(cmd))
for line in child.stdout:
logger.debug(line.rstrip())
@ -45,7 +45,7 @@ def exec_cmd(cmd):
if return_code != 0:
raise errors.ExecutedErrorNonZeroExitCode(
'Shell command executed with "{0}" '
u'Shell command executed with "{0}" '
'exit code: {1} '.format(return_code, cmd))
logger.debug('Command "{0}" successfully executed'.format(cmd))
logger.debug(u'Command "{0}" successfully executed'.format(cmd))

View File

@ -22,7 +22,7 @@ from setuptools import setup
def find_requires():
dir_path = os.path.dirname(os.path.realpath(__file__))
requirements = []
with open('{0}/requirements.txt'.format(dir_path), 'r') as reqs:
with open(u'{0}/requirements.txt'.format(dir_path), 'r') as reqs:
requirements = reqs.readlines()
return requirements