From f780e7d0b2dea27e36673b9c12f248309e188fae Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 21 2019 13:03:56 +0000 Subject: [PATCH 1/4] show load/capacity in list-channels Fixes: https://pagure.io/koji/issue/1448 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index c263a75..615c32a 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2739,6 +2739,8 @@ def anon_handle_list_channels(goptions, session, args): usage = _("usage: %prog list-channels") usage += _("\n(Specify the --help global option for a list of other help options)") parser = OptionParser(usage=usage) + parser.add_option("--simple", action="store_true", default=goptions.quiet, + help=_("Print just list of channels without additional info")) parser.add_option("--quiet", action="store_true", default=goptions.quiet, help=_("Do not print header information")) (options, args) = parser.parse_args(args) @@ -2752,10 +2754,22 @@ def anon_handle_list_channels(goptions, session, args): channel['enabled'] = len([x for x in hosts if x['enabled']]) channel['disabled'] = len(hosts) - channel['enabled'] channel['ready'] = len([x for x in hosts if x['ready']]) - if not options.quiet: - print('Channel Enb Rdy Dis') - for channel in channels: - print("%(name)-15s %(enabled)5d %(ready)5d %(disabled)5d" % channel) + channel['capacity'] = sum([x['capacity'] for x in hosts]) + channel['load'] = sum([x['task_load'] for x in hosts]) + if channel['capacity']: + channel['perc_load'] = channel['load'] / channel['capacity'] * 100.0 + else: + channel['perc_load'] = 0.0 + if options.simple: + if not options.quiet: + print('Channel') + for channel in channels: + print(channel['name']) + else: + if not options.quiet: + print('Channel Enb Rdy Dis Loa/Cap/Perc') + for channel in channels: + print("%(name)-15s %(enabled)5d %(ready)5d %(disabled)5d %(load)3d/%(capacity)3d/%(perc_load)3d%%" % channel) def anon_handle_list_hosts(goptions, session, args): From c28bfeb50d9df95ab5a87041a5dd919d834999e4 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: May 21 2019 13:20:25 +0000 Subject: [PATCH 2/4] fix test --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 615c32a..ff009cf 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2739,7 +2739,7 @@ def anon_handle_list_channels(goptions, session, args): usage = _("usage: %prog list-channels") usage += _("\n(Specify the --help global option for a list of other help options)") parser = OptionParser(usage=usage) - parser.add_option("--simple", action="store_true", default=goptions.quiet, + parser.add_option("--simple", action="store_true", default=False, help=_("Print just list of channels without additional info")) parser.add_option("--quiet", action="store_true", default=goptions.quiet, help=_("Do not print header information")) diff --git a/tests/test_cli/test_list_channels.py b/tests/test_cli/test_list_channels.py index be07412..86de1bb 100644 --- a/tests/test_cli/test_list_channels.py +++ b/tests/test_cli/test_list_channels.py @@ -27,20 +27,24 @@ class TestListChannels(unittest.TestCase): ] self.session.multiCall.return_value = [ [[ - {'enabled': True, 'ready': True}, - {'enabled': True, 'ready': False}, - {'enabled': True, 'ready': False}, + {'enabled': True, 'ready': True, 'capacity': 2.0, 'task_load': 1.34}, + {'enabled': True, 'ready': False, 'capacity': 2.0, 'task_load': 0.0}, + {'enabled': True, 'ready': False, 'capacity': 2.0, 'task_load': 0.0}, ]], [[ - {'enabled': True, 'ready': True}, - {'enabled': False, 'ready': True}, - {'enabled': True, 'ready': False}, + {'enabled': True, 'ready': True, 'capacity': 2.0, 'task_load': 1.34}, + {'enabled': False, 'ready': True, 'capacity': 2.0, 'task_load': 0.34}, + {'enabled': True, 'ready': False, 'capacity': 2.0, 'task_load': 0.0}, ]], ] anon_handle_list_channels(self.options, self.session, self.args) actual = stdout.getvalue() - expected = 'default 3 1 0\ntest 2 2 1\n' + print(actual) + expected = """\ +default 3 1 0 1/ 6/ 22% +test 2 2 1 1/ 6/ 28% +""" self.assertMultiLineEqual(actual, expected) activate_session_mock.assert_called_once_with(self.session, self.options) From 960f47b8bf500b1545d43747bc2312d0a9289e46 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 04 2019 07:28:05 +0000 Subject: [PATCH 3/4] more readable layout --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index ff009cf..276a290 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2767,9 +2767,9 @@ def anon_handle_list_channels(goptions, session, args): print(channel['name']) else: if not options.quiet: - print('Channel Enb Rdy Dis Loa/Cap/Perc') + print('Channel Enabled Ready Disbld Load Cap Perc') for channel in channels: - print("%(name)-15s %(enabled)5d %(ready)5d %(disabled)5d %(load)3d/%(capacity)3d/%(perc_load)3d%%" % channel) + print("%(name)-15s %(enabled)6d %(ready)6d %(disabled)6d %(load)6d %(capacity)6d %(perc_load)6d%%" % channel) def anon_handle_list_hosts(goptions, session, args): From 0e814abaa619fd99618aa399ecd6b1312c6c11fc Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Jun 04 2019 12:14:26 +0000 Subject: [PATCH 4/4] fix test --- diff --git a/tests/test_cli/test_list_channels.py b/tests/test_cli/test_list_channels.py index 86de1bb..663fb73 100644 --- a/tests/test_cli/test_list_channels.py +++ b/tests/test_cli/test_list_channels.py @@ -43,8 +43,8 @@ class TestListChannels(unittest.TestCase): actual = stdout.getvalue() print(actual) expected = """\ -default 3 1 0 1/ 6/ 22% -test 2 2 1 1/ 6/ 28% +default 3 1 0 1 6 22% +test 2 2 1 1 6 28% """ self.assertMultiLineEqual(actual, expected) activate_session_mock.assert_called_once_with(self.session, self.options)