Merge "api: Remove unnecessary action method prefix"

This commit is contained in:
Zuul
2026-02-28 19:38:14 +00:00
committed by Gerrit Code Review
6 changed files with 243 additions and 257 deletions
+46 -48
View File
@@ -918,6 +918,24 @@ class ServersController(wsgi.Controller):
return self._add_location(robj) return self._add_location(robj)
@wsgi.response(204)
@wsgi.expected_errors((404, 409))
@validation.response_body_schema(schema.delete_response)
def delete(self, req, id):
"""Destroys a server."""
try:
self._delete(req.environ['nova.context'], req, id)
except exception.InstanceNotFound:
msg = _("Instance could not be found")
raise exc.HTTPNotFound(explanation=msg)
except (
exception.InstanceIsLocked, exception.AllocationDeleteFailed
) 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, 'delete', id)
def _delete(self, context, req, instance_uuid): def _delete(self, context, req, instance_uuid):
instance = self._get_server(context, req, instance_uuid) instance = self._get_server(context, req, instance_uuid)
context.can(server_policies.SERVERS % 'delete', context.can(server_policies.SERVERS % 'delete',
@@ -1024,7 +1042,7 @@ class ServersController(wsgi.Controller):
@wsgi.action('confirmResize') @wsgi.action('confirmResize')
@validation.schema(schema.confirm_resize) @validation.schema(schema.confirm_resize)
@validation.response_body_schema(schema.confirm_resize_response) @validation.response_body_schema(schema.confirm_resize_response)
def _action_confirm_resize(self, req, id, body): def _confirm_resize(self, req, id, body):
context = req.environ['nova.context'] context = req.environ['nova.context']
instance = self._get_server(context, req, id) instance = self._get_server(context, req, id)
context.can(server_policies.SERVERS % 'confirm_resize', context.can(server_policies.SERVERS % 'confirm_resize',
@@ -1048,7 +1066,7 @@ class ServersController(wsgi.Controller):
@wsgi.action('revertResize') @wsgi.action('revertResize')
@validation.schema(schema.revert_resize) @validation.schema(schema.revert_resize)
@validation.response_body_schema(schema.revert_resize_response) @validation.response_body_schema(schema.revert_resize_response)
def _action_revert_resize(self, req, id, body): def _revert_resize(self, req, id, body):
context = req.environ['nova.context'] context = req.environ['nova.context']
instance = self._get_server(context, req, id) instance = self._get_server(context, req, id)
context.can(server_policies.SERVERS % 'revert_resize', context.can(server_policies.SERVERS % 'revert_resize',
@@ -1072,8 +1090,7 @@ class ServersController(wsgi.Controller):
@wsgi.action('reboot') @wsgi.action('reboot')
@validation.schema(schema.reboot) @validation.schema(schema.reboot)
@validation.response_body_schema(schema.reboot_response) @validation.response_body_schema(schema.reboot_response)
def _action_reboot(self, req, id, body): def _reboot(self, req, id, body):
reboot_type = body['reboot']['type'].upper() reboot_type = body['reboot']['type'].upper()
context = req.environ['nova.context'] context = req.environ['nova.context']
instance = self._get_server(context, req, id) instance = self._get_server(context, req, id)
@@ -1088,10 +1105,24 @@ class ServersController(wsgi.Controller):
common.raise_http_conflict_for_instance_invalid_state(state_error, common.raise_http_conflict_for_instance_invalid_state(state_error,
'reboot', id) 'reboot', id)
def _resize(self, req, instance_id, flavor_id, auto_disk_config=None): @wsgi.response(202)
"""Begin the resize process with given instance/flavor.""" @wsgi.expected_errors((400, 401, 403, 404, 409))
@wsgi.action('resize')
@validation.schema(schema.resize)
@validation.response_body_schema(schema.resize_response)
def _resize(self, req, id, body):
"""Resizes a given instance to the flavor size requested."""
resize_dict = body['resize']
flavor_id = str(resize_dict["flavorRef"])
auto_disk_config = None
auto_disk_config_raw = resize_dict.get(helpers.API_DISK_CONFIG)
if auto_disk_config_raw is not None:
auto_disk_config = helpers.disk_config_from_api(
auto_disk_config_raw)
context = req.environ["nova.context"] context = req.environ["nova.context"]
instance = self._get_server(context, req, instance_id, instance = self._get_server(context, req, id,
columns_to_join=['services', 'resources', columns_to_join=['services', 'resources',
'pci_requests', 'pci_requests',
'pci_devices', 'pci_devices',
@@ -1115,8 +1146,8 @@ class ServersController(wsgi.Controller):
) as e: ) as e:
raise exc.HTTPConflict(explanation=e.format_message()) raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error: except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error, common.raise_http_conflict_for_instance_invalid_state(
'resize', instance_id) state_error, 'resize', id)
except exception.ImageNotAuthorized: except exception.ImageNotAuthorized:
msg = _("You are not authorized to access the image " msg = _("You are not authorized to access the image "
"the instance was started with.") "the instance was started with.")
@@ -1143,23 +1174,6 @@ class ServersController(wsgi.Controller):
exception.ForbiddenWithShare) as e: exception.ForbiddenWithShare) as e:
raise exc.HTTPConflict(explanation=e.format_message()) raise exc.HTTPConflict(explanation=e.format_message())
@wsgi.response(204)
@wsgi.expected_errors((404, 409))
@validation.response_body_schema(schema.delete_response)
def delete(self, req, id):
"""Destroys a server."""
try:
self._delete(req.environ['nova.context'], req, id)
except exception.InstanceNotFound:
msg = _("Instance could not be found")
raise exc.HTTPNotFound(explanation=msg)
except (exception.InstanceIsLocked,
exception.AllocationDeleteFailed) 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,
'delete', id)
def _image_from_req_data(self, server_dict, create_kwargs): def _image_from_req_data(self, server_dict, create_kwargs):
"""Get image data from the request or raise appropriate """Get image data from the request or raise appropriate
exceptions. exceptions.
@@ -1181,21 +1195,6 @@ class ServersController(wsgi.Controller):
flavor_ref = data['server']['flavorRef'] flavor_ref = data['server']['flavorRef']
return common.get_id_from_href(flavor_ref) return common.get_id_from_href(flavor_ref)
@wsgi.response(202)
@wsgi.expected_errors((400, 401, 403, 404, 409))
@wsgi.action('resize')
@validation.schema(schema.resize)
@validation.response_body_schema(schema.resize_response)
def _action_resize(self, req, id, body):
"""Resizes a given instance to the flavor size requested."""
resize_dict = body['resize']
flavor_ref = str(resize_dict["flavorRef"])
kwargs = {}
helpers.translate_attributes(helpers.RESIZE, resize_dict, kwargs)
self._resize(req, id, flavor_ref, **kwargs)
@wsgi.response(202) @wsgi.response(202)
@wsgi.expected_errors((400, 403, 404, 409)) @wsgi.expected_errors((400, 403, 404, 409))
@wsgi.action('rebuild') @wsgi.action('rebuild')
@@ -1221,7 +1220,7 @@ class ServersController(wsgi.Controller):
@validation.response_body_schema(schema.rebuild_response_v296, '2.96', '2.97') # noqa: E501 @validation.response_body_schema(schema.rebuild_response_v296, '2.96', '2.97') # noqa: E501
@validation.response_body_schema(schema.rebuild_response_v298, '2.98', '2.99') # noqa: E501 @validation.response_body_schema(schema.rebuild_response_v298, '2.98', '2.99') # noqa: E501
@validation.response_body_schema(schema.rebuild_response_v2100, '2.100') @validation.response_body_schema(schema.rebuild_response_v2100, '2.100')
def _action_rebuild(self, req, id, body): def _rebuild(self, req, id, body):
"""Rebuild an instance with the given attributes.""" """Rebuild an instance with the given attributes."""
rebuild_dict = body['rebuild'] rebuild_dict = body['rebuild']
@@ -1387,10 +1386,9 @@ class ServersController(wsgi.Controller):
@wsgi.action('createImage') @wsgi.action('createImage')
@validation.schema(schema.create_image, '2.0', '2.0') @validation.schema(schema.create_image, '2.0', '2.0')
@validation.schema(schema.create_image, '2.1') @validation.schema(schema.create_image, '2.1')
@validation.response_body_schema( @validation.response_body_schema(schema.create_image_response, '2.0', '2.44') # noqa: E501
schema.create_image_response, '2.0', '2.44')
@validation.response_body_schema(schema.create_image_response_v245, '2.45') @validation.response_body_schema(schema.create_image_response_v245, '2.45')
def _action_create_image(self, req, id, body): def _create_image(self, req, id, body):
"""Snapshot a server instance.""" """Snapshot a server instance."""
context = req.environ['nova.context'] context = req.environ['nova.context']
instance = self._get_server(context, req, id) instance = self._get_server(context, req, id)
@@ -1499,7 +1497,7 @@ class ServersController(wsgi.Controller):
@wsgi.action('os-start') @wsgi.action('os-start')
@validation.schema(schema.start_server) @validation.schema(schema.start_server)
@validation.response_body_schema(schema.start_server_response) @validation.response_body_schema(schema.start_server_response)
def _start_server(self, req, id, body): def _start(self, req, id, body):
"""Start an instance.""" """Start an instance."""
context = req.environ['nova.context'] context = req.environ['nova.context']
instance = self._get_instance(context, id) instance = self._get_instance(context, id)
@@ -1519,7 +1517,7 @@ class ServersController(wsgi.Controller):
@wsgi.action('os-stop') @wsgi.action('os-stop')
@validation.schema(schema.stop_server) @validation.schema(schema.stop_server)
@validation.response_body_schema(schema.stop_server_response) @validation.response_body_schema(schema.stop_server_response)
def _stop_server(self, req, id, body): def _stop(self, req, id, body):
"""Stop an instance.""" """Stop an instance."""
context = req.environ['nova.context'] context = req.environ['nova.context']
instance = self._get_instance(context, id) instance = self._get_instance(context, id)
@@ -1541,7 +1539,7 @@ class ServersController(wsgi.Controller):
@wsgi.action('trigger_crash_dump') @wsgi.action('trigger_crash_dump')
@validation.schema(schema.trigger_crash_dump) @validation.schema(schema.trigger_crash_dump)
@validation.response_body_schema(schema.trigger_crash_dump_response) @validation.response_body_schema(schema.trigger_crash_dump_response)
def _action_trigger_crash_dump(self, req, id, body): def _trigger_crash_dump(self, req, id, body):
"""Trigger crash dump in an instance""" """Trigger crash dump in an instance"""
context = req.environ['nova.context'] context = req.environ['nova.context']
instance = self._get_instance(context, id) instance = self._get_instance(context, id)
@@ -88,7 +88,7 @@ class AccessIPsAPIValidationTestV21(test.TestCase):
} }
body['rebuild'].update(params) body['rebuild'].update(params)
req = fakes.HTTPRequest.blank('') req = fakes.HTTPRequest.blank('')
self.controller._action_rebuild(req, fakes.FAKE_UUID, body=body) self.controller._rebuild(req, fakes.FAKE_UUID, body=body)
def test_create_server_with_access_ipv4(self): def test_create_server_with_access_ipv4(self):
params = {v4_key: '192.168.0.10'} params = {v4_key: '192.168.0.10'}
@@ -163,29 +163,28 @@ class ServerActionsControllerTestV21(test.TestCase):
*args, **kwargs) *args, **kwargs)
def test_actions_with_locked_instance(self): def test_actions_with_locked_instance(self):
actions = ['_action_resize', '_action_confirm_resize', actions = ['_resize', '_confirm_resize',
'_action_revert_resize', '_action_reboot', '_revert_resize', '_reboot',
'_action_rebuild'] '_rebuild']
method_translations = {'_action_resize': 'resize', method_translations = {'_resize': 'resize',
'_action_confirm_resize': 'confirm_resize', '_confirm_resize': 'confirm_resize',
'_action_revert_resize': 'revert_resize', '_revert_resize': 'revert_resize',
'_action_reboot': 'reboot', '_reboot': 'reboot',
'_action_rebuild': 'rebuild'} '_rebuild': 'rebuild'}
body_map = {'_action_resize': {'resize': {'flavorRef': '2'}}, body_map = {'_resize': {'resize': {'flavorRef': '2'}},
'_action_reboot': {'reboot': {'type': 'HARD'}}, '_reboot': {'reboot': {'type': 'HARD'}},
'_action_rebuild': {'rebuild': { '_rebuild': {'rebuild': {
'imageRef': self.image_uuid, 'imageRef': self.image_uuid,
'adminPass': 'TNc53Dr8s7vw'}}, 'adminPass': 'TNc53Dr8s7vw'}},
'_action_revert_resize': {'revertResize': None}, '_revert_resize': {'revertResize': None},
'_action_confirm_resize': {'confirmResize': None}} '_confirm_resize': {'confirmResize': None}}
args_map = {'_action_resize': (('2'), {'auto_disk_config': None}), args_map = {'_resize': (('2'), {'auto_disk_config': None}),
'_action_confirm_resize': ((), {}), '_confirm_resize': ((), {}),
'_action_reboot': (('HARD',), {}), '_reboot': (('HARD',), {}),
'_action_rebuild': ((self.image_uuid, '_rebuild': ((self.image_uuid, 'TNc53Dr8s7vw'), {})}
'TNc53Dr8s7vw'), {})}
for action in actions: for action in actions:
method = method_translations.get(action) method = method_translations.get(action)
@@ -195,28 +194,28 @@ class ServerActionsControllerTestV21(test.TestCase):
def test_reboot_hard(self): def test_reboot_hard(self):
body = dict(reboot=dict(type="HARD")) body = dict(reboot=dict(type="HARD"))
self.controller._action_reboot(self.req, FAKE_UUID, body=body) self.controller._reboot(self.req, FAKE_UUID, body=body)
def test_reboot_soft(self): def test_reboot_soft(self):
body = dict(reboot=dict(type="SOFT")) body = dict(reboot=dict(type="SOFT"))
self.controller._action_reboot(self.req, FAKE_UUID, body=body) self.controller._reboot(self.req, FAKE_UUID, body=body)
def test_reboot_incorrect_type(self): def test_reboot_incorrect_type(self):
body = dict(reboot=dict(type="NOT_A_TYPE")) body = dict(reboot=dict(type="NOT_A_TYPE"))
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_reboot, self.controller._reboot,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_reboot_missing_type(self): def test_reboot_missing_type(self):
body = dict(reboot=dict()) body = dict(reboot=dict())
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_reboot, self.controller._reboot,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_reboot_none(self): def test_reboot_none(self):
body = dict(reboot=dict(type=None)) body = dict(reboot=dict(type=None))
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_reboot, self.controller._reboot,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_reboot_not_found(self): def test_reboot_not_found(self):
@@ -225,7 +224,7 @@ class ServerActionsControllerTestV21(test.TestCase):
side_effect=exception.InstanceNotFound( side_effect=exception.InstanceNotFound(
instance_id=uuids.fake)): instance_id=uuids.fake)):
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._action_reboot, self.controller._reboot,
self.req, uuids.fake, body=body) self.req, uuids.fake, body=body)
def test_reboot_raises_conflict_on_invalid_state(self): def test_reboot_raises_conflict_on_invalid_state(self):
@@ -239,7 +238,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.reboot', fake_reboot) self.stub_out('nova.compute.api.API.reboot', fake_reboot)
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_reboot, self.controller._reboot,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_reboot_soft_with_soft_in_progress_raises_conflict(self): def test_reboot_soft_with_soft_in_progress_raises_conflict(self):
@@ -249,7 +248,7 @@ class ServerActionsControllerTestV21(test.TestCase):
vm_state=vm_states.ACTIVE, vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING)) task_state=task_states.REBOOTING))
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_reboot, self.controller._reboot,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_reboot_hard_with_soft_in_progress_does_not_raise(self): def test_reboot_hard_with_soft_in_progress_does_not_raise(self):
@@ -258,7 +257,7 @@ class ServerActionsControllerTestV21(test.TestCase):
fakes.fake_compute_get(project_id=fakes.FAKE_PROJECT_ID, fakes.fake_compute_get(project_id=fakes.FAKE_PROJECT_ID,
vm_state=vm_states.ACTIVE, vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING)) task_state=task_states.REBOOTING))
self.controller._action_reboot(self.req, FAKE_UUID, body=body) self.controller._reboot(self.req, FAKE_UUID, body=body)
def test_reboot_hard_with_hard_in_progress(self): def test_reboot_hard_with_hard_in_progress(self):
body = dict(reboot=dict(type="HARD")) body = dict(reboot=dict(type="HARD"))
@@ -267,7 +266,7 @@ class ServerActionsControllerTestV21(test.TestCase):
project_id=fakes.FAKE_PROJECT_ID, project_id=fakes.FAKE_PROJECT_ID,
vm_state=vm_states.ACTIVE, vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING_HARD)) task_state=task_states.REBOOTING_HARD))
self.controller._action_reboot(self.req, FAKE_UUID, body=body) self.controller._reboot(self.req, FAKE_UUID, body=body)
def test_reboot_soft_with_hard_in_progress_raises_conflict(self): def test_reboot_soft_with_hard_in_progress_raises_conflict(self):
body = dict(reboot=dict(type="SOFT")) body = dict(reboot=dict(type="SOFT"))
@@ -277,7 +276,7 @@ class ServerActionsControllerTestV21(test.TestCase):
vm_state=vm_states.ACTIVE, vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING_HARD)) task_state=task_states.REBOOTING_HARD))
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_reboot, self.controller._reboot,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def _test_rebuild_preserve_ephemeral(self, value=None): def _test_rebuild_preserve_ephemeral(self, value=None):
@@ -297,7 +296,7 @@ class ServerActionsControllerTestV21(test.TestCase):
body['rebuild']['preserve_ephemeral'] = value body['rebuild']['preserve_ephemeral'] = value
with mock.patch.object(compute_api.API, 'rebuild') as mock_rebuild: with mock.patch.object(compute_api.API, 'rebuild') as mock_rebuild:
self.controller._action_rebuild(self.req, FAKE_UUID, body=body) self.controller._rebuild(self.req, FAKE_UUID, body=body)
if value is not None: if value is not None:
mock_rebuild.assert_called_once_with(self.context, mock.ANY, mock_rebuild.assert_called_once_with(self.context, mock.ANY,
@@ -329,7 +328,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
robj = self.controller._action_rebuild(self.req, FAKE_UUID, body=body) robj = self.controller._rebuild(self.req, FAKE_UUID, body=body)
body = robj.obj body = robj.obj
self.assertEqual(body['server']['image']['id'], uuids.image_ref) self.assertEqual(body['server']['image']['id'], uuids.image_ref)
@@ -355,7 +354,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
self.controller._action_rebuild(self.req, FAKE_UUID, body=body) self.controller._rebuild(self.req, FAKE_UUID, body=body)
self.assertEqual(info['image_href_in_call'], self.image_uuid) self.assertEqual(info['image_href_in_call'], self.image_uuid)
def test_rebuild_instance_with_image_href_uses_uuid(self): def test_rebuild_instance_with_image_href_uses_uuid(self):
@@ -367,7 +366,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_accepted_minimum_pass_disabled(self): def test_rebuild_accepted_minimum_pass_disabled(self):
@@ -388,7 +387,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
robj = self.controller._action_rebuild(self.req, FAKE_UUID, body=body) robj = self.controller._rebuild(self.req, FAKE_UUID, body=body)
body = robj.obj body = robj.obj
self.assertEqual(body['server']['image']['id'], uuids.image_ref) self.assertEqual(body['server']['image']['id'], uuids.image_ref)
@@ -406,7 +405,7 @@ class ServerActionsControllerTestV21(test.TestCase):
mock_rebuild.side_effect = exc mock_rebuild.side_effect = exc
self.assertRaises( self.assertRaises(
webob.exc.HTTPConflict, webob.exc.HTTPConflict,
self.controller._action_rebuild, self.controller._rebuild,
self.req, uuids.instance, self.req, uuids.instance,
body={'rebuild': {'imageRef': uuids.image}}) body={'rebuild': {'imageRef': uuids.image}})
@@ -422,7 +421,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self, exc, mock_rebuild): self, exc, mock_rebuild):
mock_rebuild.side_effect = exc mock_rebuild.side_effect = exc
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, uuids.instance, self.req, uuids.instance,
body={'rebuild': {'imageRef': uuids.image}}) body={'rebuild': {'imageRef': uuids.image}})
@@ -437,7 +436,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.rebuild', fake_rebuild) self.stub_out('nova.compute.api.API.rebuild', fake_rebuild)
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_accepted_with_metadata(self): def test_rebuild_accepted_with_metadata(self):
@@ -456,8 +455,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
body = self.controller._action_rebuild(self.req, FAKE_UUID, body = self.controller._rebuild(self.req, FAKE_UUID, body=body).obj
body=body).obj
self.assertEqual(body['server']['metadata'], metadata) self.assertEqual(body['server']['metadata'], metadata)
@@ -470,7 +468,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_with_too_large_metadata(self): def test_rebuild_with_too_large_metadata(self):
@@ -484,7 +482,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(self.request_too_large_error, self.assertRaises(self.request_too_large_error,
self.controller._action_rebuild, self.req, self.controller._rebuild, self.req,
FAKE_UUID, body=body) FAKE_UUID, body=body)
def test_rebuild_bad_entity(self): def test_rebuild_bad_entity(self):
@@ -495,7 +493,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_admin_pass(self): def test_rebuild_admin_pass(self):
@@ -512,8 +510,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
body = self.controller._action_rebuild(self.req, FAKE_UUID, body = self.controller._rebuild(self.req, FAKE_UUID, body=body).obj
body=body).obj
self.assertEqual(body['server']['image']['id'], uuids.image_ref) self.assertEqual(body['server']['image']['id'], uuids.image_ref)
self.assertEqual(body['server']['adminPass'], 'asdf') self.assertEqual(body['server']['adminPass'], 'asdf')
@@ -536,8 +533,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
body = self.controller._action_rebuild(self.req, FAKE_UUID, body = self.controller._rebuild(self.req, FAKE_UUID, body=body).obj
body=body).obj
self.assertEqual(body['server']['image']['id'], FAKE_UUID) self.assertEqual(body['server']['image']['id'], FAKE_UUID)
self.assertNotIn('adminPass', body['server']) self.assertNotIn('adminPass', body['server'])
@@ -552,7 +548,7 @@ class ServerActionsControllerTestV21(test.TestCase):
side_effect=exception.InstanceNotFound( side_effect=exception.InstanceNotFound(
instance_id=FAKE_UUID)): instance_id=FAKE_UUID)):
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_with_bad_image(self): def test_rebuild_with_bad_image(self):
@@ -562,7 +558,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_accessIP(self): def test_rebuild_accessIP(self):
@@ -592,7 +588,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.get', wrap_get) self.stub_out('nova.compute.api.API.get', wrap_get)
self.stub_out('nova.objects.Instance.save', fake_save) self.stub_out('nova.objects.Instance.save', fake_save)
self.controller._action_rebuild(self.req, FAKE_UUID, body=body) self.controller._rebuild(self.req, FAKE_UUID, body=body)
self.assertEqual(self._image_href, data['changes']['image_ref']) self.assertEqual(self._image_href, data['changes']['image_ref'])
self.assertEqual("", data['changes']['kernel_id']) self.assertEqual("", data['changes']['kernel_id'])
@@ -637,7 +633,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_proper_kernel_ram(self): def test_rebuild_proper_kernel_ram(self):
@@ -690,7 +686,7 @@ class ServerActionsControllerTestV21(test.TestCase):
"imageRef": "155d900f-4e14-4e4c-a73d-069cbf4541e6", "imageRef": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
}, },
} }
self.controller._action_rebuild(self.req, FAKE_UUID, body=body).obj self.controller._rebuild(self.req, FAKE_UUID, body=body).obj
self.assertEqual(instance_meta['kernel_id'], uuids.kernel_image_id) self.assertEqual(instance_meta['kernel_id'], uuids.kernel_image_id)
self.assertEqual(instance_meta['ramdisk_id'], uuids.ramdisk_image_id) self.assertEqual(instance_meta['ramdisk_id'], uuids.ramdisk_image_id)
@@ -706,7 +702,7 @@ class ServerActionsControllerTestV21(test.TestCase):
image='dummy') image='dummy')
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch.object(compute_api.API, 'rebuild') @mock.patch.object(compute_api.API, 'rebuild')
@@ -720,7 +716,7 @@ class ServerActionsControllerTestV21(test.TestCase):
mock_rebuild.side_effect = exception.InvalidArchitectureName('arm64') mock_rebuild.side_effect = exception.InvalidArchitectureName('arm64')
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch.object(compute_api.API, 'rebuild') @mock.patch.object(compute_api.API, 'rebuild')
@@ -735,7 +731,7 @@ class ServerActionsControllerTestV21(test.TestCase):
mock_rebuild.side_effect = exception.InvalidVolume('error') mock_rebuild.side_effect = exception.InvalidVolume('error')
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_server(self): def test_resize_server(self):
@@ -749,7 +745,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.resize', resize_mock) self.stub_out('nova.compute.api.API.resize', resize_mock)
self.controller._action_resize(self.req, FAKE_UUID, body=body) self.controller._resize(self.req, FAKE_UUID, body=body)
self.assertTrue(self.resize_called) self.assertTrue(self.resize_called)
@@ -757,28 +753,28 @@ class ServerActionsControllerTestV21(test.TestCase):
body = dict(resize=dict()) body = dict(resize=dict())
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_server_no_flavor_ref(self): def test_resize_server_no_flavor_ref(self):
body = dict(resize=dict(flavorRef=None)) body = dict(resize=dict(flavorRef=None))
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_server_with_extra_arg(self): def test_resize_server_with_extra_arg(self):
body = dict(resize=dict(favorRef="http://localhost/3", body = dict(resize=dict(favorRef="http://localhost/3",
extra_arg="extra_arg")) extra_arg="extra_arg"))
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_server_invalid_flavor_ref(self): def test_resize_server_invalid_flavor_ref(self):
body = dict(resize=dict(flavorRef=1.2)) body = dict(resize=dict(flavorRef=1.2))
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_with_server_not_found(self): def test_resize_with_server_not_found(self):
@@ -787,7 +783,7 @@ class ServerActionsControllerTestV21(test.TestCase):
side_effect=exception.InstanceNotFound( side_effect=exception.InstanceNotFound(
instance_id=FAKE_UUID)): instance_id=FAKE_UUID)):
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_with_image_exceptions(self): def test_resize_with_image_exceptions(self):
@@ -817,7 +813,7 @@ class ServerActionsControllerTestV21(test.TestCase):
for call_no in range(len(exceptions)): for call_no in range(len(exceptions)):
next_exception = next(expected) next_exception = next(expected)
actual = self.assertRaises(next_exception, actual = self.assertRaises(next_exception,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
if (isinstance(exceptions[call_no][0], if (isinstance(exceptions[call_no][0],
exception.NoValidHost)): exception.NoValidHost)):
@@ -835,7 +831,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def test_resize_raises_cannot_resize_disk(self, mock_resize): def test_resize_raises_cannot_resize_disk(self, mock_resize):
body = dict(resize=dict(flavorRef="http://localhost/3")) body = dict(resize=dict(flavorRef="http://localhost/3"))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch('nova.compute.api.API.resize', @mock.patch('nova.compute.api.API.resize',
@@ -844,7 +840,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def test_resize_raises_flavor_not_found(self, mock_resize): def test_resize_raises_flavor_not_found(self, mock_resize):
body = dict(resize=dict(flavorRef="http://localhost/3")) body = dict(resize=dict(flavorRef="http://localhost/3"))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_with_too_many_instances(self): def test_resize_with_too_many_instances(self):
@@ -856,7 +852,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.resize', fake_resize) self.stub_out('nova.compute.api.API.resize', fake_resize)
self.assertRaises(webob.exc.HTTPForbidden, self.assertRaises(webob.exc.HTTPForbidden,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_resize_raises_conflict_on_invalid_state(self): def test_resize_raises_conflict_on_invalid_state(self):
@@ -870,7 +866,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.resize', fake_resize) self.stub_out('nova.compute.api.API.resize', fake_resize)
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch.object(compute_api.API, 'resize') @mock.patch.object(compute_api.API, 'resize')
@@ -881,7 +877,7 @@ class ServerActionsControllerTestV21(test.TestCase):
body = dict(resize=dict(flavorRef="http://localhost/3")) body = dict(resize=dict(flavorRef="http://localhost/3"))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch('nova.compute.api.API.resize', @mock.patch('nova.compute.api.API.resize',
@@ -891,7 +887,7 @@ class ServerActionsControllerTestV21(test.TestCase):
# Tests that PciRequestAliasNotDefined is translated to a 400 error. # Tests that PciRequestAliasNotDefined is translated to a 400 error.
body = dict(resize=dict(flavorRef="http://localhost/3")) body = dict(resize=dict(flavorRef="http://localhost/3"))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch('nova.compute.api.API.resize', @mock.patch('nova.compute.api.API.resize',
@@ -899,7 +895,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def test_resize_raises_badrequest_for_accelerator(self, mock_resize): def test_resize_raises_badrequest_for_accelerator(self, mock_resize):
body = dict(resize=dict(flavorRef="http://localhost/3")) body = dict(resize=dict(flavorRef="http://localhost/3"))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@mock.patch('nova.compute.api.API.resize', @mock.patch('nova.compute.api.API.resize',
@@ -908,7 +904,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def test_resize_raises_badrequest_for_vdpaInterface(self, mock_resize): def test_resize_raises_badrequest_for_vdpaInterface(self, mock_resize):
body = dict(resize=dict(flavorRef="http://localhost/3")) body = dict(resize=dict(flavorRef="http://localhost/3"))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_resize, self.controller._resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_confirm_resize_server(self): def test_confirm_resize_server(self):
@@ -921,7 +917,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.confirm_resize', cr_mock) self.stub_out('nova.compute.api.API.confirm_resize', cr_mock)
self.controller._action_confirm_resize(self.req, FAKE_UUID, body=body) self.controller._confirm_resize(self.req, FAKE_UUID, body=body)
self.assertTrue(self.confirm_resize_called) self.assertTrue(self.confirm_resize_called)
@@ -936,7 +932,7 @@ class ServerActionsControllerTestV21(test.TestCase):
confirm_resize_mock) confirm_resize_mock)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_confirm_resize, self.controller._confirm_resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_confirm_resize_raises_conflict_on_invalid_state(self): def test_confirm_resize_raises_conflict_on_invalid_state(self):
@@ -951,7 +947,7 @@ class ServerActionsControllerTestV21(test.TestCase):
fake_confirm_resize) fake_confirm_resize)
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_confirm_resize, self.controller._confirm_resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_revert_resize_migration_not_found(self): def test_revert_resize_migration_not_found(self):
@@ -965,7 +961,7 @@ class ServerActionsControllerTestV21(test.TestCase):
revert_resize_mock) revert_resize_mock)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_revert_resize, self.controller._revert_resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_revert_resize_server_not_found(self): def test_revert_resize_server_not_found(self):
@@ -974,7 +970,7 @@ class ServerActionsControllerTestV21(test.TestCase):
side_effect=exception.InstanceNotFound( side_effect=exception.InstanceNotFound(
instance_id='bad_server_id')): instance_id='bad_server_id')):
self.assertRaises(webob. exc.HTTPNotFound, self.assertRaises(webob. exc.HTTPNotFound,
self.controller._action_revert_resize, self.controller._revert_resize,
self.req, "bad_server_id", body=body) self.req, "bad_server_id", body=body)
def test_revert_resize_server(self): def test_revert_resize_server(self):
@@ -987,8 +983,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.revert_resize', revert_mock) self.stub_out('nova.compute.api.API.revert_resize', revert_mock)
body = self.controller._action_revert_resize(self.req, FAKE_UUID, self.controller._revert_resize(self.req, FAKE_UUID, body=body)
body=body)
self.assertTrue(self.revert_resize_called) self.assertTrue(self.revert_resize_called)
@@ -1004,7 +999,7 @@ class ServerActionsControllerTestV21(test.TestCase):
fake_revert_resize) fake_revert_resize)
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_revert_resize, self.controller._revert_resize,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_create_image(self): def test_create_image(self):
@@ -1014,8 +1009,8 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
response = self.controller._action_create_image(self.req, FAKE_UUID, response = self.controller._create_image(
body=body) self.req, FAKE_UUID, body=body)
if self.image_url: if self.image_url:
expected_location = self.image_url + uuids.snapshot_id expected_location = self.image_url + uuids.snapshot_id
@@ -1035,8 +1030,7 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
req = fakes.HTTPRequest.blank('', version='2.45') req = fakes.HTTPRequest.blank('', version='2.45')
response = self.controller._action_create_image(req, FAKE_UUID, response = self.controller._create_image(req, FAKE_UUID, body=body)
body=body)
self.assertIsInstance(response, dict) self.assertIsInstance(response, dict)
self.assertEqual(uuids.snapshot_id, response['image_id']) self.assertEqual(uuids.snapshot_id, response['image_id'])
@@ -1049,7 +1043,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_create_image, self.req, self.controller._create_image, self.req,
FAKE_UUID, body=body) FAKE_UUID, body=body)
def _do_test_create_volume_backed_image( def _do_test_create_volume_backed_image(
@@ -1127,8 +1121,8 @@ class ServerActionsControllerTestV21(test.TestCase):
if mock_vol_create_side_effect: if mock_vol_create_side_effect:
mock_vol_create.side_effect = mock_vol_create_side_effect mock_vol_create.side_effect = mock_vol_create_side_effect
response = self.controller._action_create_image(self.req, response = self.controller._create_image(
FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
location = response.headers['Location'] location = response.headers['Location']
image_id = location.replace(self.image_url or image_id = location.replace(self.image_url or
@@ -1235,9 +1229,8 @@ class ServerActionsControllerTestV21(test.TestCase):
'create_snapshot_force', 'create_snapshot_force',
return_value=snapshot), return_value=snapshot),
) as (mock_get_limits, mock_vol_get, mock_vol_create): ) as (mock_get_limits, mock_vol_get, mock_vol_create):
response = self.controller._create_image(
response = self.controller._action_create_image(self.req, self.req, FAKE_UUID, body=body)
FAKE_UUID, body=body)
location = response.headers['Location'] location = response.headers['Location']
image_id = location.replace(self.image_base_url, '') image_id = location.replace(self.image_base_url, '')
image = image_service.show(None, image_id) image = image_service.show(None, image_id)
@@ -1269,8 +1262,8 @@ class ServerActionsControllerTestV21(test.TestCase):
}, },
} }
response = self.controller._action_create_image(self.req, FAKE_UUID, response = self.controller._create_image(
body=body) self.req, FAKE_UUID, body=body)
if self.image_url: if self.image_url:
expected_location = self.image_url + uuids.snapshot_id expected_location = self.image_url + uuids.snapshot_id
@@ -1291,7 +1284,7 @@ class ServerActionsControllerTestV21(test.TestCase):
body['createImage']['metadata']['foo%i' % num] = "bar" body['createImage']['metadata']['foo%i' % num] = "bar"
self.assertRaises(webob.exc.HTTPForbidden, self.assertRaises(webob.exc.HTTPForbidden,
self.controller._action_create_image, self.controller._create_image,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_create_image_no_name(self): def test_create_image_no_name(self):
@@ -1300,7 +1293,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_create_image, self.controller._create_image,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_create_image_blank_name(self): def test_create_image_blank_name(self):
@@ -1311,7 +1304,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_create_image, self.controller._create_image,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_create_image_bad_metadata(self): def test_create_image_bad_metadata(self):
@@ -1323,7 +1316,7 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(self.validation_error, self.assertRaises(self.validation_error,
self.controller._action_create_image, self.controller._create_image,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_create_image_raises_conflict_on_invalid_state(self): def test_create_image_raises_conflict_on_invalid_state(self):
@@ -1340,5 +1333,5 @@ class ServerActionsControllerTestV21(test.TestCase):
} }
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_create_image, self.controller._create_image,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@@ -43,7 +43,7 @@ class ServerStartStopTestV21(test.TestCase):
@mock.patch.object(compute_api.API, 'start') @mock.patch.object(compute_api.API, 'start')
def test_start(self, start_mock): def test_start(self, start_mock):
body = {'os-start': None} body = {'os-start': None}
self.controller._start_server(self.req, uuids.instance, body=body) self.controller._start(self.req, uuids.instance, body=body)
start_mock.assert_called_once_with(mock.ANY, mock.ANY) start_mock.assert_called_once_with(mock.ANY, mock.ANY)
@mock.patch.object(compute_api.API, 'start', @mock.patch.object(compute_api.API, 'start',
@@ -52,7 +52,7 @@ class ServerStartStopTestV21(test.TestCase):
def test_start_not_ready(self, start_mock): def test_start_not_ready(self, start_mock):
body = {'os-start': None} body = {'os-start': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._start_server, self.req, uuids.instance, body=body) self.controller._start, self.req, uuids.instance, body=body)
@mock.patch.object(compute_api.API, 'start', @mock.patch.object(compute_api.API, 'start',
side_effect=exception.InstanceIsLocked( side_effect=exception.InstanceIsLocked(
@@ -60,7 +60,7 @@ class ServerStartStopTestV21(test.TestCase):
def test_start_locked_server(self, start_mock): def test_start_locked_server(self, start_mock):
body = {'os-start': None} body = {'os-start': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._start_server, self.req, uuids.instance, body=body) self.controller._start, self.req, uuids.instance, body=body)
@mock.patch.object(compute_api.API, 'start', @mock.patch.object(compute_api.API, 'start',
side_effect=exception.InstanceIsLocked( side_effect=exception.InstanceIsLocked(
@@ -68,13 +68,13 @@ class ServerStartStopTestV21(test.TestCase):
def test_start_invalid_state(self, start_mock): def test_start_invalid_state(self, start_mock):
body = {'os-start': None} body = {'os-start': None}
ex = self.assertRaises(webob.exc.HTTPConflict, ex = self.assertRaises(webob.exc.HTTPConflict,
self.controller._start_server, self.req, uuids.instance, body=body) self.controller._start, self.req, uuids.instance, body=body)
self.assertIn('is locked', str(ex)) self.assertIn('is locked', str(ex))
@mock.patch.object(compute_api.API, 'stop') @mock.patch.object(compute_api.API, 'stop')
def test_stop(self, stop_mock): def test_stop(self, stop_mock):
body = {'os-stop': None} body = {'os-stop': None}
self.controller._stop_server(self.req, uuids.instance, body=body) self.controller._stop(self.req, uuids.instance, body=body)
stop_mock.assert_called_once_with(mock.ANY, mock.ANY) stop_mock.assert_called_once_with(mock.ANY, mock.ANY)
@mock.patch.object(compute_api.API, 'stop', @mock.patch.object(compute_api.API, 'stop',
@@ -83,7 +83,7 @@ class ServerStartStopTestV21(test.TestCase):
def test_stop_not_ready(self, stop_mock): def test_stop_not_ready(self, stop_mock):
body = {'os-stop': None} body = {'os-stop': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._stop_server, self.req, uuids.instance, body=body) self.controller._stop, self.req, uuids.instance, body=body)
@mock.patch.object(compute_api.API, 'stop', @mock.patch.object(compute_api.API, 'stop',
side_effect=exception.InstanceIsLocked( side_effect=exception.InstanceIsLocked(
@@ -91,7 +91,7 @@ class ServerStartStopTestV21(test.TestCase):
def test_stop_locked_server(self, stop_mock): def test_stop_locked_server(self, stop_mock):
body = {'os-stop': None} body = {'os-stop': None}
ex = self.assertRaises(webob.exc.HTTPConflict, ex = self.assertRaises(webob.exc.HTTPConflict,
self.controller._stop_server, self.req, uuids.instance, body=body) self.controller._stop, self.req, uuids.instance, body=body)
self.assertIn('is locked', str(ex)) self.assertIn('is locked', str(ex))
@mock.patch.object(compute_api.API, 'stop', @mock.patch.object(compute_api.API, 'stop',
@@ -100,7 +100,7 @@ class ServerStartStopTestV21(test.TestCase):
def test_stop_invalid_state(self, stop_mock): def test_stop_invalid_state(self, stop_mock):
body = {'os-stop': None} body = {'os-stop': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._stop_server, self.req, uuids.instance, body=body) self.controller._stop, self.req, uuids.instance, body=body)
@mock.patch.object(db, 'instance_get_by_uuid', @mock.patch.object(db, 'instance_get_by_uuid',
side_effect=exception.InstanceNotFound( side_effect=exception.InstanceNotFound(
@@ -108,7 +108,7 @@ class ServerStartStopTestV21(test.TestCase):
def test_start_with_bogus_id(self, get_mock): def test_start_with_bogus_id(self, get_mock):
body = {'os-start': None} body = {'os-start': None}
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._start_server, self.req, uuids.instance, body=body) self.controller._start, self.req, uuids.instance, body=body)
@mock.patch.object(db, 'instance_get_by_uuid', @mock.patch.object(db, 'instance_get_by_uuid',
side_effect=exception.InstanceNotFound( side_effect=exception.InstanceNotFound(
@@ -116,4 +116,4 @@ class ServerStartStopTestV21(test.TestCase):
def test_stop_with_bogus_id(self, get_mock): def test_stop_with_bogus_id(self, get_mock):
body = {'os-stop': None} body = {'os-stop': None}
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._stop_server, self.req, uuids.instance, body=body) self.controller._stop, self.req, uuids.instance, body=body)
@@ -2930,7 +2930,7 @@ class ServersControllerStartStopTest(ControllerTest):
def test_start(self, mock_start): def test_start(self, mock_start):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-start': None} body = {'os-start': None}
self.controller._start_server(req, FAKE_UUID, body=body) self.controller._start(req, FAKE_UUID, body=body)
mock_start.assert_called_once_with(mock.ANY, mock.ANY) mock_start.assert_called_once_with(mock.ANY, mock.ANY)
@mock.patch.object(compute_api.API, 'start') @mock.patch.object(compute_api.API, 'start')
@@ -2941,7 +2941,7 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-start': None} body = {'os-start': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._start_server, req, FAKE_UUID, body=body) self.controller._start, req, FAKE_UUID, body=body)
@mock.patch.object( @mock.patch.object(
compute_api.API, 'start', fakes.fake_actions_to_locked_server) compute_api.API, 'start', fakes.fake_actions_to_locked_server)
@@ -2949,7 +2949,7 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-start': None} body = {'os-start': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._start_server, req, FAKE_UUID, body=body) self.controller._start, req, FAKE_UUID, body=body)
@mock.patch.object(compute_api.API, 'start') @mock.patch.object(compute_api.API, 'start')
def test_start_invalid(self, mock_start): def test_start_invalid(self, mock_start):
@@ -2960,13 +2960,13 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-start': None} body = {'os-start': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._start_server, req, FAKE_UUID, body=body) self.controller._start, req, FAKE_UUID, body=body)
@mock.patch.object(compute_api.API, 'stop') @mock.patch.object(compute_api.API, 'stop')
def test_stop(self, mock_stop): def test_stop(self, mock_stop):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-stop': None} body = {'os-stop': None}
self.controller._stop_server(req, FAKE_UUID, body=body) self.controller._stop(req, FAKE_UUID, body=body)
mock_stop.assert_called_once_with(mock.ANY, mock.ANY) mock_stop.assert_called_once_with(mock.ANY, mock.ANY)
@mock.patch.object(compute_api.API, 'stop') @mock.patch.object(compute_api.API, 'stop')
@@ -2977,7 +2977,7 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-stop': None} body = {'os-stop': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._stop_server, req, FAKE_UUID, body=body) self.controller._stop, req, FAKE_UUID, body=body)
@mock.patch.object( @mock.patch.object(
compute_api.API, 'stop', fakes.fake_actions_to_locked_server) compute_api.API, 'stop', fakes.fake_actions_to_locked_server)
@@ -2985,7 +2985,7 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-stop': None} body = {'os-stop': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._stop_server, req, FAKE_UUID, body=body) self.controller._stop, req, FAKE_UUID, body=body)
@mock.patch.object(compute_api.API, 'stop') @mock.patch.object(compute_api.API, 'stop')
def test_stop_invalid_state(self, mock_stop): def test_stop_invalid_state(self, mock_stop):
@@ -2996,7 +2996,7 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID) req = fakes.HTTPRequestV21.blank(self.path_action % FAKE_UUID)
body = {'os-stop': None} body = {'os-stop': None}
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._stop_server, req, FAKE_UUID, body=body) self.controller._stop, req, FAKE_UUID, body=body)
@mock.patch('nova.db.main.api.instance_get_by_uuid') @mock.patch('nova.db.main.api.instance_get_by_uuid')
def test_start_with_bogus_id(self, mock_get): def test_start_with_bogus_id(self, mock_get):
@@ -3005,7 +3005,7 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst') req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst')
body = {'os-start': None} body = {'os-start': None}
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._start_server, req, 'test_inst', body=body) self.controller._start, req, 'test_inst', body=body)
@mock.patch('nova.db.main.api.instance_get_by_uuid') @mock.patch('nova.db.main.api.instance_get_by_uuid')
def test_stop_with_bogus_id(self, mock_get): def test_stop_with_bogus_id(self, mock_get):
@@ -3014,7 +3014,7 @@ class ServersControllerStartStopTest(ControllerTest):
req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst') req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst')
body = {'os-stop': None} body = {'os-stop': None}
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._stop_server, req, 'test_inst', body=body) self.controller._stop, req, 'test_inst', body=body)
class _ServersControllerRebuildTest(ControllerTest): class _ServersControllerRebuildTest(ControllerTest):
@@ -3061,7 +3061,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
def test_rebuild_server_with_image_not_uuid(self): def test_rebuild_server_with_image_not_uuid(self):
self.body['rebuild']['imageRef'] = 'not-uuid' self.body['rebuild']['imageRef'] = 'not-uuid'
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, self.req, FAKE_UUID,
body=self.body) body=self.body)
@@ -3071,27 +3071,27 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
'76fa36fc-c930-4bf3-8c8a-ea2a2420deb6') '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6')
self.body['rebuild']['imageRef'] = image_href self.body['rebuild']['imageRef'] = image_href
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, self.req, FAKE_UUID,
body=self.body) body=self.body)
def test_rebuild_server_with_image_as_empty_string(self): def test_rebuild_server_with_image_as_empty_string(self):
self.body['rebuild']['imageRef'] = '' self.body['rebuild']['imageRef'] = ''
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, self.req, FAKE_UUID,
body=self.body) body=self.body)
def test_rebuild_instance_name_with_spaces_in_the_middle(self): def test_rebuild_instance_name_with_spaces_in_the_middle(self):
self.body['rebuild']['name'] = 'abc def' self.body['rebuild']['name'] = 'abc def'
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.controller._action_rebuild(self.req, FAKE_UUID, body=self.body) self.controller._rebuild(self.req, FAKE_UUID, body=self.body)
def test_rebuild_instance_name_with_leading_trailing_spaces(self): def test_rebuild_instance_name_with_leading_trailing_spaces(self):
self.body['rebuild']['name'] = ' abc def ' self.body['rebuild']['name'] = ' abc def '
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_rebuild_instance_name_with_leading_trailing_spaces_compat_mode( def test_rebuild_instance_name_with_leading_trailing_spaces_compat_mode(
@@ -3105,14 +3105,13 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
with mock.patch.object(compute_api.API, 'rebuild') as mock_rebuild: with mock.patch.object(compute_api.API, 'rebuild') as mock_rebuild:
mock_rebuild.side_effect = fake_rebuild mock_rebuild.side_effect = fake_rebuild
self.controller._action_rebuild(self.req, FAKE_UUID, self.controller._rebuild(self.req, FAKE_UUID, body=self.body)
body=self.body)
def test_rebuild_instance_with_blank_metadata_key(self): def test_rebuild_instance_with_blank_metadata_key(self):
self.body['rebuild']['metadata'][''] = 'world' self.body['rebuild']['metadata'][''] = 'world'
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_rebuild_instance_with_metadata_key_too_long(self): def test_rebuild_instance_with_metadata_key_too_long(self):
@@ -3120,7 +3119,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_rebuild_instance_with_metadata_value_too_long(self): def test_rebuild_instance_with_metadata_value_too_long(self):
@@ -3128,7 +3127,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.req, self.controller._rebuild, self.req,
FAKE_UUID, body=self.body) FAKE_UUID, body=self.body)
def test_rebuild_instance_with_metadata_value_not_string(self): def test_rebuild_instance_with_metadata_value_not_string(self):
@@ -3136,7 +3135,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.req, self.controller._rebuild, self.req,
FAKE_UUID, body=self.body) FAKE_UUID, body=self.body)
@mock.patch.object(nova_fixtures.GlanceFixture, 'show', @mock.patch.object(nova_fixtures.GlanceFixture, 'show',
@@ -3149,7 +3148,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
# make min_ram larger than our instance ram size # make min_ram larger than our instance ram size
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
mock_show.assert_called_once_with( mock_show.assert_called_once_with(
self.req.environ['nova.context'], self.image_uuid, self.req.environ['nova.context'], self.image_uuid,
@@ -3165,7 +3164,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
# make min_disk larger than our instance disk size # make min_disk larger than our instance disk size
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.req, self.controller._rebuild, self.req,
FAKE_UUID, body=self.body) FAKE_UUID, body=self.body)
mock_show.assert_called_once_with( mock_show.assert_called_once_with(
self.req.environ['nova.context'], self.image_uuid, self.req.environ['nova.context'], self.image_uuid,
@@ -3180,7 +3179,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
# make image size larger than our instance disk size # make image size larger than our instance disk size
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
mock_show.assert_called_once_with( mock_show.assert_called_once_with(
self.req.environ['nova.context'], self.image_uuid, self.req.environ['nova.context'], self.image_uuid,
@@ -3190,7 +3189,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
self.body['rebuild']['name'] = ' ' self.body['rebuild']['name'] = ' '
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
@mock.patch.object(nova_fixtures.GlanceFixture, 'show', @mock.patch.object(nova_fixtures.GlanceFixture, 'show',
@@ -3201,7 +3200,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
def test_rebuild_instance_with_deleted_image(self, mock_show): def test_rebuild_instance_with_deleted_image(self, mock_show):
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
mock_show.assert_called_once_with( mock_show.assert_called_once_with(
self.req.environ['nova.context'], self.image_uuid, self.req.environ['nova.context'], self.image_uuid,
@@ -3222,7 +3221,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
): ):
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(webob.exc.HTTPForbidden, self.assertRaises(webob.exc.HTTPForbidden,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_rebuild_bad_personality(self): def test_rebuild_bad_personality(self):
@@ -3241,7 +3240,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
} }
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_personality(self): def test_rebuild_personality(self):
@@ -3259,8 +3258,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
}, },
} }
body = self.controller._action_rebuild(self.req, FAKE_UUID, body = self.controller._rebuild(self.req, FAKE_UUID, body=body).obj
body=body).obj
self.assertNotIn('personality', body['server']) self.assertNotIn('personality', body['server'])
@@ -3277,8 +3275,7 @@ class ServersControllerRebuildTest(_ServersControllerRebuildTest):
}, },
} }
body = self.controller._action_rebuild(self.req, FAKE_UUID, body = self.controller._rebuild(self.req, FAKE_UUID, body=body).obj
body=body).obj
get_only_fields = copy.deepcopy(GET_ONLY_FIELDS) get_only_fields = copy.deepcopy(GET_ONLY_FIELDS)
for field in get_only_fields: for field in get_only_fields:
self.assertNotIn(field, body['server']) self.assertNotIn(field, body['server'])
@@ -3303,7 +3300,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
if set_key_name: if set_key_name:
self.body['rebuild']['key_name'] = key_name self.body['rebuild']['key_name'] = key_name
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
server = self.controller._action_rebuild( server = self.controller._rebuild(
self.req, FAKE_UUID, self.req, FAKE_UUID,
body=self.body).obj['server'] body=self.body).obj['server']
self.assertEqual(server['id'], FAKE_UUID) self.assertEqual(server['id'], FAKE_UUID)
@@ -3325,7 +3322,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
}, },
} }
excpt = self.assertRaises(exception.ValidationError, excpt = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
self.assertIn('key_name', str(excpt)) self.assertIn('key_name', str(excpt))
@@ -3337,7 +3334,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
}, },
} }
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_user_has_no_key_pair(self): def test_rebuild_user_has_no_key_pair(self):
@@ -3351,7 +3348,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
self.mock_get.side_effect = fake_get self.mock_get.side_effect = fake_get
self.body['rebuild']['key_name'] = "a-key-name" self.body['rebuild']['key_name'] = "a-key-name"
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_rebuild_with_non_string_keypair_name(self): def test_rebuild_with_non_string_keypair_name(self):
@@ -3362,7 +3359,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
}, },
} }
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_with_invalid_keypair_name(self): def test_rebuild_with_invalid_keypair_name(self):
@@ -3373,7 +3370,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
}, },
} }
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_with_empty_keypair_name(self): def test_rebuild_with_empty_keypair_name(self):
@@ -3384,7 +3381,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
}, },
} }
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_rebuild_with_none_keypair_name(self): def test_rebuild_with_none_keypair_name(self):
@@ -3397,7 +3394,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
with mock.patch.object(objects.KeyPair, 'get_by_name') as key_get: with mock.patch.object(objects.KeyPair, 'get_by_name') as key_get:
self.body['rebuild']['key_name'] = key_name self.body['rebuild']['key_name'] = key_name
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.controller._action_rebuild( self.controller._rebuild(
self.req, FAKE_UUID, self.req, FAKE_UUID,
body=self.body) body=self.body)
# NOTE: because the api will call _get_server twice. The server # NOTE: because the api will call _get_server twice. The server
@@ -3413,7 +3410,7 @@ class ServersControllerRebuildTestV254(_ServersControllerRebuildTest):
}, },
} }
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
@@ -3439,7 +3436,7 @@ class ServersControllerRebuildTestV257(_ServersControllerRebuildTest):
} }
} }
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
self.assertIn('personality', str(ex)) self.assertIn('personality', str(ex))
@@ -3454,7 +3451,7 @@ class ServersControllerRebuildTestV257(_ServersControllerRebuildTest):
self.req.api_version_request = \ self.req.api_version_request = \
api_version_request.APIVersionRequest('2.55') api_version_request.APIVersionRequest('2.55')
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
self.assertIn('user_data', str(ex)) self.assertIn('user_data', str(ex))
@@ -3467,7 +3464,7 @@ class ServersControllerRebuildTestV257(_ServersControllerRebuildTest):
} }
} }
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
self.assertIn('user_data', str(ex)) self.assertIn('user_data', str(ex))
@@ -3480,7 +3477,7 @@ class ServersControllerRebuildTestV257(_ServersControllerRebuildTest):
} }
} }
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
self.assertIn('user_data', str(ex)) self.assertIn('user_data', str(ex))
@@ -3512,7 +3509,7 @@ class ServersControllerRebuildTestV257(_ServersControllerRebuildTest):
return instance_update_and_get_original( return instance_update_and_get_original(
ctxt, instance_uuid, values, **kwargs) ctxt, instance_uuid, values, **kwargs)
mock_update.side_effect = fake_instance_update_and_get_original mock_update.side_effect = fake_instance_update_and_get_original
self.controller._action_rebuild(self.req, FAKE_UUID, body=body) self.controller._rebuild(self.req, FAKE_UUID, body=body)
self.assertEqual(2, mock_update.call_count) self.assertEqual(2, mock_update.call_count)
@@ -3533,8 +3530,8 @@ class ServersControllerRebuildTestV219(_ServersControllerRebuildTest):
if set_desc: if set_desc:
self.body['rebuild']['description'] = desc self.body['rebuild']['description'] = desc
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
server = self.controller._action_rebuild(self.req, FAKE_UUID, server = self.controller._rebuild(
body=self.body).obj['server'] self.req, FAKE_UUID, body=self.body).obj['server']
self.assertEqual(server['id'], FAKE_UUID) self.assertEqual(server['id'], FAKE_UUID)
self.assertEqual(server['description'], desc) self.assertEqual(server['description'], desc)
@@ -3554,7 +3551,7 @@ class ServersControllerRebuildTestV219(_ServersControllerRebuildTest):
self.body['rebuild']['description'] = 'x' * 256 self.body['rebuild']['description'] = 'x' * 256
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_rebuild_server_description_invalid(self): def test_rebuild_server_description_invalid(self):
@@ -3562,7 +3559,7 @@ class ServersControllerRebuildTestV219(_ServersControllerRebuildTest):
self.body['rebuild']['description'] = "123\0d456" self.body['rebuild']['description'] = "123\0d456"
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
@@ -3607,12 +3604,12 @@ class ServersControllerRebuildTestV263(ControllerTest):
self.body['rebuild']['trusted_image_certificates'] = certs self.body['rebuild']['trusted_image_certificates'] = certs
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
server = self.controller._action_rebuild( server = self.controller._rebuild(
self.req, FAKE_UUID, body=self.body).obj['server'] self.req, FAKE_UUID, body=self.body).obj['server']
# TODO(stephenfin): This is a lie. We call '_get_server' immediately # TODO(stephenfin): This is a lie. We call '_get_server' immediately
# after making the call to 'nova.compute.api.API().rebuild_server' in # after making the call to 'nova.compute.api.API().rebuild_server' in
# '_action_rebuild', which means all we're testing here is the value # '_rebuild', which means all we're testing here is the value
# returned by 'mock_get' above. Drop it in favour of testing the calls # returned by 'mock_get' above. Drop it in favour of testing the calls
# to the API itself # to the API itself
if certs: if certs:
@@ -3658,7 +3655,7 @@ class ServersControllerRebuildTestV263(ControllerTest):
self.body['rebuild']['trusted_image_certificates'] = [''] self.body['rebuild']['trusted_image_certificates'] = ['']
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
self.assertRegex( self.assertRegex(
str(ex), str(ex),
@@ -3670,7 +3667,7 @@ class ServersControllerRebuildTestV263(ControllerTest):
self.body['rebuild']['trusted_image_certificates'] = [] self.body['rebuild']['trusted_image_certificates'] = []
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
self.assertRegex( self.assertRegex(
str(ex), str(ex),
@@ -3683,7 +3680,7 @@ class ServersControllerRebuildTestV263(ControllerTest):
'cert{}'.format(i) for i in range(51)] 'cert{}'.format(i) for i in range(51)]
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
self.assertIn('is too long', str(ex)) self.assertIn('is too long', str(ex))
@@ -3692,7 +3689,7 @@ class ServersControllerRebuildTestV263(ControllerTest):
self.body['rebuild']['trusted_image_certificates'] = ['cert', 'cert'] self.body['rebuild']['trusted_image_certificates'] = ['cert', 'cert']
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
self.assertIn('has non-unique elements', str(ex)) self.assertIn('has non-unique elements', str(ex))
@@ -3701,7 +3698,7 @@ class ServersControllerRebuildTestV263(ControllerTest):
self.body['rebuild']['trusted_image_certificates'] = [1, 2] self.body['rebuild']['trusted_image_certificates'] = [1, 2]
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
self.assertIn('is not of type', str(ex)) self.assertIn('is not of type', str(ex))
@@ -3710,7 +3707,7 @@ class ServersControllerRebuildTestV263(ControllerTest):
self.body['rebuild']['trusted_image_certificates'] = "not-an-array" self.body['rebuild']['trusted_image_certificates'] = "not-an-array"
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
self.assertIn('is not of type', str(ex)) self.assertIn('is not of type', str(ex))
@@ -3720,7 +3717,7 @@ class ServersControllerRebuildTestV263(ControllerTest):
self.req.api_version_request = \ self.req.api_version_request = \
api_version_request.APIVersionRequest('2.62') api_version_request.APIVersionRequest('2.62')
ex = self.assertRaises(exception.ValidationError, ex = self.assertRaises(exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
self.assertIn('Additional properties are not allowed', str(ex)) self.assertIn('Additional properties are not allowed', str(ex))
@@ -3762,7 +3759,7 @@ class ServersControllerRebuildTestV271(ControllerTest):
self.mock_get.return_value = fakes.stub_instance_obj(ctx, self.mock_get.return_value = fakes.stub_instance_obj(ctx,
vm_state=vm_states.ACTIVE, project_id=self.req_project_id, vm_state=vm_states.ACTIVE, project_id=self.req_project_id,
user_id=self.req_user_id) user_id=self.req_user_id)
server = self.controller._action_rebuild( server = self.controller._rebuild(
self.req, FAKE_UUID, body=self.body).obj['server'] self.req, FAKE_UUID, body=self.body).obj['server']
return server return server
@@ -3809,8 +3806,7 @@ class ServersControllerRebuildTestV275(ControllerTest):
user_id=req.environ['nova.context'].user_id) user_id=req.environ['nova.context'].user_id)
self.mock_get.side_effect = fake_get self.mock_get.side_effect = fake_get
res_dict = self.controller._action_rebuild(req, FAKE_UUID, res_dict = self.controller._rebuild(req, FAKE_UUID, body=body).obj
body=body).obj
get_only_fields_Rebuild = copy.deepcopy(GET_ONLY_FIELDS) get_only_fields_Rebuild = copy.deepcopy(GET_ONLY_FIELDS)
get_only_fields_Rebuild.remove('key_name') get_only_fields_Rebuild.remove('key_name')
for field in get_only_fields_Rebuild: for field in get_only_fields_Rebuild:
@@ -3848,8 +3844,7 @@ class ServersControllerRebuildTestV275(ControllerTest):
project_id=req.environ['nova.context'].project_id, project_id=req.environ['nova.context'].project_id,
user_id=req.environ['nova.context'].user_id) user_id=req.environ['nova.context'].user_id)
res_dict = self.controller._action_rebuild(req, FAKE_UUID, res_dict = self.controller._rebuild(req, FAKE_UUID, body=body).obj
body=body).obj
for field in GET_ONLY_FIELDS: for field in GET_ONLY_FIELDS:
if field == 'OS-EXT-SRV-ATTR:user_data': if field == 'OS-EXT-SRV-ATTR:user_data':
self.assertNotIn(field, res_dict['server']) self.assertNotIn(field, res_dict['server'])
@@ -3928,7 +3923,7 @@ class ServersControllerRebuildTestV290(ControllerTest):
# There's nothing to check here from the return value since the # There's nothing to check here from the return value since the
# 'rebuild' API is a cast and we immediately fetch the instance from # 'rebuild' API is a cast and we immediately fetch the instance from
# the database after this cast...which returns a mocked Instance # the database after this cast...which returns a mocked Instance
server = self.controller._action_rebuild( server = self.controller._rebuild(
req, FAKE_UUID, body=body, req, FAKE_UUID, body=body,
).obj['server'] ).obj['server']
@@ -3952,7 +3947,7 @@ class ServersControllerRebuildTestV290(ControllerTest):
ex = self.assertRaises( ex = self.assertRaises(
exception.ValidationError, exception.ValidationError,
self.controller._action_rebuild, self.controller._rebuild,
req, FAKE_UUID, body=body) req, FAKE_UUID, body=body)
self.assertIn('hostname', str(ex)) self.assertIn('hostname', str(ex))
@@ -4291,8 +4286,8 @@ class ServersControllerTriggerCrashDumpTest(ControllerTest):
@mock.patch.object(compute_api.API, 'trigger_crash_dump') @mock.patch.object(compute_api.API, 'trigger_crash_dump')
def test_trigger_crash_dump(self, mock_trigger_crash_dump): def test_trigger_crash_dump(self, mock_trigger_crash_dump):
ctxt = self.req.environ['nova.context'] ctxt = self.req.environ['nova.context']
self.controller._action_trigger_crash_dump(self.req, FAKE_UUID, self.controller._trigger_crash_dump(
body=self.body) self.req, FAKE_UUID, body=self.body)
mock_trigger_crash_dump.assert_called_with(ctxt, self.instance) mock_trigger_crash_dump.assert_called_with(ctxt, self.instance)
@mock.patch.object(compute_api.API, 'trigger_crash_dump') @mock.patch.object(compute_api.API, 'trigger_crash_dump')
@@ -4301,14 +4296,14 @@ class ServersControllerTriggerCrashDumpTest(ControllerTest):
instance_id=FAKE_UUID) instance_id=FAKE_UUID)
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
@mock.patch.object(compute_api.API, 'trigger_crash_dump', @mock.patch.object(compute_api.API, 'trigger_crash_dump',
fakes.fake_actions_to_locked_server) fakes.fake_actions_to_locked_server)
def test_trigger_crash_dump_locked_server(self): def test_trigger_crash_dump_locked_server(self):
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
@mock.patch.object(compute_api.API, 'trigger_crash_dump') @mock.patch.object(compute_api.API, 'trigger_crash_dump')
@@ -4318,24 +4313,24 @@ class ServersControllerTriggerCrashDumpTest(ControllerTest):
method='fake_method', state='fake_state') method='fake_method', state='fake_state')
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_trigger_crash_dump_with_bogus_id(self): def test_trigger_crash_dump_with_bogus_id(self):
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
self.req, 'test_inst', body=self.body) self.req, 'test_inst', body=self.body)
def test_trigger_crash_dump_schema_invalid_type(self): def test_trigger_crash_dump_schema_invalid_type(self):
self.body['trigger_crash_dump'] = 'not null' self.body['trigger_crash_dump'] = 'not null'
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
def test_trigger_crash_dump_schema_extra_property(self): def test_trigger_crash_dump_schema_extra_property(self):
self.body['extra_property'] = 'extra' self.body['extra_property'] = 'extra'
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
self.req, FAKE_UUID, body=self.body) self.req, FAKE_UUID, body=self.body)
@@ -8584,7 +8579,7 @@ class ServersActionsJsonTestV239(test.NoDBTestCase):
}, },
} }
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller._action_create_image, self.req, self.controller._create_image, self.req,
FAKE_UUID, body=body) FAKE_UUID, body=body)
# starting from version 2.39 no quota checks on Nova side are performed # starting from version 2.39 no quota checks on Nova side are performed
# for 'createImage' action after removing 'image-metadata' proxy API # for 'createImage' action after removing 'image-metadata' proxy API
+29 -29
View File
@@ -419,7 +419,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name = policies.SERVERS % 'show:flavor-extra-specs' rule_name = policies.SERVERS % 'show:flavor-extra-specs'
authorize_res, unauthorize_res = self.common_policy_auth( authorize_res, unauthorize_res = self.common_policy_auth(
self.project_reader_authorized_contexts, self.project_reader_authorized_contexts,
rule_name, self.controller._action_rebuild, rule_name, self.controller._rebuild,
req, self.instance.uuid, req, self.instance.uuid,
body={'rebuild': {"imageRef": uuids.fake_id}}, body={'rebuild': {"imageRef": uuids.fake_id}},
fatal=False) fatal=False)
@@ -629,7 +629,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._action_confirm_resize, self.controller._confirm_resize,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'confirmResize': None}) body={'confirmResize': None})
@@ -639,7 +639,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._action_revert_resize, self.controller._revert_resize,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'revertResize': None}) body={'revertResize': None})
@@ -649,7 +649,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._action_reboot, self.controller._reboot,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'reboot': {'type': 'soft'}}) body={'reboot': {'type': 'soft'}})
@@ -658,7 +658,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name = policies.SERVERS % 'resize' rule_name = policies.SERVERS % 'resize'
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._action_resize, self.controller._resize,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'resize': {'flavorRef': 'f1'}}) body={'resize': {'flavorRef': 'f1'}})
@@ -671,7 +671,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.policy.set_rules({rule_name: "user_id:%(user_id)s"}, self.policy.set_rules({rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
exc = self.assertRaises( exc = self.assertRaises(
exception.PolicyNotAuthorized, self.controller._action_resize, exception.PolicyNotAuthorized, self.controller._resize,
req, self.instance.uuid, body=body) req, self.instance.uuid, body=body)
self.assertEqual( self.assertEqual(
"Policy doesn't allow %s to be performed." % rule_name, "Policy doesn't allow %s to be performed." % rule_name,
@@ -684,30 +684,30 @@ class ServersPolicyTest(base.BasePolicyTest):
self.policy.set_rules({rule_name: "user_id:%(user_id)s"}, self.policy.set_rules({rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
body = {'resize': {'flavorRef': 'f1'}} body = {'resize': {'flavorRef': 'f1'}}
self.controller._action_resize(self.req, self.controller._resize(self.req,
self.instance.uuid, body=body) self.instance.uuid, body=body)
@mock.patch('nova.compute.api.API.start') @mock.patch('nova.compute.api.API.start')
def test_start_server_policy(self, mock_start): def test_start_policy(self, mock_start):
rule_name = policies.SERVERS % 'start' rule_name = policies.SERVERS % 'start'
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._start_server, self.controller._start,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'os-start': None}) body={'os-start': None})
@mock.patch('nova.compute.api.API.stop') @mock.patch('nova.compute.api.API.stop')
def test_stop_server_policy(self, mock_stop): def test_stop_policy(self, mock_stop):
rule_name = policies.SERVERS % 'stop' rule_name = policies.SERVERS % 'stop'
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._stop_server, self.controller._stop,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'os-stop': None}) body={'os-stop': None})
def test_stop_server_policy_failed_with_other_user(self): def test_stop_policy_failed_with_other_user(self):
# Change the user_id in request context. # Change the user_id in request context.
req = fakes.HTTPRequest.blank('') req = fakes.HTTPRequest.blank('')
req.environ['nova.context'].user_id = 'other-user' req.environ['nova.context'].user_id = 'other-user'
@@ -716,20 +716,20 @@ class ServersPolicyTest(base.BasePolicyTest):
self.policy.set_rules({rule_name: "user_id:%(user_id)s"}, self.policy.set_rules({rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
exc = self.assertRaises( exc = self.assertRaises(
exception.PolicyNotAuthorized, self.controller._stop_server, exception.PolicyNotAuthorized, self.controller._stop,
req, self.instance.uuid, body=body) req, self.instance.uuid, body=body)
self.assertEqual( self.assertEqual(
"Policy doesn't allow %s to be performed." % rule_name, "Policy doesn't allow %s to be performed." % rule_name,
exc.format_message()) exc.format_message())
@mock.patch('nova.compute.api.API.stop') @mock.patch('nova.compute.api.API.stop')
def test_stop_server_overridden_policy_pass_with_same_user( def test_stop_overridden_policy_pass_with_same_user(
self, mock_stop): self, mock_stop):
rule_name = policies.SERVERS % 'stop' rule_name = policies.SERVERS % 'stop'
self.policy.set_rules({rule_name: "user_id:%(user_id)s"}, self.policy.set_rules({rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
body = {'os-stop': None} body = {'os-stop': None}
self.controller._stop_server(self.req, self.controller._stop(self.req,
self.instance.uuid, body=body) self.instance.uuid, body=body)
@mock.patch('nova.compute.api.API.rebuild') @mock.patch('nova.compute.api.API.rebuild')
@@ -737,7 +737,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name = policies.SERVERS % 'rebuild' rule_name = policies.SERVERS % 'rebuild'
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._action_rebuild, self.controller._rebuild,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'rebuild': {"imageRef": uuids.fake_id}}) body={'rebuild': {"imageRef": uuids.fake_id}})
@@ -750,7 +750,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.policy.set_rules({rule_name: "user_id:%(user_id)s"}, self.policy.set_rules({rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
exc = self.assertRaises( exc = self.assertRaises(
exception.PolicyNotAuthorized, self.controller._action_rebuild, exception.PolicyNotAuthorized, self.controller._rebuild,
req, self.instance.uuid, body=body) req, self.instance.uuid, body=body)
self.assertEqual( self.assertEqual(
"Policy doesn't allow %s to be performed." % rule_name, "Policy doesn't allow %s to be performed." % rule_name,
@@ -763,7 +763,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.policy.set_rules({rule_name: "user_id:%(user_id)s"}, self.policy.set_rules({rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
body = {'rebuild': {"imageRef": uuids.fake_id}} body = {'rebuild': {"imageRef": uuids.fake_id}}
self.controller._action_rebuild(self.req, self.controller._rebuild(self.req,
self.instance.uuid, body=body) self.instance.uuid, body=body)
@mock.patch('nova.compute.api.API.rebuild') @mock.patch('nova.compute.api.API.rebuild')
@@ -790,7 +790,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
check_rule, check_rule,
self.controller._action_rebuild, self.controller._rebuild,
req, self.instance.uuid, body=body) req, self.instance.uuid, body=body)
def test_rebuild_trusted_certs_policy_failed_with_other_user(self): def test_rebuild_trusted_certs_policy_failed_with_other_user(self):
@@ -810,7 +810,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name: "user_id:%(user_id)s"}, rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
exc = self.assertRaises( exc = self.assertRaises(
exception.PolicyNotAuthorized, self.controller._action_rebuild, exception.PolicyNotAuthorized, self.controller._rebuild,
req, self.instance.uuid, body=body) req, self.instance.uuid, body=body)
self.assertEqual( self.assertEqual(
"Policy doesn't allow %s to be performed." % rule_name, "Policy doesn't allow %s to be performed." % rule_name,
@@ -831,7 +831,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.policy.set_rules( self.policy.set_rules(
{rule: "@", {rule: "@",
rule_name: "user_id:%(user_id)s"}, overwrite=False) rule_name: "user_id:%(user_id)s"}, overwrite=False)
self.controller._action_rebuild(req, self.controller._rebuild(req,
self.instance.uuid, body=body) self.instance.uuid, body=body)
@mock.patch('nova.objects.BlockDeviceMappingList.get_by_instance_uuid') @mock.patch('nova.objects.BlockDeviceMappingList.get_by_instance_uuid')
@@ -842,7 +842,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name = policies.SERVERS % 'create_image' rule_name = policies.SERVERS % 'create_image'
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._action_create_image, self.controller._create_image,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'createImage': {"name": 'test'}}) body={'createImage': {"name": 'test'}})
@@ -866,7 +866,7 @@ class ServersPolicyTest(base.BasePolicyTest):
base.rule_if_system, rule, rule_name) base.rule_if_system, rule, rule_name)
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
check_rule, check_rule,
self.controller._action_create_image, self.controller._create_image,
self.req, self.instance.uuid, self.req, self.instance.uuid,
body={'createImage': {"name": 'test'}}) body={'createImage': {"name": 'test'}})
@@ -876,7 +876,7 @@ class ServersPolicyTest(base.BasePolicyTest):
req = fakes.HTTPRequest.blank('', version='2.17') req = fakes.HTTPRequest.blank('', version='2.17')
self.common_policy_auth(self.project_action_authorized_contexts, self.common_policy_auth(self.project_action_authorized_contexts,
rule_name, rule_name,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
req, self.instance.uuid, req, self.instance.uuid,
body={'trigger_crash_dump': None}) body={'trigger_crash_dump': None})
@@ -890,7 +890,7 @@ class ServersPolicyTest(base.BasePolicyTest):
overwrite=False) overwrite=False)
exc = self.assertRaises( exc = self.assertRaises(
exception.PolicyNotAuthorized, exception.PolicyNotAuthorized,
self.controller._action_trigger_crash_dump, self.controller._trigger_crash_dump,
req, self.instance.uuid, body=body) req, self.instance.uuid, body=body)
self.assertEqual( self.assertEqual(
"Policy doesn't allow %s to be performed." % rule_name, "Policy doesn't allow %s to be performed." % rule_name,
@@ -904,7 +904,7 @@ class ServersPolicyTest(base.BasePolicyTest):
self.policy.set_rules({rule_name: "user_id:%(user_id)s"}, self.policy.set_rules({rule_name: "user_id:%(user_id)s"},
overwrite=False) overwrite=False)
body = {'trigger_crash_dump': None} body = {'trigger_crash_dump': None}
self.controller._action_trigger_crash_dump(req, self.controller._trigger_crash_dump(req,
self.instance.uuid, body=body) self.instance.uuid, body=body)
def test_server_detail_with_extended_attr_policy(self): def test_server_detail_with_extended_attr_policy(self):
@@ -967,7 +967,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name = ea_policies.BASE_POLICY_NAME rule_name = ea_policies.BASE_POLICY_NAME
authorize_res, unauthorize_res = self.common_policy_auth( authorize_res, unauthorize_res = self.common_policy_auth(
self.project_admin_authorized_contexts, self.project_admin_authorized_contexts,
rule_name, self.controller._action_rebuild, rule_name, self.controller._rebuild,
req, self.instance.uuid, req, self.instance.uuid,
body={'rebuild': {"imageRef": uuids.fake_id}}, body={'rebuild': {"imageRef": uuids.fake_id}},
fatal=False) fatal=False)
@@ -1074,7 +1074,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name = policies.SERVERS % 'show:host_status' rule_name = policies.SERVERS % 'show:host_status'
authorize_res, unauthorize_res = self.common_policy_auth( authorize_res, unauthorize_res = self.common_policy_auth(
self.project_admin_authorized_contexts, self.project_admin_authorized_contexts,
rule_name, self.controller._action_rebuild, rule_name, self.controller._rebuild,
req, self.instance.uuid, req, self.instance.uuid,
body={'rebuild': {"imageRef": uuids.fake_id}}, body={'rebuild': {"imageRef": uuids.fake_id}},
fatal=False) fatal=False)
@@ -1193,7 +1193,7 @@ class ServersPolicyTest(base.BasePolicyTest):
rule_name = policies.SERVERS % 'show:host_status:unknown-only' rule_name = policies.SERVERS % 'show:host_status:unknown-only'
authorize_res, unauthorize_res = self.common_policy_auth( authorize_res, unauthorize_res = self.common_policy_auth(
self.project_admin_authorized_contexts, self.project_admin_authorized_contexts,
rule_name, self.controller._action_rebuild, rule_name, self.controller._rebuild,
req, self.instance.uuid, req, self.instance.uuid,
body={'rebuild': {"imageRef": uuids.fake_id}}, body={'rebuild': {"imageRef": uuids.fake_id}},
fatal=False) fatal=False)