Refactor the columns generate for device profile list

Change-Id: I8f0fc90849287efa915cffdcbb2f78f140560207
This commit is contained in:
songwenping 2021-12-18 09:21:50 +00:00
parent e1cf238c5d
commit 2680c35ba5
2 changed files with 23 additions and 43 deletions

View File

@ -29,6 +29,20 @@ from cyborgclient.i18n import _
class ListDeviceProfile(command.Lister):
"""List all device profiles"""
column_headers = (
"uuid",
"name",
"groups",
"description"
)
columns = (
"uuid",
"name",
"groups",
"description"
)
detail_cols = ("created_at", "updated_at")
def get_parser(self, prog_name):
parser = super(ListDeviceProfile, self).get_parser(prog_name)
parser.add_argument(
@ -42,45 +56,17 @@ class ListDeviceProfile(command.Lister):
def take_action(self, parsed_args):
acc_client = self.app.client_manager.accelerator
if parsed_args.detail:
column_headers = (
"created_at",
"updated_at",
"uuid",
"name",
"groups",
"description"
)
columns = (
"created_at",
"updated_at",
"uuid",
"name",
"groups",
"description"
)
else:
column_headers = (
"uuid",
"name",
"groups",
"description"
)
columns = (
"uuid",
"name",
"groups",
"description"
)
self.column_headers += self.detail_cols
self.columns += self.detail_cols
data = acc_client.device_profiles()
if not data:
return (), ()
formatters = {}
return (column_headers,
return (self.column_headers,
(oscutils.get_item_properties(
s, columns, formatters=formatters) for s in data))
s, self.columns, formatters=formatters) for s in data))
class CreateDeviceProfile(command.ShowOne):

View File

@ -78,23 +78,17 @@ class TestDeviceProfileList(TestDeviceProfile):
self.mock_acc_client.device_profiles.assert_called_with(**kwargs)
collist = (
'created_at',
'updated_at',
'uuid',
'name',
'groups',
'description'
)
self.assertEqual(collist, columns)
collist = (osc_device_profile.ListDeviceProfile.columns +
osc_device_profile.ListDeviceProfile.detail_cols)
self.assertEqual(list(collist), list(columns))
datalist = [(
acc_fakes.device_profile_created_at,
acc_fakes.device_profile_updated_at,
acc_fakes.device_profile_uuid,
acc_fakes.device_profile_name,
acc_fakes.device_profile_groups,
acc_fakes.device_profile_description,
acc_fakes.device_profile_created_at,
acc_fakes.device_profile_updated_at,
), ]
self.assertEqual(datalist, list(data))