Merge "Add more columns to image list output"

This commit is contained in:
Jenkins 2014-07-26 22:20:19 +00:00 committed by Gerrit Code Review
commit 7b70143695
4 changed files with 112 additions and 2 deletions

View File

@ -291,6 +291,12 @@ class ListImage(lister.Lister):
metavar="<size>",
help="Number of images to request in each paginated request",
)
parser.add_argument(
'--long',
action='store_true',
default=False,
help='List additional fields in output',
)
return parser
def take_action(self, parsed_args):
@ -303,7 +309,11 @@ class ListImage(lister.Lister):
kwargs["page_size"] = parsed_args.page_size
data = image_client.images.list(**kwargs)
columns = ["ID", "Name"]
if parsed_args.long:
columns = ('ID', 'Name', 'Disk Format', 'Container Format',
'Size', 'Status')
else:
columns = ("ID", "Name")
return (columns, (utils.get_item_properties(s, columns) for s in data))

View File

@ -63,6 +63,12 @@ class ListImage(lister.Lister):
metavar="<size>",
help="Number of images to request in each paginated request",
)
parser.add_argument(
'--long',
action='store_true',
default=False,
help='List additional fields in output',
)
return parser
def take_action(self, parsed_args):
@ -75,7 +81,11 @@ class ListImage(lister.Lister):
kwargs["page_size"] = parsed_args.page_size
data = image_client.images.list(**kwargs)
columns = ["ID", "Name"]
if parsed_args.long:
columns = ('ID', 'Name', 'Disk Format', 'Container Format',
'Size', 'Status')
else:
columns = ("ID", "Name")
return (columns, (utils.get_item_properties(s, columns) for s in data))

View File

@ -446,3 +446,48 @@ class TestImageSet(TestImage):
image_fakes.image_id,
**kwargs
)
class TestImageList(TestImage):
def setUp(self):
super(TestImageList, self).setUp()
# This is the return value for utils.find_resource()
self.images_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(image_fakes.IMAGE),
loaded=True,
),
]
# Get the command object to test
self.cmd = image.ListImage(self.app, None)
def test_image_list_long_option(self):
arglist = [
'--long',
]
verifylist = [
('long', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.images_mock.list.assert_called_with()
collist = ('ID', 'Name', 'Disk Format', 'Container Format',
'Size', 'Status')
self.assertEqual(columns, collist)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
'',
'',
'',
), )
self.assertEqual(datalist, tuple(data))

View File

@ -61,3 +61,48 @@ class TestImageDelete(TestImage):
self.images_mock.delete.assert_called_with(
image_fakes.image_id,
)
class TestImageList(TestImage):
def setUp(self):
super(TestImageList, self).setUp()
# This is the return value for utils.find_resource()
self.images_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(image_fakes.IMAGE),
loaded=True,
),
]
# Get the command object to test
self.cmd = image.ListImage(self.app, None)
def test_image_list_long_option(self):
arglist = [
'--long',
]
verifylist = [
('long', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.images_mock.list.assert_called_with()
collist = ('ID', 'Name', 'Disk Format', 'Container Format',
'Size', 'Status')
self.assertEqual(columns, collist)
datalist = ((
image_fakes.image_id,
image_fakes.image_name,
'',
'',
'',
'',
), )
self.assertEqual(datalist, tuple(data))