Skip to content

Commit

Permalink
ceph-disk: Misc byte-string fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudha Bose <ani07nov@gmail.com>
  • Loading branch information
onyb committed Jul 15, 2016
1 parent bcfd45b commit 3e39ce2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
50 changes: 36 additions & 14 deletions src/ceph-disk/ceph_disk/main.py
Expand Up @@ -212,6 +212,7 @@ def is_dmcrypt(ptype, name):
'upstart',
'sysvinit',
'systemd',
'openrc',
'auto',
'none',
]
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-disk/tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = flake8,py27,py35
envlist = flake8,py27,py34

[testenv]
setenv =
Expand Down

0 comments on commit 3e39ce2

Please sign in to comment.