#442 list-channels CLI command
Merged 4 years ago by mikem. Opened 4 years ago by tkopecek.
tkopecek/koji issue437  into  master

file modified
+20 -1
@@ -709,7 +709,7 @@ 

      usage = _("usage: %prog add-host-to-channel [options] hostname channel")

      usage += _("\n(Specify the --help global option for a list of other help options)")

      parser = OptionParser(usage=usage)

-     parser.add_option("--list", action="store_true", help=_("List possible channels"))

+     parser.add_option("--list", action="store_true", help=optparse.SUPPRESS_HELP)

      parser.add_option("--new", action="store_true", help=_("Create channel if needed"))

      (options, args) = parser.parse_args(args)

      if not options.list and len(args) != 2:
@@ -3188,6 +3188,25 @@ 

      activate_session(session)

      session.groupReqListUnblock(tag, group, req)

  

+ def anon_handle_list_channels(options, session, args):

+     "[info] Print channels listing"

+     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("--quiet", action="store_true", help=_("Do not print header information"), default=options.quiet)

+     (options, args) = parser.parse_args(args)

+     activate_session(session)

+     channels = session.listChannels()

+     session.multicall = True

+     for channel in channels:

+         session.listHosts(channelID=channel['id'])

+     for channel, hosts in zip(channels, session.multiCall()):

+         channel['hosts'] = len(hosts[0])

+     if not options.quiet:

+         print('Channel         Hosts')

+     for channel in channels:

+         print("%(name)-15s %(hosts) 5d" % channel)

+ 

  def anon_handle_list_hosts(options, session, args):

      "[info] Print the host listing"

      usage = _("usage: %prog list-hosts [options]")

@@ -95,6 +95,7 @@ 

          latest-build              Print the latest builds for a tag

          list-api                  Print the list of XML-RPC APIs

          list-buildroot            List the rpms used in or built in a buildroot

+         list-channels             Print channels listing

          list-external-repos       List external repos

          list-groups               Print the group listings

          list-history              Display historical data

@@ -0,0 +1,41 @@ 

+ from __future__ import absolute_import

+ import mock

+ import unittest

+ from six.moves import StringIO

+ 

+ import koji

+ 

+ from . import loadcli

+ cli = loadcli.cli

+ 

+ class TestListChannels(unittest.TestCase):

+     def setUp(self):

+         self.options = mock.MagicMock()

+         self.session = mock.MagicMock()

+         self.session.getAPIVersion.return_value = koji.API_VERSION

+         self.args = mock.MagicMock()

+         self.original_parser = cli.OptionParser

+         cli.OptionParser = mock.MagicMock()

+         self.parser = cli.OptionParser.return_value

+         cli.options = self.options  # globals!!!

+ 

+     def tearDown(self):

+         cli.OptionParser = self.original_parser

+ 

+     @mock.patch('sys.stdout', new_callable=StringIO)

+     def test_list_channels(self, stdout):

+         options = mock.MagicMock()

+         options.quiet = True

+         self.parser.parse_args.return_value = [options, []]

+ 

+         # mock xmlrpc

+         self.session.listChannels.return_value = [

+             {'id': 1, 'name': 'default'},

+             {'id': 2, 'name': 'test'},

+         ]

+         self.session.multiCall.return_value = [[[1,2,3]], [[4,5]]]

+ 

+         cli.anon_handle_list_channels(self.options, self.session, self.args)

+         actual = stdout.getvalue()

+         expected = 'successfully connected to hub\ndefault             3\ntest                2\n'

+         self.assertMultiLineEqual(actual, expected)

rebased

4 years ago

new unit test fails in py3

Would we move the function of koji add-host-to-channel --list to this new command?

Would we move the function of koji add-host-to-channel --list to this new command?

I would not remove that option, in case people are relying on it, but perhaps deprecate it and hide it in the help (i.e. help=SUPPRESS_HELP).

Added SUPPRESS_HELP and rebased /fixed to python3

rebased

4 years ago

Commit 2c4f09d fixes this pull-request

Pull-Request has been merged by mikem@redhat.com

4 years ago