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 <server_id> <migration_id>

Implements blueprint: abort-live-migration

Depends-On: I1ff861e54997a069894b542bd764ac3ef1b3dbb2

Change-Id: Ic2ead126e0cf48aa54a083e97cb9d1303a5a9bbd
This commit is contained in:
Andrea Rosa 2016-02-22 16:27:52 +00:00 committed by Andrey Kurilin
parent e0c7d2c673
commit 77e50cc91b
7 changed files with 46 additions and 2 deletions

View File

@ -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")

View File

@ -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)

View File

@ -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):

View File

@ -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')

View File

@ -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)

View File

@ -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)))

View File

@ -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='<server>', help=_('Name or ID of server.'))
@cliutils.arg('migration', metavar='<migration>', 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',