Convert migrate_server v3 plugin to v2.1

Changes required to have v3 plugin natively support
the v2 API.

The migrate_live action is reverted back to os-migrateLive

Partially implements blueprint v2-on-v3-api

Change-Id: Ib3332ecfbf47ed6cad6108399083f0c26b7eebfe
This commit is contained in:
Chris Yeoh 2014-08-11 17:13:36 +09:30 committed by He Jie Xu
parent 4f0ce8ac8c
commit 941a8db372
5 changed files with 71 additions and 47 deletions

View File

@ -1,7 +1,7 @@
{
"migrate_live": {
"os-migrateLive": {
"host": "01c0cadef72d47e28a672a76060d492c",
"block_migration": false,
"disk_over_commit": false
}
}
}

View File

@ -64,16 +64,16 @@ class MigrateServerController(wsgi.Controller):
return webob.Response(status_int=202)
@extensions.expected_errors((400, 404, 409))
@wsgi.action('migrate_live')
@wsgi.action('os-migrateLive')
@validation.schema(migrate_server.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')
block_migration = body["migrate_live"]["block_migration"]
disk_over_commit = body["migrate_live"]["disk_over_commit"]
host = body["migrate_live"]["host"]
block_migration = body["os-migrateLive"]["block_migration"]
disk_over_commit = body["os-migrateLive"]["disk_over_commit"]
host = body["os-migrateLive"]["host"]
block_migration = strutils.bool_from_string(block_migration,
strict=True)
@ -101,7 +101,7 @@ class MigrateServerController(wsgi.Controller):
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'migrate_live')
'os-migrateLive')
return webob.Response(status_int=202)

View File

@ -12,23 +12,31 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
from nova.api.validation import parameter_types
host = copy.deepcopy(parameter_types.hostname)
host['type'] = ['string', 'null']
migrate_live = {
'type': 'object',
'properties': {
'migrate_live': {
'os-migrateLive': {
'type': 'object',
'properties': {
'block_migration': parameter_types.boolean,
'disk_over_commit': parameter_types.boolean,
'host': parameter_types.hostname,
'host': host
},
'required': ['block_migration', 'disk_over_commit', 'host'],
'additionalProperties': False,
},
},
'required': ['migrate_live'],
'required': ['os-migrateLive'],
'additionalProperties': False,
}
host = copy.deepcopy(parameter_types.hostname)
host['type'] = ['string', 'null']

View File

@ -39,43 +39,54 @@ class MigrateServerTests(admin_only_action_common.CommonTests):
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,
'os-migrateLive': 'live_migrate'}
body_map = {'os-migrateLive': {'host': 'hostname',
'block_migration': False,
'disk_over_commit': False}}
args_map = {'os-migrateLive': ((False, False, 'hostname'), {})}
self._test_actions(['migrate', 'os-migrateLive'], body_map=body_map,
method_translations=method_translations,
args_map=args_map)
def test_migrate_none_hostname(self):
method_translations = {'migrate': 'resize',
'os-migrateLive': 'live_migrate'}
body_map = {'os-migrateLive': {'host': None,
'block_migration': False,
'disk_over_commit': False}}
args_map = {'os-migrateLive': ((False, False, None), {})}
self._test_actions(['migrate', 'os-migrateLive'], 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',
body_map = {'os-migrateLive': {'host': 'hostname',
'block_migration': False,
'disk_over_commit': False}}
self._test_actions_with_non_existed_instance(
['migrate', 'migrate_live'], body_map=body_map)
['migrate', 'os-migrateLive'], 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'), {})}
'os-migrateLive': 'live_migrate'}
body_map = {'os-migrateLive': {'host': 'hostname',
'block_migration': False,
'disk_over_commit': False}}
args_map = {'os-migrateLive': ((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)
['migrate', 'os-migrateLive'], body_map=body_map,
args_map=args_map, method_translations=method_translations)
def test_actions_with_locked_instance(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'), {})}
'os-migrateLive': 'live_migrate'}
body_map = {'os-migrateLive': {'host': 'hostname',
'block_migration': False,
'disk_over_commit': False}}
args_map = {'os-migrateLive': ((False, False, 'hostname'), {})}
self._test_actions_with_locked_instance(
['migrate', 'migrate_live'], body_map=body_map, args_map=args_map,
method_translations=method_translations)
['migrate', 'os-migrateLive'], body_map=body_map,
args_map=args_map, method_translations=method_translations)
def _test_migrate_exception(self, exc_info, expected_result):
self.mox.StubOutWithMock(self.compute_api, 'resize')
@ -102,7 +113,7 @@ class MigrateServerTests(admin_only_action_common.CommonTests):
self.mox.ReplayAll()
res = self._make_request('/servers/%s/action' % instance.uuid,
{'migrate_live': param})
{'os-migrateLive': param})
self.assertEqual(202, res.status_int)
def test_migrate_live_enabled(self):
@ -119,34 +130,39 @@ class MigrateServerTests(admin_only_action_common.CommonTests):
def test_migrate_live_without_host(self):
res = self._make_request('/servers/FAKE/action',
{'migrate_live': {'block_migration': False,
'disk_over_commit': False}})
{'os-migrateLive':
{'block_migration': False,
'disk_over_commit': False}})
self.assertEqual(400, res.status_int)
def test_migrate_live_without_block_migration(self):
res = self._make_request('/servers/FAKE/action',
{'migrate_live': {'host': 'hostname',
'disk_over_commit': False}})
{'os-migrateLive':
{'host': 'hostname',
'disk_over_commit': False}})
self.assertEqual(400, res.status_int)
def test_migrate_live_without_disk_over_commit(self):
res = self._make_request('/servers/FAKE/action',
{'migrate_live': {'host': 'hostname',
'block_migration': False}})
{'os-migrateLive':
{'host': 'hostname',
'block_migration': 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}})
{'os-migrateLive':
{'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"}})
{'os-migrateLive':
{'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,
@ -160,7 +176,7 @@ class MigrateServerTests(admin_only_action_common.CommonTests):
self.mox.ReplayAll()
res = self._make_request('/servers/%s/action' % instance.uuid,
{'migrate_live':
{'os-migrateLive':
{'host': 'hostname',
'block_migration': False,
'disk_over_commit': False}})

View File

@ -1,5 +1,5 @@
{
"migrate_live": {
"os-migrateLive": {
"host": "%(hostname)s",
"block_migration": false,
"disk_over_commit": false