def doCall(method, *args, **kwargs): log = up2dateLog.initLog() cfg = config.initUp2dateConfig() ret = None attempt_count = 1 attempts = cfg["networkRetries"] or 5 while 1: failure = 0 ret = None try: ret = apply(method, args, kwargs) except KeyboardInterrupt: raise up2dateErrors.CommunicationError( "Connection aborted by the user") # if we get a socket error, keep tryingx2 except (socket.error, socket.sslerror), e: log.log_me("A socket error occurred: %s, attempt #%s" % (e, attempt_count)) if attempt_count >= attempts: if len(e.args) > 1: raise up2dateErrors.CommunicationError(e.args[1]) else: raise up2dateErrors.CommunicationError(e.args[0]) else: failure = 1 except httplib.IncompleteRead: print "httplib.IncompleteRead" raise up2dateErrors.CommunicationError("httplib.IncompleteRead")
def getHeader(self, pkg, lite = None, msgCallback = None, progressCallback = None): hdr = None try: ret = self.s.up2date.header(up2dateAuth.getSystemId(), pkg) except KeyboardInterrupt: raise up2dateErrors.CommunicationError("Connection aborted by the user") except (socket.error, socket.sslerror), e: if len(e.args) > 1: raise up2dateErrors.CommunicationError(e.args[1]) else: raise up2dateErrors.CommunicationError(e.args[0])
def activateHardwareInfo(username, password, hardwareInfo, orgId=None): """Tries to activate an entitlement linked to the hardware info that we read from the bios. Returns an ActivationResult. Can raise: Invalid number. Hardware info is not entitling. Communication errors, etc """ ## import pprint ## pprint.pprint(hardwareInfo) other = {} if orgId: other = {'org_id': orgId} server = rhnserver.RhnServer() result = server.registration.activate_hardware_info( username, password, hardwareInfo, other) statusCode = result['status_code'] regNum = result['registration_number'] log.log_debug('Server returned status code %s' % statusCode) if statusCode == 0: return ActivationResult(ActivationResult.ACTIVATED_NOW, regNum) elif statusCode == 1: return ActivationResult(ActivationResult.ALREADY_USED, regNum) else: message = "The server returned unknown status code %s while activating" \ " the hardware info." % statusCode raise up2dateErrors.CommunicationError(message)
def unsubscribeChannels(channels, username, passwd): s = rpcServer.getServer() try: channels = rpcServer.doCall(s.up2date.unsubscribeChannels, up2dateAuth.getSystemId(), channels, username, passwd) except rpclib.Fault, f: if f.faultCode == -36: raise up2dateErrors.PasswordError(f.faultString) else: raise up2dateErrors.CommunicationError(f.faultString)
def doCall(method, *args, **kwargs): log = up2dateLog.initLog() log.log_debug("rpcServer: Calling XMLRPC %s" % method.__dict__['_Method__name']) cfg = config.initUp2dateConfig() ret = None attempt_count = 1 try: attempts = int(cfg["networkRetries"]) except ValueError: attempts = 1 if attempts <= 0: attempts = 1 while 1: failure = 0 ret = None try: ret = method(*args, **kwargs) except KeyboardInterrupt: raise up2dateErrors.CommunicationError( _("Connection aborted by the user")), None, sys.exc_info()[2] # if we get a socket error, keep tryingx2 except (socket.error, socket.sslerror), e: log.log_me("A socket error occurred: %s, attempt #%s" % (e, attempt_count)) if attempt_count >= attempts: if len(e.args) > 1: raise up2dateErrors.CommunicationError( e.args[1]), None, sys.exc_info()[2] else: raise up2dateErrors.CommunicationError( e.args[0]), None, sys.exc_info()[2] else: failure = 1 except httplib.IncompleteRead: print "httplib.IncompleteRead" raise up2dateErrors.CommunicationError( "httplib.IncompleteRead"), None, sys.exc_info()[2]
def maybeUpdateVersion(): cfg = config.initUp2dateConfig() try: idVer = rpclib.xmlrpclib.loads(getSystemId())[0][0]['os_release'] except: # they may not even have a system id yet. return 0 systemVer = up2dateUtils.getVersion() if idVer != systemVer: s = rpcServer.getServer() try: newSystemId = rpcServer.doCall(s.registration.upgrade_version, getSystemId(), systemVer) except rpclib.Fault, f: raise up2dateErrors.CommunicationError(f.faultString) path = cfg["systemIdPath"] dir = path[:string.rfind(path, "/")] if not os.access(dir, os.W_OK): try: os.mkdir(dir) except: return 0 if not os.access(dir, os.W_OK): return 0 if os.access(path, os.F_OK): # already have systemid file there; let's back it up savePath = path + ".save" try: os.rename(path, savePath) except: return 0 f = open(path, "w") f.write(newSystemId) f.close() try: os.chmod(path, 0600) except: pass
class Up2datePackageSource(PackageSource): def __init__(self, server, proxyHost, cacheObject = None): self.s = server PackageSource.__init__(self, cacheObject = cacheObject) # fetch it from the network, no caching of any sort def getHeader(self, pkg, lite = None, msgCallback = None, progressCallback = None): hdr = None try: ret = self.s.up2date.header(up2dateAuth.getSystemId(), pkg) except KeyboardInterrupt: raise up2dateErrors.CommunicationError("Connection aborted by the user") except (socket.error, socket.sslerror), e: if len(e.args) > 1: raise up2dateErrors.CommunicationError(e.args[1]) else: raise up2dateErrors.CommunicationError(e.args[0]) except rpclib.ProtocolError, e: raise up2dateErrors.CommunicationError(e.errmsg)
def doCall(method, *args, **kwargs): log = up2dateLog.initLog() log.log_debug("rpcServer: Calling XMLRPC %s" % method.__dict__['_Method__name']) cfg = config.initUp2dateConfig() ret = None attempt_count = 1 try: attempts = int(cfg["networkRetries"]) except ValueError: attempts = 1 if attempts <= 0: attempts = 1 while 1: failure = 0 ret = None try: ret = method(*args, **kwargs) except KeyboardInterrupt: raise (up2dateErrors.CommunicationError( _("Connection aborted by the user")), None, sys.exc_info()[2]) # if we get a socket error, keep tryingx2 except (socket.error, socket.sslerror): log.log_me("A socket error occurred: %s, attempt #%s" % (sys.exc_info()[1], attempt_count)) if attempt_count >= attempts: if len(e.args) > 1: raise (up2dateErrors.CommunicationError(e.args[1]), None, sys.exc_info()[2]) else: raise (up2dateErrors.CommunicationError(e.args[0]), None, sys.exc_info()[2]) else: failure = 1 except httplib.IncompleteRead: print "httplib.IncompleteRead" raise (up2dateErrors.CommunicationError("httplib.IncompleteRead"), None, sys.exc_info()[2]) except urllib2.HTTPError: e = sys.exc_info()[1] msg = "\nAn HTTP error occurred:\n" msg = msg + "URL: %s\n" % e.filename msg = msg + "Status Code: %s\n" % e.code msg = msg + "Error Message: %s\n" % e.msg log.log_me(msg) raise (up2dateErrors.CommunicationError(msg), None, sys.exc_info()[2]) except xmlrpclib.ProtocolError: e = sys.exc_info()[1] log.log_me("A protocol error occurred: %s , attempt #%s," % (e.errmsg, attempt_count)) if e.errcode == 404: log.log_me("Could not find URL, %s" % (e.url)) log.log_me("Check server name and/or URL, then retry\n") (errCode, errMsg) = rpclib.reportError(e.headers) reset = 0 if abs(errCode) == 34: log.log_me("Auth token timeout occurred\n errmsg: %s" % errMsg) # this calls login, which in tern calls doCall (ie, # this function) but login should never get a 34, so # should be safe from recursion up2dateAuth.updateLoginInfo() # the servers are being throttle to pay users only, catch the # exceptions and display a nice error message if abs(errCode) == 51: log.log_me(_("Server has refused connection due to high load")) raise (up2dateErrors.CommunicationError(e.errmsg), None, sys.exc_info()[2]) # if we get a 404 from our server, thats pretty # fatal... no point in retrying over and over. Note that # errCode == 17 is specific to our servers, if the # serverURL is just pointing somewhere random they will # get a 0 for errcode and will raise a CommunicationError if abs(errCode) == 17: #in this case, the args are the package string, so lets try to # build a useful error message if type(args[0]) == type([]): pkg = args[0] else: pkg = args[1] if type(pkg) == type([]): pkgName = "%s-%s-%s.%s" % (pkg[0], pkg[1], pkg[2], pkg[4]) else: pkgName = pkg msg = "File Not Found: %s\n%s" % (pkgName, errMsg) log.log_me(msg) raise (up2dateErrors.FileNotFoundError(msg), None, sys.exc_info()[2]) if not reset: if attempt_count >= attempts: raise (up2dateErrors.CommunicationError(e.errmsg), None, sys.exc_info()[2]) else: failure = 1 except xmlrpclib.ResponseError: raise (up2dateErrors.CommunicationError( "Broken response from the server."), None, sys.exc_info()[2]) if ret != None: break else: failure = 1 if failure: # rest for five seconds before trying again time.sleep(5) attempt_count = attempt_count + 1 if attempt_count > attempts: raise up2dateErrors.CommunicationError( "The data returned from the server was incomplete") return ret
def __exception_from_fault(self, fault): if fault.faultCode == -3: # This username is already taken, or the password is incorrect. exception = up2dateErrors.AuthenticationOrAccountCreationError( fault.faultString) elif fault.faultCode == -2: # Invalid username and password combination. exception = up2dateErrors.AuthenticationOrAccountCreationError( fault.faultString) elif fault.faultCode == -1: exception = up2dateErrors.UnknownMethodException(fault.faultString) elif fault.faultCode == -13: # Username is too short. exception = up2dateErrors.LoginMinLengthError(fault.faultString) elif fault.faultCode == -14: # too short password exception = up2dateErrors.PasswordMinLengthError(fault.faultString) elif fault.faultCode == -15: # bad chars in username exception = up2dateErrors.ValidationError(fault.faultString) elif fault.faultCode == -16: # Invalid product registration code. # TODO Should this really be a validation error? exception = up2dateErrors.ValidationError(fault.faultString) elif fault.faultCode == -19: # invalid exception = up2dateErrors.NoBaseChannelError(fault.faultString) elif fault.faultCode == -31: # No entitlement exception = up2dateErrors.InsuffMgmntEntsError(fault.faultString) elif fault.faultCode == -36: # rhnException.py says this means "Invalid action." # TODO find out which is right exception = up2dateErrors.PasswordError(fault.faultString) elif abs(fault.faultCode) == 49: exception = up2dateErrors.AbuseError(fault.faultString) elif abs(fault.faultCode) == 60: exception = up2dateErrors.AuthenticationTicketError( fault.faultString) elif abs(fault.faultCode) == 105: exception = up2dateErrors.RhnUuidUniquenessError(fault.faultString) elif fault.faultCode == 99: exception = up2dateErrors.DelayError(fault.faultString) elif abs(fault.faultCode) == 91: exception = up2dateErrors.InsuffMgmntEntsError(fault.faultString) elif fault.faultCode == -106: # Invalid username. exception = up2dateErrors.ValidationError(fault.faultString) elif fault.faultCode == -600: # Invalid username. exception = up2dateErrors.InvalidRegistrationNumberError( fault.faultString) elif fault.faultCode == -601: # No entitlements associated with given hardware info exception = up2dateErrors.NotEntitlingError(fault.faultString) elif fault.faultCode == -602: # No entitlements associated with reg num exception = up2dateErrors.NotEntitlingError(fault.faultString) elif fault.faultCode == -2001 or fault.faultCode == -700: exception = up2dateErrors.AuthenticationOrAccountCreationError( fault.faultString) elif fault.faultCode == -701: exception = up2dateErrors.PasswordMaxLengthError(fault.faultString) elif fault.faultCode == -61: exception = up2dateErrors.ActivationKeyUsageLimitError( fault.faultString) elif fault.faultCode == -5: exception = up2dateErrors.UnableToCreateUser(fault.faultString) else: exception = up2dateErrors.CommunicationError(fault.faultString) return exception
msgCallback = None, progressCallback = None): hdr = None try: ret = self.s.up2date.header(up2dateAuth.getSystemId(), pkg) except KeyboardInterrupt: raise up2dateErrors.CommunicationError("Connection aborted by the user") except (socket.error, socket.sslerror), e: if len(e.args) > 1: raise up2dateErrors.CommunicationError(e.args[1]) else: raise up2dateErrors.CommunicationError(e.args[0]) except rpclib.ProtocolError, e: raise up2dateErrors.CommunicationError(e.errmsg) except rpclib.ResponseError: raise up2dateErrors.CommunicationError("Broken response from the server."); except rpclib.Fault, f: raise up2dateErrors.CommunicationError(f.faultString) bin = ret[0] hdr = rpmUtils.readHeaderBlob(bin.data) rpmSourceUtils.saveHeader(hdr) self.headerCache["%s-%s-%s.%s" % (hdr['name'], hdr['version'], hdr['release'], hdr['arch'])] = hdr return hdr def callback(total, complete): print "-- %s bytes of %s" % (total, complete)
raise up2dateErrors.CommunicationError( e.args[0]), None, sys.exc_info()[2] else: failure = 1 except httplib.IncompleteRead: print "httplib.IncompleteRead" raise up2dateErrors.CommunicationError( "httplib.IncompleteRead"), None, sys.exc_info()[2] except urllib2.HTTPError, e: msg = "\nAn HTTP error occurred:\n" msg = msg + "URL: %s\n" % e.filename msg = msg + "Status Code: %s\n" % e.code msg = msg + "Error Message: %s\n" % e.msg log.log_me(msg) raise up2dateErrors.CommunicationError( msg), None, sys.exc_info()[2] except xmlrpclib.ProtocolError, e: log.log_me("A protocol error occurred: %s , attempt #%s," % (e.errmsg, attempt_count)) if e.errcode == 404: log.log_me("Could not find URL, %s" % (e.url)) log.log_me("Check server name and/or URL, then retry\n") (errCode, errMsg) = rpclib.reportError(e.headers) reset = 0 if abs(errCode) == 34: log.log_me("Auth token timeout occurred\n errmsg: %s" % errMsg) # this calls login, which in tern calls doCall (ie, # this function) but login should never get a 34, so
raise up2dateErrors.CommunicationError(e.args[1]) else: raise up2dateErrors.CommunicationError(e.args[0]) else: failure = 1 except httplib.IncompleteRead: print "httplib.IncompleteRead" raise up2dateErrors.CommunicationError("httplib.IncompleteRead") except urllib2.HTTPError, e: msg = "\nAn HTTP error occurred:\n" msg = msg + "URL: %s\n" % e.filename msg = msg + "Status Code: %s\n" % e.code msg = msg + "Error Message: %s\n" % e.msg log.log_me(msg) raise up2dateErrors.CommunicationError(msg) except rpclib.ProtocolError, e: log.log_me("A protocol error occurred: %s , attempt #%s," % (e.errmsg, attempt_count)) (errCode, errMsg) = rpclib.reportError(e.headers) reset = 0 if abs(errCode) == 34: log.log_me("Auth token timeout occurred\n errmsg: %s" % errMsg) # this calls login, which in tern calls doCall (ie, # this function) but login should never get a 34, so # should be safe from recursion rd = repoDirector.initRepoDirector() rd.updateAuthInfo()