Skip to content

Commit

Permalink
minor code simplification and logging for issue rockstor#1494
Browse files Browse the repository at this point in the history
Move to single return in get_dev_byid_name to simplify
code and ease logging.
  • Loading branch information
phillxnet committed Nov 16, 2016
1 parent 2406857 commit 0939026
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/rockstor/system/osi.py
Expand Up @@ -1334,6 +1334,7 @@ def get_dev_byid_name(device_name, remove_path=False):
indicates if a by-id type name was found. ie (return_name, is_byid)
"""
logger.debug('GET_DEV_BYID_NAME CALLED WITH DEV-NAME=%s' % device_name)
logger.debug('GET_DEV_BYID_NAME remove path = %s' % remove_path)
# Until we find a by-id type name set this flag as False.
is_byid = False
# Until we find a by-id type name we will be returning device_name
Expand Down Expand Up @@ -1373,17 +1374,19 @@ def get_dev_byid_name(device_name, remove_path=False):
# Return the longest by-id name found in the DEVLINKS line
# or the first if multiple by-id names were of equal length.
return_name = byid_name
# Honour our path strip request in all cases if we can.
# Honour our path strip request in all cases if we can, or if
# no remove_path request by parameter flag or no path delimiter chars found
# in return_name then leave as is.
if remove_path:
# Strip the path from the beginning of our return_name.
# For use in Disk.name db field for example.
# Split return_name by path delimiter char '/' into it's fields.
return_name_fields = return_name.split('/')
if len(return_name_fields) > 1:
# Original device_name has path delimiters in: assume it has a path.
return return_name_fields[-1], is_byid
# No remove_path request by parameter flag or no path delimiter chars found
# in return_name so leave as is and returning.
# return return_name_fields[-1], is_byid
return_name = return_name_fields[-1]
logger.debug('GET_DEV_BYID_NAME RETURN=%s %s' % (return_name, is_byid))
return return_name, is_byid


Expand Down

0 comments on commit 0939026

Please sign in to comment.