From a3062c9226fe34b5834a8186c36758627ff09db4 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: May 17 2022 08:42:10 +0000 Subject: CLI: list-channels with specific arch Fixes: https://pagure.io/koji/issue/1877 --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 42213c3..e9ee55d 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -3025,6 +3025,7 @@ def anon_handle_list_channels(goptions, session, args): help="Limit to not enabled channels") parser.add_option("--disabled", action="store_false", dest="enabled", help="Alias for --not-enabled") + parser.add_option("--arch", help="Limit to channels with specific arch") (options, args) = parser.parse_args(args) ensure_connection(session, goptions) opts = {} @@ -3040,7 +3041,10 @@ def anon_handle_list_channels(goptions, session, args): first_item = {} session.multicall = True for channel in channels: - session.listHosts(channelID=channel['id']) + if options.arch is not None: + session.listHosts(channelID=channel['id'], arches=options.arch) + else: + session.listHosts(channelID=channel['id']) for channel, [hosts] in zip(channels, session.multiCall()): channel['enabled_host'] = len([x for x in hosts if x['enabled']]) channel['disabled'] = len(hosts) - channel['enabled_host'] diff --git a/tests/test_cli/test_list_channels.py b/tests/test_cli/test_list_channels.py index 1ac30fc..2d28b89 100644 --- a/tests/test_cli/test_list_channels.py +++ b/tests/test_cli/test_list_channels.py @@ -34,14 +34,33 @@ class TestListChannels(utils.CliTestCase): self.list_hosts_mc = [ [[ - {'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}, + {'arch': 'x86_64', 'enabled': True, 'ready': True, 'capacity': 2.0, + 'task_load': 1.34}, + {'arch': 'ppc', 'enabled': True, 'ready': False, 'capacity': 2.0, + 'task_load': 0.0}, + {'arch': 'x86_64', 'enabled': True, 'ready': False, 'capacity': 2.0, + 'task_load': 0.0}, ]], [[ - {'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}, + {'arch': 'ppc', 'enabled': True, 'ready': True, 'capacity': 2.0, + 'task_load': 1.34}, + {'arch': 'x86_64', 'enabled': False, 'ready': True, 'capacity': 2.0, + 'task_load': 0.34}, + {'arch': 'ppc', 'enabled': True, 'ready': False, 'capacity': 2.0, + 'task_load': 0.0}, + ]] + ] + + self.list_hosts_mc_arch = [ + [[ + {'arch': 'x86_64', 'enabled': True, 'ready': True, 'capacity': 2.0, + 'task_load': 1.34}, + {'arch': 'x86_64', 'enabled': True, 'ready': False, 'capacity': 2.0, + 'task_load': 0.0}, + ]], + [[ + {'arch': 'x86_64', 'enabled': False, 'ready': True, 'capacity': 2.0, + 'task_load': 0.34}, ]] ] @@ -225,6 +244,24 @@ test [disabled] self.assertMultiLineEqual(actual, expected) self.ensure_connection_mock.assert_called_once_with(self.session, self.options) + @mock.patch('sys.stdout', new_callable=StringIO) + def test_list_channels_with_arch(self, stdout): + self.session.listChannels.return_value = self.list_channels + self.session.multiCall.return_value = self.list_hosts_mc_arch + args = [] + self.options.quiet = False + + anon_handle_list_channels(self.options, self.session, args) + + actual = stdout.getvalue() + expected = "Channel Enabled Ready Disbld Load Cap Perc \n" \ + "-------------------------------------------------------------\n" \ + "default 2 1 0 1 4 33%\n" \ + "test [disabled] 0 1 1 0 2 17%\n" + + self.assertMultiLineEqual(actual, expected) + self.ensure_connection_mock.assert_called_once_with(self.session, self.options) + def test_list_channels_help(self): self.assert_help( anon_handle_list_channels, @@ -240,6 +277,7 @@ Options: --enabled Limit to enabled channels --not-enabled Limit to not enabled channels --disabled Alias for --not-enabled + --arch=ARCH Limit to channels with specific arch """ % self.progname)