Skip to content

Conversation

@Kami
Copy link
Member

@Kami Kami commented Feb 18, 2016

This pull request updates base Action class to utilize action_service argument and expose datastore management methods via this action_service instance variable.

Using action_service makes it consistent with sensors and also allows us to expand and add additional functionality to action service in the future.

In addition to that, it includes some other changes:

  • Make sure that we pass mock action service and datastore to the Action instance which is available to action unit tests.
  • Add some more test for BaseActionTestCase
  • Random lint fixes and cleanup

TODO

done
# Lint Python pack management actions
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models contrib/packs/actions/pack_mgmt/ || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc --load-plugins=pylint_plugins.api_models contrib/packs/actions/ || exit 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we added some new Python files there but we didn't lint files there before so some lint violations managed to slip in.

Kami added 3 commits February 18, 2016 16:59
datastore management methods via the action service.

This way the whole interface is consistent with the existing sensor interface
(sensor_service).
…ervice to

the Action class used by unit tests.
# Methods for datastore management
##################################

def list_values(self, local=True, prefix=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just let datastore_service be a pass through and expect actions to access self.datastore_service directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way it's consistent with existing sensor service interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not a fan of the pattern but consistency is better in this regard.

@Kami Kami changed the title [WIP] Action unit testing fixes and lint cleanup Python runner actions datastore access changes, action unit testing fixes and lint cleanup Feb 18, 2016
self.logger = get_logger_for_action(action_name=self.__class__.__name__)

# action_service is late assigned post class instatiation in "setup()"
self.datastore = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.action_service

@Kami
Copy link
Member Author

Kami commented Feb 18, 2016

Also, just a heads up.

There is some similar / duplicated code in the mocks, etc. but I plan to add tests, etc. first and address / refactor that later.

@manasdk
Copy link
Contributor

manasdk commented Feb 18, 2016

@vcabbage @andrew-regan

Likely some actions you have in place will be affected. Since this is not released yet we should be ok changing the interface.

@Kami
Copy link
Member Author

Kami commented Feb 18, 2016

@manasdk Yeah, thanks for the heads up - I planned to ping @vcabbage once the PR is fully ready (including doc changes, etc.).

This will most likely happen tomorrow and I will provide more details to them then :)

@andrew-regan
Copy link
Contributor

Thanks for the heads up!

@andrew-regan
Copy link
Contributor

👍

@Kami
Copy link
Member Author

Kami commented Feb 22, 2016

@manasdk and I discussed the offline the other day and decided to go with another approach which is consistent with sensors.

We will first try to pass action_service argument to the Action class constructor and if that doesn't work (e.g. old action which hasn't been updated yet), we will simply fall back to the late assignment on the action instance post instantiation.

This is not ideal, but good thing is that a lot of Action classes doesn't override the constructor and we control st2contrib so it's easy to update most of the actions.

Eventually, (e.g. after next .minor) release we should also consider dropping this late assignment fall back since by then most actions should be updated.

Kami added 3 commits February 22, 2016 14:09
… to the

Action class constructor.

If that doesn't work (e.g. old action which hasn't been updated yet), result to
late assignment.
@Kami
Copy link
Member Author

Kami commented Feb 22, 2016

I will go ahead and merge those + documentation changes into master.

I updated affected actions in core packs which are bundled in this repo, but I will wait with actions in st2contrib until more users upgrade to the latest version and / or pack versioning is in place.

I could update it so it also works with older versions of StackStorm, but it would require more boiler plate code...

Kami added a commit that referenced this pull request Feb 22, 2016
Python runner actions datastore access changes, action unit testing fixes and lint cleanup
@Kami Kami merged commit fdabb5d into master Feb 22, 2016
@Kami Kami deleted the action_testing_fixes branch February 22, 2016 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants