PR#3363: CLI: list-channels with specific arch

Merges #3363
https://pagure.io/koji/pull-request/3363

Fixes: #1877
https://pagure.io/koji/issue/1877
RFE: list available capacity/load of each channel per arch
This commit is contained in:
Tester 2022-06-20 09:33:48 +02:00
commit 348258201b
2 changed files with 49 additions and 7 deletions

View file

@ -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']

View file

@ -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)