Replace is_valid_boolstr with strutils.bool_from_string method

Bug #1460575 reported by Rajesh Tailor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Undecided
Rajesh Tailor

Bug Description

Replace is_valid_boolstr with strutils.bool_from_string method
to remove code duplication. Also remove is_valid_boolstr method from cinder/utils module.

At some places in code where strutils.bool_from_string is already used but
unnecessary checking of basestring or bool type is also done.

Need to refactor that piece of code and remove unnecessary checking,
as strutils.bool_from_string first convert value to string and returns
accordingly boolean after taking default params into consideration as well.

for eg.:
Example: admin_actions.py->method _migrate_volume

if isinstance(force_host_copy, basestring):
            try:
                force_host_copy = strutils.bool_from_string(force_host_copy,
                                                            strict=True)
            except ValueError:
                raise exc.HTTPBadRequest(
                    explanation=_("Bad value for 'force_host_copy'"))
        elif not isinstance(force_host_copy, bool):
            raise exc.HTTPBadRequest(
                explanation=_("'force_host_copy' not string or bool"))

should be

try:
     force_host_copy = strutils.bool_from_string(force_host_copy, strict=True)
except ValueError:
    msg = _("Invalid value '%s' for force_host_copy.") % force_host_copy
    raise exc.HTTPBadRequest(explanation=msg)

Changed in cinder:
assignee: nobody → Rajesh Tailor (rajesh-tailor)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/187470

Changed in cinder:
status: New → In Progress
Revision history for this message
Rajesh Tailor (rajesh-tailor) wrote :

Hi,

In proposed patch, is_valid_boolstr method of cinder/utils module is not removed because it is being used by v1 api.

Changed in cinder:
status: In Progress → Fix Committed
Changed in cinder:
milestone: none → liberty-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in cinder:
milestone: liberty-2 → 7.0.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.