From 77e50cc91b328b1f7681cfc6f31bc41e40ab214e Mon Sep 17 00:00:00 2001 From: Andrea Rosa Date: Mon, 22 Feb 2016 16:27:52 +0000 Subject: [PATCH] Support for abort an ongoing live migration In Nova API microversion 2.24 there is a new operation which allows to abort a running live migration. This change is to enable this feature at the client side implementing a new method to call the new nova API: nova live-migration-abort Implements blueprint: abort-live-migration Depends-On: I1ff861e54997a069894b542bd764ac3ef1b3dbb2 Change-Id: Ic2ead126e0cf48aa54a083e97cb9d1303a5a9bbd --- novaclient/__init__.py | 2 +- .../tests/unit/fixture_data/server_migrations.py | 4 ++++ novaclient/tests/unit/v2/fakes.py | 3 +++ .../tests/unit/v2/test_server_migrations.py | 10 ++++++++++ novaclient/tests/unit/v2/test_shell.py | 5 +++++ novaclient/v2/server_migrations.py | 15 ++++++++++++++- novaclient/v2/shell.py | 9 +++++++++ 7 files changed, 46 insertions(+), 2 deletions(-) diff --git a/novaclient/__init__.py b/novaclient/__init__.py index c7bff3351..af127d4e8 100644 --- a/novaclient/__init__.py +++ b/novaclient/__init__.py @@ -25,4 +25,4 @@ API_MIN_VERSION = api_versions.APIVersion("2.1") # when client supported the max version, and bumped sequentially, otherwise # the client may break due to server side new version may include some # backward incompatible change. -API_MAX_VERSION = api_versions.APIVersion("2.23") +API_MAX_VERSION = api_versions.APIVersion("2.24") diff --git a/novaclient/tests/unit/fixture_data/server_migrations.py b/novaclient/tests/unit/fixture_data/server_migrations.py index 93f299fbe..5e946eef5 100644 --- a/novaclient/tests/unit/fixture_data/server_migrations.py +++ b/novaclient/tests/unit/fixture_data/server_migrations.py @@ -76,3 +76,7 @@ class Fixture(base.Fixture): status_code=200, json=get_migration, headers=self.json_headers) + url = self.url('1234', 'migrations', '1') + self.requests.register_uri('DELETE', url, + status_code=202, + headers=self.json_headers) diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py index 85f4b74bc..0d84abf9b 100644 --- a/novaclient/tests/unit/v2/fakes.py +++ b/novaclient/tests/unit/v2/fakes.py @@ -2495,6 +2495,9 @@ class FakeHTTPClient(base_client.HTTPClient): }]} return (200, FAKE_RESPONSE_HEADERS, migrations) + def delete_servers_1234_migrations_1(self): + return (202, {}, None) + class FakeSessionClient(fakes.FakeClient, client.Client): diff --git a/novaclient/tests/unit/v2/test_server_migrations.py b/novaclient/tests/unit/v2/test_server_migrations.py index e4a2b4bac..d0d8cdcc7 100644 --- a/novaclient/tests/unit/v2/test_server_migrations.py +++ b/novaclient/tests/unit/v2/test_server_migrations.py @@ -80,3 +80,13 @@ class ServerMigrationsTestV223(ServerMigrationsTest): self.assert_request_id(migration, fakes.FAKE_REQUEST_ID_LIST) self.assert_called('GET', '/servers/1234/migrations/1') + + +class ServerMigrationsTestV224(ServerMigrationsTest): + def setUp(self): + super(ServerMigrationsTestV224, self).setUp() + self.cs.api_version = api_versions.APIVersion("2.24") + + def test_live_migration_abort(self): + self.cs.server_migrations.live_migration_abort(1234, 1) + self.assert_called('DELETE', '/servers/1234/migrations/1') diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 7d1502eb2..8c0f0f0f5 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1697,6 +1697,11 @@ class ShellTest(utils.TestCase): api_version='2.23') self.assert_called('GET', '/servers/1234/migrations/1') + def test_live_migration_abort(self): + self.run_command('live-migration-abort sample-server 1', + api_version='2.24') + self.assert_called('DELETE', '/servers/1234/migrations/1') + def test_host_evacuate_live_with_no_target_host(self): self.run_command('host-evacuate-live hyper') self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0) diff --git a/novaclient/v2/server_migrations.py b/novaclient/v2/server_migrations.py index 68ee94c9b..a85e85f27 100644 --- a/novaclient/v2/server_migrations.py +++ b/novaclient/v2/server_migrations.py @@ -64,4 +64,17 @@ class ServerMigrationsManager(base.ManagerWithFind): :returns: An instance of novaclient.base.ListWithMeta """ return self._list( - '/servers/%s/migrations' % base.getid(server), "migrations") + '/servers/%s/migrations' % (base.getid(server)), "migrations") + + @api_versions.wraps("2.24") + def live_migration_abort(self, server, migration): + """ + Cancel an ongoing live migration + + :param server: The :class:`Server` (or its ID) + :param migration: Migration id that will be cancelled + :returns: An instance of novaclient.base.TupleWithMeta + """ + return self._delete( + '/servers/%s/migrations/%s' % (base.getid(server), + base.getid(migration))) diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 1dc728f82..5847a11f2 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -3883,6 +3883,15 @@ def do_server_migration_show(cs, args): utils.print_dict(migration._info) +@api_versions.wraps("2.24") +@cliutils.arg('server', metavar='', help=_('Name or ID of server.')) +@cliutils.arg('migration', metavar='', help=_('ID of migration.')) +def do_live_migration_abort(cs, args): + """Abort an on-going live migration.""" + server = _find_server(cs, args.server) + cs.server_migrations.live_migration_abort(server, args.migration) + + @cliutils.arg( '--all-tenants', action='store_const',