agent sync and async decorators change method signature

Bug #1314148 reported by Vladimir Kozhukalov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ironic
Fix Released
Low
Szymon Wróblewski

Bug Description

There two decorators

ironic_python_agent/extensions/base.py:async_command
ironic_python_agent/extensions/base.py:sync_command

They are implemented so that they change decorated method signature, which is really bad practice. Example

@sync_command
def orig_method(self, **kw):
...

sync decorator returns lambda which has one additional argument 'command_name'

def sync_command(func):
    def decorated(self, command_name, **kw):
         ...
         func(self, **kw)
         ...
    return decorated

Besides, command_name argument looks a bit excess in execute method in BaseAgentExtension. We need to remove this extra argument and use something like __name__ wherever we need to know method name.

Dmitry Tantsur (divius)
Changed in ironic:
status: New → Triaged
importance: Undecided → Low
tags: added: low-hanging-fruit
Changed in ironic:
assignee: nobody → Szymon Wróblewski (bluex)
status: Triaged → In Progress
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/117529

Changed in ironic:
status: In Progress → Won't Fix
Revision history for this message
Szymon Wróblewski (bluex) wrote :

I can still propose solution that both separates the API from the implementation and fixes this issue - take a look at http://paste.openstack.org/show/104236/

By moving "command_name" to decorator signature decorated method is named only once during decoration, so we don't need to explicitly pass this custom name whenever we want to call decorated method.

Changed in ironic:
status: Won't Fix → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ironic-python-agent (master)

Reviewed: https://review.openstack.org/117529
Committed: https://git.openstack.org/cgit/openstack/ironic-python-agent/commit/?id=324f037eb02b240d612e58e27e97503a8e490681
Submitter: Jenkins
Branch: master

commit 324f037eb02b240d612e58e27e97503a8e490681
Author: Szymon Wroblewski <email address hidden>
Date: Thu Sep 11 10:49:33 2014 +0200

    Enhance decorators in agent and automate creation of command_map

    sync_command and async_command in ironic_python_agent/extensions/base.py
    are implemented so that they change decorated method signature,
    which is really bad practice. Example:

    @sync_command
    def orig_method(self, **kw):
    ...

    sync_command decorator returns lambda which has one additional
    argument 'command_name'

    def sync_command(func):
        def decorated(self, command_name, **kw):
             ...
             func(self, **kw)
             ...
        return decorated

    Additional parameter 'command_name' is moved from decorated function to
    decorator signature in both decorators. Every call of decorated functions
    is fixed, BaseAgentExtension.execute is updated to not send this extra
    argument. BaseAgentExtension.__init__ automatically generates command_map
    from decorated methods.

    Change-Id: Iff0f495bc8d9c731892feb0f4759a7f10ee76328
    Closes-Bug: 1314148

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