Small fixes in openstack-actions
* OpenStackAction.client_method -> OpenStackAction.client_method_name * Added test where we can see how parameters are passed from the DSL to Action instance Change-Id: Iaa5712f913a3c1688cf7f60f3ac4faab49642fe0
This commit is contained in:
parent
4e71b1a69f
commit
5f7a32ef47
@ -45,8 +45,8 @@ class OpenStackActionGenerator(action_generator.ActionGenerator):
|
|||||||
if not method_name:
|
if not method_name:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
action_class = type(str(method_name), (cls.base_action_class,), {})
|
action_class = type(str(method_name), (cls.base_action_class,),
|
||||||
setattr(action_class, 'client_method', method_name)
|
{'client_method_name': method_name})
|
||||||
|
|
||||||
return action_class
|
return action_class
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class OpenStackAction(base.Action):
|
|||||||
"""
|
"""
|
||||||
_kwargs_for_run = {}
|
_kwargs_for_run = {}
|
||||||
_client_class = None
|
_client_class = None
|
||||||
client_method = None
|
client_method_name = None
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self._kwargs_for_run = kwargs
|
self._kwargs_for_run = kwargs
|
||||||
@ -42,7 +42,7 @@ class OpenStackAction(base.Action):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_client_method(self):
|
def _get_client_method(self):
|
||||||
hierarchy_list = self.client_method.split('.')
|
hierarchy_list = self.client_method_name.split('.')
|
||||||
attribute = self._get_client()
|
attribute = self._get_client()
|
||||||
for attr in hierarchy_list:
|
for attr in hierarchy_list:
|
||||||
attribute = getattr(attribute, attr)
|
attribute = getattr(attribute, attr)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
Workflow:
|
Workflow:
|
||||||
tasks:
|
tasks:
|
||||||
nova_server_list:
|
nova_server_findall:
|
||||||
action: nova.servers_list
|
action: nova.servers_findall
|
||||||
|
parameters:
|
||||||
|
status: ACTIVE
|
||||||
|
tenant_id: 8e44eb2ce32
|
||||||
|
@ -29,4 +29,4 @@ class GlanceGeneratorTest(base.BaseTestCase):
|
|||||||
self.assertIsNotNone(generator)
|
self.assertIsNotNone(generator)
|
||||||
self.assertIn(short_action_name, action_classes)
|
self.assertIn(short_action_name, action_classes)
|
||||||
self.assertTrue(issubclass(action_class, actions.GlanceAction))
|
self.assertTrue(issubclass(action_class, actions.GlanceAction))
|
||||||
self.assertEqual("images.list", action_class.client_method)
|
self.assertEqual("images.list", action_class.client_method_name)
|
||||||
|
@ -29,3 +29,4 @@ class HeatGeneratorTest(base.BaseTestCase):
|
|||||||
self.assertIsNotNone(generator)
|
self.assertIsNotNone(generator)
|
||||||
self.assertIn(short_action_name, action_classes)
|
self.assertIn(short_action_name, action_classes)
|
||||||
self.assertTrue(issubclass(action_class, actions.HeatAction))
|
self.assertTrue(issubclass(action_class, actions.HeatAction))
|
||||||
|
self.assertEqual("stacks.list", action_class.client_method_name)
|
||||||
|
@ -29,4 +29,4 @@ class KeystoneGeneratorTest(base.BaseTestCase):
|
|||||||
self.assertIsNotNone(generator)
|
self.assertIsNotNone(generator)
|
||||||
self.assertIn(short_action_name, action_classes)
|
self.assertIn(short_action_name, action_classes)
|
||||||
self.assertTrue(issubclass(action_class, actions.KeystoneAction))
|
self.assertTrue(issubclass(action_class, actions.KeystoneAction))
|
||||||
self.assertEqual("users.create", action_class.client_method)
|
self.assertEqual("users.create", action_class.client_method_name)
|
||||||
|
@ -29,4 +29,4 @@ class NovaGeneratorTest(base.BaseTestCase):
|
|||||||
self.assertIsNotNone(generator)
|
self.assertIsNotNone(generator)
|
||||||
self.assertIn(short_action_name, action_classes)
|
self.assertIn(short_action_name, action_classes)
|
||||||
self.assertTrue(issubclass(action_class, actions.NovaAction))
|
self.assertTrue(issubclass(action_class, actions.NovaAction))
|
||||||
self.assertEqual("servers.get", action_class.client_method)
|
self.assertEqual("servers.get", action_class.client_method_name)
|
||||||
|
@ -23,7 +23,7 @@ class OpenStackActionTest(base.BaseTestCase):
|
|||||||
def test_nova_action(self, mocked):
|
def test_nova_action(self, mocked):
|
||||||
method_name = "servers.get"
|
method_name = "servers.get"
|
||||||
action_class = actions.NovaAction
|
action_class = actions.NovaAction
|
||||||
action_class.client_method = method_name
|
action_class.client_method_name = method_name
|
||||||
params = {'server': '1234-abcd'}
|
params = {'server': '1234-abcd'}
|
||||||
action = action_class(**params)
|
action = action_class(**params)
|
||||||
action.run()
|
action.run()
|
||||||
@ -35,7 +35,7 @@ class OpenStackActionTest(base.BaseTestCase):
|
|||||||
def test_glance_action(self, mocked):
|
def test_glance_action(self, mocked):
|
||||||
method_name = "images.delete"
|
method_name = "images.delete"
|
||||||
action_class = actions.GlanceAction
|
action_class = actions.GlanceAction
|
||||||
action_class.client_method = method_name
|
action_class.client_method_name = method_name
|
||||||
params = {'image': '1234-abcd'}
|
params = {'image': '1234-abcd'}
|
||||||
action = action_class(**params)
|
action = action_class(**params)
|
||||||
action.run()
|
action.run()
|
||||||
@ -47,7 +47,7 @@ class OpenStackActionTest(base.BaseTestCase):
|
|||||||
def test_keystone_action(self, mocked):
|
def test_keystone_action(self, mocked):
|
||||||
method_name = "users.get"
|
method_name = "users.get"
|
||||||
action_class = actions.KeystoneAction
|
action_class = actions.KeystoneAction
|
||||||
action_class.client_method = method_name
|
action_class.client_method_name = method_name
|
||||||
params = {'user': '1234-abcd'}
|
params = {'user': '1234-abcd'}
|
||||||
action = action_class(**params)
|
action = action_class(**params)
|
||||||
action.run()
|
action.run()
|
||||||
@ -59,7 +59,7 @@ class OpenStackActionTest(base.BaseTestCase):
|
|||||||
def test_heat_action(self, mocked):
|
def test_heat_action(self, mocked):
|
||||||
method_name = "stacks.get"
|
method_name = "stacks.get"
|
||||||
action_class = actions.HeatAction
|
action_class = actions.HeatAction
|
||||||
action_class.client_method = method_name
|
action_class.client_method_name = method_name
|
||||||
params = {'id': '1234-abcd'}
|
params = {'id': '1234-abcd'}
|
||||||
action = action_class(**params)
|
action = action_class(**params)
|
||||||
action.run()
|
action.run()
|
||||||
|
@ -16,9 +16,11 @@ import mock
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from mistral.actions.openstack import actions
|
from mistral.actions.openstack import actions
|
||||||
|
from mistral import context as auth_context
|
||||||
from mistral.db import api as db_api
|
from mistral.db import api as db_api
|
||||||
from mistral import engine
|
from mistral import engine
|
||||||
from mistral.engine.drivers.default import engine as concrete_engine
|
from mistral.engine.drivers.default import engine as concrete_engine
|
||||||
|
from mistral.engine.drivers.default import executor
|
||||||
from mistral.engine import states
|
from mistral.engine import states
|
||||||
from mistral.openstack.common import log as logging
|
from mistral.openstack.common import log as logging
|
||||||
from mistral.tests import base
|
from mistral.tests import base
|
||||||
@ -100,14 +102,34 @@ class OpenStackActionsEngineTest(base.EngineTestCase):
|
|||||||
|
|
||||||
@mock.patch.object(actions.NovaAction, 'run',
|
@mock.patch.object(actions.NovaAction, 'run',
|
||||||
mock.Mock(return_value="servers"))
|
mock.Mock(return_value="servers"))
|
||||||
|
@mock.patch.object(executor.DefaultExecutor, "handle_task",
|
||||||
|
mock.MagicMock())
|
||||||
def test_nova_action(self):
|
def test_nova_action(self):
|
||||||
context = {}
|
context = {}
|
||||||
wb = create_workbook('openstack_tasks/nova.yaml')
|
wb = create_workbook('openstack_tasks/nova.yaml')
|
||||||
task_name = 'nova_server_list'
|
task_name = 'nova_server_findall'
|
||||||
|
task_params = {'status': 'ACTIVE', 'tenant_id': '8e44eb2ce32'}
|
||||||
execution = self.engine.start_workflow_execution(wb['name'],
|
execution = self.engine.start_workflow_execution(wb['name'],
|
||||||
task_name,
|
task_name,
|
||||||
context)
|
context)
|
||||||
|
|
||||||
|
tasks = db_api.tasks_get(workbook_name=wb['name'],
|
||||||
|
execution_id=execution['id'])
|
||||||
|
|
||||||
|
self.assertEqual(1, len(tasks))
|
||||||
|
task = self._assert_single_item(tasks, name=task_name)
|
||||||
|
|
||||||
|
executor.DefaultExecutor.handle_task.assert_called_once_with(
|
||||||
|
auth_context.ctx(),
|
||||||
|
params=task_params,
|
||||||
|
task_id=task['id'],
|
||||||
|
action_name="nova.servers_findall"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.engine.convey_task_result(task['id'],
|
||||||
|
states.SUCCESS,
|
||||||
|
"servers")
|
||||||
|
|
||||||
# We have to reread execution to get its latest version.
|
# We have to reread execution to get its latest version.
|
||||||
execution = db_api.execution_get(execution['id'])
|
execution = db_api.execution_get(execution['id'])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user