Merge "Fix admin extension gives 500 when listing instances"

This commit is contained in:
Jenkins 2013-08-23 00:08:43 +00:00 committed by Gerrit Code Review
commit 1467437f83
5 changed files with 46 additions and 19 deletions

View File

@ -32,7 +32,8 @@ class Server(object):
self.id = server['id']
self.status = server['status']
self.name = server['name']
self.host = server['host']
self.host = server['hostId']
self.host = server.get('hostId') or server['host']
@staticmethod
def list_from_account_server_list(servers):

View File

@ -49,7 +49,10 @@ def load_mgmt_instance(cls, context, id):
try:
instance = load_instance(cls, context, id, needs_server=True)
client = remote.create_nova_client(context)
server = client.rdservers.get(instance.server_id)
try:
server = client.rdservers.get(instance.server_id)
except AttributeError:
server = client.servers.get(instance.server_id)
instance.server.host = server.host
instance.server.deleted = server.deleted
instance.server.deleted_at = server.deleted_at

View File

@ -31,15 +31,21 @@ class MgmtInstanceView(InstanceDetailView):
else:
server = self.instance.server
result['instance']['server'] = {
'deleted': server.deleted,
'deleted_at': server.deleted_at,
'host': server.host,
'id': server.id,
'local_id': server.local_id,
'name': server.name,
'status': server.status,
'tenant_id': server.tenant_id,
}
if hasattr(server, 'hostId'):
result['instance']['server']['host'] = server.hostId
else:
result['instance']['server']['host'] = server.host
if hasattr(server, 'deleted'):
result['instance']['server']['deleted'] = server.deleted
if hasattr(server, 'deleted_at'):
result['instance']['server']['deleted_at'] = server.deleted_at
if hasattr(server, 'local_id'):
result['instance']['server']['local_id'] = server.local_id
try:
service_status = self.instance.service_status.status.api_status

View File

@ -20,6 +20,7 @@ from proboscis.asserts import assert_equal
from proboscis.asserts import assert_raises
from proboscis.asserts import assert_true
from proboscis.check import Check
from proboscis import SkipTest
from trove import tests
from trove.tests.config import CONFIG
@ -101,16 +102,24 @@ def mgmt_instance_get():
instance.has_field('volume', None)
#TODO(tim-simpson): Validate additional fields, assert
# no extra fields exist.
with CollectionCheck("server", api_instance.server) as server:
server.has_element("addresses", dict)
server.has_element("deleted", bool)
server.has_element("deleted_at", (basestring, None))
server.has_element("host", basestring)
server.has_element("id", basestring)
server.has_element("local_id", int)
server.has_element("name", basestring)
server.has_element("status", basestring)
server.has_element("tenant_id", basestring)
if api_instance.server is not None:
print "the real content of server: %s" % dir(api_instance.server)
print "the type of server: %s" % type(api_instance.server)
print "the real content of api_instance: %s" % dir(api_instance)
print "the type of api_instance: %s" % type(api_instance)
print hasattr(api_instance, "server")
with CollectionCheck("server", api_instance.server) as server:
server.has_element("addresses", dict)
server.has_element("deleted", bool)
server.has_element("deleted_at", (basestring, None))
server.has_element("host", basestring)
server.has_element("id", basestring)
server.has_element("local_id", int)
server.has_element("name", basestring)
server.has_element("status", basestring)
server.has_element("tenant_id", basestring)
if (CONFIG.trove_volume_support and
CONFIG.trove_main_instance_has_volume):
with CollectionCheck("volume", api_instance.volume) as volume:
@ -215,6 +224,11 @@ class MgmtInstancesIndex(object):
expected_fields.append('volume')
index = self.client.management.index()
if not hasattr(index, "deleted"):
raise SkipTest("instance index must have a "
"deleted label for this test")
for instance in index:
with Check() as check:
for field in expected_fields:
@ -227,6 +241,9 @@ class MgmtInstancesIndex(object):
Make sure that the deleted= filter works as expected, and no instances
are excluded.
"""
if not hasattr(self.client.management.index, 'deleted'):
raise SkipTest("instance index must have a deleted "
"label for this test")
instance_counts = []
for deleted_filter in (True, False):
filtered_index = self.client.management.index(

View File

@ -116,7 +116,7 @@ class FakeServer(object):
for volume in self.volumes:
info_vols.append({'id': volume.id})
volume.set_attachment(id)
self.host = FAKE_HOSTS[0]
self.hostId = FAKE_HOSTS[0]
self.old_host = None
setattr(self, 'OS-EXT-AZ:availability_zone', 'nova')
@ -134,7 +134,7 @@ class FakeServer(object):
def revert_resize(self):
if self.status != "VERIFY_RESIZE":
raise RuntimeError("Not in resize confirm mode.")
self.host = self.old_host
self.hostId = self.old_host
self.old_host = None
self.flavor_ref = self.old_flavor_ref
self.old_flavor_ref = None
@ -520,7 +520,7 @@ class FakeAccount(object):
server_dict['id'] = server.id
server_dict['name'] = server.name
server_dict['status'] = server.status
server_dict['host'] = server.host
server_dict['hostId'] = server.hostId
ret.append(server_dict)
return ret