From c9c212c81a430b46b7447ea9f918fedfd0d6b154 Mon Sep 17 00:00:00 2001 From: Kirill Tyugaev Date: Tue, 18 Jul 2023 12:31:06 +0300 Subject: [PATCH] wokflow: add update_workflow proxy method Change-Id: I939530af74174f6b0db706295a34612bb643ca38 --- doc/source/user/proxies/workflow.rst | 4 ++-- .../tests/unit/workflow/test_workflow.py | 1 + .../tests/unit/workflow/v2/test_proxy.py | 3 +++ openstack/workflow/v2/_proxy.py | 15 ++++++++++++ openstack/workflow/v2/workflow.py | 23 +++++++++++++++---- .../update_workflow-ecdef6056ef2687b.yaml | 3 +++ 6 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/update_workflow-ecdef6056ef2687b.yaml diff --git a/doc/source/user/proxies/workflow.rst b/doc/source/user/proxies/workflow.rst index cd866e82f..f47baa55d 100644 --- a/doc/source/user/proxies/workflow.rst +++ b/doc/source/user/proxies/workflow.rst @@ -15,8 +15,8 @@ Workflow Operations .. autoclass:: openstack.workflow.v2._proxy.Proxy :noindex: - :members: create_workflow, delete_workflow, get_workflow, - find_workflow, workflows + :members: create_workflow, update_workflow, delete_workflow, + get_workflow, find_workflow, workflows Execution Operations ^^^^^^^^^^^^^^^^^^^^ diff --git a/openstack/tests/unit/workflow/test_workflow.py b/openstack/tests/unit/workflow/test_workflow.py index efab05db4..0e2f7e983 100644 --- a/openstack/tests/unit/workflow/test_workflow.py +++ b/openstack/tests/unit/workflow/test_workflow.py @@ -33,6 +33,7 @@ class TestWorkflow(base.TestCase): self.assertTrue(sot.allow_fetch) self.assertTrue(sot.allow_list) self.assertTrue(sot.allow_create) + self.assertTrue(sot.allow_commit) self.assertTrue(sot.allow_delete) def test_instantiate(self): diff --git a/openstack/tests/unit/workflow/v2/test_proxy.py b/openstack/tests/unit/workflow/v2/test_proxy.py index 551b57a0c..3f8b56352 100644 --- a/openstack/tests/unit/workflow/v2/test_proxy.py +++ b/openstack/tests/unit/workflow/v2/test_proxy.py @@ -37,6 +37,9 @@ class TestWorkflowProxy(test_proxy_base.TestProxyBase): def test_workflow_create(self): self.verify_create(self.proxy.create_workflow, workflow.Workflow) + def test_workflow_update(self): + self.verify_update(self.proxy.update_workflow, workflow.Workflow) + def test_execution_create(self): self.verify_create(self.proxy.create_execution, execution.Execution) diff --git a/openstack/workflow/v2/_proxy.py b/openstack/workflow/v2/_proxy.py index a12552ab8..98c67b739 100644 --- a/openstack/workflow/v2/_proxy.py +++ b/openstack/workflow/v2/_proxy.py @@ -34,6 +34,21 @@ class Proxy(proxy.Proxy): """ return self._create(_workflow.Workflow, **attrs) + def update_workflow(self, workflow, **attrs): + """Update workflow from attributes + + :param workflow: The value can be either the name of a workflow or a + :class:`~openstack.workflow.v2.workflow.Workflow` + instance. + :param dict attrs: Keyword arguments which will be used to update + a :class:`~openstack.workflow.v2.workflow.Workflow`, + comprised of the properties on the Workflow class. + + :returns: The results of workflow update + :rtype: :class:`~openstack.workflow.v2.workflow.Workflow` + """ + return self._update(_workflow.Workflow, workflow, **attrs) + def get_workflow(self, *attrs): """Get a workflow diff --git a/openstack/workflow/v2/workflow.py b/openstack/workflow/v2/workflow.py index ef3e6b785..e4f96f4eb 100644 --- a/openstack/workflow/v2/workflow.py +++ b/openstack/workflow/v2/workflow.py @@ -20,6 +20,7 @@ class Workflow(resource.Resource): # capabilities allow_create = True + allow_commit = True allow_list = True allow_fetch = True allow_delete = True @@ -47,7 +48,7 @@ class Workflow(resource.Resource): #: The time at which the workflow was created updated_at = resource.Body("updated_at") - def create(self, session, prepend_key=True, base_path=None): + def _request_kwargs(self, prepend_key=True, base_path=None): request = self._prepare_request( requires_id=False, prepend_key=prepend_key, base_path=base_path ) @@ -61,9 +62,23 @@ class Workflow(resource.Resource): uri = request.url + scope request.headers.update(headers) - response = session.post( - uri, json=None, headers=request.headers, **kwargs - ) + return dict(url=uri, json=None, headers=request.headers, **kwargs) + def create(self, session, prepend_key=True, base_path=None): + kwargs = self._request_kwargs( + prepend_key=prepend_key, base_path=base_path + ) + response = session.post(**kwargs) self._translate_response(response, has_body=False) return self + + def update(self, session, prepend_key=True, base_path=None): + kwargs = self._request_kwargs( + prepend_key=prepend_key, base_path=base_path + ) + response = session.put(**kwargs) + self._translate_response(response, has_body=False) + return self + + def commit(self, *args, **kwargs): + return self.update(*args, **kwargs) diff --git a/releasenotes/notes/update_workflow-ecdef6056ef2687b.yaml b/releasenotes/notes/update_workflow-ecdef6056ef2687b.yaml new file mode 100644 index 000000000..516004ff5 --- /dev/null +++ b/releasenotes/notes/update_workflow-ecdef6056ef2687b.yaml @@ -0,0 +1,3 @@ +features: + - | + Added ``update_workflow`` to the workflow proxy.