IPA clean up how Error classes set details

Bug #1408817 reported by Ruby Loo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ironic
Fix Released
Low
Ruby Loo

Bug Description

The Error classes in errors.py all (I think) inherit from RESTError class. This class is serializable, and will serialize self.details. Subclasses can modify this by setting their own self.details.

There are two ways that the subclasses can do this:
1. if the parent class's __init__() accepts a 'detail' parameter, the subclass invokes that and passes the detail
2. in the subclass's __init__(), self.details is set to the desired details string

Looking at the classes, there seems to be some confusion (or maybe to hedge their bets), both 1 & 2 above are done. Eg IronicAPIError.

In addition, there was at least one case where unknowingly, someone subclassed directly from RESTError, and thought that passing details to RESTError's __init__() would suffice :-(

It would be good if this file was cleaned up and consistent, so as not to cause confusion. My suggestion is to change RESTError's __init__ to take a details=None parameter, and if details, set self.details = details. (And delete the setting #2 from subclasses unless they are needed.)

Unit tests would be a bonus.

Dmitry Tantsur (divius)
Changed in ironic:
status: New → Triaged
Ruby Loo (rloo)
Changed in ironic:
assignee: nobody → Ruby Loo (rloo)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ironic-python-agent (master)

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

Changed in ironic:
status: Triaged → In Progress
Ruby Loo (rloo)
tags: added: agent
Changed in ironic:
assignee: Ruby Loo (rloo) → Josh Gachnang (joshnang)
assignee: Josh Gachnang (joshnang) → Ruby Loo (rloo)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ironic-python-agent (master)

Reviewed: https://review.openstack.org/146924
Committed: https://git.openstack.org/cgit/openstack/ironic-python-agent/commit/?id=166f56da9464c07ee07f537710a37a2f2e8d59fb
Submitter: Jenkins
Branch: master

commit 166f56da9464c07ee07f537710a37a2f2e8d59fb
Author: Ruby Loo <email address hidden>
Date: Tue Jan 13 16:48:27 2015 +0000

    Consistent way to set details for Error instances

    This fixes and cleans up (making it consistent) how error
    instances set their details value. The base class RESTError
    will set the details value; all subclasses should call their
    parent's __init__().

    Unit tests were added to test that the Error instances are
    initialized correctly.

    Change-Id: I2390fa0012f8e4e6d73cbfb188f1733dfe85e65a
    Closes-Bug: #1408817

Changed in ironic:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in ironic:
milestone: none → kilo-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in ironic:
milestone: kilo-2 → 2015.1.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.