From e614f8ea76ffc872df2b246990db343db66c71cb Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 29 Aug 2024 14:38:48 +0100 Subject: [PATCH] Remove unexpected Resource.update overrides These should actually be Resource.commit. Change-Id: I59374b7cdd0dbba8de0dab28e46f9b08f0f1aa59 Signed-off-by: Stephen Finucane --- openstack/orchestration/v1/_proxy.py | 4 ++-- openstack/orchestration/v1/stack.py | 20 +++++++++++-------- .../tests/unit/orchestration/v1/test_proxy.py | 4 ++-- .../tests/unit/orchestration/v1/test_stack.py | 20 ++++--------------- openstack/workflow/v2/workflow.py | 15 ++++++++++---- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/openstack/orchestration/v1/_proxy.py b/openstack/orchestration/v1/_proxy.py index bcc461e76..49904115f 100644 --- a/openstack/orchestration/v1/_proxy.py +++ b/openstack/orchestration/v1/_proxy.py @@ -167,7 +167,7 @@ class Proxy(proxy.Proxy): """ return self._get(_stack.Stack, stack, resolve_outputs=resolve_outputs) - def update_stack(self, stack, preview=False, **attrs): + def update_stack(self, stack, *, preview=False, **attrs): """Update a stack :param stack: The value can be the ID of a stack or a @@ -181,7 +181,7 @@ class Proxy(proxy.Proxy): when no resource can be found. """ res = self._get_resource(_stack.Stack, stack, **attrs) - return res.update(self, preview) + return res.commit(self, preview) def delete_stack(self, stack, ignore_missing=True): """Delete a stack diff --git a/openstack/orchestration/v1/stack.py b/openstack/orchestration/v1/stack.py index 2001ca383..62a816f72 100644 --- a/openstack/orchestration/v1/stack.py +++ b/openstack/orchestration/v1/stack.py @@ -117,14 +117,18 @@ class Stack(resource.Resource): # heat doesn't accept resource_key in its request. return super().create(session, prepend_key=False, base_path=base_path) - def commit(self, session, base_path=None): - # This overrides the default behavior of resource creation because - # heat doesn't accept resource_key in its request. - return super().commit( - session, prepend_key=False, has_body=False, base_path=None - ) - - def update(self, session, preview=False): + def commit( + self, + session, + prepend_key=True, + has_body=True, + retry_on_conflict=None, + base_path=None, + *, + microversion=None, + preview=False, + **kwargs, + ): # This overrides the default behavior of resource update because # we need to use other endpoint for update preview. base_path = None diff --git a/openstack/tests/unit/orchestration/v1/test_proxy.py b/openstack/tests/unit/orchestration/v1/test_proxy.py index 72691b18e..846d44068 100644 --- a/openstack/tests/unit/orchestration/v1/test_proxy.py +++ b/openstack/tests/unit/orchestration/v1/test_proxy.py @@ -96,7 +96,7 @@ class TestOrchestrationStack(TestOrchestrationProxy): def test_update_stack(self): self._verify( - 'openstack.orchestration.v1.stack.Stack.update', + 'openstack.orchestration.v1.stack.Stack.commit', self.proxy.update_stack, expected_result='result', method_args=['stack'], @@ -106,7 +106,7 @@ class TestOrchestrationStack(TestOrchestrationProxy): def test_update_stack_preview(self): self._verify( - 'openstack.orchestration.v1.stack.Stack.update', + 'openstack.orchestration.v1.stack.Stack.commit', self.proxy.update_stack, expected_result='result', method_args=['stack'], diff --git a/openstack/tests/unit/orchestration/v1/test_stack.py b/openstack/tests/unit/orchestration/v1/test_stack.py index be7dd05b3..e9614ec08 100644 --- a/openstack/tests/unit/orchestration/v1/test_stack.py +++ b/openstack/tests/unit/orchestration/v1/test_stack.py @@ -188,18 +188,6 @@ class TestStack(base.TestCase): ) self.assertEqual(mock_create.return_value, res) - @mock.patch.object(resource.Resource, 'commit') - def test_commit(self, mock_commit): - sess = mock.Mock() - sot = stack.Stack() - - res = sot.commit(sess) - - mock_commit.assert_called_once_with( - sess, prepend_key=False, has_body=False, base_path=None - ) - self.assertEqual(mock_commit.return_value, res) - def test_check(self): sess = mock.Mock() sot = stack.Stack(**FAKE) @@ -287,7 +275,7 @@ class TestStack(base.TestCase): f'stacks/{FAKE_NAME}/{FAKE_ID}/export', ) - def test_update(self): + def test_commit(self): sess = mock.Mock() sess.default_microversion = None @@ -299,7 +287,7 @@ class TestStack(base.TestCase): sot = stack.Stack(**FAKE) body = sot._body.dirty.copy() - sot.update(sess) + sot.commit(sess) sess.put.assert_called_with( f'/stacks/{FAKE_NAME}/{FAKE_ID}', @@ -308,7 +296,7 @@ class TestStack(base.TestCase): json=body, ) - def test_update_preview(self): + def test_commit_preview(self): sess = mock.Mock() sess.default_microversion = None @@ -320,7 +308,7 @@ class TestStack(base.TestCase): sot = stack.Stack(**FAKE) body = sot._body.dirty.copy() - ret = sot.update(sess, preview=True) + ret = sot.commit(sess, preview=True) sess.put.assert_called_with( f'stacks/{FAKE_NAME}/{FAKE_ID}/preview', diff --git a/openstack/workflow/v2/workflow.py b/openstack/workflow/v2/workflow.py index e4f96f4eb..47e1afe9d 100644 --- a/openstack/workflow/v2/workflow.py +++ b/openstack/workflow/v2/workflow.py @@ -72,13 +72,20 @@ class Workflow(resource.Resource): self._translate_response(response, has_body=False) return self - def update(self, session, prepend_key=True, base_path=None): + def commit( + self, + session, + prepend_key=True, + has_body=True, + retry_on_conflict=None, + base_path=None, + *, + microversion=None, + **kwargs, + ): 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)