summaryrefslogtreecommitdiff
path: root/novaclient/tests
diff options
context:
space:
mode:
authorzhangbailin <zhangbailin@inspur.com>2020-03-12 18:44:36 +0800
committerzhangbailin <zhangbailin@inspur.com>2020-04-09 08:52:05 +0800
commit4d6c70d25df99a4f28f263cd3160c74ccf1343e3 (patch)
tree64ab8962905dee361f94d2b417081d1e77e5971b /novaclient/tests
parentea092b29880e71f0ba2d8e1eb93a9cf73edee2a2 (diff)
downloadpython-novaclient-4d6c70d25df99a4f28f263cd3160c74ccf1343e3.tar.gz
Microversion 2.85: Change volume-update CLI
This commit add a new CLI ``nova volume-update [--[no-]delete-on-termination] <server> <src_volume> <dest_volume>`` to update 'delete_on_termination' for an attached volume, that the user can decide whether to delete attached volumes when destroying the server. Depends-On: https://review.opendev.org/#/c/711194/ Change-Id: I1fc64fb6e6611c92c6b72265e1bf4b32e9c45f0a Blueprint: destroy-instance-with-datavolume
Diffstat (limited to 'novaclient/tests')
-rw-r--r--novaclient/tests/unit/v2/test_shell.py36
-rw-r--r--novaclient/tests/unit/v2/test_volumes.py23
2 files changed, 57 insertions, 2 deletions
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py
index 18badc0b..d21252bd 100644
--- a/novaclient/tests/unit/v2/test_shell.py
+++ b/novaclient/tests/unit/v2/test_shell.py
@@ -3992,11 +3992,43 @@ class ShellTest(utils.TestCase):
{'volumeAttachment':
{'volumeId': 'Work'}})
- def test_volume_update(self):
- self.run_command('volume-update sample-server Work Work')
+ def test_volume_update_pre_v285(self):
+ """Before microversion 2.85, we should keep the original behavior"""
+ self.run_command('volume-update sample-server Work Work',
+ api_version='2.84')
self.assert_called('PUT', '/servers/1234/os-volume_attachments/Work',
{'volumeAttachment': {'volumeId': 'Work'}})
+ def test_volume_update_swap_v285(self):
+ """Microversion 2.85, we should also keep the original behavior."""
+ self.run_command('volume-update sample-server Work Work',
+ api_version='2.85')
+ self.assert_called('PUT', '/servers/1234/os-volume_attachments/Work',
+ {'volumeAttachment': {'volumeId': 'Work'}})
+
+ def test_volume_update_v285(self):
+ self.run_command('volume-update sample-server --delete-on-termination '
+ 'Work Work', api_version='2.85')
+ body = {'volumeAttachment':
+ {'volumeId': 'Work', 'delete_on_termination': True}}
+ self.assert_called('PUT', '/servers/1234/os-volume_attachments/Work',
+ body)
+
+ self.run_command('volume-update sample-server '
+ '--no-delete-on-termination '
+ 'Work Work', api_version='2.85')
+ body = {'volumeAttachment':
+ {'volumeId': 'Work', 'delete_on_termination': False}}
+ self.assert_called('PUT', '/servers/1234/os-volume_attachments/Work',
+ body)
+
+ def test_volume_update_v285_conflicting(self):
+ self.assertRaises(
+ SystemExit, self.run_command,
+ 'volume-update sample-server --delete-on-termination '
+ '--no-delete-on-termination Work Work',
+ api_version='2.85')
+
def test_volume_detach(self):
self.run_command('volume-detach sample-server Work')
self.assert_called('DELETE',
diff --git a/novaclient/tests/unit/v2/test_volumes.py b/novaclient/tests/unit/v2/test_volumes.py
index d18f8466..93ea1c96 100644
--- a/novaclient/tests/unit/v2/test_volumes.py
+++ b/novaclient/tests/unit/v2/test_volumes.py
@@ -156,3 +156,26 @@ class VolumesV279Test(VolumesV249Test):
volume_id='15e59938-07d5-11e1-90e3-e3dffe0c5983',
delete_on_termination=True)
self.assertIn('delete_on_termination', str(ex))
+
+
+class VolumesV285Test(VolumesV279Test):
+ api_version = "2.85"
+
+ def test_volume_update_server_volume(self):
+ v = self.cs.volumes.update_server_volume(
+ server_id=1234,
+ src_volid='Work',
+ dest_volid='Work',
+ delete_on_termination=True
+ )
+ self.assert_request_id(v, fakes.FAKE_REQUEST_ID_LIST)
+ self.cs.assert_called('PUT',
+ '/servers/1234/os-volume_attachments/Work')
+ self.assertIsInstance(v, volumes.Volume)
+
+ def test_volume_update_server_volume_pre_v285(self):
+ self.cs.api_version = api_versions.APIVersion('2.84')
+ ex = self.assertRaises(
+ TypeError, self.cs.volumes.update_server_volume, "1234",
+ 'Work', 'Work', delete_on_termination=True)
+ self.assertIn('delete_on_termination', str(ex))