Merge "Remove duplicate columns from list output"
This commit is contained in:
@@ -218,6 +218,14 @@ class ShellTest(utils.TestCase):
|
||||
mock_print.assert_called_once_with(mock.ANY, key_list,
|
||||
exclude_unavailable=True, sortby_index=0)
|
||||
|
||||
@mock.patch("cinderclient.utils.print_list")
|
||||
def test_list_duplicate_fields(self, mock_print):
|
||||
self.run_command('list --field Status,id,Size,status')
|
||||
self.assert_called('GET', '/volumes/detail')
|
||||
key_list = ['ID', 'Status', 'Size']
|
||||
mock_print.assert_called_once_with(mock.ANY, key_list,
|
||||
exclude_unavailable=True, sortby_index=0)
|
||||
|
||||
@mock.patch("cinderclient.utils.print_list")
|
||||
def test_list_field_with_tenant(self, mock_print):
|
||||
self.run_command('list --field Status,Name,Size,Bootable '
|
||||
|
||||
@@ -83,6 +83,14 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command(command)
|
||||
self.assert_called('GET', '/volumes/detail?group_id=fake_id')
|
||||
|
||||
@mock.patch("cinderclient.utils.print_list")
|
||||
def test_list_duplicate_fields(self, mock_print):
|
||||
self.run_command('list --field Status,id,Size,status')
|
||||
self.assert_called('GET', '/volumes/detail')
|
||||
key_list = ['ID', 'Status', 'Size']
|
||||
mock_print.assert_called_once_with(mock.ANY, key_list,
|
||||
exclude_unavailable=True, sortby_index=0)
|
||||
|
||||
def test_list_availability_zone(self):
|
||||
self.run_command('availability-zone-list')
|
||||
self.assert_called('GET', '/os-availability-zone')
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import copy
|
||||
import os
|
||||
import warnings
|
||||
@@ -154,7 +155,11 @@ def do_list(cs, args):
|
||||
setattr(vol, 'attached_to', ','.join(map(str, servers)))
|
||||
|
||||
if field_titles:
|
||||
key_list = ['ID'] + field_titles
|
||||
# Remove duplicate fields
|
||||
key_list = ['ID']
|
||||
unique_titles = [k for k in collections.OrderedDict.fromkeys(
|
||||
[x.title().strip() for x in field_titles]) if k != 'Id']
|
||||
key_list.extend(unique_titles)
|
||||
else:
|
||||
key_list = ['ID', 'Status', 'Name', 'Size', 'Volume Type',
|
||||
'Bootable', 'Attached to']
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import os
|
||||
|
||||
from oslo_utils import strutils
|
||||
@@ -171,7 +172,11 @@ def do_list(cs, args):
|
||||
setattr(vol, 'attached_to', ','.join(map(str, servers)))
|
||||
|
||||
if field_titles:
|
||||
key_list = ['ID'] + field_titles
|
||||
# Remove duplicate fields
|
||||
key_list = ['ID']
|
||||
unique_titles = [k for k in collections.OrderedDict.fromkeys(
|
||||
[x.title().strip() for x in field_titles]) if k != 'Id']
|
||||
key_list.extend(unique_titles)
|
||||
else:
|
||||
key_list = ['ID', 'Status', 'Name', 'Size', 'Volume Type',
|
||||
'Bootable', 'Attached to']
|
||||
|
||||
Reference in New Issue
Block a user