def testUpdateLoginInfoSingletonWorks(self): "Verify that up2dateAuth.updateLoginInfo returns the proper auth info every time" ret1 = up2dateAuth.updateLoginInfo() import repoDirector rd = repoDirector.initRepoDirector() ret2 = up2dateAuth.updateLoginInfo() self.__verifyTokens(rd)
def _testRhnLogin(self): try: up2dateAuth.updateLoginInfo() return True except up2dateErrors.ServerCapabilityError, e: print e return False
def __ncCallback(self): t = time.time() if (self.authtime - t) < 60: up2dateAuth.updateLoginInfo() self.__setupRhnHttpHeaders() self.nc.setHeaders(self.http_headers, self.reponame) self.authtime = time.time() + int(float(self.http_headers['X-RHN-Auth-Expire-Offset']))
def _testRhnLogin(self): try: up2dateAuth.updateLoginInfo() return True except up2dateErrors.ServerCapabilityError: print sys.exc_info()[1] return False except up2dateErrors.AuthenticationError: return False except up2dateErrors.RhnServerException: log = up2dateLog.initLog() log.log_me('There was a RhnServerException while testing login:\n') log.log_exception(*sys.exc_info()) return False
def _testRhnLogin(self): try: up2dateAuth.updateLoginInfo() return True except up2dateErrors.ServerCapabilityError: print(sys.exc_info()[1]) return False except up2dateErrors.AuthenticationError: return False except up2dateErrors.RhnServerException: log = up2dateLog.initLog() log.log_me('There was a RhnServerException while testing login:\n') log.log_exception(*sys.exc_info()) return False
def testUp2dateLoginInfoWorks(self): "Verify that up2dateAuth.updateLoginInfo retuns a working authToken" import repoDirector rd = repoDirector.initRepoDirector() ret2 = up2dateAuth.updateLoginInfo() self.__verifyTokens(rd)
def testUpdateLoginInfoCredsType(self): "Verify that up2dateAuth.updateLoginInfo returns login credentials in a dict" ret = up2dateAuth.updateLoginInfo() if type(ret) == type({}): if not ret.has_key('X-RHN-Auth'): self.fail("Expected a dict containing a X-RHN-AUTH header, didnt get it") else: self.fail("Expected a dict containing headers, but the return is not a dict")
def __run_remote_actions(self): # the list of caps the client needs caps = capabilities.Capabilities() status_report = CheckCli.__build_status_report() action = self.__get_action(status_report) while action != "" and action != {}: self.__verify_server_capabilities(caps) if self.is_valid_action(action): try: up2dateAuth.updateLoginInfo() except up2dateErrors.ServerCapabilityError: print(sys.exc_info()[1]) sys.exit(1) self.handle_action(action) action = self.__get_action(status_report)
def __run_remote_actions(self): # the list of caps the client needs caps = capabilities.Capabilities() status_report = CheckCli.__build_status_report() action = self.__get_action(status_report) while action != "" and action != {}: self.__verify_server_capabilities(caps) if self.is_valid_action(action): try: up2dateAuth.updateLoginInfo() except up2dateErrors.ServerCapabilityError, e: print e sys.exit(1) self.handle_action(action) action = self.__get_action(status_report)
def testUpdateLoginInfoSingleton(self): "Verify that up2dateAuth.updateLoginInfo returns the proper auth info" # test for bugs #124335, #115385 ret1 = up2dateAuth.updateLoginInfo() ret2 = up2dateAuth.updateLoginInfo() assert ret1 == ret2
def updateAuthInfo(self): li = up2dateAuth.updateLoginInfo() self._loginInfo = li serverSettings = ServerSettings() self.s = getGETServer(li, serverSettings)
def updateAuthInfo(self): li = up2dateAuth.updateLoginInfo() self._loginInfo=li serverSettings = ServerSettings() self.s = getGETServer(li, serverSettings)
def setUp(self): up2dateAuth.updateLoginInfo() print up2dateAuth.loginInfo self.__setupData() self._realSetup("8.0-workstation-i386-1")
def testUpdateLoginInfo(self): "test that up2dateAuth.up2dateLoginInfo works without exceptions" ret = up2dateAuth.updateLoginInfo()
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_with_tb( up2dateErrors.CommunicationError( _("Connection aborted by the user"))) # if we get a socket error, keep tryingx2 except (socket.error, SSL.socket_error): log.log_me("A socket error occurred: %s, attempt #%s" % (sys.exc_info()[1], attempt_count)) if attempt_count >= attempts: e = sys.exc_info()[1] if len(e.args) > 1: raise_with_tb(up2dateErrors.CommunicationError(e.args[1])) else: raise_with_tb(up2dateErrors.CommunicationError(e.args[0])) else: failure = 1 except httplib.IncompleteRead: print("httplib.IncompleteRead") raise_with_tb( up2dateErrors.CommunicationError("httplib.IncompleteRead")) 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_with_tb(up2dateErrors.CommunicationError(msg)) 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 from up2date_client import up2dateAuth 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_with_tb(up2dateErrors.CommunicationError(e.errmsg)) # 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_with_tb(up2dateErrors.FileNotFoundError(msg)) if not reset: if attempt_count >= attempts: raise_with_tb(up2dateErrors.CommunicationError(e.errmsg)) else: failure = 1 except xmlrpclib.ResponseError: raise_with_tb( up2dateErrors.CommunicationError( "Broken response from the server.")) 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
try: print ' list', for i in obj: print i, except: print 'FAILED' elif '__module__' in dir(obj): print 'DEBUGPRINT module %s' % obj.__module__ print ' repr', obj print ' dir', dir(obj) else: print 'DEBUGPRINT unknown ', dir(obj) print ' repr', obj print ' dir', dir(obj) print registered = getSystemId('rhel3as-i386') up2dateAuth.updateLoginInfo() cfg = config.initUp2dateConfig() repos = repoDirector.initRepoDirector() ### Print channels debugprint(rhnChannel) debugprint(rhnChannel.rhnChannelList()) debugprint(rhnChannel.rhnChannelList().list) debugprint(rhnChannel.getChannels(force=1)) debugprint(rhnChannel.getChannels(force=1).list) for channel in rhnChannel.rhnChannelList().list: print channel['label'], print for channel in rhnChannel.getChannels(force=1).list: print channel['label'], print
print i, except: print 'FAILED' elif '__module__' in dir(obj): print 'DEBUGPRINT module %s' % obj.__module__ print ' repr', obj print ' dir', dir(obj) else: print 'DEBUGPRINT unknown ', dir(obj) print ' repr', obj print ' dir', dir(obj) print registered = getSystemId('rhel3as-i386') up2dateAuth.updateLoginInfo() cfg = config.initUp2dateConfig() repos = repoDirector.initRepoDirector() ### Print channels debugprint(rhnChannel) debugprint(rhnChannel.rhnChannelList()) debugprint(rhnChannel.rhnChannelList().list) debugprint(rhnChannel.getChannels(force=1)) debugprint(rhnChannel.getChannels(force=1).list) for channel in rhnChannel.rhnChannelList().list: print channel['label'], print for channel in rhnChannel.getChannels(force=1).list: print channel['label'],
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_with_tb(up2dateErrors.CommunicationError(_( "Connection aborted by the user"))) # if we get a socket error, keep tryingx2 except (socket.error, SSL.socket_error): log.log_me("A socket error occurred: %s, attempt #%s" % ( sys.exc_info()[1], attempt_count)) if attempt_count >= attempts: e = sys.exc_info()[1] if len(e.args) > 1: raise_with_tb(up2dateErrors.CommunicationError(e.args[1])) else: raise_with_tb(up2dateErrors.CommunicationError(e.args[0])) else: failure = 1 except httplib.IncompleteRead: print("httplib.IncompleteRead") raise_with_tb(up2dateErrors.CommunicationError("httplib.IncompleteRead")) 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_with_tb(up2dateErrors.CommunicationError(msg)) 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 from up2date_client import up2dateAuth 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_with_tb(up2dateErrors.CommunicationError(e.errmsg)) # 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_with_tb(up2dateErrors.FileNotFoundError(msg)) if not reset: if attempt_count >= attempts: raise_with_tb(up2dateErrors.CommunicationError(e.errmsg)) else: failure = 1 except xmlrpclib.ResponseError: raise_with_tb(up2dateErrors.CommunicationError( "Broken response from the server.")) 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 run(self): log.log_debug("Running %s" % self.name) self.pwin.draw() self.screen.refresh() reg_info = None try: # reg_info dict contains: 'system_id', 'channels', # 'failed_channels', 'slots', 'failed_slots' log.log_debug('other is %s' % str(self.tui.other)) reg_info = rhnreg.registerSystem2(self.tui.userName, self.tui.password, self.tui.profileName, other = self.tui.other) reg_info = reg_info.rawDict systemId = sstr(reg_info['system_id']) except up2dateErrors.CommunicationError: e = sys.exc_info()[1] FatalErrorWindow(self.screen, _("Problem registering system:\n") + e.errmsg) except up2dateErrors.RhnUuidUniquenessError: e = sys.exc_info()[1] FatalErrorWindow(self.screen, _("Problem registering system:\n") + e.errmsg) except up2dateErrors.InsuffMgmntEntsError: e = sys.exc_info()[1] FatalErrorWindow(self.screen, _("Problem registering system:\n") + e.errmsg) except up2dateErrors.RegistrationDeniedError: e = sys.exc_info()[1] FatalErrorWindow(self.screen, _("Problem registering system:\n") + e.errmsg) except up2dateErrors.ActivationKeyUsageLimitError: FatalErrorWindow(self.screen, ACT_KEY_USAGE_LIMIT_ERROR) except: log.log_exception(*sys.exc_info()) FatalErrorWindow(self.screen, _("Problem registering system.")) # write the system id out. if not rhnreg.writeSystemId(systemId): FatalErrorWindow(self.screen, _("Problem writing out system id to disk.")) self.setScale(1, 4) # include the info from the oeminfo file as well self.oemInfo = rhnreg.getOemInfo() self.setScale(2, 4) # maybe upload hardware profile if self.tui.includeHardware: try: rhnreg.sendHardware(systemId, self.tui.hardware) except up2dateErrors.CommunicationError: e = sys.exc_info()[1] FatalErrorWindow(self.screen, _("Problem sending hardware profile:\n") + e.errmsg) except: log.log_exception(*sys.exc_info()) FatalErrorWindow(self.screen, _("Problem sending hardware profile.")) self.setScale(3, 4) # build up package list if necessary if self.tui.includePackages: try: rhnreg.sendPackages(systemId, self.tui.selectedPackages) except up2dateErrors.CommunicationError: e = sys.exc_info()[1] FatalErrorWindow(self.screen, _("Problem sending package list:\n") + e.errmsg) except: log.log_exception(*sys.exc_info()) FatalErrorWindow(self.screen, _("Problem sending package list.")) li = None try: li = up2dateAuth.updateLoginInfo() except up2dateErrors.InsuffMgmntEntsError: FatalErrorWindow(self.screen, sys.exc_info()[1]) # Send virtualization information to the server. rhnreg.sendVirtInfo(systemId) # enable yum-rhn-plugin / dnf-plugin-spacewalk try: self.tui.pm_plugin_present, self.tui.pm_plugin_conf_changed = rhnreg.pluginEnable() except IOError: e = sys.exc_info()[1] WarningWindow(self.screen, _("Could not open %s\n%s is not enabled.\n") % (PM_PLUGIN_CONF, PM_PLUGIN_NAME) + e.errmsg) self.tui.pm_plugin_conf_error = 1 rhnreg.spawnRhnCheckForUI() self.setScale(4, 4) # Pop the pwin (Progress bar window) self.screen.popWindow() self.tui.reg_info = reg_info return "next"