#2705 cli: show connection exception
Merged a year ago by tkopecek. Opened a year ago by tkopecek.
tkopecek/koji issue2592  into  master

file modified
+28 -28
@@ -930,7 +930,7 @@ 

      parser.add_option("--yum-proxy", help=_("Specify a yum proxy"))

      parser.add_option("-o", metavar="FILE", dest="ofile", help=_("Output to a file"))

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

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      if args:

          # for historical reasons, we also accept buildroot name as first arg

          if not options.name:
@@ -2359,7 +2359,7 @@ 

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

      if len(args) == 0:

          parser.error(_("A tag name must be specified"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      if options.all:

          if len(args) > 1:

              parser.error(_("A package name may not be combined with --all"))
@@ -2427,7 +2427,7 @@ 

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

      if len(args) != 0:

          parser.error(_("This command takes no arguments"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      for x in sorted(session._listapi(), key=lambda x: x['name']):

          if 'argdesc' in x:

              args = x['argdesc']
@@ -2473,7 +2473,7 @@ 

          parser.error(_("A tag name must be specified"))

      elif len(args) > 2:

          parser.error(_("Only one package name may be specified"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      pathinfo = koji.PathInfo()

      package = None

      if len(args) > 1:
@@ -2572,7 +2572,7 @@ 

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

      if len(args) != 1:

          parser.error(_("Incorrect number of arguments"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      buildrootID = int(args[0])

      opts = {}

      if options.built:
@@ -2599,7 +2599,7 @@ 

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

      if len(args) > 1:

          parser.error(_("Only one package name may be specified"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      package = None

      if len(args) > 0:

          package = args[0]
@@ -2667,7 +2667,7 @@ 

      opts = {}

      if options.incl_blocked:

          opts['incl_blocked'] = True

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      event = koji.util.eventFromOpts(session, options)

      if event:

          opts['event'] = event['id']
@@ -2796,7 +2796,7 @@ 

      parser.add_option("--quiet", action="store_true", default=goptions.quiet,

                        help=_("Do not print header information"))

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

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      channels = session.listChannels()

      channels = sorted(channels, key=lambda x: x['name'])

      session.multicall = True
@@ -2846,7 +2846,7 @@ 

      parser.add_option("--description", action="store_true", help=_("Show descriptions"))

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

      opts = {}

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      if options.arch:

          opts['arches'] = options.arch

      if options.channel:
@@ -2947,7 +2947,7 @@ 

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

      if len(args) != 0:

          parser.error(_("This command takes no arguments"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      opts = {}

      if options.owner:

          user = session.getUser(options.owner)
@@ -3041,7 +3041,7 @@ 

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

      if len(args) != 0:

          parser.error(_("This command takes no arguments"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      opts = {}

      for key in ('type', 'prefix', 'pattern'):

          value = getattr(options, key)
@@ -3141,7 +3141,7 @@ 

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

      if len(args) < 1:

          parser.error(_("Please specify an RPM"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      for rpm in args:

          info = session.getRPM(rpm)

          if info is None:
@@ -3213,7 +3213,7 @@ 

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

      if len(args) < 1:

          parser.error(_("Please specify a build"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      for build in args:

          if build.isdigit():

              build = int(build)
@@ -3311,7 +3311,7 @@ 

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

      if len(args) < 1:

          parser.error(_("Please specify a host"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      for host in args:

          if host.isdigit():

              host = int(host)
@@ -4025,7 +4025,7 @@ 

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

      if len(args) != 0:

          parser.error(_("This command takes no arguments"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

  

      fmt = "%(name)-30s %(build_tag_name)-30s %(dest_tag_name)-30s"

      if not options.quiet:
@@ -4107,7 +4107,7 @@ 

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

      if len(args) != 1:

          parser.error(_("This command takes exactly one argument: a tag name or ID"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      event = koji.util.eventFromOpts(session, options)

      if event:

          event['timestr'] = time.asctime(time.localtime(event['ts']))
@@ -4160,7 +4160,7 @@ 

      parser.add_option("--build", help=_("Show tags associated with a build"))

      parser.add_option("--package", help=_("Show tags associated with a package"))

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

-     ensure_connection(session)

+     ensure_connection(session, goptions)

  

      pkginfo = {}

      buildinfo = {}
@@ -4523,7 +4523,7 @@ 

      if not limited and not options.all:

          parser.error(_("Please specify an option to limit the query"))

  

-     ensure_connection(session)

+     ensure_connection(session, goptions)

  

      if options.watch:

          if not kwargs.get('afterEvent') and not kwargs.get('after'):
@@ -4844,7 +4844,7 @@ 

      if len(args) < 1:

          parser.error(_("You must specify at least one task ID"))

  

-     ensure_connection(session)

+     ensure_connection(session, goptions)

  

      for arg in args:

          task_id = int(arg)
@@ -4862,7 +4862,7 @@ 

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

      if len(args) < 1:

          parser.error(_("Please specify a tag"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      event = koji.util.eventFromOpts(session, options)

      event_opts = {}

      if event:
@@ -5358,7 +5358,7 @@ 

          parser.error(_("Incorrect number of arguments"))

      if options.incl_blocked and (options.comps or options.spec):

          parser.error(_("--show-blocked doesn't make sense for comps/spec output"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      tag = args[0]

      callopts = {}

      if options.incl_blocked:
@@ -5393,7 +5393,7 @@ 

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

      if len(args) > 0:

          parser.error(_("This command takes no arguments"))

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      opts = {}

      event = koji.util.eventFromOpts(session, options)

      if event:
@@ -6493,7 +6493,7 @@ 

      if options.mine:

          activate_session(session, goptions)

      else:

-         ensure_connection(session)

+         ensure_connection(session, goptions)

      if selection:

          tasks = [task['id'] for task in _list_tasks(options, session)]

          if not tasks:
@@ -6534,7 +6534,7 @@ 

              print(_("You've no active tasks."))

              return

      else:

-         ensure_connection(session)

+         ensure_connection(session, goptions)

          tasks = []

          for task in args:

              try:
@@ -6776,7 +6776,7 @@ 

      elif len(args) > 1:

          parser.error(_("Only a single package N-V-R or build ID may be specified"))

  

-     ensure_connection(session)

+     ensure_connection(session, options)

      build = args[0]

  

      if build.isdigit():
@@ -7002,7 +7002,7 @@ 

      if len(suboptions.arches) > 0:

          suboptions.arches = ",".join(suboptions.arches).split(",")

  

-     ensure_connection(session)

+     ensure_connection(session, options)

  

      # get downloadable tasks

  
@@ -7434,7 +7434,7 @@ 

          parser.error(_("Use --user or --mine."))

  

      if options.user:

-         ensure_connection(session)

+         ensure_connection(session, goptions)

          user = session.getUser(options.user)

          if not user:

              error("User %s does not exist" % options.user)
@@ -7692,7 +7692,7 @@ 

  

  def handle_version(goptions, session, args):

      """Report client and hub versions"""

-     ensure_connection(session)

+     ensure_connection(session, goptions)

      print('Client: %s' % koji.__version__)

      try:

          version = session.getKojiVersion()

file modified
+7 -3
@@ -135,11 +135,15 @@ 

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

  

  

- def ensure_connection(session):

+ def ensure_connection(session, options=None):

      try:

          ret = session.getAPIVersion()

-     except requests.exceptions.ConnectionError:

-         error(_("Error: Unable to connect to server"))

+     except requests.exceptions.ConnectionError as ex:

+         warn(_("Error: Unable to connect to server"))

+         if options and getattr(options, 'debug', False):

+             error(str(ex))

+         else:

+             error()

      if ret != koji.API_VERSION:

          warn(_("WARNING: The server is at API version %d and "

                 "the client is at %d" % (ret, koji.API_VERSION)))

file modified
+1
@@ -746,6 +746,7 @@ 

              except Exception:

                  return offline_reply(start_response, msg="database outage")

              h = ModXMLRPCRequestHandler(registry)

+             h.logger.error("original: %s", h.__class__)

              if environ.get('CONTENT_TYPE') == 'application/octet-stream':

                  response = h._wrap_handler(h.handle_upload, environ)

              else:

@@ -80,7 +80,7 @@ 

          expected = ''

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@@ -105,7 +105,7 @@ 

          expected = 'No such task: #123333\n'

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_not_called()

  
@@ -147,7 +147,7 @@ 

          expected = ''

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_called_once_with(task_id)

          self.assertEqual(self.list_task_output_all_volumes.mock_calls, [
@@ -188,7 +188,7 @@ 

          expected = ''

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@@ -223,7 +223,7 @@ 

          expected = 'No files for download found.\n'

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@@ -256,7 +256,7 @@ 

          expected = 'Task 123333 has not finished yet.\n'

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)
@@ -287,7 +287,7 @@ 

          expected = 'Child task 22222 has not finished yet.\n'

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_called_once_with(task_id)

          self.list_task_output_all_volumes.assert_called_once_with(self.session, 22222)
@@ -314,7 +314,7 @@ 

          expected = 'Invalid file name: somerpm..src.rpm\n'

          self.assertMultiLineEqual(actual, expected)

          # Finally, assert that things were called as we expected.

-         self.ensure_connection.assert_called_once_with(self.session)

+         self.ensure_connection.assert_called_once_with(self.session, self.options)

          self.session.getTaskInfo.assert_called_once_with(task_id)

          self.session.getTaskChildren.assert_not_called()

          self.list_task_output_all_volumes.assert_called_once_with(self.session, task_id)

@@ -44,4 +44,4 @@ 

  test                 2      2      1      1      6     28%

  """

          self.assertMultiLineEqual(actual, expected)

-         ensure_connection_mock.assert_called_once_with(self.session)

+         ensure_connection_mock.assert_called_once_with(self.session, self.options)

@@ -91,7 +91,7 @@ 

  

          self.maxDiff=None

          self.assertMultiLineEqual(actual, expected)

-         ensure_connection_mock.assert_called_once_with(self.session)

+         ensure_connection_mock.assert_called_once_with(self.session, self.options)

          self.session.getTag.assert_has_calls([mock.call(1), mock.call(1)])

          self.session.getPackage.assert_has_calls([mock.call(11), mock.call(11)])

          self.session.getUser.assert_called_once_with('random_name')

@@ -70,7 +70,7 @@ 

          args = ['tag', 'pkg', '--latest', '--inherit', '--event=1000']

  

          anon_handle_list_tagged(self.options, self.session, args)

-         ensure_connection_mock.assert_called_once_with(self.session)

+         ensure_connection_mock.assert_called_once_with(self.session, self.options)

          self.session.getTag.assert_called_once_with('tag', event=1000)

          self.session.listTagged.assert_called_once_with('tag',

                                                          event=1000,
@@ -106,7 +106,7 @@ 

                  '--arch=x86_64', '--arch=noarch']

  

          anon_handle_list_tagged(self.options, self.session, args)

-         ensure_connection_mock.assert_called_once_with(self.session)

+         ensure_connection_mock.assert_called_once_with(self.session, self.options)

          self.session.getTag.assert_called_once_with('tag', event=None)

          self.session.listTaggedRPMS.assert_called_once_with('tag',

                                                              package='pkg',
@@ -161,7 +161,7 @@ 

                                                   'maven_artifact_id': 'artifact'}]

  

          anon_handle_list_tagged(self.options, self.session, args)

-         ensure_connection_mock.assert_called_once_with(self.session)

+         ensure_connection_mock.assert_called_once_with(self.session, self.options)

          self.session.getTag.assert_called_once_with('tag', event=None)

          self.session.listTagged.assert_called_once_with('tag',

                                                          package='pkg',

For anonymous calls (whose use ensure_connection) is now shown also
original exception if --debug is specified.

Fixes: https://pagure.io/koji/issue/2592

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

a year ago

Metadata Update from @mfilip:
- Pull-request tagged with: testing-done

a year ago

Commit 5a5bdc7 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago