Merge "Fix heat stack _action function to handle exception"

This commit is contained in:
Zuul 2023-08-25 08:42:46 +00:00 committed by Gerrit Code Review
commit 6b6ac851a2
2 changed files with 11 additions and 3 deletions

View File

@ -165,8 +165,9 @@ class Stack(resource.Resource):
def _action(self, session, body):
"""Perform stack actions"""
url = utils.urljoin(self.base_path, self._get_id(self), 'actions')
resp = session.post(url, json=body)
return resp.json()
resp = session.post(url, json=body, microversion=self.microversion)
exceptions.raise_from_response(resp)
return resp
def check(self, session):
return self._action(session, {'check': ''})

View File

@ -206,12 +206,19 @@ class TestStack(base.TestCase):
sess = mock.Mock()
sot = stack.Stack(**FAKE)
sot._action = mock.Mock()
sot._action.side_effect = [
test_resource.FakeResponse(None, 200, None),
exceptions.BadRequestException(message='oops'),
exceptions.NotFoundException(message='oops'),
]
body = {'check': ''}
sot.check(sess)
sot._action.assert_called_with(sess, body)
self.assertRaises(exceptions.BadRequestException, sot.check, sess)
self.assertRaises(exceptions.NotFoundException, sot.check, sess)
def test_fetch(self):
sess = mock.Mock()
sess.default_microversion = None