Merge "Add workflow service (mistral)"

This commit is contained in:
Jenkins 2017-01-24 16:45:12 +00:00 committed by Gerrit Code Review
commit 499bf2e3c2
9 changed files with 449 additions and 0 deletions

View File

@ -71,6 +71,7 @@ from openstack.object_store import object_store_service
from openstack.orchestration import orchestration_service
from openstack.telemetry.alarm import alarm_service
from openstack.telemetry import telemetry_service
from openstack.workflow import workflow_service
_logger = logging.getLogger(__name__)
@ -108,6 +109,7 @@ class Profile(object):
self._add_service(
orchestration_service.OrchestrationService(version="v1"))
self._add_service(telemetry_service.TelemetryService(version="v2"))
self._add_service(workflow_service.WorkflowService(version="v2"))
if plugins:
for plugin in plugins:

View File

@ -151,6 +151,8 @@ class TestConnection(base.TestCase):
conn.orchestration.__class__.__module__)
self.assertEqual('openstack.telemetry.v2._proxy',
conn.telemetry.__class__.__module__)
self.assertEqual('openstack.workflow.v2._proxy',
conn.workflow.__class__.__module__)
def _prepare_test_config(self):
# Create a temporary directory where our test config will live

View File

@ -33,6 +33,7 @@ class TestProfile(base.TestCase):
'object-store',
'orchestration',
'volume',
'workflowv2',
]
self.assertEqual(expected, prof.service_keys)

View File

@ -0,0 +1,50 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import testtools
from openstack.workflow.v2 import execution
FAKE_INPUT = {
'cluster_id': '8c74607c-5a74-4490-9414-a3475b1926c2',
'node_id': 'fba2cc5d-706f-4631-9577-3956048d13a2',
'flavor_id': '1'
}
FAKE = {
'id': 'ffaed25e-46f5-4089-8e20-b3b4722fd597',
'workflow_name': 'cluster-coldmigration',
'input': FAKE_INPUT,
}
class TestExecution(testtools.TestCase):
def setUp(self):
super(TestExecution, self).setUp()
def test_basic(self):
sot = execution.Execution()
self.assertEqual('execution', sot.resource_key)
self.assertEqual('executions', sot.resources_key)
self.assertEqual('/executions', sot.base_path)
self.assertEqual('workflowv2', sot.service.service_type)
self.assertTrue(sot.allow_get)
self.assertTrue(sot.allow_list)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_delete)
def test_instantiate(self):
sot = execution.Execution(**FAKE)
self.assertEqual(FAKE['id'], sot.id)
self.assertEqual(FAKE['workflow_name'], sot.workflow_name)
self.assertEqual(FAKE['input'], sot.input)

View File

@ -0,0 +1,64 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack.tests.unit import test_proxy_base2
from openstack.workflow.v2 import _proxy
from openstack.workflow.v2 import execution
from openstack.workflow.v2 import workflow
class TestWorkflowProxy(test_proxy_base2.TestProxyBase):
def setUp(self):
super(TestWorkflowProxy, self).setUp()
self.proxy = _proxy.Proxy(self.session)
def test_workflows(self):
self.verify_list(self.proxy.workflows,
workflow.Workflow,
paginated=True)
def test_executions(self):
self.verify_list(self.proxy.executions,
execution.Execution,
paginated=True)
def test_workflow_get(self):
self.verify_get(self.proxy.get_workflow,
workflow.Workflow)
def test_execution_get(self):
self.verify_get(self.proxy.get_execution,
execution.Execution)
def test_workflow_create(self):
self.verify_create(self.proxy.create_workflow,
workflow.Workflow)
def test_execution_create(self):
self.verify_create(self.proxy.create_execution,
execution.Execution)
def test_workflow_delete(self):
self.verify_delete(self.proxy.delete_workflow,
workflow.Workflow, True)
def test_execution_delete(self):
self.verify_delete(self.proxy.delete_execution,
execution.Execution, True)
def test_workflow_find(self):
self.verify_find(self.proxy.find_workflow,
workflow.Workflow)
def test_execution_find(self):
self.verify_find(self.proxy.find_execution,
execution.Execution)

View File

@ -0,0 +1,45 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import testtools
from openstack.workflow.v2 import workflow
FAKE = {
'scope': 'private',
'id': 'ffaed25e-46f5-4089-8e20-b3b4722fd597',
'definition': 'workflow_def',
}
class TestWorkflow(testtools.TestCase):
def setUp(self):
super(TestWorkflow, self).setUp()
def test_basic(self):
sot = workflow.Workflow()
self.assertEqual('workflow', sot.resource_key)
self.assertEqual('workflows', sot.resources_key)
self.assertEqual('/workflows', sot.base_path)
self.assertEqual('workflowv2', sot.service.service_type)
self.assertTrue(sot.allow_get)
self.assertTrue(sot.allow_list)
self.assertTrue(sot.allow_create)
self.assertTrue(sot.allow_delete)
def test_instantiate(self):
sot = workflow.Workflow(**FAKE)
self.assertEqual(FAKE['id'], sot.id)
self.assertEqual(FAKE['scope'], sot.scope)
self.assertEqual(FAKE['definition'], sot.definition)

View File

@ -0,0 +1,168 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack import proxy2
from openstack.workflow.v2 import execution as _execution
from openstack.workflow.v2 import workflow as _workflow
class Proxy(proxy2.BaseProxy):
def create_workflow(self, **attrs):
"""Create a new workflow from attributes
:param dict attrs: Keyword arguments which will be used to create
a :class:`~openstack.workflow.v2.workflow.Workflow`,
comprised of the properties on the Workflow class.
:returns: The results of workflow creation
:rtype: :class:`~openstack.workflow.v2.workflow.Workflow`
"""
return self._create(_workflow.Workflow, **attrs)
def get_workflow(self, *attrs):
"""Get a workflow
:param workflow: The value can be the name of a workflow or
:class:`~openstack.workflow.v2.workflow.Workflow` instance.
:returns: One :class:`~openstack.workflow.v2.workflow.Workflow`
:raises: :class:`~openstack.exceptions.ResourceNotFound` when no
workflow matching the name could be found.
"""
return self._get(_workflow.Workflow, *attrs)
def workflows(self, **query):
"""Retrieve a generator of workflows
:param kwargs \*\*query: Optional query parameters to be sent to
restrict the workflows to be returned. Available parameters
include:
* limit: Requests at most the specified number of items be
returned from the query.
* marker: Specifies the ID of the last-seen workflow. Use the
limit parameter to make an initial limited request and use
the ID of the last-seen workflow from the response as the
marker parameter value in a subsequent limited request.
:returns: A generator of workflow instances.
"""
return self._list(_workflow.Workflow, paginated=True, **query)
def delete_workflow(self, value, ignore_missing=True):
"""Delete a workflow
:param value: The value can be either the name of a workflow or a
:class:`~openstack.workflow.v2.workflow.Workflow`
instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will
be raised when the workflow does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent workflow.
:returns: ``None``
"""
return self._delete(_workflow.Workflow, value,
ignore_missing=ignore_missing)
def find_workflow(self, name_or_id, ignore_missing=True):
"""Find a single workflow
:param name_or_id: The name or ID of an workflow.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: One :class:`~openstack.compute.v2.workflow.Extension` or
None
"""
return self._find(_workflow.Workflow, name_or_id,
ignore_missing=ignore_missing)
def create_execution(self, **attrs):
"""Create a new execution from attributes
:param workflow_name: The name of target workflow to execute.
:param dict attrs: Keyword arguments which will be used to create
a :class:`~openstack.workflow.v2.execution.Execution`,
comprised of the properties on the Execution class.
:returns: The results of execution creation
:rtype: :class:`~openstack.workflow.v2.execution.Execution`
"""
return self._create(_execution.Execution, **attrs)
def get_execution(self, *attrs):
"""Get a execution
:param workflow_name: The name of target workflow to execute.
:param execution: The value can be either the ID of a execution or a
:class:`~openstack.workflow.v2.execution.Execution` instance.
:returns: One :class:`~openstack.workflow.v2.execution.Execution`
:raises: :class:`~openstack.exceptions.ResourceNotFound` when no
execution matching the criteria could be found.
"""
return self._get(_execution.Execution, *attrs)
def executions(self, **query):
"""Retrieve a generator of executions
:param kwargs \*\*query: Optional query parameters to be sent to
restrict the executions to be returned. Available parameters
include:
* limit: Requests at most the specified number of items be
returned from the query.
* marker: Specifies the ID of the last-seen execution. Use the
limit parameter to make an initial limited request and use
the ID of the last-seen execution from the response as the
marker parameter value in a subsequent limited request.
:returns: A generator of execution instances.
"""
return self._list(_execution.Execution, paginated=True, **query)
def delete_execution(self, value, ignore_missing=True):
"""Delete an execution
:param value: The value can be either the name of a execution or a
:class:`~openstack.workflow.v2.execute.Execution`
instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the execution does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent execution.
:returns: ``None``
"""
return self._delete(_execution.Execution, value,
ignore_missing=ignore_missing)
def find_execution(self, name_or_id, ignore_missing=True):
"""Find a single execution
:param name_or_id: The name or ID of an execution.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the resource does not exist.
When set to ``True``, None will be returned when
attempting to find a nonexistent resource.
:returns: One :class:`~openstack.compute.v2.execution.Execution` or
None
"""
return self._find(_execution.Execution, name_or_id,
ignore_missing=ignore_missing)

View File

@ -0,0 +1,55 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack import resource2 as resource
from openstack.workflow import workflow_service
class Execution(resource.Resource):
resource_key = 'execution'
resources_key = 'executions'
base_path = '/executions'
service = workflow_service.WorkflowService()
# capabilities
allow_create = True
allow_list = True
allow_get = True
allow_delete = True
_query_mapping = resource.QueryParameters(
'marker', 'limit', 'sort_keys', 'sort_dirs', 'fields', 'params',
'include_output')
workflow_name = resource.Body("workflow_name")
workflow_id = resource.Body("workflow_id")
description = resource.Body("description")
task_execution_id = resource.Body("task_execution_id")
status = resource.Body("state")
status_info = resource.Body("state_info")
input = resource.Body("input")
output = resource.Body("output")
created_at = resource.Body("created_at")
updated_at = resource.Body("updated_at")
def create(self, session, prepend_key=True):
request = self._prepare_request(requires_id=False,
prepend_key=prepend_key)
request_body = request.body["execution"]
response = session.post(request.uri,
endpoint_filter=self.service,
json=request_body,
headers=request.headers)
self._translate_response(response, has_body=True)
return self

View File

@ -0,0 +1,62 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack import resource2 as resource
from openstack.workflow import workflow_service
class Workflow(resource.Resource):
resource_key = 'workflow'
resources_key = 'workflows'
base_path = '/workflows'
service = workflow_service.WorkflowService()
# capabilities
allow_create = True
allow_list = True
allow_get = True
allow_delete = True
_query_mapping = resource.QueryParameters(
'marker', 'limit', 'sort_keys', 'sort_dirs', 'fields')
name = resource.Body("name")
input = resource.Body("input")
definition = resource.Body("definition")
tags = resource.Body("tags")
scope = resource.Body("scope")
project_id = resource.Body("project_id")
created_at = resource.Body("created_at")
updated_at = resource.Body("updated_at")
def create(self, session, prepend_key=True):
request = self._prepare_request(requires_id=False,
prepend_key=prepend_key)
headers = {
"Content-Type": 'text/plain'
}
kwargs = {
"data": self.definition,
}
scope = "?scope=%s" % self.scope
uri = request.uri + scope
request.headers.update(headers)
response = session.post(uri,
endpoint_filter=self.service,
json=None,
headers=request.headers, **kwargs)
self._translate_response(response, has_body=False)
return self