From 34d23cd12720559ecb95b3783837d06746ea5518 Mon Sep 17 00:00:00 2001 From: Thiago Brito Date: Wed, 17 Feb 2021 18:05:24 -0300 Subject: [PATCH] Adding retype_volume to BlockStorageCloudMixin We are missing some "/action" operations for volumes so this patch adds the ability to retype volumes to the sdk. Signed-off-by: Thiago Brito Change-Id: I6f8d58705db3c71abffd0e939d692bb02b8b1f32 --- openstack/block_storage/v3/volume.py | 10 ++++++++++ .../tests/unit/block_storage/v3/test_proxy.py | 12 ++++++++++++ .../tests/unit/block_storage/v3/test_volume.py | 15 +++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/openstack/block_storage/v3/volume.py b/openstack/block_storage/v3/volume.py index 477c03005..bef5a2fbd 100644 --- a/openstack/block_storage/v3/volume.py +++ b/openstack/block_storage/v3/volume.py @@ -119,5 +119,15 @@ class Volume(resource.Resource): body = {'os-update_readonly_flag': {'readonly': readonly}} self._action(session, body) + def retype(self, session, new_type, migration_policy): + """Retype volume considering the migration policy""" + body = { + 'os-retype': { + 'new_type': new_type, + 'migration_policy': migration_policy + } + } + self._action(session, body) + VolumeDetail = Volume diff --git a/openstack/tests/unit/block_storage/v3/test_proxy.py b/openstack/tests/unit/block_storage/v3/test_proxy.py index a83e5db4e..93b0b747b 100644 --- a/openstack/tests/unit/block_storage/v3/test_proxy.py +++ b/openstack/tests/unit/block_storage/v3/test_proxy.py @@ -172,6 +172,18 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase): method_args=["value", False], expected_args=[False]) + def test_volume_retype_without_migration_policy(self): + self._verify("openstack.block_storage.v3.volume.Volume.retype", + self.proxy.retype_volume, + method_args=["value", "rbd"], + expected_args=["rbd", "never"]) + + def test_volume_retype_with_migration_policy(self): + self._verify("openstack.block_storage.v3.volume.Volume.retype", + self.proxy.retype_volume, + method_args=["value", "rbd", "on-demand"], + expected_args=["rbd", "on-demand"]) + def test_backend_pools(self): self.verify_list(self.proxy.backend_pools, stats.Pools) diff --git a/openstack/tests/unit/block_storage/v3/test_volume.py b/openstack/tests/unit/block_storage/v3/test_volume.py index ac1a238f9..b6a4fc836 100644 --- a/openstack/tests/unit/block_storage/v3/test_volume.py +++ b/openstack/tests/unit/block_storage/v3/test_volume.py @@ -147,3 +147,18 @@ class TestVolume(base.TestCase): body = {'os-update_readonly_flag': {'readonly': False}} headers = {'Accept': ''} self.sess.post.assert_called_with(url, json=body, headers=headers) + + def test_retype(self): + sot = volume.Volume(**VOLUME) + + self.assertIsNone(sot.retype(self.sess, 'rbd', 'on-demand')) + + url = 'volumes/%s/action' % FAKE_ID + body = { + 'os-retype': { + 'new_type': 'rbd', + 'migration_policy': 'on-demand' + } + } + headers = {'Accept': ''} + self.sess.post.assert_called_with(url, json=body, headers=headers)