[openstack-dev] [mistral] Mistral Custom Actions API Design

Ryan Brady rbrady at redhat.com
Fri Mar 10 20:52:56 UTC 2017

On Fri, Mar 10, 2017 at 5:16 AM, Renat Akhmerov <renat.akhmerov at gmail.com>

> On 10 Mar 2017, at 15:09, Dougal Matthews <dougal at redhat.com> wrote:
> On 10 March 2017 at 04:22, Renat Akhmerov <renat.akhmerov at gmail.com>
> wrote:
>> Hi,
>> I probably like the base class approach better too.
>> However, I’m trying to understand if we need this variety of classes.
>>    - Do we need a separate class for asynchronous actions? IMO, since
>>    is_sync() is just an instance method that can potentially return both True
>>    and False based on the instance state shouldn’t be introduced by a special
>>    class. Otherwise it’s confusing that a classes declared as AsyncAction can
>>    actually be synchronous (if its is_sync() returns True). So maybe we should
>>    just leave this method in the base class.
>>    - I”m also wondering if we should just always pass “context” into
>>    run() method. Those action implementations that don’t need it could just
>>    ignore it. Not sure though.
>> This is a good point. I had originally thought it would be backwards
> incompatible to make this change - however, users will need to update their
> actions to inherit from mistral-lib so they will need to opt in. Then in
> mistral we can do something like...
> if isinstance(action, mistral_lib.Action):
>     action.run(ctx)
> else:
>     # deprecation warning about action now inheriting from mistral_lib and
> taking a context etc.
>     action.run()
> Yes, right.

The example here by Dougal looks like the way to move forward.  Thanks for
all of the feedback.

> As far as mixin approach, I’d say I’d be ok with having mixing for
>> context-based actions. Although, like Dougal said, it may be a little
>> harder to read, this approach gives a huge flexibility for long term.
>> Imagine if we want to have a class of actions that some different kind of
>> information. Just making it up… For example, some of my actions need to be
>> aware of some policies (Congress-like) or information about metrics of the
>> current operating system (this is probably a bad example because it’s easy
>> to use standard Python modules but I’m just trying to illustrate the idea).
>> In this case we could have PolicyMixin and OperatingSystemMixin that would
>> set required info into the instance state or provide with handle interfaces
>> for more advanced uses.
> I like the idea of mixins if we can see a future with many small
> components that can be included in an action class. However, like you I
> didn't manage to think of any real examples.
> It should be possible to migrate to a mixin approach later if we have the
> need.
> Well, I didn’t manage to find real use cases probably because I don’t
> develop lots of actions :) Although the example with policies seems almost
> real to me. This is something that was raised several times during design
> sessions in the past. Anyway, I agree with you that seems like we can add
> mixins later if we want to. I don’t see any reasons now why not.
One of the pain points for me as an action developer is the OpenStack
actions[1].  Since they all use the same method name to retrieve the
underlying client, you cannot simply inherit from more than one so you are
forced to rewrite the client access methods.  We saw this in creating
actions for TripleO[2].  In the base action in TripleO, we have actions
that make calls to more than one OpenStack client and so we end up
re-writing and maintaining code.  IMO the idea of using multiple
inheritance there would be helpful.  It may not require the mixin approach
here, but rather a design change in the generator to ensure the method
names don't match.

[1] https://github.com/openstack/mistral/blob/master/mistral
[2] https://github.com/openstack/tripleo-common/blob/master/

> Renat Akhmerov
> @Nokia
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Ryan Brady
Cloud Engineering
rbrady at redhat.com
919.890.8925 <(919)%20890-8925>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20170310/a49cdb37/attachment.html>

More information about the OpenStack-dev mailing list