Merge "Use UUIDs instead of IDs for OSAPI servers."
This commit is contained in:
commit
022afb9b06
@ -113,21 +113,31 @@ def get_pagination_params(request):
|
||||
|
||||
"""
|
||||
params = {}
|
||||
for param in ['marker', 'limit']:
|
||||
if not param in request.GET:
|
||||
continue
|
||||
try:
|
||||
params[param] = int(request.GET[param])
|
||||
except ValueError:
|
||||
msg = _('%s param must be an integer') % param
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
if params[param] < 0:
|
||||
msg = _('%s param must be positive') % param
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
if 'limit' in request.GET:
|
||||
params['limit'] = _get_limit_param(request)
|
||||
if 'marker' in request.GET:
|
||||
params['marker'] = _get_marker_param(request)
|
||||
return params
|
||||
|
||||
|
||||
def _get_limit_param(request):
|
||||
"""Extract integer limit from request or fail"""
|
||||
try:
|
||||
limit = int(request.GET['limit'])
|
||||
except ValueError:
|
||||
msg = _('limit param must be an integer')
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
if limit < 0:
|
||||
msg = _('limit param must be positive')
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
return limit
|
||||
|
||||
|
||||
def _get_marker_param(request):
|
||||
"""Extract marker id from request or fail"""
|
||||
return request.GET['marker']
|
||||
|
||||
|
||||
def limited(items, request, max_limit=FLAGS.osapi_max_limit):
|
||||
"""
|
||||
Return a slice of items according to requested offset and limit.
|
||||
@ -178,7 +188,7 @@ def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit):
|
||||
if marker:
|
||||
start_index = -1
|
||||
for i, item in enumerate(items):
|
||||
if item['id'] == marker:
|
||||
if item['id'] == marker or item.get('uuid') == marker:
|
||||
start_index = i + 1
|
||||
break
|
||||
if start_index < 0:
|
||||
|
@ -19,6 +19,7 @@ from webob import exc
|
||||
import webob
|
||||
|
||||
from nova import compute
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
@ -200,8 +201,8 @@ def _translate_attachment_summary_view(_context, vol):
|
||||
d['id'] = volume_id
|
||||
|
||||
d['volumeId'] = volume_id
|
||||
if vol.get('instance_id'):
|
||||
d['serverId'] = vol['instance_id']
|
||||
if vol.get('instance'):
|
||||
d['serverId'] = vol['instance']['uuid']
|
||||
if vol.get('mountpoint'):
|
||||
d['device'] = vol['mountpoint']
|
||||
|
||||
@ -245,7 +246,8 @@ class VolumeAttachmentController(object):
|
||||
LOG.debug("volume_id not found")
|
||||
return faults.Fault(exc.HTTPNotFound())
|
||||
|
||||
if str(vol['instance_id']) != server_id:
|
||||
instance = vol['instance']
|
||||
if instance is None or str(instance['uuid']) != server_id:
|
||||
LOG.debug("instance_id != server_id")
|
||||
return faults.Fault(exc.HTTPNotFound())
|
||||
|
||||
@ -307,7 +309,8 @@ class VolumeAttachmentController(object):
|
||||
except exception.NotFound:
|
||||
return faults.Fault(exc.HTTPNotFound())
|
||||
|
||||
if str(vol['instance_id']) != server_id:
|
||||
instance = vol['instance']
|
||||
if instance is None or str(instance['uuid']) != server_id:
|
||||
LOG.debug("instance_id != server_id")
|
||||
return faults.Fault(exc.HTTPNotFound())
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
<attribute name="userId"> <text/> </attribute>
|
||||
<attribute name="tenantId"> <text/> </attribute>
|
||||
<attribute name="id"> <text/> </attribute>
|
||||
<attribute name="uuid"> <text/> </attribute>
|
||||
<attribute name="updated"> <text/> </attribute>
|
||||
<attribute name="created"> <text/> </attribute>
|
||||
<attribute name="hostId"> <text/> </attribute>
|
||||
|
@ -204,7 +204,7 @@ class Controller(object):
|
||||
return kernel_id, ramdisk_id
|
||||
|
||||
@staticmethod
|
||||
def _do_get_kernel_ramdisk_from_image(image_meta):
|
||||
def _do_get_kernel_ramdisk_from_image(image_meta):
|
||||
"""Given an ImageService image_meta, return kernel and ramdisk image
|
||||
ids if present.
|
||||
|
||||
@ -585,6 +585,7 @@ class Controller(object):
|
||||
rotation factor to be deleted.
|
||||
|
||||
"""
|
||||
context = req.environ["nova.context"]
|
||||
entity = input_dict["createBackup"]
|
||||
|
||||
try:
|
||||
@ -607,13 +608,10 @@ class Controller(object):
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
# preserve link to server in image properties
|
||||
server_ref = os.path.join(req.application_url,
|
||||
'servers',
|
||||
str(instance_id))
|
||||
server_ref = os.path.join(req.application_url, 'servers', instance_id)
|
||||
props = {'instance_ref': server_ref}
|
||||
|
||||
metadata = entity.get('metadata', {})
|
||||
context = req.environ["nova.context"]
|
||||
common.check_img_metadata_quota_limit(context, metadata)
|
||||
try:
|
||||
props.update(metadata)
|
||||
@ -678,44 +676,6 @@ class Controller(object):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@exception.novaclient_converter
|
||||
@scheduler_api.redirect_handler
|
||||
def get_lock(self, req, id):
|
||||
"""
|
||||
return the boolean state of (instance with id)'s lock
|
||||
|
||||
"""
|
||||
context = req.environ['nova.context']
|
||||
try:
|
||||
self.compute_api.get_lock(context, id)
|
||||
except Exception:
|
||||
readable = traceback.format_exc()
|
||||
LOG.exception(_("Compute.api::get_lock %s"), readable)
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@exception.novaclient_converter
|
||||
@scheduler_api.redirect_handler
|
||||
def get_ajax_console(self, req, id):
|
||||
"""Returns a url to an instance's ajaxterm console."""
|
||||
try:
|
||||
self.compute_api.get_ajax_console(req.environ['nova.context'],
|
||||
int(id))
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@exception.novaclient_converter
|
||||
@scheduler_api.redirect_handler
|
||||
def get_vnc_console(self, req, id):
|
||||
"""Returns a url to an instance's ajaxterm console."""
|
||||
try:
|
||||
self.compute_api.get_vnc_console(req.environ['nova.context'],
|
||||
int(id))
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@exception.novaclient_converter
|
||||
@scheduler_api.redirect_handler
|
||||
def diagnostics(self, req, id):
|
||||
@ -737,7 +697,7 @@ class Controller(object):
|
||||
error=item.error))
|
||||
return dict(actions=actions)
|
||||
|
||||
def resize(self, req, instance_id, flavor_id):
|
||||
def _resize(self, req, instance_id, flavor_id):
|
||||
"""Begin the resize process with given instance/flavor."""
|
||||
context = req.environ["nova.context"]
|
||||
|
||||
@ -870,7 +830,7 @@ class Controller(object):
|
||||
msg = _("Resize requests require 'flavorRef' attribute.")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
return self.resize(req, id, flavor_ref)
|
||||
return self._resize(req, id, flavor_ref)
|
||||
|
||||
def _action_rebuild(self, info, request, instance_id):
|
||||
context = request.environ['nova.context']
|
||||
@ -915,6 +875,7 @@ class Controller(object):
|
||||
@common.check_snapshots_enabled
|
||||
def _action_create_image(self, input_dict, req, instance_id):
|
||||
"""Snapshot a server instance."""
|
||||
context = req.environ['nova.context']
|
||||
entity = input_dict.get("createImage", {})
|
||||
|
||||
try:
|
||||
@ -929,13 +890,10 @@ class Controller(object):
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
# preserve link to server in image properties
|
||||
server_ref = os.path.join(req.application_url,
|
||||
'servers',
|
||||
str(instance_id))
|
||||
server_ref = os.path.join(req.application_url, 'servers', instance_id)
|
||||
props = {'instance_ref': server_ref}
|
||||
|
||||
metadata = entity.get('metadata', {})
|
||||
context = req.environ['nova.context']
|
||||
common.check_img_metadata_quota_limit(context, metadata)
|
||||
try:
|
||||
props.update(metadata)
|
||||
@ -998,7 +956,6 @@ def make_server(elem, detailed=False):
|
||||
elem.set('id')
|
||||
|
||||
if detailed:
|
||||
elem.set('uuid')
|
||||
elem.set('userId', 'user_id')
|
||||
elem.set('tenantId', 'tenant_id')
|
||||
elem.set('updated')
|
||||
|
@ -52,13 +52,12 @@ class ViewBuilder(object):
|
||||
server = self._build_simple(inst)
|
||||
|
||||
self._build_links(server['server'], inst)
|
||||
server['server']['uuid'] = inst['uuid']
|
||||
|
||||
return server
|
||||
|
||||
def _build_simple(self, inst):
|
||||
"""Return a simple model of a server."""
|
||||
return dict(server=dict(id=inst['id'], name=inst['display_name']))
|
||||
return dict(server=dict(id=inst['uuid'], name=inst['display_name']))
|
||||
|
||||
def _build_detail(self, inst):
|
||||
"""Returns a detailed model of a server."""
|
||||
@ -66,7 +65,7 @@ class ViewBuilder(object):
|
||||
task_state = inst.get('task_state')
|
||||
|
||||
inst_dict = {
|
||||
'id': inst['id'],
|
||||
'id': inst['uuid'],
|
||||
'name': inst['display_name'],
|
||||
'user_id': inst.get('user_id', ''),
|
||||
'tenant_id': inst.get('project_id', ''),
|
||||
@ -137,8 +136,8 @@ class ViewBuilder(object):
|
||||
}
|
||||
|
||||
def _build_links(self, response, inst):
|
||||
href = self.generate_href(inst["id"])
|
||||
bookmark = self.generate_bookmark(inst["id"])
|
||||
href = self.generate_href(inst["uuid"])
|
||||
bookmark = self.generate_bookmark(inst["uuid"])
|
||||
|
||||
links = [
|
||||
{
|
||||
|
@ -1481,7 +1481,7 @@ class API(base.Base):
|
||||
self.db.queue_get_for(context, FLAGS.compute_topic, host),
|
||||
{"method": "attach_volume",
|
||||
"args": {"volume_id": volume_id,
|
||||
"instance_id": instance_id,
|
||||
"instance_id": instance['id'],
|
||||
"mountpoint": device}})
|
||||
|
||||
def detach_volume(self, context, volume_id):
|
||||
|
@ -45,7 +45,7 @@ class AdminActionsTest(test.TestCase):
|
||||
def test_admin_api_enabled(self):
|
||||
app = fakes.wsgi_app()
|
||||
for _action in self._actions:
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank('/v1.1/fake/servers/abcd/action')
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps({_action: None})
|
||||
req.content_type = 'application/json'
|
||||
@ -56,7 +56,7 @@ class AdminActionsTest(test.TestCase):
|
||||
FLAGS.allow_admin_api = False
|
||||
app = fakes.wsgi_app()
|
||||
for _action in self._actions:
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank('/v1.1/fake/servers/abcd/action')
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps({_action: None})
|
||||
req.content_type = 'application/json'
|
||||
|
@ -27,18 +27,23 @@ from nova.tests.api.openstack import fakes
|
||||
|
||||
class DiskConfigTest(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DiskConfigTest, self).setUp()
|
||||
self.uuid = '70f6db34-de8d-4fbd-aafb-4065bdfa6114'
|
||||
self.url = '/v1.1/openstack/servers/%s/os-disk-config' % self.uuid
|
||||
|
||||
def test_retrieve_disk_config(self):
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
return {'managed_disk': True}
|
||||
|
||||
self.stubs.Set(compute.api.API, 'routing_get', fake_compute_get)
|
||||
req = webob.Request.blank('/v1.1/openstack/servers/50/os-disk-config')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.headers['Accept'] = 'application/json'
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 200)
|
||||
body = json.loads(res.body)
|
||||
self.assertEqual(body['server']['managed_disk'], True)
|
||||
self.assertEqual(int(body['server']['id']), 50)
|
||||
self.assertEqual(body['server']['id'], self.uuid)
|
||||
|
||||
def test_set_disk_config(self):
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
@ -50,7 +55,7 @@ class DiskConfigTest(test.TestCase):
|
||||
self.stubs.Set(compute.api.API, 'update', fake_compute_update)
|
||||
self.stubs.Set(compute.api.API, 'routing_get', fake_compute_get)
|
||||
|
||||
req = webob.Request.blank('/v1.1/openstack/servers/50/os-disk-config')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.headers['Accept'] = 'application/json'
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
@ -60,14 +65,14 @@ class DiskConfigTest(test.TestCase):
|
||||
self.assertEqual(res.status_int, 200)
|
||||
body = json.loads(res.body)
|
||||
self.assertEqual(body['server']['managed_disk'], False)
|
||||
self.assertEqual(int(body['server']['id']), 50)
|
||||
self.assertEqual(body['server']['id'], self.uuid)
|
||||
|
||||
def test_retrieve_disk_config_bad_server_fails(self):
|
||||
def fake_compute_get(*args, **kwargs):
|
||||
raise exception.NotFound()
|
||||
|
||||
self.stubs.Set(compute.api.API, 'routing_get', fake_compute_get)
|
||||
req = webob.Request.blank('/v1.1/openstack/servers/50/os-disk-config')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.headers['Accept'] = 'application/json'
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 404)
|
||||
@ -84,7 +89,7 @@ class DiskConfigTest(test.TestCase):
|
||||
self.stubs.Set(compute.api.API, 'update', fake_compute_update)
|
||||
self.stubs.Set(compute.api.API, 'routing_get', fake_compute_get)
|
||||
|
||||
req = webob.Request.blank('/v1.1/openstack/servers/50/os-disk-config')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.headers['Accept'] = 'application/json'
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
|
@ -42,7 +42,8 @@ class ServerVirtualInterfaceTest(test.TestCase):
|
||||
super(ServerVirtualInterfaceTest, self).tearDown()
|
||||
|
||||
def test_get_virtual_interfaces_list(self):
|
||||
req = webob.Request.blank('/v1.1/123/servers/1/os-virtual-interfaces')
|
||||
url = '/v1.1/123/servers/abcd/os-virtual-interfaces'
|
||||
req = webob.Request.blank(url)
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 200)
|
||||
res_dict = json.loads(res.body)
|
||||
|
@ -22,12 +22,14 @@ from nova import flags
|
||||
from nova import test
|
||||
from nova.compute import instance_types
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests.api.openstack.test_servers import fake_gen_uuid
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
|
||||
|
||||
def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
|
||||
global _block_device_mapping_seen
|
||||
_block_device_mapping_seen = kwargs.get('block_device_mapping')
|
||||
@ -36,7 +38,7 @@ def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
|
||||
resv_id = None
|
||||
return ([{'id': 1,
|
||||
'display_name': 'test_server',
|
||||
'uuid': fake_gen_uuid(),
|
||||
'uuid': FAKE_UUID,
|
||||
'instance_type': dict(inst_type),
|
||||
'access_ip_v4': '1.2.3.4',
|
||||
'access_ip_v6': 'fead::1234',
|
||||
@ -76,7 +78,7 @@ class BootFromVolumeTest(test.TestCase):
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 200)
|
||||
server = json.loads(res.body)['server']
|
||||
self.assertEqual(1, server['id'])
|
||||
self.assertEqual(FAKE_UUID, server['id'])
|
||||
self.assertEqual(2, int(server['flavor']['id']))
|
||||
self.assertEqual(u'test_server', server['name'])
|
||||
self.assertEqual(3, int(server['image']['id']))
|
||||
|
@ -149,22 +149,34 @@ def stub_out_networking(stubs):
|
||||
stubs.Set(nova.flags, '_get_my_ip', get_my_ip)
|
||||
|
||||
|
||||
def stub_out_compute_api_snapshot(stubs):
|
||||
class stub_out_compute_api_snapshot(object):
|
||||
|
||||
def __init__(self, stubs):
|
||||
self.stubs = stubs
|
||||
self.extra_props_last_call = None
|
||||
stubs.Set(nova.compute.API, 'snapshot', self.snapshot)
|
||||
|
||||
def snapshot(self, context, instance_id, name, extra_properties=None):
|
||||
self.extra_props_last_call = extra_properties
|
||||
props = dict(instance_id=instance_id, instance_ref=instance_id)
|
||||
props.update(extra_properties or {})
|
||||
return dict(id='123', status='ACTIVE', name=name, properties=props)
|
||||
stubs.Set(nova.compute.API, 'snapshot', snapshot)
|
||||
|
||||
|
||||
def stub_out_compute_api_backup(stubs):
|
||||
class stub_out_compute_api_backup(object):
|
||||
|
||||
def __init__(self, stubs):
|
||||
self.stubs = stubs
|
||||
self.extra_props_last_call = None
|
||||
stubs.Set(nova.compute.API, 'backup', self.backup)
|
||||
|
||||
def backup(self, context, instance_id, name, backup_type, rotation,
|
||||
extra_properties=None):
|
||||
self.extra_props_last_call = extra_properties
|
||||
props = dict(instance_id=instance_id, instance_ref=instance_id,
|
||||
backup_type=backup_type, rotation=rotation)
|
||||
props.update(extra_properties or {})
|
||||
return dict(id='123', status='ACTIVE', name=name, properties=props)
|
||||
stubs.Set(nova.compute.API, 'backup', backup)
|
||||
|
||||
|
||||
def stub_out_nw_api_get_instance_nw_info(stubs, func=None):
|
||||
@ -225,7 +237,8 @@ def _make_image_fixtures():
|
||||
image_id += 1
|
||||
|
||||
# Snapshot for User 1
|
||||
server_ref = 'http://localhost/v1.1/servers/42'
|
||||
uuid = 'aa640691-d1a7-4a67-9d3c-d35ee6b3cc74'
|
||||
server_ref = 'http://localhost/v1.1/servers/' + uuid
|
||||
snapshot_properties = {'instance_ref': server_ref, 'user_id': 'fake'}
|
||||
for status in ('queued', 'saving', 'active', 'killed',
|
||||
'deleted', 'pending_delete'):
|
||||
|
@ -172,14 +172,9 @@ class PaginationParamsTest(test.TestCase):
|
||||
|
||||
def test_valid_marker(self):
|
||||
""" Test valid marker param. """
|
||||
req = Request.blank('/?marker=1')
|
||||
self.assertEqual(common.get_pagination_params(req), {'marker': 1})
|
||||
|
||||
def test_invalid_marker(self):
|
||||
""" Test invalid marker param. """
|
||||
req = Request.blank('/?marker=-2')
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPBadRequest, common.get_pagination_params, req)
|
||||
req = Request.blank('/?marker=263abb28-1de6-412f-b00b-f0ee0c4333c2')
|
||||
self.assertEqual(common.get_pagination_params(req),
|
||||
{'marker': '263abb28-1de6-412f-b00b-f0ee0c4333c2'})
|
||||
|
||||
def test_valid_limit(self):
|
||||
""" Test valid limit param. """
|
||||
@ -194,9 +189,10 @@ class PaginationParamsTest(test.TestCase):
|
||||
|
||||
def test_valid_limit_and_marker(self):
|
||||
""" Test valid limit and marker parameters. """
|
||||
req = Request.blank('/?limit=20&marker=40')
|
||||
marker = '263abb28-1de6-412f-b00b-f0ee0c4333c2'
|
||||
req = Request.blank('/?limit=20&marker=%s' % marker)
|
||||
self.assertEqual(common.get_pagination_params(req),
|
||||
{'marker': 40, 'limit': 20})
|
||||
{'marker': marker, 'limit': 20})
|
||||
|
||||
|
||||
class MiscFunctionsTest(test.TestCase):
|
||||
|
@ -297,7 +297,7 @@ class ActionExtensionTest(ExtensionTestCase):
|
||||
|
||||
def test_extended_action(self):
|
||||
body = dict(add_tweedle=dict(name="test"))
|
||||
url = "/123/servers/1/action"
|
||||
url = "/123/servers/abcd/action"
|
||||
response = self._send_server_action_request(url, body)
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual("Tweedle Beetle Added.", response.body)
|
||||
@ -309,7 +309,7 @@ class ActionExtensionTest(ExtensionTestCase):
|
||||
|
||||
def test_invalid_action_body(self):
|
||||
body = dict(blah=dict(name="test")) # Doesn't exist
|
||||
url = "/123/servers/1/action"
|
||||
url = "/123/servers/abcd/action"
|
||||
response = self._send_server_action_request(url, body)
|
||||
self.assertEqual(400, response.status_int)
|
||||
|
||||
|
@ -69,8 +69,9 @@ class ImagesControllerTest(test.TestCase):
|
||||
href = "http://localhost/v1.1/fake/images/124"
|
||||
bookmark = "http://localhost/fake/images/124"
|
||||
alternate = "%s/fake/images/124" % utils.generate_glance_url()
|
||||
server_href = "http://localhost/v1.1/servers/42"
|
||||
server_bookmark = "http://localhost/servers/42"
|
||||
server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
|
||||
server_href = "http://localhost/v1.1/servers/" + server_uuid
|
||||
server_bookmark = "http://localhost/servers/" + server_uuid
|
||||
|
||||
expected_image = {
|
||||
"image": {
|
||||
@ -83,7 +84,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
"minDisk": 0,
|
||||
"minRam": 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -94,7 +95,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
}],
|
||||
},
|
||||
"metadata": {
|
||||
"instance_ref": "http://localhost/v1.1/servers/42",
|
||||
"instance_ref": server_href,
|
||||
"user_id": "fake",
|
||||
},
|
||||
"links": [{
|
||||
@ -113,7 +114,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
self.assertEqual(expected_image, actual_image)
|
||||
self.assertDictMatch(expected_image, actual_image)
|
||||
|
||||
def test_get_image_404(self):
|
||||
fake_req = fakes.HTTPRequest.blank('/v1.1/fake/images/unknown')
|
||||
@ -395,8 +396,9 @@ class ImagesControllerTest(test.TestCase):
|
||||
response = self.controller.detail(request)
|
||||
response_list = response["images"]
|
||||
|
||||
server_href = "http://localhost/v1.1/servers/42"
|
||||
server_bookmark = "http://localhost/servers/42"
|
||||
server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
|
||||
server_href = "http://localhost/v1.1/servers/" + server_uuid
|
||||
server_bookmark = "http://localhost/servers/" + server_uuid
|
||||
alternate = "%s/fake/images/%s"
|
||||
|
||||
expected = [{
|
||||
@ -427,7 +429,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'id': '124',
|
||||
'name': 'queued snapshot',
|
||||
'metadata': {
|
||||
u'instance_ref': u'http://localhost/v1.1/servers/42',
|
||||
u'instance_ref': server_href,
|
||||
u'user_id': u'fake',
|
||||
},
|
||||
'updated': NOW_API_FORMAT,
|
||||
@ -437,7 +439,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'minDisk': 0,
|
||||
'minRam': 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -465,7 +467,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'id': '125',
|
||||
'name': 'saving snapshot',
|
||||
'metadata': {
|
||||
u'instance_ref': u'http://localhost/v1.1/servers/42',
|
||||
u'instance_ref': server_href,
|
||||
u'user_id': u'fake',
|
||||
},
|
||||
'updated': NOW_API_FORMAT,
|
||||
@ -475,7 +477,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'minDisk': 0,
|
||||
'minRam': 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -503,7 +505,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'id': '126',
|
||||
'name': 'active snapshot',
|
||||
'metadata': {
|
||||
u'instance_ref': u'http://localhost/v1.1/servers/42',
|
||||
u'instance_ref': server_href,
|
||||
u'user_id': u'fake',
|
||||
},
|
||||
'updated': NOW_API_FORMAT,
|
||||
@ -513,7 +515,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'minDisk': 0,
|
||||
'minRam': 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -541,7 +543,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'id': '127',
|
||||
'name': 'killed snapshot',
|
||||
'metadata': {
|
||||
u'instance_ref': u'http://localhost/v1.1/servers/42',
|
||||
u'instance_ref': server_href,
|
||||
u'user_id': u'fake',
|
||||
},
|
||||
'updated': NOW_API_FORMAT,
|
||||
@ -551,7 +553,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'minDisk': 0,
|
||||
'minRam': 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -579,7 +581,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'id': '128',
|
||||
'name': 'deleted snapshot',
|
||||
'metadata': {
|
||||
u'instance_ref': u'http://localhost/v1.1/servers/42',
|
||||
u'instance_ref': server_href,
|
||||
u'user_id': u'fake',
|
||||
},
|
||||
'updated': NOW_API_FORMAT,
|
||||
@ -589,7 +591,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'minDisk': 0,
|
||||
'minRam': 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -617,7 +619,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'id': '129',
|
||||
'name': 'pending_delete snapshot',
|
||||
'metadata': {
|
||||
u'instance_ref': u'http://localhost/v1.1/servers/42',
|
||||
u'instance_ref': server_href,
|
||||
u'user_id': u'fake',
|
||||
},
|
||||
'updated': NOW_API_FORMAT,
|
||||
@ -627,7 +629,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'minDisk': 0,
|
||||
'minRam': 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -685,8 +687,9 @@ class ImagesControllerTest(test.TestCase):
|
||||
response_list = response["images"]
|
||||
response_links = response["images_links"]
|
||||
|
||||
server_href = "http://localhost/v1.1/servers/42"
|
||||
server_bookmark = "http://localhost/servers/42"
|
||||
server_uuid = "aa640691-d1a7-4a67-9d3c-d35ee6b3cc74"
|
||||
server_href = "http://localhost/v1.1/servers/" + server_uuid
|
||||
server_bookmark = "http://localhost/servers/" + server_uuid
|
||||
alternate = "%s/fake/images/%s"
|
||||
|
||||
expected = [{
|
||||
@ -717,7 +720,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'id': '124',
|
||||
'name': 'queued snapshot',
|
||||
'metadata': {
|
||||
u'instance_ref': u'http://localhost/v1.1/servers/42',
|
||||
u'instance_ref': server_href,
|
||||
u'user_id': u'fake',
|
||||
},
|
||||
'updated': NOW_API_FORMAT,
|
||||
@ -727,7 +730,7 @@ class ImagesControllerTest(test.TestCase):
|
||||
'progress': 25,
|
||||
'minRam': 0,
|
||||
'server': {
|
||||
'id': '42',
|
||||
'id': server_uuid,
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": server_href,
|
||||
@ -817,10 +820,10 @@ class ImagesControllerTest(test.TestCase):
|
||||
|
||||
def test_image_filter_server(self):
|
||||
image_service = self.mox.CreateMockAnything()
|
||||
# 'server' should be converted to 'property-instance_ref'
|
||||
filters = {'property-instance_ref': 'http://localhost:8774/servers/12'}
|
||||
request = fakes.HTTPRequest.blank('/v1.1/images?server='
|
||||
'http://localhost:8774/servers/12')
|
||||
uuid = 'fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf'
|
||||
ref = 'http://localhost:8774/servers/' + uuid
|
||||
filters = {'property-instance_ref': ref}
|
||||
request = fakes.HTTPRequest.blank('/v1.1/images?server=' + ref)
|
||||
context = request.environ['nova.context']
|
||||
image_service.index(context, filters=filters).AndReturn([])
|
||||
self.mox.ReplayAll()
|
||||
@ -912,10 +915,11 @@ class ImagesControllerTest(test.TestCase):
|
||||
|
||||
def test_image_detail_filter_server(self):
|
||||
image_service = self.mox.CreateMockAnything()
|
||||
# 'server' should be converted to 'property-instance_ref'
|
||||
filters = {'property-instance_ref': 'http://localhost:8774/servers/12'}
|
||||
request = fakes.HTTPRequest.blank('/v1.1/fake/images/detail?server='
|
||||
'http://localhost:8774/servers/12')
|
||||
uuid = 'fa95aaf5-ab3b-4cd8-88c0-2be7dd051aaf'
|
||||
ref = 'http://localhost:8774/servers/' + uuid
|
||||
url = '/v1.1/fake/images/detail?server=' + ref
|
||||
filters = {'property-instance_ref': ref}
|
||||
request = fakes.HTTPRequest.blank(url)
|
||||
context = request.environ['nova.context']
|
||||
image_service.index(context, filters=filters).AndReturn([])
|
||||
self.mox.ReplayAll()
|
||||
@ -991,8 +995,9 @@ class ImagesControllerTest(test.TestCase):
|
||||
class ImageXMLSerializationTest(test.TestCase):
|
||||
|
||||
TIMESTAMP = "2010-10-11T10:30:22Z"
|
||||
SERVER_HREF = 'http://localhost/v1.1/servers/123'
|
||||
SERVER_BOOKMARK = 'http://localhost/servers/123'
|
||||
SERVER_UUID = 'aa640691-d1a7-4a67-9d3c-d35ee6b3cc74'
|
||||
SERVER_HREF = 'http://localhost/v1.1/servers/' + SERVER_UUID
|
||||
SERVER_BOOKMARK = 'http://localhost/servers/' + SERVER_UUID
|
||||
IMAGE_HREF = 'http://localhost/v1.1/fake/images/%s'
|
||||
IMAGE_NEXT = 'http://localhost/v1.1/fake/images?limit=%s&marker=%s'
|
||||
IMAGE_BOOKMARK = 'http://localhost/fake/images/%s'
|
||||
@ -1009,7 +1014,7 @@ class ImageXMLSerializationTest(test.TestCase):
|
||||
'status': 'ACTIVE',
|
||||
'progress': 80,
|
||||
'server': {
|
||||
'id': '1',
|
||||
'id': self.SERVER_UUID,
|
||||
'links': [
|
||||
{
|
||||
'href': self.SERVER_HREF,
|
||||
@ -1055,7 +1060,7 @@ class ImageXMLSerializationTest(test.TestCase):
|
||||
'minRam': 10,
|
||||
'minDisk': 100,
|
||||
'server': {
|
||||
'id': '1',
|
||||
'id': self.SERVER_UUID,
|
||||
'links': [
|
||||
{
|
||||
'href': self.SERVER_HREF,
|
||||
@ -1124,7 +1129,7 @@ class ImageXMLSerializationTest(test.TestCase):
|
||||
'updated': self.TIMESTAMP,
|
||||
'status': 'ACTIVE',
|
||||
'server': {
|
||||
'id': '1',
|
||||
'id': self.SERVER_UUID,
|
||||
'links': [
|
||||
{
|
||||
'href': self.SERVER_HREF,
|
||||
@ -1186,7 +1191,7 @@ class ImageXMLSerializationTest(test.TestCase):
|
||||
'updated': self.TIMESTAMP,
|
||||
'status': 'ACTIVE',
|
||||
'server': {
|
||||
'id': '1',
|
||||
'id': self.SERVER_UUID,
|
||||
'links': [
|
||||
{
|
||||
'href': self.SERVER_HREF,
|
||||
@ -1300,7 +1305,7 @@ class ImageXMLSerializationTest(test.TestCase):
|
||||
'progress': 80,
|
||||
'minRam': 256,
|
||||
'server': {
|
||||
'id': '1',
|
||||
'id': self.SERVER_UUID,
|
||||
'links': [
|
||||
{
|
||||
'href': self.SERVER_HREF,
|
||||
@ -1372,7 +1377,7 @@ class ImageXMLSerializationTest(test.TestCase):
|
||||
'progress': 80,
|
||||
'minDisk': 5,
|
||||
'server': {
|
||||
'id': '1',
|
||||
'id': self.SERVER_UUID,
|
||||
'links': [
|
||||
{
|
||||
'href': self.SERVER_HREF,
|
||||
@ -1574,7 +1579,7 @@ class ImageXMLSerializationTest(test.TestCase):
|
||||
'updated': self.TIMESTAMP,
|
||||
'status': 'ACTIVE',
|
||||
'server': {
|
||||
'id': '1',
|
||||
'id': self.SERVER_UUID,
|
||||
'links': [
|
||||
{
|
||||
'href': self.SERVER_HREF,
|
||||
|
@ -19,12 +19,17 @@ from nova.tests.api.openstack import fakes
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
FAKE_UUID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
|
||||
|
||||
|
||||
def return_server_by_id(context, id):
|
||||
return stub_instance(id)
|
||||
|
||||
|
||||
def return_server_by_uuid(context, uuid):
|
||||
return stub_instance(1, uuid=uuid)
|
||||
|
||||
|
||||
def instance_update(context, instance_id, kwargs):
|
||||
return stub_instance(instance_id)
|
||||
|
||||
@ -47,12 +52,15 @@ def return_server_with_uuid_and_state(vm_state, task_state=None):
|
||||
|
||||
|
||||
def stub_instance(id, metadata=None, image_ref="10", flavor_id="1",
|
||||
name=None, vm_state=None, task_state=None):
|
||||
name=None, vm_state=None, task_state=None, uuid=None):
|
||||
if metadata is not None:
|
||||
metadata_items = [{'key':k, 'value':v} for k, v in metadata.items()]
|
||||
else:
|
||||
metadata_items = [{'key':'seq', 'value':id}]
|
||||
|
||||
if uuid is None:
|
||||
uuid = FAKE_UUID
|
||||
|
||||
inst_type = instance_types.get_instance_type_by_flavor_id(int(flavor_id))
|
||||
|
||||
instance = {
|
||||
@ -89,7 +97,7 @@ def stub_instance(id, metadata=None, image_ref="10", flavor_id="1",
|
||||
"metadata": metadata_items,
|
||||
"access_ip_v4": "",
|
||||
"access_ip_v6": "",
|
||||
"uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
|
||||
"uuid": uuid,
|
||||
"virtual_interfaces": [],
|
||||
"progress": 0,
|
||||
}
|
||||
@ -121,11 +129,13 @@ class ServerActionsTest(test.TestCase):
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
fakes.stub_out_auth(self.stubs)
|
||||
self.stubs.Set(nova.db.api, 'instance_get', return_server_by_id)
|
||||
self.stubs.Set(nova.db, 'instance_get_by_uuid', return_server_by_uuid)
|
||||
self.stubs.Set(nova.db.api, 'instance_update', instance_update)
|
||||
|
||||
fakes.stub_out_glance(self.stubs)
|
||||
fakes.stub_out_nw_api(self.stubs)
|
||||
fakes.stub_out_compute_api_snapshot(self.stubs)
|
||||
self.snapshot = fakes.stub_out_compute_api_snapshot(self.stubs)
|
||||
self.backup = fakes.stub_out_compute_api_backup(self.stubs)
|
||||
service_class = 'nova.image.glance.GlanceImageService'
|
||||
self.service = utils.import_object(service_class)
|
||||
self.context = context.RequestContext(1, None)
|
||||
@ -133,6 +143,8 @@ class ServerActionsTest(test.TestCase):
|
||||
self.sent_to_glance = {}
|
||||
fakes.stub_out_glance_add_image(self.stubs, self.sent_to_glance)
|
||||
self.flags(allow_instance_snapshots=True)
|
||||
self.uuid = FAKE_UUID
|
||||
self.url = '/v1.1/fake/servers/%s/action' % self.uuid
|
||||
|
||||
def tearDown(self):
|
||||
self.stubs.UnsetAll()
|
||||
@ -140,7 +152,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_bad_body(self):
|
||||
body = {}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -149,7 +161,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_unknown_action(self):
|
||||
body = {'sockTheFox': {'fakekey': '1234'}}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -160,19 +172,19 @@ class ServerActionsTest(test.TestCase):
|
||||
mock_method = MockSetAdminPassword()
|
||||
self.stubs.Set(nova.compute.api.API, 'set_admin_password', mock_method)
|
||||
body = {'changePassword': {'adminPass': '1234pass'}}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 202)
|
||||
self.assertEqual(mock_method.instance_id, '1')
|
||||
self.assertEqual(mock_method.instance_id, self.uuid)
|
||||
self.assertEqual(mock_method.password, '1234pass')
|
||||
|
||||
def test_server_change_password_xml(self):
|
||||
mock_method = MockSetAdminPassword()
|
||||
self.stubs.Set(nova.compute.api.API, 'set_admin_password', mock_method)
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = "application/xml"
|
||||
req.body = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -181,12 +193,12 @@ class ServerActionsTest(test.TestCase):
|
||||
adminPass="1234pass"/>"""
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 202)
|
||||
self.assertEqual(mock_method.instance_id, '1')
|
||||
self.assertEqual(mock_method.instance_id, self.uuid)
|
||||
self.assertEqual(mock_method.password, '1234pass')
|
||||
|
||||
def test_server_change_password_not_a_string(self):
|
||||
body = {'changePassword': {'adminPass': 1234}}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -195,7 +207,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_change_password_bad_request(self):
|
||||
body = {'changePassword': {'pass': '12345'}}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -204,7 +216,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_change_password_empty_string(self):
|
||||
body = {'changePassword': {'adminPass': ''}}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -213,7 +225,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_change_password_none(self):
|
||||
body = {'changePassword': {'adminPass': None}}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -222,7 +234,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_reboot_hard(self):
|
||||
body = dict(reboot=dict(type="HARD"))
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -231,7 +243,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_reboot_soft(self):
|
||||
body = dict(reboot=dict(type="SOFT"))
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -240,7 +252,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_reboot_incorrect_type(self):
|
||||
body = dict(reboot=dict(type="NOT_A_TYPE"))
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -249,7 +261,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_server_reboot_missing_type(self):
|
||||
body = dict(reboot=dict())
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -266,7 +278,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -285,13 +297,12 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
state = vm_states.BUILDING
|
||||
new_return_server = return_server_with_state(state)
|
||||
self.stubs.Set(nova.db.api, 'instance_get', new_return_server)
|
||||
self.stubs.Set(nova.db, 'instance_get_by_uuid',
|
||||
return_server_with_uuid_and_state(state))
|
||||
def fake_rebuild(*args, **kwargs):
|
||||
raise exception.RebuildRequiresActiveInstance
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
self.stubs.Set(nova.compute.api.API, 'rebuild', fake_rebuild)
|
||||
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -312,7 +323,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -330,7 +341,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -345,7 +356,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -364,7 +375,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -383,7 +394,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -404,7 +415,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -426,7 +437,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = 'application/json'
|
||||
req.body = json.dumps(body)
|
||||
@ -436,7 +447,7 @@ class ServerActionsTest(test.TestCase):
|
||||
|
||||
def test_resize_server(self):
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.content_type = 'application/json'
|
||||
req.method = 'POST'
|
||||
body_dict = dict(resize=dict(flavorRef="http://localhost/3"))
|
||||
@ -454,7 +465,7 @@ class ServerActionsTest(test.TestCase):
|
||||
self.assertEqual(self.resize_called, True)
|
||||
|
||||
def test_resize_server_no_flavor(self):
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.content_type = 'application/json'
|
||||
req.method = 'POST'
|
||||
body_dict = dict(resize=dict())
|
||||
@ -464,7 +475,7 @@ class ServerActionsTest(test.TestCase):
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_resize_server_no_flavor_ref(self):
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.content_type = 'application/json'
|
||||
req.method = 'POST'
|
||||
body_dict = dict(resize=dict(flavorRef=None))
|
||||
@ -474,7 +485,7 @@ class ServerActionsTest(test.TestCase):
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_confirm_resize_server(self):
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.content_type = 'application/json'
|
||||
req.method = 'POST'
|
||||
body_dict = dict(confirmResize=None)
|
||||
@ -492,7 +503,7 @@ class ServerActionsTest(test.TestCase):
|
||||
self.assertEqual(self.confirm_resize_called, True)
|
||||
|
||||
def test_confirm_resize_migration_not_found(self):
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.content_type = 'application/json'
|
||||
req.method = 'POST'
|
||||
body_dict = dict(confirmResize=None)
|
||||
@ -510,7 +521,7 @@ class ServerActionsTest(test.TestCase):
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_revert_resize_migration_not_found(self):
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.content_type = 'application/json'
|
||||
req.method = 'POST'
|
||||
body_dict = dict(revertResize=None)
|
||||
@ -528,7 +539,7 @@ class ServerActionsTest(test.TestCase):
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_revert_resize_server(self):
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.content_type = 'application/json'
|
||||
req.method = 'POST'
|
||||
body_dict = dict(revertResize=None)
|
||||
@ -551,7 +562,7 @@ class ServerActionsTest(test.TestCase):
|
||||
'name': 'Snapshot 1',
|
||||
},
|
||||
}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -559,6 +570,9 @@ class ServerActionsTest(test.TestCase):
|
||||
self.assertEqual(202, response.status_int)
|
||||
location = response.headers['Location']
|
||||
self.assertEqual('http://localhost/v1.1/fake/images/123', location)
|
||||
server_location = self.snapshot.extra_props_last_call['instance_ref']
|
||||
expected_server_location = 'http://localhost/v1.1/servers/' + self.uuid
|
||||
self.assertEqual(expected_server_location, server_location)
|
||||
|
||||
def test_create_image_snapshots_disabled(self):
|
||||
"""Don't permit a snapshot if the allow_instance_snapshots flag is
|
||||
@ -570,7 +584,7 @@ class ServerActionsTest(test.TestCase):
|
||||
'name': 'Snapshot 1',
|
||||
},
|
||||
}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -584,7 +598,7 @@ class ServerActionsTest(test.TestCase):
|
||||
'metadata': {'key': 'asdf'},
|
||||
},
|
||||
}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -602,7 +616,7 @@ class ServerActionsTest(test.TestCase):
|
||||
}
|
||||
for num in range(FLAGS.quota_metadata_items + 1):
|
||||
body['createImage']['metadata']['foo%i' % num] = "bar"
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -613,7 +627,7 @@ class ServerActionsTest(test.TestCase):
|
||||
body = {
|
||||
'createImage': {},
|
||||
}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -627,7 +641,7 @@ class ServerActionsTest(test.TestCase):
|
||||
'metadata': 'henry',
|
||||
},
|
||||
}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -640,7 +654,7 @@ class ServerActionsTest(test.TestCase):
|
||||
raise exception.InstanceSnapshotting
|
||||
self.stubs.Set(nova.compute.API, 'snapshot', snapshot)
|
||||
|
||||
req = webob.Request.blank('/v1.1/fakes/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps({
|
||||
"createImage": {
|
||||
@ -663,13 +677,16 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
response = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(202, response.status_int)
|
||||
self.assertTrue(response.headers['Location'])
|
||||
server_location = self.backup.extra_props_last_call['instance_ref']
|
||||
expected_server_location = 'http://localhost/v1.1/servers/' + self.uuid
|
||||
self.assertEqual(expected_server_location, server_location)
|
||||
|
||||
def test_create_backup_admin_api_off(self):
|
||||
"""The happy path for creating backups"""
|
||||
@ -683,7 +700,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -702,7 +719,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -723,7 +740,7 @@ class ServerActionsTest(test.TestCase):
|
||||
}
|
||||
for num in range(FLAGS.quota_metadata_items + 1):
|
||||
body['createBackup']['metadata']['foo%i' % num] = "bar"
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -741,7 +758,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -759,7 +776,7 @@ class ServerActionsTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -777,7 +794,7 @@ class ServerActionsTest(test.TestCase):
|
||||
'rotation': 1,
|
||||
},
|
||||
}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
@ -789,7 +806,7 @@ class ServerActionsTest(test.TestCase):
|
||||
self.flags(allow_admin_api=True)
|
||||
|
||||
body = {'createBackup': 'go'}
|
||||
req = webob.Request.blank('/v1.1/fake/servers/1/action')
|
||||
req = webob.Request.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
@ -23,6 +23,7 @@ import nova.db.api
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import test
|
||||
from nova import utils
|
||||
from nova.tests.api.openstack import fakes
|
||||
|
||||
|
||||
@ -79,15 +80,18 @@ class ServerMetaDataTest(test.TestCase):
|
||||
super(ServerMetaDataTest, self).setUp()
|
||||
fakes.stub_out_key_pair_funcs(self.stubs)
|
||||
self.stubs.Set(nova.db.api, 'instance_get', return_server)
|
||||
self.stubs.Set(nova.db, 'instance_get_by_uuid', return_server)
|
||||
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_server_metadata)
|
||||
|
||||
self.controller = server_metadata.Controller()
|
||||
self.uuid = utils.gen_uuid()
|
||||
self.url = '/v1.1/fake/servers/%s/metadata' % self.uuid
|
||||
|
||||
def test_index(self):
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
res_dict = self.controller.index(req, '1')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
res_dict = self.controller.index(req, self.uuid)
|
||||
|
||||
expected = {
|
||||
'metadata': {
|
||||
@ -101,75 +105,75 @@ class ServerMetaDataTest(test.TestCase):
|
||||
def test_index_nonexistant_server(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_server_nonexistant)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/100/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.index, req, '100')
|
||||
self.controller.index, req, self.url)
|
||||
|
||||
def test_index_no_data(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_empty_server_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
res_dict = self.controller.index(req, '1')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
res_dict = self.controller.index(req, self.uuid)
|
||||
expected = {'metadata': {}}
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
||||
def test_show(self):
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key2')
|
||||
res_dict = self.controller.show(req, '1', 'key2')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key2')
|
||||
res_dict = self.controller.show(req, self.uuid, 'key2')
|
||||
expected = {'meta': {'key2': 'value2'}}
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
||||
def test_show_nonexistant_server(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_server_nonexistant)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/100/metadata/key2')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key2')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.show, req, '100', 'key2')
|
||||
self.controller.show, req, self.uuid, 'key2')
|
||||
|
||||
def test_show_meta_not_found(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_empty_server_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key6')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.show, req, '1', 'key6')
|
||||
self.controller.show, req, self.uuid, 'key6')
|
||||
|
||||
def test_delete(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_server_metadata)
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_delete',
|
||||
delete_server_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key2')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key2')
|
||||
req.method = 'DELETE'
|
||||
res = self.controller.delete(req, '1', 'key2')
|
||||
res = self.controller.delete(req, self.uuid, 'key2')
|
||||
|
||||
self.assertEqual(None, res)
|
||||
|
||||
def test_delete_nonexistant_server(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_get', return_server_nonexistant)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key1')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.delete, req, '1', 'key1')
|
||||
self.controller.delete, req, self.uuid, 'key1')
|
||||
|
||||
def test_delete_meta_not_found(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_empty_server_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key6')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key6')
|
||||
req.method = 'DELETE'
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.delete, req, '1', 'key6')
|
||||
self.controller.delete, req, self.uuid, 'key6')
|
||||
|
||||
def test_create(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_get',
|
||||
return_server_metadata)
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.content_type = "application/json"
|
||||
body = {"metadata": {"key9": "value9"}}
|
||||
req.body = json.dumps(body)
|
||||
res_dict = self.controller.create(req, '1', body)
|
||||
res_dict = self.controller.create(req, self.uuid, body)
|
||||
|
||||
body['metadata'].update({
|
||||
"key1": "value1",
|
||||
@ -181,28 +185,28 @@ class ServerMetaDataTest(test.TestCase):
|
||||
def test_create_empty_body(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.create, req, '1', None)
|
||||
self.controller.create, req, self.uuid, None)
|
||||
|
||||
def test_create_nonexistant_server(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_get', return_server_nonexistant)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/100/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'POST'
|
||||
body = {"metadata": {"key1": "value1"}}
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.create, req, '100', body)
|
||||
self.controller.create, req, self.uuid, body)
|
||||
|
||||
def test_update_all(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
expected = {
|
||||
@ -212,49 +216,49 @@ class ServerMetaDataTest(test.TestCase):
|
||||
},
|
||||
}
|
||||
req.body = json.dumps(expected)
|
||||
res_dict = self.controller.update_all(req, '1', expected)
|
||||
res_dict = self.controller.update_all(req, self.uuid, expected)
|
||||
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
||||
def test_update_all_empty_container(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
expected = {'metadata': {}}
|
||||
req.body = json.dumps(expected)
|
||||
res_dict = self.controller.update_all(req, '1', expected)
|
||||
res_dict = self.controller.update_all(req, self.uuid, expected)
|
||||
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
||||
def test_update_all_malformed_container(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
expected = {'meta': {}}
|
||||
req.body = json.dumps(expected)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update_all, req, '1', expected)
|
||||
self.controller.update_all, req, self.uuid, expected)
|
||||
|
||||
def test_update_all_malformed_data(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
expected = {'metadata': ['asdf']}
|
||||
req.body = json.dumps(expected)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update_all, req, '1', expected)
|
||||
self.controller.update_all, req, self.uuid, expected)
|
||||
|
||||
def test_update_all_nonexistant_server(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_get', return_server_nonexistant)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/100/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.content_type = "application/json"
|
||||
body = {'metadata': {'key10': 'value10'}}
|
||||
@ -266,12 +270,12 @@ class ServerMetaDataTest(test.TestCase):
|
||||
def test_update_item(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key1')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": "value1"}}
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
res_dict = self.controller.update(req, '1', 'key1', body)
|
||||
res_dict = self.controller.update(req, self.uuid, 'key1', body)
|
||||
expected = {'meta': {'key1': 'value1'}}
|
||||
self.assertEqual(expected, res_dict)
|
||||
|
||||
@ -284,41 +288,41 @@ class ServerMetaDataTest(test.TestCase):
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPNotFound,
|
||||
self.controller.update, req, '1', 'key1', body)
|
||||
self.controller.update, req, self.uuid, 'key1', body)
|
||||
|
||||
def test_update_item_empty_body(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key1')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update, req, '1', 'key1', None)
|
||||
self.controller.update, req, self.uuid, 'key1', None)
|
||||
|
||||
def test_update_item_too_many_keys(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/key1')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": "value1", "key2": "value2"}}
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update, req, '1', 'key1', body)
|
||||
self.controller.update, req, self.uuid, 'key1', body)
|
||||
|
||||
def test_update_item_body_uri_mismatch(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
return_create_instance_metadata)
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata/bad')
|
||||
req = fakes.HTTPRequest.blank(self.url + '/bad')
|
||||
req.method = 'PUT'
|
||||
body = {"meta": {"key1": "value1"}}
|
||||
req.body = json.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.update, req, '1', 'bad', body)
|
||||
self.controller.update, req, self.uuid, 'bad', body)
|
||||
|
||||
def test_too_many_metadata_items_on_create(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
@ -326,13 +330,13 @@ class ServerMetaDataTest(test.TestCase):
|
||||
data = {"metadata": {}}
|
||||
for num in range(FLAGS.quota_metadata_items + 1):
|
||||
data['metadata']['key%i' % num] = "blah"
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'POST'
|
||||
req.body = json.dumps(data)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
|
||||
self.controller.create, req, '1', data)
|
||||
self.controller.create, req, self.uuid, data)
|
||||
|
||||
def test_too_many_metadata_items_on_update_item(self):
|
||||
self.stubs.Set(nova.db.api, 'instance_metadata_update',
|
||||
@ -340,10 +344,10 @@ class ServerMetaDataTest(test.TestCase):
|
||||
data = {"metadata": {}}
|
||||
for num in range(FLAGS.quota_metadata_items + 1):
|
||||
data['metadata']['key%i' % num] = "blah"
|
||||
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/1/metadata')
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
req.method = 'PUT'
|
||||
req.body = json.dumps(data)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
|
||||
self.controller.update_all, req, '1', data)
|
||||
self.controller.update_all, req, self.uuid, data)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,25 +15,29 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import feedparser
|
||||
import json
|
||||
|
||||
import feedparser
|
||||
from lxml import etree
|
||||
import stubout
|
||||
import webob
|
||||
from lxml import etree
|
||||
|
||||
from nova import context
|
||||
from nova import test
|
||||
from nova.api.openstack import versions
|
||||
from nova.api.openstack import views
|
||||
from nova.api.openstack import wsgi
|
||||
from nova.api.openstack import xmlutil
|
||||
from nova import context
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import common
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova import utils
|
||||
|
||||
|
||||
NS = {
|
||||
'atom': 'http://www.w3.org/2005/Atom',
|
||||
'ns': 'http://docs.openstack.org/compute/api/v1.1'
|
||||
}
|
||||
|
||||
VERSIONS = {
|
||||
"v1.1": {
|
||||
"id": "v1.1",
|
||||
@ -382,14 +386,15 @@ class VersionsTest(test.TestCase):
|
||||
Make sure multi choice responses do not have content-type
|
||||
application/atom+xml (should use default of json)
|
||||
"""
|
||||
req = webob.Request.blank('/servers/2')
|
||||
req = webob.Request.blank('/servers')
|
||||
req.accept = "application/atom+xml"
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 300)
|
||||
self.assertEqual(res.content_type, "application/json")
|
||||
|
||||
def test_multi_choice_server(self):
|
||||
req = webob.Request.blank('/servers/2')
|
||||
uuid = str(utils.gen_uuid())
|
||||
req = webob.Request.blank('/servers/' + uuid)
|
||||
req.accept = "application/json"
|
||||
res = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(res.status_int, 300)
|
||||
@ -402,7 +407,7 @@ class VersionsTest(test.TestCase):
|
||||
"status": "CURRENT",
|
||||
"links": [
|
||||
{
|
||||
"href": "http://localhost/v1.1/servers/2",
|
||||
"href": "http://localhost/v1.1/servers/" + uuid,
|
||||
"rel": "self",
|
||||
},
|
||||
],
|
||||
|
@ -285,7 +285,6 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
|
||||
undisco_move = last_days_of_disco_moves[0]
|
||||
self.assertEquals(undisco_move['id'], volume_id)
|
||||
self.assertEquals(undisco_move['mountpoint'], device)
|
||||
self.assertEquals(undisco_move['instance_id'], server_id)
|
||||
|
||||
def test_create_volume_with_metadata(self):
|
||||
"""Creates and deletes a volume."""
|
||||
|
Loading…
Reference in New Issue
Block a user