Merge "Allow to override _max_microversion for Volume._action function"
This commit is contained in:
commit
f9da8c8a8a
openstack
@ -113,15 +113,15 @@ class Volume(resource.Resource, metadata.MetadataMixin):
|
||||
|
||||
_max_microversion = "3.60"
|
||||
|
||||
def _action(self, session, body, microversion=None):
|
||||
def _action(self, session, body, microversion=None, action='patch'):
|
||||
"""Preform volume actions given the message body."""
|
||||
# NOTE: This is using Volume.base_path instead of self.base_path
|
||||
# as both Volume and VolumeDetail instances can be acted on, but
|
||||
# the URL used is sans any additional /detail/ part.
|
||||
url = utils.urljoin(Volume.base_path, self.id, 'action')
|
||||
resp = session.post(
|
||||
url, json=body, microversion=self._max_microversion
|
||||
)
|
||||
if microversion is None:
|
||||
microversion = self._get_microversion(session, action=action)
|
||||
resp = session.post(url, json=body, microversion=microversion)
|
||||
exceptions.raise_from_response(resp)
|
||||
return resp
|
||||
|
||||
|
@ -150,7 +150,7 @@ class TestVolumeActions(TestVolume):
|
||||
self.resp.status_code = 200
|
||||
self.resp.json = mock.Mock(return_value=self.resp.body)
|
||||
self.sess = mock.Mock(spec=adapter.Adapter)
|
||||
self.sess.default_microversion = '3.0'
|
||||
self.sess.default_microversion = '3.60'
|
||||
self.sess.post = mock.Mock(return_value=self.resp)
|
||||
self.sess._get_connection = mock.Mock(return_value=self.cloud)
|
||||
|
||||
@ -662,7 +662,7 @@ class TestVolumeActions(TestVolume):
|
||||
self.sess.post.assert_called_with(
|
||||
url,
|
||||
json=body,
|
||||
microversion='3.0',
|
||||
microversion='3.60',
|
||||
headers={},
|
||||
params={},
|
||||
)
|
||||
@ -728,3 +728,12 @@ class TestVolumeActions(TestVolume):
|
||||
self.sess.post.assert_called_with(
|
||||
url, json=body, microversion=sot._max_microversion
|
||||
)
|
||||
|
||||
def test_set_microversion(self):
|
||||
sot = volume.Volume(**VOLUME)
|
||||
self.sess.default_microversion = '3.50'
|
||||
self.assertIsNone(sot.extend(self.sess, '20'))
|
||||
|
||||
url = 'volumes/%s/action' % FAKE_ID
|
||||
body = {"os-extend": {"new_size": "20"}}
|
||||
self.sess.post.assert_called_with(url, json=body, microversion="3.50")
|
||||
|
Loading…
x
Reference in New Issue
Block a user