From 8ca1cc637013972491744b8318d30e9256bc4165 Mon Sep 17 00:00:00 2001 From: Yan Xing'an Date: Wed, 26 Oct 2016 23:48:58 -0700 Subject: Add --long option and more columns to the hypervisor list command Support --long option and more columns in output of hypervisor list command, including 'Hypervisor Type', 'Host IP', 'State', and 'vCPU Used', 'vCPUs', 'Memory MB Used', 'Memory MB' with --long option. Change-Id: I0c790c7835309dded03e230cf497168e19404537 Closes-Bug: #1637074 --- .../tests/unit/compute/v2/test_hypervisor.py | 67 +++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'openstackclient/tests') diff --git a/openstackclient/tests/unit/compute/v2/test_hypervisor.py b/openstackclient/tests/unit/compute/v2/test_hypervisor.py index e39570af..7200d04e 100644 --- a/openstackclient/tests/unit/compute/v2/test_hypervisor.py +++ b/openstackclient/tests/unit/compute/v2/test_hypervisor.py @@ -48,19 +48,63 @@ class TestHypervisorList(TestHypervisor): self.columns = ( "ID", - "Hypervisor Hostname" + "Hypervisor Hostname", + "Hypervisor Type", + "Host IP", + "State" + ) + self.columns_long = ( + "ID", + "Hypervisor Hostname", + "Hypervisor Type", + "Host IP", + "State", + "vCPUs Used", + "vCPUs", + "Memory MB Used", + "Memory MB" ) self.data = ( ( self.hypervisors[0].id, self.hypervisors[0].hypervisor_hostname, + self.hypervisors[0].hypervisor_type, + self.hypervisors[0].host_ip, + self.hypervisors[0].state ), ( self.hypervisors[1].id, self.hypervisors[1].hypervisor_hostname, + self.hypervisors[1].hypervisor_type, + self.hypervisors[1].host_ip, + self.hypervisors[1].state ), ) + self.data_long = ( + ( + self.hypervisors[0].id, + self.hypervisors[0].hypervisor_hostname, + self.hypervisors[0].hypervisor_type, + self.hypervisors[0].host_ip, + self.hypervisors[0].state, + self.hypervisors[0].vcpus_used, + self.hypervisors[0].vcpus, + self.hypervisors[0].memory_mb_used, + self.hypervisors[0].memory_mb + ), + ( + self.hypervisors[1].id, + self.hypervisors[1].hypervisor_hostname, + self.hypervisors[1].hypervisor_type, + self.hypervisors[1].host_ip, + self.hypervisors[1].state, + self.hypervisors[1].vcpus_used, + self.hypervisors[1].vcpus, + self.hypervisors[1].memory_mb_used, + self.hypervisors[1].memory_mb + ), + ) # Get the command object to test self.cmd = hypervisor.ListHypervisor(self.app, None) @@ -93,6 +137,9 @@ class TestHypervisorList(TestHypervisor): ( self.hypervisors[0].id, self.hypervisors[0].hypervisor_hostname, + self.hypervisors[1].hypervisor_type, + self.hypervisors[1].host_ip, + self.hypervisors[1].state, ), ) @@ -123,6 +170,24 @@ class TestHypervisorList(TestHypervisor): self.cmd.take_action, parsed_args) + def test_hypervisor_list_long_option(self): + arglist = [ + '--long', + ] + verifylist = [ + ('long', True), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # In base command class Lister in cliff, abstract method take_action() + # returns a tuple containing the column names and an iterable + # containing the data to be listed. + columns, data = self.cmd.take_action(parsed_args) + + self.hypervisors_mock.list.assert_called_with() + self.assertEqual(self.columns_long, columns) + self.assertEqual(self.data_long, tuple(data)) + class TestHypervisorShow(TestHypervisor): -- cgit v1.2.1