diff options
| author | zhangbailin <zhangbailin@inspur.com> | 2019-06-13 21:22:28 +0800 |
|---|---|---|
| committer | Matt Riedemann <mriedem.os@gmail.com> | 2019-08-28 17:43:22 -0400 |
| commit | ecfa521b2126e2f0cee25969a7d2c4c8637abba2 (patch) | |
| tree | 0efcfecd3d091d0f32c38906bfaba646a31998bd /novaclient/tests/unit | |
| parent | a3e44e8b39492e9604724cdfc5c9d2ede06e6c02 (diff) | |
| download | python-novaclient-ecfa521b2126e2f0cee25969a7d2c4c8637abba2.tar.gz | |
Microversion 2.77: Support Specifying AZ to unshelve
This patch adds a new parameter ``--availability-zone`` to ``nova
unshelve`` command. This can help users to specify an ``availability_zone``
to unshelve a shelve offloaded server from 2.77 microversion.
Depends-On: https://review.opendev.org/#/c/663851/
Implements: blueprint support-specifying-az-when-restore-shelved-server
Change-Id: I8bce8f430bc54f03bacc105e37fc8b3bbf2432c2
Diffstat (limited to 'novaclient/tests/unit')
| -rw-r--r-- | novaclient/tests/unit/fixture_data/servers.py | 2 | ||||
| -rw-r--r-- | novaclient/tests/unit/v2/fakes.py | 12 | ||||
| -rw-r--r-- | novaclient/tests/unit/v2/test_servers.py | 36 | ||||
| -rw-r--r-- | novaclient/tests/unit/v2/test_shell.py | 22 |
4 files changed, 71 insertions, 1 deletions
diff --git a/novaclient/tests/unit/fixture_data/servers.py b/novaclient/tests/unit/fixture_data/servers.py index d3354469..9962842a 100644 --- a/novaclient/tests/unit/fixture_data/servers.py +++ b/novaclient/tests/unit/fixture_data/servers.py @@ -456,6 +456,8 @@ class V1(Base): return None elif action == 'lock': return None + elif action == 'unshelve': + return None elif action == 'rebuild': body = body[action] adminPass = body.get('adminPass', 'randompassword') diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py index 29ec8887..faf5f6f4 100644 --- a/novaclient/tests/unit/v2/fakes.py +++ b/novaclient/tests/unit/v2/fakes.py @@ -775,7 +775,7 @@ class FakeSessionClient(base_client.SessionClient): none_actions = ['revertResize', 'os-stop', 'os-start', 'forceDelete', 'restore', 'pause', 'unpause', 'unlock', 'unrescue', 'resume', 'suspend', 'shelve', - 'shelveOffload', 'unshelve', 'resetNetwork'] + 'shelveOffload', 'resetNetwork'] type_actions = ['os-getVNCConsole', 'os-getSPICEConsole', 'os-getRDPConsole'] @@ -852,6 +852,16 @@ class FakeSessionClient(base_client.SessionClient): assert set(body[action].keys()) == expected else: assert body[action] is None + elif action == 'unshelve': + if self.api_version < api_versions.APIVersion("2.77"): + assert body[action] is None + else: + # In 2.77 and above, we allow body to be one of these: + # {'unshelve': None} + # {'unshelve': {'availability_zone': 'foo-az'}} + if body[action] is not None: + assert set(body[action].keys()) == set( + ['availability_zone']) elif action == 'rebuild': body = body[action] adminPass = body.get('adminPass', 'randompassword') diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py index 62c8d8d4..5ef987fa 100644 --- a/novaclient/tests/unit/v2/test_servers.py +++ b/novaclient/tests/unit/v2/test_servers.py @@ -1839,3 +1839,39 @@ class ServersV274Test(ServersV273Test): hypervisor_hostname="new-host") self.assertIn("'host' argument is only allowed since microversion " "2.74", six.text_type(ex)) + + +class ServersV277Test(ServersV274Test): + + api_version = "2.77" + + def test_unshelve_with_az(self): + s = self.cs.servers.get(1234) + # Test going through the Server object. + ret = s.unshelve(availability_zone='foo-az') + self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST) + self.assert_called('POST', '/servers/1234/action', + {'unshelve': { + 'availability_zone': 'foo-az'}}) + # Test going through the ServerManager directly. + ret = self.cs.servers.unshelve(s, availability_zone='foo-az') + self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST) + self.assert_called('POST', '/servers/1234/action', + {'unshelve': { + 'availability_zone': 'foo-az'}}) + + def test_unshelve_server_pre_277_fails_with_specified_az(self): + self.cs.api_version = api_versions.APIVersion('2.76') + s = self.cs.servers.get(1234) + # Test going through the Server object. + ex = self.assertRaises(TypeError, + s.unshelve, + availability_zone='foo-az') + self.assertIn("unexpected keyword argument 'availability_zone'", + six.text_type(ex)) + # Test going through the ServerManager directly. + ex = self.assertRaises(TypeError, + self.cs.servers.unshelve, + s, availability_zone='foo-az') + self.assertIn("unexpected keyword argument 'availability_zone'", + six.text_type(ex)) diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 7eb86d7a..2dc8a38a 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -2258,6 +2258,27 @@ class ShellTest(utils.TestCase): self.run_command('unshelve sample-server') self.assert_called('POST', '/servers/1234/action', {'unshelve': None}) + def test_unshelve_pre_v277_with_az_fails(self): + """Tests that trying to unshelve with an --availability-zone before + 2.77 is an error. + """ + self.assertRaises(SystemExit, + self.run_command, + 'unshelve --availability-zone foo-az sample-server', + api_version='2.76') + + def test_unshelve_v277(self): + # Test backward compat without an AZ specified. + self.run_command('unshelve sample-server', + api_version='2.77') + self.assert_called('POST', '/servers/1234/action', + {'unshelve': None}) + # Test with specifying an AZ. + self.run_command('unshelve --availability-zone foo-az sample-server', + api_version='2.77') + self.assert_called('POST', '/servers/1234/action', + {'unshelve': {'availability_zone': 'foo-az'}}) + def test_migrate(self): self.run_command('migrate sample-server') self.assert_called('POST', '/servers/1234/action', {'migrate': None}) @@ -4277,6 +4298,7 @@ class ShellTest(utils.TestCase): 74, # There are no version-wrapped shell method changes for this. 75, # There are no version-wrapped shell method changes for this. 76, # doesn't require any changes in novaclient. + 77, # There are no version-wrapped shell method changes for this. ]) versions_supported = set(range(0, novaclient.API_MAX_VERSION.ver_minor + 1)) |
