PR#1916: replace xmlrpc_client exception with requests

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

Fixes: #1914
https://pagure.io/koji/issue/1914
kojid doesn't fail correctly during the startup problems
This commit is contained in:
Tomas Kopecek 2020-02-21 12:40:47 +01:00
commit fbfeff5df7
5 changed files with 14 additions and 11 deletions

View file

@ -47,6 +47,7 @@ from gzip import GzipFile
from optparse import SUPPRESS_HELP, OptionParser
import Cheetah.Template
import requests
import rpm
import six
import six.moves.xmlrpc_client
@ -6335,7 +6336,7 @@ if __name__ == "__main__":
options.serverca)
except koji.AuthError as e:
quit("Error: Unable to log in: %s" % e)
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
quit("Error: Unable to connect to server %s" % (options.server))
elif options.user:
try:
@ -6343,7 +6344,7 @@ if __name__ == "__main__":
session.login()
except koji.AuthError:
quit("Error: Unable to log in. Bad credentials?")
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
quit("Error: Unable to connect to server %s" % (options.server))
elif krbV or requests_kerberos:
krb_principal = options.krb_principal
@ -6369,7 +6370,7 @@ if __name__ == "__main__":
#make sure it works
try:
ret = session.echo("OK")
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
quit("Error: Unable to connect to server %s" % (options.server))
if ret != ["OK"]:
quit("Error: incorrect server response: %r" % (ret))

View file

@ -108,7 +108,7 @@ def get_usage_str(usage):
def ensure_connection(session):
try:
ret = session.getAPIVersion()
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
error(_("Error: Unable to connect to server"))
if ret != koji.API_VERSION:
warn(_("WARNING: The server is at API version %d and the client is at %d" % (ret, koji.API_VERSION)))

View file

@ -19,9 +19,10 @@ import sys
import time
from string import Template
import requests
import six
import six.moves.configparser
import six.moves.xmlrpc_client # for ProtocolError and Fault
import six.moves.xmlrpc_client # for Fault
from six.moves import email_mime_text as MIMEText
import koji
@ -349,7 +350,7 @@ def warn(msg):
def ensure_connection(session):
try:
ret = session.getAPIVersion()
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
error(_("Error: Unable to connect to server"))
if ret != koji.API_VERSION:
warn(_("WARNING: The server is at API version %d and the client is at %d" % (ret, koji.API_VERSION)))

View file

@ -35,9 +35,10 @@ import sys
import time
import urllib2
import requests
import rpm
import six
import six.moves.xmlrpc_client # for ProtocolError and Fault
import six.moves.xmlrpc_client # for Fault
from six.moves import range
import koji
@ -283,7 +284,7 @@ def warn(msg):
def ensure_connection(session):
try:
ret = session.getAPIVersion()
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
error(_("Error: Unable to connect to server"))
if ret != koji.API_VERSION:
warn(_("WARNING: The server is at API version %d and the client is at "

View file

@ -1107,7 +1107,7 @@ if __name__ == "__main__":
options.serverca)
except koji.AuthError as e:
quit("Error: Unable to log in: %s" % e)
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
quit("Error: Unable to connect to server %s" % (options.server))
elif options.user:
try:
@ -1115,7 +1115,7 @@ if __name__ == "__main__":
session.login()
except koji.AuthError:
quit("Error: Unable to log in. Bad credentials?")
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
quit("Error: Unable to connect to server %s" % (options.server))
elif krbV:
krb_principal = options.krb_principal
@ -1141,7 +1141,7 @@ if __name__ == "__main__":
#make sure it works
try:
ret = session.echo("OK")
except six.moves.xmlrpc_client.ProtocolError:
except requests.exceptions.ConnectionError:
quit("Error: Unable to connect to server %s" % (options.server))
if ret != ["OK"]:
quit("Error: incorrect server response: %r" % (ret))