there is no need to check if the input is None or not.

Bug #1675630 reported by Jeffrey Guan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
senlin
Fix Released
Undecided
Jeffrey Guan

Bug Description

Found on Master branch.

Description:

For the function validate in senlin/policies/scaling_policy.py, the check to make sure self.adjustment_number,
 self.adjustment_min_step and self.cooldown is not needed.
    def validate(self, context, validate_props=False):
        super(ScalingPolicy, self).validate(context, validate_props)

        if self.adjustment_number is not None and self.adjustment_number <= 0:
            msg = _("the 'number' for 'adjustment' must be > 0")
            raise exc.InvalidSpec(message=msg)

        if (self.adjustment_min_step is not None and
                self.adjustment_min_step < 0):
            msg = _("the 'min_step' for 'adjustment' must be >= 0")
            raise exc.InvalidSpec(message=msg)

        if self.cooldown is not None and self.cooldown < 0:
            msg = _("the 'cooldown' for 'adjustment' must be >= 0")
            raise exc.InvalidSpec(message=msg)

Analysis:

Take self.adjustment_number for example. It's type is constrained to schema.Number, and in the Number class,
there is a function to_schema_type():
278 def to_schema_type(self, value):
279 if isinstance(value, numbers.Number):
280 return value
281
282 try:
283 return int(value)
284 except ValueError:
285 try:
286 return float(value)
287 except ValueError:
288 msg = _("The value '%s' is not a valid number.") % value
289 raise exc.ESchema(message=msg)

and a check already here, in my opinion, there is no need to do extra check-none in the function "validate".

Changed in senlin:
assignee: nobody → Jeffrey Guan (double12gzh)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to senlin (master)

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

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to senlin (master)

Reviewed: https://review.openstack.org/449430
Committed: https://git.openstack.org/cgit/openstack/senlin/commit/?id=b39f22f35dcf4fdabc8ff8b30a59d4412955a7b4
Submitter: Jenkins
Branch: master

commit b39f22f35dcf4fdabc8ff8b30a59d4412955a7b4
Author: Jeffrey Guan <double12gzh@163.com>
Date: Fri Mar 24 01:00:38 2017 -0400

    There is no need to check if the input is None or not.

    Found on Master branch.

    For the function "validate" in senlin/policies/scaling_policy.py,
    the check to make sure self.adjustment_min_step,
    self.cooldown and self.adjustment_number is validate is not needed.

    The validattion for their type is already constrained by schema type.

    Change-Id: I3c7fa5978ff768540abf70d25cfee6bad5da736f
    Closes-Bug: #1675630

Changed in senlin:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/senlin 4.0.0.0b1

This issue was fixed in the openstack/senlin 4.0.0.0b1 development milestone.

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.