From 3e39ce2f1a190e2b9a361f691e6b5af1ae582655 Mon Sep 17 00:00:00 2001 From: Anirudha Bose Date: Mon, 11 Jul 2016 21:59:15 +0530 Subject: [PATCH] ceph-disk: Misc byte-string fixes Signed-off-by: Anirudha Bose --- src/ceph-disk/ceph_disk/main.py | 50 ++++++++++++++++++++++++--------- src/ceph-disk/tox.ini | 2 +- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index 57059ad28f1a32..77e60e3b967afb 100755 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -212,6 +212,7 @@ def is_dmcrypt(ptype, name): 'upstart', 'sysvinit', 'systemd', + 'openrc', 'auto', 'none', ] @@ -266,8 +267,8 @@ class Error(Exception): """ def __str__(self): - doc = self.__doc__.strip() - return ': '.join([doc] + [str(a) for a in self.args]) + doc = _bytes2str(self.__doc__.strip()) + return ': '.join([doc] + [_bytes2str(a) for a in self.args]) class MountError(Error): @@ -325,7 +326,7 @@ def is_systemd(): """ Detect whether systemd is running """ - with open('/proc/1/comm', 'rb') as f: + with open('/proc/1/comm', 'r') as f: return 'systemd' in f.read() @@ -381,7 +382,7 @@ def _get_command_executable(arguments): Return the full path for an executable, raise if the executable is not found. If the executable has already a full path do not perform any checks. """ - if arguments[0].startswith('/'): # an absolute path + if os.path.isabs(arguments[0]): # an absolute path return arguments executable = which(arguments[0]) if not executable: @@ -751,7 +752,7 @@ def is_mounted(dev): continue mounts_dev = fields[0] path = fields[1] - if mounts_dev.startswith(b'/') and os.path.exists(mounts_dev): + if os.path.isabs(mounts_dev) and os.path.exists(mounts_dev): mounts_dev = os.path.realpath(mounts_dev) if mounts_dev == dev: return _bytes2str(path) @@ -1977,8 +1978,7 @@ def prepare_file(self): ' (ceph-osd will resize and allocate)', self.name, getattr(self.args, self.name)) - with open(getattr(self.args, self.name), 'wb') as space_file: - pass + space_file = open(getattr(self.args, self.name), 'wb') LOG.debug('%s is file %s', self.name.capitalize(), @@ -1987,6 +1987,7 @@ def prepare_file(self): 'not the same device as the osd data' % self.name) self.space_symlink = space_file + space_file.close() def prepare_device(self): reusing_partition = False @@ -2876,6 +2877,20 @@ def start_daemon( 'ceph-osd@{osd_id}'.format(osd_id=osd_id), ], ) + elif os.path.exists(os.path.join(path, 'openrc')): + base_script = '/etc/init.d/ceph-osd' + osd_script = '{base}.{osd_id}'.format( + base=base_script, + osd_id=osd_id + ) + if not os.path.exists(osd_script): + os.symlink(base_script, osd_script) + command_check_call( + [ + osd_script, + 'start', + ], + ) else: raise Error('{cluster} osd.{osd_id} is not tagged ' 'with an init system'.format( @@ -2933,6 +2948,13 @@ def stop_daemon( 'ceph-osd@{osd_id}'.format(osd_id=osd_id), ], ) + elif os.path.exists(os.path.join(path, 'openrc')): + command_check_call( + [ + '/etc/init.d/ceph-osd.{osd_id}'.format(osd_id=osd_id), + 'stop', + ], + ) else: raise Error('{cluster} osd.{osd_id} is not tagged with an init ' ' system'.format(cluster=cluster, osd_id=osd_id)) @@ -3103,7 +3125,7 @@ def mount_activate( fstype=fstype, mount_options=mount_options, ) - return (cluster, osd_id) + return cluster, osd_id except: LOG.error('Failed to activate') @@ -3153,7 +3175,7 @@ def activate_dir( raise Error('unable to create symlink %s -> %s' % (canonical, path)) - return (cluster, osd_id) + return cluster, osd_id def find_cluster_by_uuid(_uuid): @@ -3547,7 +3569,7 @@ def _remove_lockbox(uuid): command(['umount', canonical]) for name in os.listdir(lockbox): path = os.path.join(lockbox, name) - if (os.path.islink(path) and os.readlink(path) == canonical): + if os.path.islink(path) and os.readlink(path) == canonical: os.unlink(path) @@ -3577,7 +3599,7 @@ def destroy_lookup_device(args, predicate, description): else: dmcrypt = False if predicate(partition): - return (dmcrypt, partition) + return dmcrypt, partition raise Error('found no device matching ', description) @@ -3779,7 +3801,7 @@ def is_swap(dev): if len(fields) < 3: continue swaps_dev = fields[0] - if swaps_dev.startswith(b'/') and os.path.exists(swaps_dev): + if os.path.isabs(swaps_dev) and os.path.exists(swaps_dev): swaps_dev = os.path.realpath(swaps_dev) if swaps_dev == dev: return True @@ -3818,7 +3840,7 @@ def split_dev_base_partnum(dev): b = block_path(dev) partnum = open(os.path.join(b, 'partition')).read().strip() base = get_partition_base(dev) - return (base, partnum) + return base, partnum def get_partition_type(part): @@ -4504,7 +4526,7 @@ def make_trigger_parser(subparsers): trigger_parser.add_argument( '--sync', action='store_true', default=None, - help=('do operation synchronously; do not trigger systemd'), + help='do operation synchronously; do not trigger systemd', ) trigger_parser.set_defaults( func=main_trigger, diff --git a/src/ceph-disk/tox.ini b/src/ceph-disk/tox.ini index b5231085b2174d..109c34ecaaebcf 100644 --- a/src/ceph-disk/tox.ini +++ b/src/ceph-disk/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = flake8,py27,py35 +envlist = flake8,py27,py34 [testenv] setenv =