Skip to content

Commit 499bf2e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add workflow service (mistral)"
2 parents 955ee31 + 5c95942 commit 499bf2e

File tree

9 files changed

+449
-0
lines changed

9 files changed

+449
-0
lines changed

openstack/profile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
from openstack.orchestration import orchestration_service
7272
from openstack.telemetry.alarm import alarm_service
7373
from openstack.telemetry import telemetry_service
74+
from openstack.workflow import workflow_service
7475

7576
_logger = logging.getLogger(__name__)
7677

@@ -108,6 +109,7 @@ def __init__(self, plugins=None):
108109
self._add_service(
109110
orchestration_service.OrchestrationService(version="v1"))
110111
self._add_service(telemetry_service.TelemetryService(version="v2"))
112+
self._add_service(workflow_service.WorkflowService(version="v2"))
111113

112114
if plugins:
113115
for plugin in plugins:

openstack/tests/unit/test_connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def test_create_session(self):
151151
conn.orchestration.__class__.__module__)
152152
self.assertEqual('openstack.telemetry.v2._proxy',
153153
conn.telemetry.__class__.__module__)
154+
self.assertEqual('openstack.workflow.v2._proxy',
155+
conn.workflow.__class__.__module__)
154156

155157
def _prepare_test_config(self):
156158
# Create a temporary directory where our test config will live

openstack/tests/unit/test_profile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_init(self):
3333
'object-store',
3434
'orchestration',
3535
'volume',
36+
'workflowv2',
3637
]
3738
self.assertEqual(expected, prof.service_keys)
3839

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import testtools
14+
15+
from openstack.workflow.v2 import execution
16+
17+
FAKE_INPUT = {
18+
'cluster_id': '8c74607c-5a74-4490-9414-a3475b1926c2',
19+
'node_id': 'fba2cc5d-706f-4631-9577-3956048d13a2',
20+
'flavor_id': '1'
21+
}
22+
23+
FAKE = {
24+
'id': 'ffaed25e-46f5-4089-8e20-b3b4722fd597',
25+
'workflow_name': 'cluster-coldmigration',
26+
'input': FAKE_INPUT,
27+
}
28+
29+
30+
class TestExecution(testtools.TestCase):
31+
32+
def setUp(self):
33+
super(TestExecution, self).setUp()
34+
35+
def test_basic(self):
36+
sot = execution.Execution()
37+
self.assertEqual('execution', sot.resource_key)
38+
self.assertEqual('executions', sot.resources_key)
39+
self.assertEqual('/executions', sot.base_path)
40+
self.assertEqual('workflowv2', sot.service.service_type)
41+
self.assertTrue(sot.allow_get)
42+
self.assertTrue(sot.allow_list)
43+
self.assertTrue(sot.allow_create)
44+
self.assertTrue(sot.allow_delete)
45+
46+
def test_instantiate(self):
47+
sot = execution.Execution(**FAKE)
48+
self.assertEqual(FAKE['id'], sot.id)
49+
self.assertEqual(FAKE['workflow_name'], sot.workflow_name)
50+
self.assertEqual(FAKE['input'], sot.input)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstack.tests.unit import test_proxy_base2
14+
from openstack.workflow.v2 import _proxy
15+
from openstack.workflow.v2 import execution
16+
from openstack.workflow.v2 import workflow
17+
18+
19+
class TestWorkflowProxy(test_proxy_base2.TestProxyBase):
20+
def setUp(self):
21+
super(TestWorkflowProxy, self).setUp()
22+
self.proxy = _proxy.Proxy(self.session)
23+
24+
def test_workflows(self):
25+
self.verify_list(self.proxy.workflows,
26+
workflow.Workflow,
27+
paginated=True)
28+
29+
def test_executions(self):
30+
self.verify_list(self.proxy.executions,
31+
execution.Execution,
32+
paginated=True)
33+
34+
def test_workflow_get(self):
35+
self.verify_get(self.proxy.get_workflow,
36+
workflow.Workflow)
37+
38+
def test_execution_get(self):
39+
self.verify_get(self.proxy.get_execution,
40+
execution.Execution)
41+
42+
def test_workflow_create(self):
43+
self.verify_create(self.proxy.create_workflow,
44+
workflow.Workflow)
45+
46+
def test_execution_create(self):
47+
self.verify_create(self.proxy.create_execution,
48+
execution.Execution)
49+
50+
def test_workflow_delete(self):
51+
self.verify_delete(self.proxy.delete_workflow,
52+
workflow.Workflow, True)
53+
54+
def test_execution_delete(self):
55+
self.verify_delete(self.proxy.delete_execution,
56+
execution.Execution, True)
57+
58+
def test_workflow_find(self):
59+
self.verify_find(self.proxy.find_workflow,
60+
workflow.Workflow)
61+
62+
def test_execution_find(self):
63+
self.verify_find(self.proxy.find_execution,
64+
execution.Execution)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import testtools
14+
15+
from openstack.workflow.v2 import workflow
16+
17+
18+
FAKE = {
19+
'scope': 'private',
20+
'id': 'ffaed25e-46f5-4089-8e20-b3b4722fd597',
21+
'definition': 'workflow_def',
22+
}
23+
24+
25+
class TestWorkflow(testtools.TestCase):
26+
27+
def setUp(self):
28+
super(TestWorkflow, self).setUp()
29+
30+
def test_basic(self):
31+
sot = workflow.Workflow()
32+
self.assertEqual('workflow', sot.resource_key)
33+
self.assertEqual('workflows', sot.resources_key)
34+
self.assertEqual('/workflows', sot.base_path)
35+
self.assertEqual('workflowv2', sot.service.service_type)
36+
self.assertTrue(sot.allow_get)
37+
self.assertTrue(sot.allow_list)
38+
self.assertTrue(sot.allow_create)
39+
self.assertTrue(sot.allow_delete)
40+
41+
def test_instantiate(self):
42+
sot = workflow.Workflow(**FAKE)
43+
self.assertEqual(FAKE['id'], sot.id)
44+
self.assertEqual(FAKE['scope'], sot.scope)
45+
self.assertEqual(FAKE['definition'], sot.definition)

openstack/workflow/v2/_proxy.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstack import proxy2
14+
from openstack.workflow.v2 import execution as _execution
15+
from openstack.workflow.v2 import workflow as _workflow
16+
17+
18+
class Proxy(proxy2.BaseProxy):
19+
20+
def create_workflow(self, **attrs):
21+
"""Create a new workflow from attributes
22+
23+
:param dict attrs: Keyword arguments which will be used to create
24+
a :class:`~openstack.workflow.v2.workflow.Workflow`,
25+
comprised of the properties on the Workflow class.
26+
27+
:returns: The results of workflow creation
28+
:rtype: :class:`~openstack.workflow.v2.workflow.Workflow`
29+
"""
30+
return self._create(_workflow.Workflow, **attrs)
31+
32+
def get_workflow(self, *attrs):
33+
"""Get a workflow
34+
35+
:param workflow: The value can be the name of a workflow or
36+
:class:`~openstack.workflow.v2.workflow.Workflow` instance.
37+
38+
:returns: One :class:`~openstack.workflow.v2.workflow.Workflow`
39+
:raises: :class:`~openstack.exceptions.ResourceNotFound` when no
40+
workflow matching the name could be found.
41+
"""
42+
return self._get(_workflow.Workflow, *attrs)
43+
44+
def workflows(self, **query):
45+
"""Retrieve a generator of workflows
46+
47+
:param kwargs \*\*query: Optional query parameters to be sent to
48+
restrict the workflows to be returned. Available parameters
49+
include:
50+
51+
* limit: Requests at most the specified number of items be
52+
returned from the query.
53+
* marker: Specifies the ID of the last-seen workflow. Use the
54+
limit parameter to make an initial limited request and use
55+
the ID of the last-seen workflow from the response as the
56+
marker parameter value in a subsequent limited request.
57+
58+
:returns: A generator of workflow instances.
59+
"""
60+
return self._list(_workflow.Workflow, paginated=True, **query)
61+
62+
def delete_workflow(self, value, ignore_missing=True):
63+
"""Delete a workflow
64+
65+
:param value: The value can be either the name of a workflow or a
66+
:class:`~openstack.workflow.v2.workflow.Workflow`
67+
instance.
68+
:param bool ignore_missing: When set to ``False``
69+
:class:`~openstack.exceptions.ResourceNotFound` will
70+
be raised when the workflow does not exist.
71+
When set to ``True``, no exception will be set when
72+
attempting to delete a nonexistent workflow.
73+
74+
:returns: ``None``
75+
"""
76+
return self._delete(_workflow.Workflow, value,
77+
ignore_missing=ignore_missing)
78+
79+
def find_workflow(self, name_or_id, ignore_missing=True):
80+
"""Find a single workflow
81+
82+
:param name_or_id: The name or ID of an workflow.
83+
:param bool ignore_missing: When set to ``False``
84+
:class:`~openstack.exceptions.ResourceNotFound` will be
85+
raised when the resource does not exist.
86+
When set to ``True``, None will be returned when
87+
attempting to find a nonexistent resource.
88+
:returns: One :class:`~openstack.compute.v2.workflow.Extension` or
89+
None
90+
"""
91+
return self._find(_workflow.Workflow, name_or_id,
92+
ignore_missing=ignore_missing)
93+
94+
def create_execution(self, **attrs):
95+
"""Create a new execution from attributes
96+
97+
:param workflow_name: The name of target workflow to execute.
98+
:param dict attrs: Keyword arguments which will be used to create
99+
a :class:`~openstack.workflow.v2.execution.Execution`,
100+
comprised of the properties on the Execution class.
101+
102+
:returns: The results of execution creation
103+
:rtype: :class:`~openstack.workflow.v2.execution.Execution`
104+
"""
105+
return self._create(_execution.Execution, **attrs)
106+
107+
def get_execution(self, *attrs):
108+
"""Get a execution
109+
110+
:param workflow_name: The name of target workflow to execute.
111+
:param execution: The value can be either the ID of a execution or a
112+
:class:`~openstack.workflow.v2.execution.Execution` instance.
113+
114+
:returns: One :class:`~openstack.workflow.v2.execution.Execution`
115+
:raises: :class:`~openstack.exceptions.ResourceNotFound` when no
116+
execution matching the criteria could be found.
117+
"""
118+
return self._get(_execution.Execution, *attrs)
119+
120+
def executions(self, **query):
121+
"""Retrieve a generator of executions
122+
123+
:param kwargs \*\*query: Optional query parameters to be sent to
124+
restrict the executions to be returned. Available parameters
125+
include:
126+
127+
* limit: Requests at most the specified number of items be
128+
returned from the query.
129+
* marker: Specifies the ID of the last-seen execution. Use the
130+
limit parameter to make an initial limited request and use
131+
the ID of the last-seen execution from the response as the
132+
marker parameter value in a subsequent limited request.
133+
134+
:returns: A generator of execution instances.
135+
"""
136+
return self._list(_execution.Execution, paginated=True, **query)
137+
138+
def delete_execution(self, value, ignore_missing=True):
139+
"""Delete an execution
140+
141+
:param value: The value can be either the name of a execution or a
142+
:class:`~openstack.workflow.v2.execute.Execution`
143+
instance.
144+
:param bool ignore_missing: When set to ``False``
145+
:class:`~openstack.exceptions.ResourceNotFound` will be
146+
raised when the execution does not exist.
147+
When set to ``True``, no exception will be set when
148+
attempting to delete a nonexistent execution.
149+
150+
:returns: ``None``
151+
"""
152+
return self._delete(_execution.Execution, value,
153+
ignore_missing=ignore_missing)
154+
155+
def find_execution(self, name_or_id, ignore_missing=True):
156+
"""Find a single execution
157+
158+
:param name_or_id: The name or ID of an execution.
159+
:param bool ignore_missing: When set to ``False``
160+
:class:`~openstack.exceptions.ResourceNotFound` will be
161+
raised when the resource does not exist.
162+
When set to ``True``, None will be returned when
163+
attempting to find a nonexistent resource.
164+
:returns: One :class:`~openstack.compute.v2.execution.Execution` or
165+
None
166+
"""
167+
return self._find(_execution.Execution, name_or_id,
168+
ignore_missing=ignore_missing)

0 commit comments

Comments
 (0)