From 2da27356238391b17ffa4f73303aa35f87ebc6d0 Mon Sep 17 00:00:00 2001 From: Anna Shen Date: Thu, 15 Aug 2013 12:41:40 -0700 Subject: [PATCH] Fix admin extension gives 500 when listing instances Bug# 1210322 Change-Id: Ib2c5e3d43688f0bb002eefc1c1ca4d347aa71f3c --- trove/extensions/account/models.py | 3 +- trove/extensions/mgmt/instances/models.py | 5 ++- trove/extensions/mgmt/instances/views.py | 14 ++++++--- trove/tests/api/mgmt/instances.py | 37 +++++++++++++++++------ trove/tests/fakes/nova.py | 6 ++-- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/trove/extensions/account/models.py b/trove/extensions/account/models.py index 0eb6afca72..29197a9429 100644 --- a/trove/extensions/account/models.py +++ b/trove/extensions/account/models.py @@ -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): diff --git a/trove/extensions/mgmt/instances/models.py b/trove/extensions/mgmt/instances/models.py index 40c62b7b85..e0cf8cb3d0 100644 --- a/trove/extensions/mgmt/instances/models.py +++ b/trove/extensions/mgmt/instances/models.py @@ -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 diff --git a/trove/extensions/mgmt/instances/views.py b/trove/extensions/mgmt/instances/views.py index f5cd4e4ad1..643e877486 100644 --- a/trove/extensions/mgmt/instances/views.py +++ b/trove/extensions/mgmt/instances/views.py @@ -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 diff --git a/trove/tests/api/mgmt/instances.py b/trove/tests/api/mgmt/instances.py index 3330d0d973..cfd20a9b09 100644 --- a/trove/tests/api/mgmt/instances.py +++ b/trove/tests/api/mgmt/instances.py @@ -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( diff --git a/trove/tests/fakes/nova.py b/trove/tests/fakes/nova.py index 8e4c5325cb..75c9b8d840 100644 --- a/trove/tests/fakes/nova.py +++ b/trove/tests/fakes/nova.py @@ -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