Fix up the imports on a recent change to follow coding spec

Essentially, we want to avoid doing:

    from module import f1, f2, f2

and instead doL

    import module

    module.f1()

This helps with reading the code and understanding where the functions
come from.

Change-Id: I1bc06441dc5595e8a0c84a5b5c3db5d88b68a4f2
This commit is contained in:
Alex Kavanagh 2017-10-25 14:21:46 +01:00
parent 52306f8419
commit b15237b3c5
3 changed files with 38 additions and 50 deletions

View File

@ -21,35 +21,23 @@ import sys
sys.path.append('lib')
sys.path.append('hooks')
from charmhelpers.core.hookenv import (
config,
action_get,
)
import charmhelpers.contrib.storage.linux.ceph as ch_ceph
import charmhelpers.core.hookenv as hookenv
from charmhelpers.contrib.storage.linux.ceph import (
CephBrokerRq,
send_request_if_needed,
)
from ceph.utils import (
osdize,
tune_dev,
)
from ceph_hooks import (
get_journal_devices,
)
import ceph_hooks
import ceph.utils
def add_device(request, device_path, bucket=None):
osdize(dev, config('osd-format'),
get_journal_devices(), config('osd-reformat'),
config('ignore-device-errors'),
config('osd-encrypt'),
config('bluestore'))
ceph.utils.osdize(dev, hookenv.config('osd-format'),
ceph_hooks.get_journal_devices(),
hookenv.config('osd-reformat'),
hookenv.config('ignore-device-errors'),
hookenv.config('osd-encrypt'),
hookenv.config('bluestore'))
# Make it fast!
if config('autotune'):
tune_dev(dev)
if hookenv.config('autotune'):
ceph.utils.tune_dev(dev)
mounts = filter(lambda disk: device_path
in disk.device, psutil.disk_partitions())
if mounts:
@ -64,7 +52,7 @@ def add_device(request, device_path, bucket=None):
def get_devices():
devices = []
for path in action_get('osd-devices').split(' '):
for path in hookenv.action_get('osd-devices').split(' '):
path = path.strip()
if os.path.isabs(path):
devices.append(path)
@ -73,9 +61,9 @@ def get_devices():
if __name__ == "__main__":
request = CephBrokerRq()
request = ch_ceph.CephBrokerRq()
for dev in get_devices():
request = add_device(request=request,
device_path=dev,
bucket=action_get("bucket"))
send_request_if_needed(request, relation='mon')
bucket=hookenv.action_get("bucket"))
ch_ceph.send_request_if_needed(request, relation='mon')

View File

@ -26,10 +26,10 @@ import sys
sys.path.append('hooks/')
sys.path.append('lib/')
from charmhelpers.core.hookenv import action_set
import charmhelpers.core.hookenv as hookenv
from ceph.utils import unmounted_disks
import ceph.utils
if __name__ == '__main__':
action_set({
'disks': unmounted_disks()})
hookenv.action_set({
'disks': ceph.utils.unmounted_disks()})

View File

@ -20,11 +20,9 @@ import sys
sys.path.append('hooks/')
sys.path.append('lib/')
from charmhelpers.core.hookenv import action_get, log, config, action_fail
import charmhelpers.core.hookenv as hookenv
from ceph.utils import (
replace_osd,
)
import ceph.utils
"""
Given a OSD number this script will attempt to turn that back into a mount
@ -38,9 +36,11 @@ def get_disk_stats():
with open('/proc/diskstats', 'r') as diskstats:
return diskstats.readlines()
except IOError as err:
log('Could not open /proc/diskstats. Error: {}'.format(err.message))
action_fail('replace-osd failed because /proc/diskstats could not '
'be opened {}'.format(err.message))
hookenv.log('Could not open /proc/diskstats. Error: {}'
.format(err.message))
hookenv.action_fail(
'replace-osd failed because /proc/diskstats could not '
'be opened {}'.format(err.message))
return None
@ -64,8 +64,8 @@ def lookup_device_name(major_number, minor_number):
# Found our device. Return its name
return parts[2]
except ValueError as value_err:
log('Could not convert {} or {} into an integer. Error: {}'
.format(parts[0], parts[1], value_err.message))
hookenv.log('Could not convert {} or {} into an integer. Error: {}'
.format(parts[0], parts[1], value_err.message))
continue
return None
@ -85,15 +85,15 @@ def get_device_number(osd_number):
if __name__ == '__main__':
dead_osd_number = action_get("osd-number")
replacement_device = action_get("replacement-device")
dead_osd_number = hookenv.action_get("osd-number")
replacement_device = hookenv.action_get("replacement-device")
major, minor = get_device_number(dead_osd_number)
device_name = lookup_device_name(major, minor)
osd_format = config('osd-format')
osd_journal = config('osd-journal')
osd_format = hookenv.config('osd-format')
osd_journal = hookenv.config('osd-journal')
replace_osd(dead_osd_number=dead_osd_number,
dead_osd_device="/dev/{}".format(device_name),
new_osd_device=replacement_device,
osd_format=osd_format,
osd_journal=osd_journal)
ceph.utils.replace_osd(dead_osd_number=dead_osd_number,
dead_osd_device="/dev/{}".format(device_name),
new_osd_device=replacement_device,
osd_format=osd_format,
osd_journal=osd_journal)