From aa7c55ad0755981bdc17c9419a449b8d6b6d7a31 Mon Sep 17 00:00:00 2001 From: Valeriy Ponomaryov Date: Thu, 1 Oct 2015 12:42:05 +0300 Subject: [PATCH] Fix display of availability-zone for manila-manage command Commands "manila-manage service list" and "manila-manage host list" were displaying availability zone instance instead of its name. Such bug appeared after implementation of Availability zone model. So, fix it by providing 'name' field of availability zone model. Change-Id: I14c3451380df01853183aed265344b1783c95939 Closes-Bug: #1499677 --- manila/cmd/manage.py | 16 +++++++++++----- manila/tests/cmd/test_manage.py | 12 ++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/manila/cmd/manage.py b/manila/cmd/manage.py index 8c9af60c..75afff9c 100755 --- a/manila/cmd/manage.py +++ b/manila/cmd/manage.py @@ -189,14 +189,15 @@ class HostCommands(object): ctxt = context.get_admin_context() services = db.service_get_all(ctxt) if zone: - services = [s for s in services if s['availability_zone'] == zone] + services = [ + s for s in services if s['availability_zone']['name'] == zone] hosts = [] for srv in services: if not [h for h in hosts if h['host'] == srv['host']]: hosts.append(srv) for h in hosts: - print("%-25s\t%-15s" % (h['host'], h['availability_zone'])) + print("%-25s\t%-15s" % (h['host'], h['availability_zone']['name'])) class DbCommands(object): @@ -332,9 +333,14 @@ class ServiceCommands(object): status = 'enabled' if svc['disabled']: status = 'disabled' - print(print_format % (svc['binary'], svc['host'].partition('.')[0], - svc['availability_zone'], status, art, - svc['updated_at'])) + print(print_format % ( + svc['binary'], + svc['host'].partition('.')[0], + svc['availability_zone']['name'], + status, + art, + svc['updated_at'], + )) CATEGORIES = { diff --git a/manila/tests/cmd/test_manage.py b/manila/tests/cmd/test_manage.py index b7ff94a5..fd2bc98f 100644 --- a/manila/tests/cmd/test_manage.py +++ b/manila/tests/cmd/test_manage.py @@ -166,11 +166,11 @@ class ManilaCmdManageTestCase(test.TestCase): def test_list(self, print_mock): serv_1 = { 'host': 'fake_host1', - 'availability_zone': 'avail_zone1', + 'availability_zone': {'name': 'avail_zone1'}, } serv_2 = { 'host': 'fake_host2', - 'availability_zone': 'avail_zone2', + 'availability_zone': {'name': 'avail_zone2'}, } self.mock_object(db, 'service_get_all', mock.Mock(return_value=[serv_1, serv_2])) @@ -188,11 +188,11 @@ class ManilaCmdManageTestCase(test.TestCase): def test_list_zone_is_none(self, print_mock): serv_1 = { 'host': 'fake_host1', - 'availability_zone': 'avail_zone1', + 'availability_zone': {'name': 'avail_zone1'}, } serv_2 = { 'host': 'fake_host2', - 'availability_zone': 'avail_zone2', + 'availability_zone': {'name': 'avail_zone2'}, } self.mock_object(db, 'service_get_all', mock.Mock(return_value=[serv_1, serv_2])) @@ -292,7 +292,7 @@ class ManilaCmdManageTestCase(test.TestCase): get_admin_context.return_value = ctxt service = {'binary': 'manila-binary', 'host': 'fake-host.fake-domain', - 'availability_zone': 'fake-zone', + 'availability_zone': {'name': 'fake-zone'}, 'updated_at': '2014-06-30 11:22:33', 'disabled': False} service_get_all.return_value = [service] @@ -307,7 +307,7 @@ class ManilaCmdManageTestCase(test.TestCase): 'Updated At') service_format = format % (service['binary'], service['host'].partition('.')[0], - service['availability_zone'], + service['availability_zone']['name'], 'enabled', ':-)', service['updated_at'])