#11 Comment/karma submit: just use bodhi-client CLI called by os.system
Closed 3 years ago by frantisekz. Opened 4 years ago by kparal.

file modified
+26 -15
@@ -30,12 +30,14 @@ 

  import re

  

  from optparse import OptionParser

+ from shlex import quote

  from textwrap import wrap

  

  # extra python modules

  # Used to catch fedora.client.AuthError and fedora.client.ServerError

  # exceptions

  import fedora

+ import bodhi

  

  # fedora_cert is optional. It is only used to get the real fas_username, which

  # is also supplied as a command line option and eventually in a config file.
@@ -827,22 +829,31 @@ 

                      pass

  

      def send_comment(self, bc, update, comment, karma):

-         orig_retries = bc.retries

-         bc.retries = 1

-         for retry in range(0, self.options.retries + 1):

+         # Prepare command for bodhi CLI

+         command = "bodhi updates comment --karma {} --user {} {} {}".format(

+             karma, self.options.fas_username, update["updateid"], quote(comment)

+         )

+         res = os.system(command)

+         if res != 0:

+             # If return code isn't 0, something went wrong, try to explain or workaround some cases

+             if res == 1:

+                 return (False, 'Failed to connect to bodhi, is your internet connection working?')

+             # Try to workaround https://github.com/fedora-infra/bodhi/issues/3298

+             homedir = os.path.expanduser("~")

+             if not homedir:

+                 # Bail out if we weren't able to get homedir

+                 return (False, 'Failed to get homedir')

+             self.warning("Working around https://github.com/fedora-infra/bodhi/issues/3298 ...")

              try:

-                 res = bc.comment(update["updateid"], comment, karma=karma)

-                 bc.retries = orig_retries

-                 return (True, res)

-             except fedora.client.AuthError as e:

-                 self.warning("Authentication error")

-                 bc.password = getpass.getpass('FAS password for %s: ' %

-                                               self.options.fas_username)

-             except fedora.client.ServerError as e:

-                 self.warning("Server error: %s" % str(e))

- 

-         bc.retries = orig_retries

-         return (False, 'too many errors')

+                 os.remove(homedir + '/.fedora/openidbaseclient-sessions.cache')

+             except FileNotFoundError:

+                 return (False, 'Failed to remove ~/.fedora/openidbaseclient-sessions.cache')

+             res = os.system(command)

+             if res != 0:

+                 return (False, 'Failed to submit comment and karma')

+             return (True, res)

+ 

+         return (True, res)

  

  

  if __name__ == "__main__":

This is a rebased #9 as a local branch so that we can easily collaborate on it.

Since we think we know what the real bug is now - this doesn't have to be quite so ugly, does it? We could avoid calling the bodhi CLI client and just use Bodhi client library API to clear cached session and explicitly re-login if we get an error?

Frantisek tried that first, and unfortunately it didn't work for him. Even when the auth cache was removed, the API calls didn't work. He had to use the CLI that created a proper cache file, then API worked as well. I replicated that problem on my system as well.

There's a function for clearing the cached data from the current process, might have needed to call that too - if you just wipe the file, then the current process still has the cached data stored in memory, but a new process won't get it of course. Anyhow, now I have a proper server side fix pending upstream, so we shouldn't need this. In fact if we want to fix it in a hurry and don't want to wait for a new Bodhi to be deployed in production, I could probably do a client library-side fix for this in the package...

So, upstream fix ( https://github.com/fedora-infra/bodhi/pull/3833 ) seems merged, thanks @adamwill

I think we can wait till it's deployed in production instead of merging this hack?

Yes, let's wait until this is in production, and then test vanilla FEK whether it is fixed. Thanks a lot, @adamwill.

Pull-Request has been closed by frantisekz

3 years ago

Info: The upstream fix works, and that's why we could abandon this PR.

Metadata