From 7d838f19330c20a12605f63e8f32735793308622 Mon Sep 17 00:00:00 2001 From: yuyangbj Date: Thu, 17 Dec 2015 11:46:28 +0800 Subject: [PATCH] Show availability_zone info in CLI neutron agent-list Like nova service-list, we should show availability zone information in agent-list result. It will leave empty if the agent is not belong to any zone. Change-Id: I210b3668c247f06b0c14debe22409ce99836e024 Partially-implements: blueprint add-availability-zone --- neutronclient/neutron/v2_0/agent.py | 4 ++-- neutronclient/tests/unit/test_cli20_agents.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/neutronclient/neutron/v2_0/agent.py b/neutronclient/neutron/v2_0/agent.py index 123924c4a..110afc61c 100644 --- a/neutronclient/neutron/v2_0/agent.py +++ b/neutronclient/neutron/v2_0/agent.py @@ -29,8 +29,8 @@ class ListAgent(neutronV20.ListCommand): """List agents.""" resource = 'agent' - list_columns = ['id', 'agent_type', 'host', 'alive', 'admin_state_up', - 'binary'] + list_columns = ['id', 'agent_type', 'host', 'availability_zone', 'alive', + 'admin_state_up', 'binary'] _formatters = {'heartbeat_timestamp': _format_timestamp} sorting_support = True diff --git a/neutronclient/tests/unit/test_cli20_agents.py b/neutronclient/tests/unit/test_cli20_agents.py index d28e869ff..7641d2741 100644 --- a/neutronclient/tests/unit/test_cli20_agents.py +++ b/neutronclient/tests/unit/test_cli20_agents.py @@ -54,6 +54,22 @@ class CLITestV20Agent(test_cli20.CLITestV20Base): self.assertIn("alive", ag.keys()) self.assertIn(smile, ag.values()) + def test_list_agents_zone_field(self): + contents = {'agents': [{'availability_zone': 'myzone'}]} + args = ['-f', 'json'] + resources = "agents" + + cmd = agent.ListAgent(test_cli20.MyApp(sys.stdout), None) + self._test_list_columns(cmd, resources, contents, args) + _str = self.fake_stdout.make_string() + + returned_agents = jsonutils.loads(_str) + self.assertEqual(1, len(returned_agents)) + ag = returned_agents[0] + self.assertEqual(1, len(ag)) + self.assertIn("availability_zone", ag.keys()) + self.assertIn('myzone', ag.values()) + def test_update_agent(self): # agent-update myid --admin-state-down --description mydescr. resource = 'agent'