Add Swift Service OpenStack Actions

Implements: blueprint mistral-support-swift-service-methods
Change-Id: I41649d15c57e16bffcf7870a52bc01177aae7cc8
This commit is contained in:
Dougal Matthews 2018-04-09 17:26:41 +01:00
parent fde8ca1085
commit 1a65bc447e
5 changed files with 57 additions and 3 deletions

View File

@ -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'
]

View File

@ -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'

View File

@ -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",

View File

@ -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],

View File

@ -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()