diff --git a/mistral/actions/generator_factory.py b/mistral/actions/generator_factory.py index 8ca409d81..f73bfc0e8 100644 --- a/mistral/actions/generator_factory.py +++ b/mistral/actions/generator_factory.py @@ -19,9 +19,9 @@ from mistral.actions.openstack.action_generator import base SUPPORTED_MODULES = [ 'Nova', 'Glance', 'Keystone', 'Heat', 'Neutron', 'Cinder', - 'Trove', 'Ironic', 'Baremetal Introspection', 'Swift', 'Zaqar', 'Barbican', - 'Mistral', 'Designate', 'Magnum', 'Murano', 'Tacker', 'Aodh', 'Gnocchi', - 'Glare' + 'Trove', 'Ironic', 'Baremetal Introspection', 'Swift', 'SwiftService', + 'Zaqar', 'Barbican', 'Mistral', 'Designate', 'Magnum', 'Murano', 'Tacker', + 'Aodh', 'Gnocchi', 'Glare' ] diff --git a/mistral/actions/openstack/actions.py b/mistral/actions/openstack/actions.py index 4fc1b1dde..e8713e0f3 100644 --- a/mistral/actions/openstack/actions.py +++ b/mistral/actions/openstack/actions.py @@ -67,6 +67,7 @@ neutronclient = _try_import('neutronclient.v2_0.client') novaclient = _try_import('novaclient.client') senlinclient = _try_import('senlinclient.v1.client') swift_client = _try_import('swiftclient.client') +swiftservice = _try_import('swiftclient.service') tackerclient = _try_import('tackerclient.v1_0.client') troveclient = _try_import('troveclient.v1.client') zaqarclient = _try_import('zaqarclient.queues.client') @@ -401,6 +402,35 @@ class SwiftAction(base.OpenStackAction): ) +class SwiftServiceAction(base.OpenStackAction): + _service_name = 'swift' + + @classmethod + def _get_client_class(cls): + return swiftservice.SwiftService + + def _create_client(self, context): + + LOG.debug("Swift action security context: %s", context) + + swift_endpoint = self.get_service_endpoint() + + swift_opts = { + 'os_storage_url': swift_endpoint.url % { + 'tenant_id': context.project_id + }, + 'os_auth_token': context.auth_token, + 'os_region_name': swift_endpoint.region, + 'os_project_id': context.security.project_id, + } + + return swiftservice.SwiftService(options=swift_opts) + + @classmethod + def _get_client_method(cls, client): + return getattr(client, cls.client_method_name) + + class ZaqarAction(base.OpenStackAction): _service_type = 'messaging' diff --git a/mistral/actions/openstack/mapping.json b/mistral/actions/openstack/mapping.json index c34e35d74..6e7c50699 100644 --- a/mistral/actions/openstack/mapping.json +++ b/mistral/actions/openstack/mapping.json @@ -955,6 +955,17 @@ "copy_object": "copy_object", "get_capabilities": "get_capabilities" }, + "swiftservice": { + "_comment": "It uses swiftclient.service.", + "capabilities": "capabilities", + "copy": "copy", + "delete": "delete", + "download": "download", + "list": "list", + "post": "post", + "stat": "stat", + "upload": "upload" + }, "zaqar": { "_comment": "It uses zaqarclient.v2.", "claim_messages": "claim_messages", diff --git a/mistral/tests/unit/actions/openstack/test_generator.py b/mistral/tests/unit/actions/openstack/test_generator.py index 2705995b7..5bd46a84a 100644 --- a/mistral/tests/unit/actions/openstack/test_generator.py +++ b/mistral/tests/unit/actions/openstack/test_generator.py @@ -43,6 +43,7 @@ MODULE_MAPPING = { 'baremetal_introspection': ['baremetal_introspection.introspect', actions.BaremetalIntrospectionAction], 'swift': ['swift.head_account', actions.SwiftAction], + 'swiftservice': ['swiftservice.delete', actions.SwiftServiceAction], 'zaqar': ['zaqar.queue_messages', actions.ZaqarAction], 'barbican': ['barbican.orders_list', actions.BarbicanAction], 'mistral': ['mistral.workflows_get', actions.MistralAction], diff --git a/mistral/tests/unit/actions/openstack/test_openstack_actions.py b/mistral/tests/unit/actions/openstack/test_openstack_actions.py index 486e55c2b..80e089604 100644 --- a/mistral/tests/unit/actions/openstack/test_openstack_actions.py +++ b/mistral/tests/unit/actions/openstack/test_openstack_actions.py @@ -199,6 +199,18 @@ class OpenStackActionTest(base.BaseTestCase): mocked().get_object.assert_called_once_with(container='foo', object='bar') + @mock.patch.object(actions.SwiftServiceAction, '_get_client') + def test_swift_service_action(self, mocked): + mock_ctx = mock.Mock() + method_name = "list" + action_class = actions.SwiftServiceAction + action_class.client_method_name = method_name + action = action_class() + action.run(mock_ctx) + + self.assertTrue(mocked().list.called) + mocked().list.assert_called_once_with() + @mock.patch.object(actions.ZaqarAction, '_get_client') def test_zaqar_action(self, mocked): mock_ctx = mock.Mock()