Skip to content

Commit

Permalink
Fixing wok_log redundancy and i18n.py error messages
Browse files Browse the repository at this point in the history
This patch removes wok_log calls when they are just
reproducing the same message of a call to a wok.exception
(NotFoundError, OperationFailed ...) class. Wok exceptions
already write the messages into the log and calling
wok_log is redundant.

Any other use of wok_log was preserved (logging a message
that didn't appear to the user, for example).

i18n.py messages were fixed along the way (wrong use of
message strings, typos, etc).

Files affected: model/diskparts.py, model/filesystem.py,
model/firmware.py, model/fs_utils.py, model/ibm_sep.py

Signed-off-by: Daniel Henrique Barboza <[email protected]>
  • Loading branch information
danielhb committed Jul 14, 2016
1 parent 32f2841 commit aea7709
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 59 deletions.
15 changes: 8 additions & 7 deletions i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@
"GINPOWER002E": _("Failed to retrieve power management profiles: Daemon 'tuned-adm' is not active."),
"GINPOWER003E": _("Failed to retrieve power management profiles: Package 'tuned-adm' is not installed."),
"GINPOWER004E": _("Error activating power saving profile %(profile)s, error: %(err)s."),
"GINFS00001E": _("Failed to retrieve details of the specified filesystem"),
"GINFS00002E": _("Failed to unmount the filesystems"),
"GINFS00001E": _("Failed to retrieve details of the %(name)s filesystem."),
"GINFS00002E": _("Failed to unmount filesystem %(name)s, error: %(err)s"),
"GINFS00003E": _("Parsing df output failed."),
"GINFS00004E": _("error in filesystem get list util"),
"GINFS00005E": _("error in filesystem info fetch util"),
Expand All @@ -213,12 +213,13 @@

"GINFS00011E": _("Unable to open fstab"),
"GINFS00012E": _("Unable to write fstab"),
"GINFS00013E": _("Failed to retrieve list of filesystems."),
"GINFS00013E": _("Failed to retrieve list of filesystems. Error: %(err)s"),
"GINFS00014E": _("required server ip addr"),
"GINFS00015E": _("required remote share location"),
"GINFS00016E": _("required type as local or nfs"),
"GINFS00017E": _("Invalid type needs to be either local or nfs"),
"GINFS00018E": _("NFS mount failed"),
"GINFS00019E": _("Filesystem %(name)s already mounted in fstab."),

"GINSP00001E": _("File location required for creating a swap device."),
"GINSP00002E": _("Type required for creating a swap device."),
Expand All @@ -241,13 +242,13 @@
"GINSP00019E": _("Unable to get single swap device info: directory /proc/swaps not found."),
"GINSP00020E": _("File already in use."),

"GINPART00001E": _("Fetching list of partitions failed"),
"GINPART00002E": _("Create partition failed"),
"GINPART00001E": _("Fetching list of partitions failed. Error: %(err)s"),
"GINPART00002E": _("Create partition failed. Error: %(err)s"),
"GINPART00003E": _("Error retrieving information of partition %(name)s : %(err)s"),
"GINPART00004E": _("Partition already mounted"),
"GINPART00005E": _("Format partition failed"),
"GINPART00006E": _("Change type for partition failed"),
"GINPART00007E": _("Delete partition failed"),
"GINPART00006E": _("Change type for partition failed. Error: %(err)s"),
"GINPART00007E": _("Delete partition failed. Error: %(err)s"),
"GINPART00008E": _("Required parameter device name"),
"GINPART00009E": _("Required parameter partition size"),
"GINPART00011E": _("fdisk command failed"),
Expand Down
19 changes: 7 additions & 12 deletions model/diskparts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from wok.model.tasks import TaskModel
from wok.plugins.gingerbase.disks import fetch_disks_partitions
from wok.plugins.gingerbase.disks import _get_vgname, get_partition_details
from wok.utils import add_task, wok_log
from wok.utils import add_task


class PartitionsModel(object):
Expand All @@ -34,9 +34,8 @@ def get_list(self, _name=None):
try:
result = fetch_disks_partitions()
except OperationFailed as e:
wok_log.error("Fetching list of partitions failed")
raise OperationFailed("GINPART00001E",
{'err': e})
{'err': e.message})
result_names = []
for i in result:
part_path = i['path']
Expand Down Expand Up @@ -66,9 +65,8 @@ def create(self, params):
try:
return utils.create_disk_part(dev_name, part_size)
except OperationFailed as e:
wok_log.error("Create partition failed")
raise OperationFailed("GINPART00002E",
{'err': e})
{'err': e.message})


class PartitionModel(object):
Expand All @@ -89,12 +87,11 @@ def lookup(self, name, dev=None):
return part_details

except NotFoundError:
wok_log.error("partition %s not found" % name)
raise NotFoundError("GINPART00014E", {'name': name})

except OperationFailed as e:
wok_log.error("lookup method of partition failed")
raise OperationFailed("GINPART00003E", {'name': name, 'err': e})
raise OperationFailed("GINPART00003E",
{'name': name, 'err': e.message})

def format(self, name, fstype):

Expand All @@ -120,15 +117,13 @@ def change_type(self, name, type):
try:
utils.change_part_type(name, type)
except OperationFailed as e:
wok_log.error("change type for partition failed")
raise OperationFailed("GINPART00006E",
{'err': e})
{'err': e.message})
return name

def delete(self, name):
try:
utils.delete_part(name)
except OperationFailed as e:
wok_log.error("delete partition failed")
raise OperationFailed("GINPART00007E",
{'err': e})
{'err': e.message})
10 changes: 2 additions & 8 deletions model/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from wok.exception import NotFoundError, OperationFailed
from wok.exception import InvalidParameter, MissingParameter
from wok.utils import wok_log


class FileSystemsModel(object):
Expand Down Expand Up @@ -83,9 +82,8 @@ def get_list(self):
fs_names = fs_utils._get_fs_names()

except OperationFailed as e:
wok_log.error("Fetching list of filesystems failed")
raise OperationFailed("GINFS00013E",
{'err': e})
{'err': e.message})

return fs_names

Expand All @@ -107,16 +105,12 @@ def lookup(self, name):
raise ValueError

except ValueError:
wok_log.error("Filesystem %s"
" not found." % name)
raise NotFoundError("GINFS00001E", {'name': name})

def delete(self, name):
try:
fs_utils._umount_partition(name)
fs_utils.remove_persist(name)
except OperationFailed as e:
wok_log.error("Unmounting filesystem %s"
" failed." % name)
raise OperationFailed("GINFS00002E",
{'err': e})
{'name': name, 'err': e.message})
9 changes: 1 addition & 8 deletions model/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, **kargs):
def lookup(self, *args):
output, error, rc = run_command('lsmcode')
if rc:
wok_log.error('Unable to retreive firmware level.')
wok_log.error('Unable to retrieve firmware level.')
return {'level': 'Unknown'}
# Cut out the chatter from the command output
# First, need check what type of output was returned due to diffs
Expand All @@ -66,13 +66,10 @@ def lookup(self, *args):

def upgrade(self, ident, fw_path=None, pow_ok=None):
if detect_live_vm():
wok_log.error('Cannot update system fw while running VMs.')
raise OperationFailed('GINFW0001E')

# Process argumets provided by user: firmware path and overwrite-perm
if fw_path is None:
wok_log.error('FW update failed: '
'No image file found in the package file.')
raise OperationFailed('GINFW0003E')

ms = magic.open(magic.NONE)
Expand All @@ -90,8 +87,6 @@ def upgrade(self, ident, fw_path=None, pow_ok=None):
image_file, ext = os.path.splitext(os.path.basename(fw_path))
image_file = os.path.join('/tmp/fwupdate', '%s.img' % image_file)
if not os.path.exists(image_file):
wok_log.error('FW update failed: '
'No image file found in the package file.')
raise OperationFailed('GINFW0003E')
else:
image_file = fw_path
Expand Down Expand Up @@ -146,10 +141,8 @@ def _execute_task(self, cb, params):

if rc:
if params['operation'] == 'update':
wok_log.error('Error flashing firmware. Details:\n %s' % error)
raise OperationFailed('GINFW0004E', {'error': error})
else:
wok_log.error('Async run_command error: ', error)
raise OperationFailed('GINFW0008E', {'error': error})

cb('OK', True)
14 changes: 3 additions & 11 deletions model/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def unpersist_swap_dev(dev):
output = []
fo.close()
except:
wok_log.error("Unable to open fstab")
raise OperationFailed("GINFS00011E")

try:
Expand All @@ -201,8 +200,7 @@ def unpersist_swap_dev(dev):
fo.writelines(output)
fo.close()
except:
wok_log.error("Unable to write fstab")
raise OperationFailed("GINFS00013E")
raise OperationFailed("GINFS00012E")


def _mnt_exists(mount):
Expand Down Expand Up @@ -238,16 +236,14 @@ def make_persist(dev, mntpt):
"""
try:
if _mnt_exists(mntpt):
wok_log.error("entry in fstab already exists")
raise OperationFailed("%s already mounted", mntpt)
raise OperationFailed("GINFS00019E", {'name': mntpt})
else:
fs_info = _get_fs_info(mntpt)
fo = open("/etc/fstab", "a+")
fo.write(dev + " " + mntpt + " " + fs_info['type'] + " " +
"defaults 1 2")
fo.close()
except:
wok_log.error("Unable to open fstab")
raise OperationFailed("GINFS00011E")


Expand All @@ -263,8 +259,7 @@ def remove_persist(mntpt):
output = []
fo.close()
except:
wok_log.error("Unable to open fstab")
raise OperationFailed("GINFS00012E")
raise OperationFailed("GINFS00011E")

try:
fo = open("/etc/fstab", "w")
Expand All @@ -276,7 +271,6 @@ def remove_persist(mntpt):
fo.writelines(output)
fo.close()
except:
wok_log.error("Unable to write fstab")
raise OperationFailed("GINFS00012E")


Expand All @@ -297,6 +291,4 @@ def nfsmount(server, share, mount_point):
nfs_cmd = ['mount', server + ':' + share, mount_point]
nfs_out, err, rc = run_command(nfs_cmd)
if rc:
wok_log.error("nfs mount failed")
raise OperationFailed("GINFS00018E", err)
return
14 changes: 1 addition & 13 deletions model/ibm_sep.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import re

from wok.exception import OperationFailed, NotFoundError
from wok.utils import wok_log, run_command
from wok.utils import run_command

SUBSCRIBER = re.compile("(Subscriber_[0-9]*: hostname=)(?P<hostname>.*)\
(,port=)(?P<port>.*)(,community=)(?P<community>.*)")
Expand All @@ -38,8 +38,6 @@ def addSEP(params):
'-c', params['community']]
output, error, rc = run_command(cmd)
if rc != 0:
wok_log.error('SEP execution error: %s - %s - %s' % (cmd, rc,
error))
raise OperationFailed('GINSEP0010E', {'error': error})

return params['hostname']
Expand All @@ -64,16 +62,12 @@ def start(self, params=None):
cmd = ['systemctl', 'start', 'sepctl']
output, error, rc = run_command(cmd)
if rc != 0:
wok_log.error('SEP service initialization error: %s - %s - %s'
% (cmd, rc, error))
raise OperationFailed('GINSEP0008E', {'error': error})

def stop(self, params=None):
cmd = ['systemctl', 'stop', 'sepctl']
output, error, rc = run_command(cmd)
if rc != 0:
wok_log.error('Error stopping SEP service: %s - %s - %s' % (cmd,
rc, error))
raise OperationFailed('GINSEP0009E', {'error': error})

def is_feature_available(self):
Expand All @@ -100,8 +94,6 @@ def _get_subscriber(self):

# error: report
if rc != 0:
wok_log.error('SEP execution error: %s - %s - %s' % (cmd, rc,
error))
raise OperationFailed('GINSEP0007E')

if len(output) > 1:
Expand Down Expand Up @@ -138,8 +130,6 @@ def lookup(self, subscription):

# error: report
if rc != 0:
wok_log.error('SEP execution error: %s - %s - %s' % (cmd, rc,
error))
raise OperationFailed('GINSEP0005E', {'error': error})

if len(output) > 1:
Expand Down Expand Up @@ -184,6 +174,4 @@ def delete(self, host):
output, error, rc = run_command(cmd)

if rc != 0:
wok_log.error('SEP execution error: %s - %s - %s' % (cmd, rc,
error))
raise OperationFailed('GINSEP0011E', {'error': error})

0 comments on commit aea7709

Please sign in to comment.