Adds migrate server extension for V3 API
Moves the migrate/live-migrate server functionality out of admin_actions into its own extension. This part of the blueprint v3-admin-actions-split allows more selective enablement of features contained in the admin actions extension. Note the XML api samples are no longer generated because bp remove-v3-xml-api has been approved. Refactor removes some exception handling for migrate along with the relevant tests as those exceptions will never occur. Partially implements bp v3-api-admin-actions-split DocImpact: Adds os-migrate-server extension and moves migrate/live-migrate functionality out of os-admin-actions into this new extension. Change-Id: I6b29f501ad6bb9a6401b1c20cd419d9e05fe369b
This commit is contained in:
parent
6d593641a0
commit
830ac0f065
10
doc/v3/api_samples/os-migrate-server/server-post-req.json
Normal file
10
doc/v3/api_samples/os-migrate-server/server-post-req.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"server" : {
|
||||
"name" : "new-server-test",
|
||||
"image_ref" : "http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b",
|
||||
"flavor_ref" : "http://openstack.example.com/flavors/1",
|
||||
"metadata" : {
|
||||
"My Server Name" : "Apache1"
|
||||
}
|
||||
}
|
||||
}
|
16
doc/v3/api_samples/os-migrate-server/server-post-resp.json
Normal file
16
doc/v3/api_samples/os-migrate-server/server-post-resp.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"server": {
|
||||
"admin_password": "DM3QzjhGTzLB",
|
||||
"id": "bebeec79-497e-4711-a311-d0d2e3dfc73b",
|
||||
"links": [
|
||||
{
|
||||
"href": "http://openstack.example.com/v3/servers/bebeec79-497e-4711-a311-d0d2e3dfc73b",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "http://openstack.example.com/servers/bebeec79-497e-4711-a311-d0d2e3dfc73b",
|
||||
"rel": "bookmark"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -42,9 +42,7 @@
|
||||
"compute_extension:v3:os-admin-actions:reset_network": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:inject_network_info": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:create_backup": "rule:admin_or_owner",
|
||||
"compute_extension:v3:os-admin-actions:migrate_live": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:reset_state": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:migrate": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-password": "",
|
||||
"compute_extension:v3:os-admin-password:discoverable": "",
|
||||
"compute_extension:aggregates": "rule:admin_api",
|
||||
@ -174,6 +172,9 @@
|
||||
"compute_extension:v3:os-lock-server:discoverable": "",
|
||||
"compute_extension:v3:os-lock-server:lock": "rule:admin_or_owner",
|
||||
"compute_extension:v3:os-lock-server:unlock": "rule:admin_or_owner",
|
||||
"compute_extension:v3:os-migrate-server:discoverable": "",
|
||||
"compute_extension:v3:os-migrate-server:migrate": "rule:admin_api",
|
||||
"compute_extension:v3:os-migrate-server:migrate_live": "rule:admin_api",
|
||||
"compute_extension:multinic": "",
|
||||
"compute_extension:v3:os-multinic": "",
|
||||
"compute_extension:v3:os-multinic:discoverable": "",
|
||||
|
@ -25,7 +25,6 @@ from nova.compute import vm_states
|
||||
from nova import exception
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.openstack.common import strutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
ALIAS = "os-admin-actions"
|
||||
@ -44,34 +43,6 @@ class AdminActionsController(wsgi.Controller):
|
||||
super(AdminActionsController, self).__init__(*args, **kwargs)
|
||||
self.compute_api = compute.API()
|
||||
|
||||
@extensions.expected_errors((400, 404, 409, 413))
|
||||
@wsgi.action('migrate')
|
||||
def _migrate(self, req, id, body):
|
||||
"""Permit admins to migrate a server to a new host."""
|
||||
context = req.environ['nova.context']
|
||||
authorize(context, 'migrate')
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
want_objects=True)
|
||||
try:
|
||||
self.compute_api.resize(req.environ['nova.context'], instance)
|
||||
except exception.QuotaError as error:
|
||||
raise exc.HTTPRequestEntityTooLarge(
|
||||
explanation=error.format_message(),
|
||||
headers={'Retry-After': 0})
|
||||
except exception.InstanceIsLocked as e:
|
||||
raise exc.HTTPConflict(explanation=e.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'migrate')
|
||||
except exception.FlavorNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.CannotResizeToSameFlavor as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.format_message())
|
||||
except exception.TooManyInstances as e:
|
||||
raise exc.HTTPRequestEntityTooLarge(explanation=e.format_message())
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@extensions.expected_errors((404, 409))
|
||||
@wsgi.action('reset_network')
|
||||
def _reset_network(self, req, id, body):
|
||||
@ -168,49 +139,6 @@ class AdminActionsController(wsgi.Controller):
|
||||
|
||||
return resp
|
||||
|
||||
@extensions.expected_errors((400, 404, 409))
|
||||
@wsgi.action('migrate_live')
|
||||
def _migrate_live(self, req, id, body):
|
||||
"""Permit admins to (live) migrate a server to a new host."""
|
||||
context = req.environ["nova.context"]
|
||||
authorize(context, 'migrate_live')
|
||||
|
||||
try:
|
||||
block_migration = body["migrate_live"]["block_migration"]
|
||||
disk_over_commit = body["migrate_live"]["disk_over_commit"]
|
||||
host = body["migrate_live"]["host"]
|
||||
except (TypeError, KeyError):
|
||||
msg = _("host, block_migration and disk_over_commit must "
|
||||
"be specified for live migration.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
block_migration = strutils.bool_from_string(block_migration,
|
||||
strict=True)
|
||||
disk_over_commit = strutils.bool_from_string(disk_over_commit,
|
||||
strict=True)
|
||||
except ValueError as err:
|
||||
raise exc.HTTPBadRequest(explanation=str(err))
|
||||
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
want_objects=True)
|
||||
self.compute_api.live_migrate(context, instance, block_migration,
|
||||
disk_over_commit, host)
|
||||
except (exception.ComputeServiceUnavailable,
|
||||
exception.InvalidHypervisorType,
|
||||
exception.UnableToMigrateToSelf,
|
||||
exception.DestinationHypervisorTooOld,
|
||||
exception.NoValidHost,
|
||||
exception.InvalidLocalStorage,
|
||||
exception.InvalidSharedStorage,
|
||||
exception.MigrationPreCheckError) as ex:
|
||||
raise exc.HTTPBadRequest(explanation=ex.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'migrate_live')
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@extensions.expected_errors((400, 404))
|
||||
@wsgi.action('reset_state')
|
||||
def _reset_state(self, req, id, body):
|
||||
|
126
nova/api/openstack/compute/plugins/v3/migrate_server.py
Normal file
126
nova/api/openstack/compute/plugins/v3/migrate_server.py
Normal file
@ -0,0 +1,126 @@
|
||||
# Copyright 2011 OpenStack Foundation
|
||||
# Copyright 2013 IBM Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack import common
|
||||
from nova.api.openstack import extensions
|
||||
from nova.api.openstack import wsgi
|
||||
from nova import compute
|
||||
from nova import exception
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.openstack.common import strutils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
ALIAS = "os-migrate-server"
|
||||
|
||||
|
||||
def authorize(context, action_name):
|
||||
action = 'v3:%s:%s' % (ALIAS, action_name)
|
||||
extensions.extension_authorizer('compute', action)(context)
|
||||
|
||||
|
||||
class MigrateServerController(wsgi.Controller):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MigrateServerController, self).__init__(*args, **kwargs)
|
||||
self.compute_api = compute.API()
|
||||
|
||||
@extensions.expected_errors((400, 404, 409, 413))
|
||||
@wsgi.action('migrate')
|
||||
def _migrate(self, req, id, body):
|
||||
"""Permit admins to migrate a server to a new host."""
|
||||
context = req.environ['nova.context']
|
||||
authorize(context, 'migrate')
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
want_objects=True)
|
||||
try:
|
||||
self.compute_api.resize(req.environ['nova.context'], instance)
|
||||
except exception.TooManyInstances as e:
|
||||
raise exc.HTTPRequestEntityTooLarge(explanation=e.format_message())
|
||||
except exception.QuotaError as error:
|
||||
raise exc.HTTPRequestEntityTooLarge(
|
||||
explanation=error.format_message(),
|
||||
headers={'Retry-After': 0})
|
||||
except exception.InstanceIsLocked as e:
|
||||
raise exc.HTTPConflict(explanation=e.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'migrate')
|
||||
except exception.InstanceNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@extensions.expected_errors((400, 404, 409))
|
||||
@wsgi.action('migrate_live')
|
||||
def _migrate_live(self, req, id, body):
|
||||
"""Permit admins to (live) migrate a server to a new host."""
|
||||
context = req.environ["nova.context"]
|
||||
authorize(context, 'migrate_live')
|
||||
|
||||
try:
|
||||
block_migration = body["migrate_live"]["block_migration"]
|
||||
disk_over_commit = body["migrate_live"]["disk_over_commit"]
|
||||
host = body["migrate_live"]["host"]
|
||||
except (TypeError, KeyError):
|
||||
msg = _("host, block_migration and disk_over_commit must "
|
||||
"be specified for live migration.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
block_migration = strutils.bool_from_string(block_migration,
|
||||
strict=True)
|
||||
disk_over_commit = strutils.bool_from_string(disk_over_commit,
|
||||
strict=True)
|
||||
except ValueError as err:
|
||||
raise exc.HTTPBadRequest(explanation=str(err))
|
||||
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
want_objects=True)
|
||||
self.compute_api.live_migrate(context, instance, block_migration,
|
||||
disk_over_commit, host)
|
||||
except (exception.ComputeServiceUnavailable,
|
||||
exception.InvalidHypervisorType,
|
||||
exception.UnableToMigrateToSelf,
|
||||
exception.DestinationHypervisorTooOld,
|
||||
exception.NoValidHost,
|
||||
exception.InvalidLocalStorage,
|
||||
exception.InvalidSharedStorage,
|
||||
exception.MigrationPreCheckError) as ex:
|
||||
raise exc.HTTPBadRequest(explanation=ex.format_message())
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'migrate_live')
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
class MigrateServer(extensions.V3APIExtensionBase):
|
||||
"""Enable migrate and live-migrate server actions."""
|
||||
|
||||
name = "MigrateServer"
|
||||
alias = ALIAS
|
||||
namespace = "http://docs.openstack.org/compute/ext/%s/api/v3" % ALIAS
|
||||
version = 1
|
||||
|
||||
def get_controller_extensions(self):
|
||||
controller = MigrateServerController()
|
||||
extension = extensions.ControllerExtension(self, 'servers', controller)
|
||||
return [extension]
|
||||
|
||||
def get_resources(self):
|
||||
return []
|
@ -69,17 +69,21 @@ class CommonMixin(object):
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def _test_action(self, action, body=None, method=None):
|
||||
def _test_action(self, action, body=None, method=None,
|
||||
compute_api_args_map={}):
|
||||
if method is None:
|
||||
method = action
|
||||
|
||||
instance = self._stub_instance_get()
|
||||
getattr(self.compute_api, method)(self.context, instance)
|
||||
|
||||
args, kwargs = compute_api_args_map.get(action, ((), {}))
|
||||
getattr(self.compute_api, method)(self.context, instance, *args,
|
||||
**kwargs)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance.uuid,
|
||||
{action: None})
|
||||
{action: body})
|
||||
self.assertEqual(202, res.status_int)
|
||||
# Do these here instead of tearDown because this method is called
|
||||
# more than once for the same test case
|
||||
@ -116,18 +120,22 @@ class CommonMixin(object):
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def _test_locked_instance(self, action, method=None):
|
||||
def _test_locked_instance(self, action, method=None, body=None,
|
||||
compute_api_args_map={}):
|
||||
if method is None:
|
||||
method = action
|
||||
|
||||
instance = self._stub_instance_get()
|
||||
getattr(self.compute_api, method)(self.context, instance).AndRaise(
|
||||
|
||||
args, kwargs = compute_api_args_map.get(action, ((), {}))
|
||||
getattr(self.compute_api, method)(self.context, instance, *args,
|
||||
**kwargs).AndRaise(
|
||||
exception.InstanceIsLocked(instance_uuid=instance.uuid))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance.uuid,
|
||||
{action: None})
|
||||
{action: body})
|
||||
self.assertEqual(409, res.status_int)
|
||||
# Do these here instead of tearDown because this method is called
|
||||
# more than once for the same test case
|
||||
@ -136,11 +144,14 @@ class CommonMixin(object):
|
||||
|
||||
|
||||
class CommonTests(CommonMixin, test.NoDBTestCase):
|
||||
def _test_actions(self, actions, method_translations={}):
|
||||
def _test_actions(self, actions, method_translations={}, body_map={},
|
||||
args_map={}):
|
||||
for action in actions:
|
||||
method = method_translations.get(action)
|
||||
body = body_map.get(action)
|
||||
self.mox.StubOutWithMock(self.compute_api, method or action)
|
||||
self._test_action(action, method=method)
|
||||
self._test_action(action, method=method, body=body,
|
||||
compute_api_args_map=args_map)
|
||||
# Re-mock this.
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
@ -163,10 +174,13 @@ class CommonTests(CommonMixin, test.NoDBTestCase):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
def _test_actions_with_locked_instance(self, actions,
|
||||
method_translations={}):
|
||||
method_translations={},
|
||||
body_map={}, args_map={}):
|
||||
for action in actions:
|
||||
method = method_translations.get(action)
|
||||
body = body_map.get(action)
|
||||
self.mox.StubOutWithMock(self.compute_api, method or action)
|
||||
self._test_locked_instance(action, method=method)
|
||||
self._test_locked_instance(action, method=method, body=body,
|
||||
compute_api_args_map=args_map)
|
||||
# Re-mock this.
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
@ -156,42 +156,17 @@ class CommonMixin(object):
|
||||
|
||||
class AdminActionsTest(CommonMixin, test.NoDBTestCase):
|
||||
def test_actions(self):
|
||||
actions = ['migrate', 'reset_network', 'inject_network_info']
|
||||
method_translations = {'migrate': 'resize'}
|
||||
actions = ['reset_network', 'inject_network_info']
|
||||
|
||||
for action in actions:
|
||||
method = method_translations.get(action)
|
||||
self.mox.StubOutWithMock(self.compute_api, method or action)
|
||||
self._test_action(action, method=method)
|
||||
# Re-mock this.
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
def test_actions_raise_conflict_on_invalid_state(self):
|
||||
actions = ['migrate', 'migrate_live']
|
||||
method_translations = {'migrate': 'resize',
|
||||
'migrate_live': 'live_migrate'}
|
||||
|
||||
body_map = {'migrate_live': {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}}
|
||||
args_map = {'migrate_live': ((False, False, 'hostname'), {})}
|
||||
|
||||
for action in actions:
|
||||
method = method_translations.get(action)
|
||||
self.mox.StubOutWithMock(self.compute_api, method or action)
|
||||
self._test_invalid_state(action, method=method,
|
||||
body_map=body_map,
|
||||
compute_api_args_map=args_map)
|
||||
self.mox.StubOutWithMock(self.compute_api, action)
|
||||
self._test_action(action)
|
||||
# Re-mock this.
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
def test_actions_with_non_existed_instance(self):
|
||||
actions = ['migrate', 'reset_network', 'inject_network_info',
|
||||
'reset_state', 'migrate_live']
|
||||
body_map = {'reset_state': {'state': 'active'},
|
||||
'migrate_live': {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}}
|
||||
actions = ['reset_network', 'inject_network_info', 'reset_state']
|
||||
body_map = {'reset_state': {'state': 'active'}}
|
||||
for action in actions:
|
||||
self._test_non_existing_instance(action,
|
||||
body_map=body_map)
|
||||
@ -199,134 +174,14 @@ class AdminActionsTest(CommonMixin, test.NoDBTestCase):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
def test_actions_with_locked_instance(self):
|
||||
actions = ['migrate', 'reset_network', 'inject_network_info']
|
||||
method_translations = {'migrate': 'resize'}
|
||||
actions = ['reset_network', 'inject_network_info']
|
||||
|
||||
for action in actions:
|
||||
method = method_translations.get(action)
|
||||
self.mox.StubOutWithMock(self.compute_api, method or action)
|
||||
self._test_locked_instance(action, method=method)
|
||||
self.mox.StubOutWithMock(self.compute_api, action)
|
||||
self._test_locked_instance(action)
|
||||
# Re-mock this.
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
def _test_migrate_exception(self, exc_info, expected_result):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'resize')
|
||||
instance = self._stub_instance_get()
|
||||
self.compute_api.resize(self.context, instance).AndRaise(exc_info)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance['uuid'],
|
||||
{'migrate': None})
|
||||
self.assertEqual(expected_result, res.status_int)
|
||||
|
||||
def test_migrate_resize_to_same_flavor(self):
|
||||
exc_info = exception.CannotResizeToSameFlavor()
|
||||
self._test_migrate_exception(exc_info, 400)
|
||||
|
||||
def test_migrate_too_many_instances(self):
|
||||
exc_info = exception.TooManyInstances(overs='', req='', used=0,
|
||||
allowed=0, resource='')
|
||||
self._test_migrate_exception(exc_info, 413)
|
||||
|
||||
def _test_migrate_live_succeeded(self, param):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'live_migrate')
|
||||
instance = self._stub_instance_get()
|
||||
self.compute_api.live_migrate(self.context, instance, False,
|
||||
False, 'hostname')
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance.uuid,
|
||||
{'migrate_live': param})
|
||||
self.assertEqual(202, res.status_int)
|
||||
|
||||
def test_migrate_live_enabled(self):
|
||||
param = {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}
|
||||
self._test_migrate_live_succeeded(param)
|
||||
|
||||
def test_migrate_live_enabled_with_string_param(self):
|
||||
param = {'host': 'hostname',
|
||||
'block_migration': "False",
|
||||
'disk_over_commit': "False"}
|
||||
self._test_migrate_live_succeeded(param)
|
||||
|
||||
def test_migrate_live_missing_dict_param(self):
|
||||
res = self._make_request('/servers/FAKE/action',
|
||||
{'migrate_live': {'dummy': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_migrate_live_with_invalid_block_migration(self):
|
||||
res = self._make_request('/servers/FAKE/action',
|
||||
{'migrate_live': {'host': 'hostname',
|
||||
'block_migration': "foo",
|
||||
'disk_over_commit': False}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_migrate_live_with_invalid_disk_over_commit(self):
|
||||
res = self._make_request('/servers/FAKE/action',
|
||||
{'migrate_live': {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': "foo"}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def _test_migrate_live_failed_with_exception(self, fake_exc,
|
||||
uuid=None):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'live_migrate')
|
||||
|
||||
instance = self._stub_instance_get(uuid=uuid)
|
||||
self.compute_api.live_migrate(self.context, instance, False,
|
||||
False, 'hostname').AndRaise(fake_exc)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance.uuid,
|
||||
{'migrate_live':
|
||||
{'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
self.assertIn(unicode(fake_exc), res.body)
|
||||
|
||||
def test_migrate_live_compute_service_unavailable(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.ComputeServiceUnavailable(host='host'))
|
||||
|
||||
def test_migrate_live_invalid_hypervisor_type(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.InvalidHypervisorType())
|
||||
|
||||
def test_migrate_live_unable_to_migrate_to_self(self):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.UnableToMigrateToSelf(instance_id=uuid,
|
||||
host='host'),
|
||||
uuid=uuid)
|
||||
|
||||
def test_migrate_live_destination_hypervisor_too_old(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.DestinationHypervisorTooOld())
|
||||
|
||||
def test_migrate_live_no_valid_host(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.NoValidHost(reason=''))
|
||||
|
||||
def test_migrate_live_invalid_local_storage(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.InvalidLocalStorage(path='', reason=''))
|
||||
|
||||
def test_migrate_live_invalid_shared_storage(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.InvalidSharedStorage(path='', reason=''))
|
||||
|
||||
def test_migrate_live_pre_check_error(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.MigrationPreCheckError(reason=''))
|
||||
|
||||
|
||||
class CreateBackupTests(CommonMixin, test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
|
@ -0,0 +1,186 @@
|
||||
# Copyright 2011 OpenStack Foundation
|
||||
# Copyright 2013 IBM Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.api.openstack.compute.plugins.v3 import migrate_server
|
||||
from nova import exception
|
||||
from nova.openstack.common import uuidutils
|
||||
from nova.tests.api.openstack.compute.plugins.v3 import \
|
||||
admin_only_action_common
|
||||
from nova.tests.api.openstack import fakes
|
||||
|
||||
|
||||
class MigrateServerTests(admin_only_action_common.CommonTests):
|
||||
def setUp(self):
|
||||
super(MigrateServerTests, self).setUp()
|
||||
self.controller = migrate_server.MigrateServerController()
|
||||
self.compute_api = self.controller.compute_api
|
||||
|
||||
def _fake_controller(*args, **kwargs):
|
||||
return self.controller
|
||||
|
||||
self.stubs.Set(migrate_server, 'MigrateServerController',
|
||||
_fake_controller)
|
||||
self.app = fakes.wsgi_app_v3(init_only=('servers',
|
||||
'os-migrate-server'),
|
||||
fake_auth_context=self.context)
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
def test_migrate(self):
|
||||
method_translations = {'migrate': 'resize',
|
||||
'migrate_live': 'live_migrate'}
|
||||
body_map = {'migrate_live': {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}}
|
||||
args_map = {'migrate_live': ((False, False, 'hostname'), {})}
|
||||
self._test_actions(['migrate', 'migrate_live'], body_map=body_map,
|
||||
method_translations=method_translations,
|
||||
args_map=args_map)
|
||||
|
||||
def test_migrate_with_non_existed_instance(self):
|
||||
body_map = {'migrate_live': {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}}
|
||||
self._test_actions_with_non_existed_instance(
|
||||
['migrate', 'migrate_live'], body_map=body_map)
|
||||
|
||||
def test_migrate_raise_conflict_on_invalid_state(self):
|
||||
method_translations = {'migrate': 'resize',
|
||||
'migrate_live': 'live_migrate'}
|
||||
body_map = {'migrate_live': {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}}
|
||||
args_map = {'migrate_live': ((False, False, 'hostname'), {})}
|
||||
self._test_actions_raise_conflict_on_invalid_state(
|
||||
['migrate', 'migrate_live'], body_map=body_map, args_map=args_map,
|
||||
method_translations=method_translations)
|
||||
|
||||
def test_actions_with_locked_instance(self):
|
||||
method_translations = {'migrate': 'resize'}
|
||||
self._test_actions_with_locked_instance(['migrate'],
|
||||
method_translations=method_translations)
|
||||
|
||||
def _test_migrate_exception(self, exc_info, expected_result):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'resize')
|
||||
instance = self._stub_instance_get()
|
||||
self.compute_api.resize(self.context, instance).AndRaise(exc_info)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance['uuid'],
|
||||
{'migrate': None})
|
||||
self.assertEqual(expected_result, res.status_int)
|
||||
|
||||
def test_migrate_too_many_instances(self):
|
||||
exc_info = exception.TooManyInstances(overs='', req='', used=0,
|
||||
allowed=0, resource='')
|
||||
self._test_migrate_exception(exc_info, 413)
|
||||
|
||||
def _test_migrate_live_succeeded(self, param):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'live_migrate')
|
||||
instance = self._stub_instance_get()
|
||||
self.compute_api.live_migrate(self.context, instance, False,
|
||||
False, 'hostname')
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance.uuid,
|
||||
{'migrate_live': param})
|
||||
self.assertEqual(202, res.status_int)
|
||||
|
||||
def test_migrate_live_enabled(self):
|
||||
param = {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}
|
||||
self._test_migrate_live_succeeded(param)
|
||||
|
||||
def test_migrate_live_enabled_with_string_param(self):
|
||||
param = {'host': 'hostname',
|
||||
'block_migration': "False",
|
||||
'disk_over_commit': "False"}
|
||||
self._test_migrate_live_succeeded(param)
|
||||
|
||||
def test_migrate_live_missing_dict_param(self):
|
||||
res = self._make_request('/servers/FAKE/action',
|
||||
{'migrate_live': {'dummy': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_migrate_live_with_invalid_block_migration(self):
|
||||
res = self._make_request('/servers/FAKE/action',
|
||||
{'migrate_live': {'host': 'hostname',
|
||||
'block_migration': "foo",
|
||||
'disk_over_commit': False}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_migrate_live_with_invalid_disk_over_commit(self):
|
||||
res = self._make_request('/servers/FAKE/action',
|
||||
{'migrate_live': {'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': "foo"}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def _test_migrate_live_failed_with_exception(self, fake_exc,
|
||||
uuid=None):
|
||||
self.mox.StubOutWithMock(self.compute_api, 'live_migrate')
|
||||
|
||||
instance = self._stub_instance_get(uuid=uuid)
|
||||
self.compute_api.live_migrate(self.context, instance, False,
|
||||
False, 'hostname').AndRaise(fake_exc)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance.uuid,
|
||||
{'migrate_live':
|
||||
{'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False}})
|
||||
self.assertEqual(400, res.status_int)
|
||||
self.assertIn(unicode(fake_exc), res.body)
|
||||
|
||||
def test_migrate_live_compute_service_unavailable(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.ComputeServiceUnavailable(host='host'))
|
||||
|
||||
def test_migrate_live_invalid_hypervisor_type(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.InvalidHypervisorType())
|
||||
|
||||
def test_migrate_live_unable_to_migrate_to_self(self):
|
||||
uuid = uuidutils.generate_uuid()
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.UnableToMigrateToSelf(instance_id=uuid,
|
||||
host='host'),
|
||||
uuid=uuid)
|
||||
|
||||
def test_migrate_live_destination_hypervisor_too_old(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.DestinationHypervisorTooOld())
|
||||
|
||||
def test_migrate_live_no_valid_host(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.NoValidHost(reason=''))
|
||||
|
||||
def test_migrate_live_invalid_local_storage(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.InvalidLocalStorage(path='', reason=''))
|
||||
|
||||
def test_migrate_live_invalid_shared_storage(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.InvalidSharedStorage(path='', reason=''))
|
||||
|
||||
def test_migrate_live_pre_check_error(self):
|
||||
self._test_migrate_live_failed_with_exception(
|
||||
exception.MigrationPreCheckError(reason=''))
|
@ -118,9 +118,7 @@ policy_data = """
|
||||
"compute_extension:v3:os-admin-actions:reset_network": "",
|
||||
"compute_extension:v3:os-admin-actions:inject_network_info": "",
|
||||
"compute_extension:v3:os-admin-actions:create_backup": "",
|
||||
"compute_extension:v3:os-admin-actions:migrate_live": "",
|
||||
"compute_extension:v3:os-admin-actions:reset_state": "",
|
||||
"compute_extension:v3:os-admin-actions:migrate": "",
|
||||
"compute_extension:v3:os-admin-password": "",
|
||||
"compute_extension:aggregates": "rule:admin_api",
|
||||
"compute_extension:v3:os-aggregates:index": "rule:admin_api",
|
||||
@ -229,6 +227,8 @@ policy_data = """
|
||||
"compute_extension:v3:keypairs:delete": "",
|
||||
"compute_extension:v3:os-lock-server:lock": "",
|
||||
"compute_extension:v3:os-lock-server:unlock": "",
|
||||
"compute_extension:v3:os-migrate-server:migrate": "",
|
||||
"compute_extension:v3:os-migrate-server:migrate_live": "",
|
||||
"compute_extension:multinic": "",
|
||||
"compute_extension:v3:os-multinic": "",
|
||||
"compute_extension:networks": "",
|
||||
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"server" : {
|
||||
"name" : "new-server-test",
|
||||
"image_ref" : "%(glance_host)s/images/%(image_id)s",
|
||||
"flavor_ref" : "%(host)s/flavors/1",
|
||||
"metadata" : {
|
||||
"My Server Name" : "Apache1"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"server": {
|
||||
"admin_password": "%(password)s",
|
||||
"id": "%(id)s",
|
||||
"links": [
|
||||
{
|
||||
"href": "%(host)s/v3/servers/%(uuid)s",
|
||||
"rel": "self"
|
||||
},
|
||||
{
|
||||
"href": "%(host)s/servers/%(uuid)s",
|
||||
"rel": "bookmark"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -13,8 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.conductor import manager as conductor_manager
|
||||
from nova import db
|
||||
from nova.tests.image import fake
|
||||
from nova.tests.integrated.v3 import test_servers
|
||||
|
||||
@ -30,12 +28,6 @@ class AdminActionsSamplesJsonTest(test_servers.ServersSampleBase):
|
||||
super(AdminActionsSamplesJsonTest, self).setUp()
|
||||
self.uuid = self._post_server()
|
||||
|
||||
def test_post_migrate(self):
|
||||
# Get api samples to migrate server request.
|
||||
response = self._do_post('servers/%s/action' % self.uuid,
|
||||
'admin-actions-migrate', {})
|
||||
self.assertEqual(response.status, 202)
|
||||
|
||||
def test_post_reset_network(self):
|
||||
# Get api samples to reset server network request.
|
||||
response = self._do_post('servers/%s/action' % self.uuid,
|
||||
@ -63,35 +55,6 @@ class AdminActionsSamplesJsonTest(test_servers.ServersSampleBase):
|
||||
'admin-actions-backup-server', {})
|
||||
self.assertEqual(response.status, 202)
|
||||
|
||||
def test_post_live_migrate_server(self):
|
||||
# Get api samples to server live migrate request.
|
||||
def fake_live_migrate(_self, context, instance, scheduler_hint,
|
||||
block_migration, disk_over_commit):
|
||||
self.assertEqual(self.uuid, instance["uuid"])
|
||||
host = scheduler_hint["host"]
|
||||
self.assertEqual(self.compute.host, host)
|
||||
|
||||
self.stubs.Set(conductor_manager.ComputeTaskManager,
|
||||
'_live_migrate',
|
||||
fake_live_migrate)
|
||||
|
||||
def fake_get_compute(context, host):
|
||||
service = dict(host=host,
|
||||
binary='nova-compute',
|
||||
topic='compute',
|
||||
report_count=1,
|
||||
updated_at='foo',
|
||||
hypervisor_type='bar',
|
||||
hypervisor_version='1',
|
||||
disabled=False)
|
||||
return {'compute_node': [service]}
|
||||
self.stubs.Set(db, "service_get_by_compute_host", fake_get_compute)
|
||||
|
||||
response = self._do_post('servers/%s/action' % self.uuid,
|
||||
'admin-actions-live-migrate',
|
||||
{'hostname': self.compute.host})
|
||||
self.assertEqual(response.status, 202)
|
||||
|
||||
def test_post_reset_state(self):
|
||||
# get api samples to server reset state request.
|
||||
response = self._do_post('servers/%s/action' % self.uuid,
|
||||
|
66
nova/tests/integrated/v3/test_migrate_server.py
Normal file
66
nova/tests/integrated/v3/test_migrate_server.py
Normal file
@ -0,0 +1,66 @@
|
||||
# Copyright 2012 Nebula, Inc.
|
||||
# Copyright 2013 IBM Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.conductor import manager as conductor_manager
|
||||
from nova import db
|
||||
from nova.tests.integrated.v3 import test_servers
|
||||
|
||||
|
||||
class MigrateServerSamplesJsonTest(test_servers.ServersSampleBase):
|
||||
extension_name = "os-migrate-server"
|
||||
ctype = 'json'
|
||||
|
||||
def setUp(self):
|
||||
"""setUp Method for MigrateServer api samples extension
|
||||
|
||||
This method creates the server that will be used in each tests
|
||||
"""
|
||||
super(MigrateServerSamplesJsonTest, self).setUp()
|
||||
self.uuid = self._post_server()
|
||||
|
||||
def test_post_migrate(self):
|
||||
# Get api samples to migrate server request.
|
||||
response = self._do_post('servers/%s/action' % self.uuid,
|
||||
'migrate-server', {})
|
||||
self.assertEqual(response.status, 202)
|
||||
|
||||
def test_post_live_migrate_server(self):
|
||||
# Get api samples to server live migrate request.
|
||||
def fake_live_migrate(_self, context, instance, scheduler_hint,
|
||||
block_migration, disk_over_commit):
|
||||
self.assertEqual(self.uuid, instance["uuid"])
|
||||
host = scheduler_hint["host"]
|
||||
self.assertEqual(self.compute.host, host)
|
||||
|
||||
self.stubs.Set(conductor_manager.ComputeTaskManager,
|
||||
'_live_migrate',
|
||||
fake_live_migrate)
|
||||
|
||||
def fake_get_compute(context, host):
|
||||
service = dict(host=host,
|
||||
binary='nova-compute',
|
||||
topic='compute',
|
||||
report_count=1,
|
||||
updated_at='foo',
|
||||
hypervisor_type='bar',
|
||||
hypervisor_version='1',
|
||||
disabled=False)
|
||||
return {'compute_node': [service]}
|
||||
self.stubs.Set(db, "service_get_by_compute_host", fake_get_compute)
|
||||
|
||||
response = self._do_post('servers/%s/action' % self.uuid,
|
||||
'live-migrate-server',
|
||||
{'hostname': self.compute.host})
|
||||
self.assertEqual(response.status, 202)
|
@ -89,6 +89,7 @@ nova.api.v3.extensions =
|
||||
instance_usage_audit_log = nova.api.openstack.compute.plugins.v3.instance_usage_audit_log:InstanceUsageAuditLog
|
||||
keypairs = nova.api.openstack.compute.plugins.v3.keypairs:Keypairs
|
||||
lock_server = nova.api.openstack.compute.plugins.v3.lock_server:LockServer
|
||||
migrate_server = nova.api.openstack.compute.plugins.v3.migrate_server:MigrateServer
|
||||
migrations = nova.api.openstack.compute.plugins.v3.migrations:Migrations
|
||||
multinic = nova.api.openstack.compute.plugins.v3.multinic:Multinic
|
||||
multiple_create = nova.api.openstack.compute.plugins.v3.multiple_create:MultipleCreate
|
||||
|
Loading…
Reference in New Issue
Block a user