Merge "Correct the action name for admin_actions API v3"
This commit is contained in:
commit
d960e71772
@ -38,11 +38,11 @@
|
||||
"compute_extension:v3:os-admin-actions:resume": "rule:admin_or_owner",
|
||||
"compute_extension:v3:os-admin-actions:lock": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:unlock": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:resetNetwork": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:injectNetworkInfo": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:createBackup": "rule:admin_or_owner",
|
||||
"compute_extension:v3:os-admin-actions:migrateLive": "rule:admin_api",
|
||||
"compute_extension:v3:os-admin-actions:resetState": "rule:admin_api",
|
||||
"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:aggregates": "rule:admin_api",
|
||||
"compute_extension:v3:os-aggregates": "rule:admin_api",
|
||||
|
@ -127,11 +127,11 @@ class AdminActionsController(wsgi.Controller):
|
||||
raise exc.HTTPBadRequest()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@wsgi.action('resetNetwork')
|
||||
@wsgi.action('reset_network')
|
||||
def _reset_network(self, req, id, body):
|
||||
"""Permit admins to reset networking on a server."""
|
||||
context = req.environ['nova.context']
|
||||
authorize(context, 'resetNetwork')
|
||||
authorize(context, 'reset_network')
|
||||
try:
|
||||
instance = self.compute_api.get(context, id)
|
||||
self.compute_api.reset_network(context, instance)
|
||||
@ -141,11 +141,11 @@ class AdminActionsController(wsgi.Controller):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@wsgi.action('injectNetworkInfo')
|
||||
@wsgi.action('inject_network_info')
|
||||
def _inject_network_info(self, req, id, body):
|
||||
"""Permit admins to inject network info into a server."""
|
||||
context = req.environ['nova.context']
|
||||
authorize(context, 'injectNetworkInfo')
|
||||
authorize(context, 'inject_network_info')
|
||||
try:
|
||||
instance = self.compute_api.get(context, id)
|
||||
self.compute_api.inject_network_info(context, instance)
|
||||
@ -189,7 +189,7 @@ class AdminActionsController(wsgi.Controller):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@wsgi.action('createBackup')
|
||||
@wsgi.action('create_backup')
|
||||
def _create_backup(self, req, id, body):
|
||||
"""Backup a server instance.
|
||||
|
||||
@ -202,10 +202,10 @@ class AdminActionsController(wsgi.Controller):
|
||||
|
||||
"""
|
||||
context = req.environ["nova.context"]
|
||||
authorize(context, 'createBackup')
|
||||
authorize(context, 'create_backup')
|
||||
|
||||
try:
|
||||
entity = body["createBackup"]
|
||||
entity = body["create_backup"]
|
||||
except (KeyError, TypeError):
|
||||
raise exc.HTTPBadRequest(_("Malformed request body"))
|
||||
|
||||
@ -215,20 +215,20 @@ class AdminActionsController(wsgi.Controller):
|
||||
rotation = entity["rotation"]
|
||||
|
||||
except KeyError as missing_key:
|
||||
msg = _("createBackup entity requires %s attribute") % missing_key
|
||||
msg = _("create_backup entity requires %s attribute") % missing_key
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
except TypeError:
|
||||
msg = _("Malformed createBackup entity")
|
||||
msg = _("Malformed create_backup entity")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
try:
|
||||
rotation = int(rotation)
|
||||
except ValueError:
|
||||
msg = _("createBackup attribute 'rotation' must be an integer")
|
||||
msg = _("create_backup attribute 'rotation' must be an integer")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
if rotation < 0:
|
||||
msg = _("createBackup attribute 'rotation' must be greater "
|
||||
msg = _("create_backup attribute 'rotation' must be greater "
|
||||
"than or equal to zero")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
@ -251,7 +251,7 @@ class AdminActionsController(wsgi.Controller):
|
||||
backup_type, rotation, extra_properties=props)
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'createBackup')
|
||||
'create_backup')
|
||||
|
||||
resp = webob.Response(status_int=202)
|
||||
|
||||
@ -263,16 +263,16 @@ class AdminActionsController(wsgi.Controller):
|
||||
|
||||
return resp
|
||||
|
||||
@wsgi.action('os-migrateLive')
|
||||
@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, 'migrateLive')
|
||||
authorize(context, 'migrate_live')
|
||||
|
||||
try:
|
||||
block_migration = body["os-migrateLive"]["block_migration"]
|
||||
disk_over_commit = body["os-migrateLive"]["disk_over_commit"]
|
||||
host = body["os-migrateLive"]["host"]
|
||||
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.")
|
||||
@ -300,15 +300,15 @@ class AdminActionsController(wsgi.Controller):
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@wsgi.action('os-resetState')
|
||||
@wsgi.action('reset_state')
|
||||
def _reset_state(self, req, id, body):
|
||||
"""Permit admins to reset the state of a server."""
|
||||
context = req.environ["nova.context"]
|
||||
authorize(context, 'resetState')
|
||||
authorize(context, 'reset_state')
|
||||
|
||||
# Identify the desired state from the body
|
||||
try:
|
||||
state = state_map[body["os-resetState"]["state"]]
|
||||
state = state_map[body["reset_state"]["state"]]
|
||||
except (TypeError, KeyError):
|
||||
msg = _("Desired state must be specified. Valid states "
|
||||
"are: %s") % ', '.join(sorted(state_map.keys()))
|
||||
@ -321,7 +321,7 @@ class AdminActionsController(wsgi.Controller):
|
||||
raise exc.HTTPNotFound(_("Server not found"))
|
||||
except Exception:
|
||||
readable = traceback.format_exc()
|
||||
LOG.exception(_("Compute.api::resetState %s"), readable)
|
||||
LOG.exception(_("Compute.api::reset_state %s"), readable)
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@ -330,7 +330,7 @@ class AdminActions(extensions.V3APIExtensionBase):
|
||||
"""Enable admin-only server actions
|
||||
|
||||
Actions include: pause, unpause, suspend, resume, migrate,
|
||||
resetNetwork, injectNetworkInfo, lock, unlock, createBackup
|
||||
reset_network, inject_network_info, lock, unlock, create_backup
|
||||
"""
|
||||
|
||||
name = "AdminActions"
|
||||
|
@ -76,7 +76,7 @@ def fake_compute_api_get(self, context, instance_uuid, want_objects=False):
|
||||
class AdminActionsTest(test.TestCase):
|
||||
|
||||
_actions = ('pause', 'unpause', 'suspend', 'resume', 'migrate',
|
||||
'resetNetwork', 'injectNetworkInfo', 'lock', 'unlock')
|
||||
'reset_network', 'inject_network_info', 'lock', 'unlock')
|
||||
|
||||
_methods = ('pause', 'unpause', 'suspend', 'resume', 'resize',
|
||||
'reset_network', 'inject_network_info', 'lock', 'unlock')
|
||||
@ -134,7 +134,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v3/servers/%s/action' % self.UUID)
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dumps({
|
||||
'os-migrateLive': {
|
||||
'migrate_live': {
|
||||
'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False,
|
||||
@ -169,7 +169,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v3/servers/%s/action' % self.UUID)
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dumps({
|
||||
'os-migrateLive': {
|
||||
'migrate_live': {
|
||||
'dummy': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False,
|
||||
@ -189,7 +189,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v3/servers/%s/action' % self.UUID)
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dumps({
|
||||
'os-migrateLive': {
|
||||
'migrate_live': {
|
||||
'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False,
|
||||
@ -227,7 +227,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v3/servers/%s/action' % self.UUID)
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dumps({
|
||||
'os-migrateLive': {
|
||||
'migrate_live': {
|
||||
'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False,
|
||||
@ -265,7 +265,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v3/servers/%s/action' % self.UUID)
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dumps({
|
||||
'os-migrateLive': {
|
||||
'migrate_live': {
|
||||
'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False,
|
||||
@ -303,7 +303,7 @@ class AdminActionsTest(test.TestCase):
|
||||
req = webob.Request.blank('/v3/servers/%s/action' % self.UUID)
|
||||
req.method = 'POST'
|
||||
req.body = jsonutils.dumps({
|
||||
'os-migrateLive': {
|
||||
'migrate_live': {
|
||||
'host': 'hostname',
|
||||
'block_migration': False,
|
||||
'disk_over_commit': False,
|
||||
@ -353,7 +353,7 @@ class CreateBackupTests(test.TestCase):
|
||||
|
||||
def test_create_backup_with_metadata(self):
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'backup_type': 'daily',
|
||||
'rotation': 1,
|
||||
@ -369,7 +369,7 @@ class CreateBackupTests(test.TestCase):
|
||||
|
||||
def test_create_backup_with_too_much_metadata(self):
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'backup_type': 'daily',
|
||||
'rotation': 1,
|
||||
@ -377,7 +377,7 @@ class CreateBackupTests(test.TestCase):
|
||||
},
|
||||
}
|
||||
for num in range(CONF.quota_metadata_items + 1):
|
||||
body['createBackup']['metadata']['foo%i' % num] = "bar"
|
||||
body['create_backup']['metadata']['foo%i' % num] = "bar"
|
||||
|
||||
request = self._get_request(body)
|
||||
response = request.get_response(self.app)
|
||||
@ -386,7 +386,7 @@ class CreateBackupTests(test.TestCase):
|
||||
def test_create_backup_no_name(self):
|
||||
# Name is required for backups.
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'backup_type': 'daily',
|
||||
'rotation': 1,
|
||||
},
|
||||
@ -399,7 +399,7 @@ class CreateBackupTests(test.TestCase):
|
||||
def test_create_backup_no_rotation(self):
|
||||
# Rotation is required for backup requests.
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'backup_type': 'daily',
|
||||
},
|
||||
@ -414,7 +414,7 @@ class CreateBackupTests(test.TestCase):
|
||||
for backup requests
|
||||
"""
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'backup_type': 'daily',
|
||||
'rotation': -1,
|
||||
@ -428,7 +428,7 @@ class CreateBackupTests(test.TestCase):
|
||||
def test_create_backup_no_backup_type(self):
|
||||
# Backup Type (daily or weekly) is required for backup requests.
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'rotation': 1,
|
||||
},
|
||||
@ -439,7 +439,7 @@ class CreateBackupTests(test.TestCase):
|
||||
self.assertEqual(response.status_int, 400)
|
||||
|
||||
def test_create_backup_bad_entity(self):
|
||||
body = {'createBackup': 'go'}
|
||||
body = {'create_backup': 'go'}
|
||||
|
||||
request = self._get_request(body)
|
||||
response = request.get_response(self.app)
|
||||
@ -448,7 +448,7 @@ class CreateBackupTests(test.TestCase):
|
||||
def test_create_backup_rotation_is_zero(self):
|
||||
# The happy path for creating backups if rotation is zero.
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'backup_type': 'daily',
|
||||
'rotation': 0,
|
||||
@ -464,7 +464,7 @@ class CreateBackupTests(test.TestCase):
|
||||
def test_create_backup_rotation_is_positive(self):
|
||||
# The happy path for creating backups if rotation is positive.
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'backup_type': 'daily',
|
||||
'rotation': 1,
|
||||
@ -479,7 +479,7 @@ class CreateBackupTests(test.TestCase):
|
||||
|
||||
def test_create_backup_raises_conflict_on_invalid_state(self):
|
||||
body = {
|
||||
'createBackup': {
|
||||
'create_backup': {
|
||||
'name': 'Backup 1',
|
||||
'backup_type': 'daily',
|
||||
'rotation': 1,
|
||||
@ -521,23 +521,23 @@ class ResetStateTests(test.TestCase):
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.admin_api._reset_state,
|
||||
self.request, 'inst_id',
|
||||
{"os-resetState": None})
|
||||
{"reset_state": None})
|
||||
|
||||
def test_bad_state(self):
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.admin_api._reset_state,
|
||||
self.request, 'inst_id',
|
||||
{"os-resetState": {"state": "spam"}})
|
||||
{"reset_state": {"state": "spam"}})
|
||||
|
||||
def test_no_instance(self):
|
||||
self.exists = False
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.admin_api._reset_state,
|
||||
self.request, 'inst_id',
|
||||
{"os-resetState": {"state": "active"}})
|
||||
{"reset_state": {"state": "active"}})
|
||||
|
||||
def test_reset_active(self):
|
||||
body = {"os-resetState": {"state": "active"}}
|
||||
body = {"reset_state": {"state": "active"}}
|
||||
result = self.admin_api._reset_state(self.request, 'inst_id', body)
|
||||
|
||||
self.assertEqual(result.status_int, 202)
|
||||
@ -545,7 +545,7 @@ class ResetStateTests(test.TestCase):
|
||||
task_state=None))
|
||||
|
||||
def test_reset_error(self):
|
||||
body = {"os-resetState": {"state": "error"}}
|
||||
body = {"reset_state": {"state": "error"}}
|
||||
result = self.admin_api._reset_state(self.request, 'inst_id', body)
|
||||
|
||||
self.assertEqual(result.status_int, 202)
|
||||
|
@ -116,11 +116,11 @@ policy_data = """
|
||||
"compute_extension:v3:os-admin-actions:resume": "",
|
||||
"compute_extension:v3:os-admin-actions:lock": "",
|
||||
"compute_extension:v3:os-admin-actions:unlock": "",
|
||||
"compute_extension:v3:os-admin-actions:resetNetwork": "",
|
||||
"compute_extension:v3:os-admin-actions:injectNetworkInfo": "",
|
||||
"compute_extension:v3:os-admin-actions:createBackup": "",
|
||||
"compute_extension:v3:os-admin-actions:migrateLive": "",
|
||||
"compute_extension:v3:os-admin-actions:resetState": "",
|
||||
"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:aggregates": "",
|
||||
"compute_extension:v3:os-aggregates": "",
|
||||
|
Loading…
Reference in New Issue
Block a user