def activateValueSetFunctor(self, phase, data): for logFunc in self._log("activate-value-set-functor").debug3Func(): logFunc( "activateValueSetFunctor(): called, myIsActive=%s, phase=%s, data=%s, candidate=%s, running=%s, functor=%s", self.myIsActive, phase, data, self.myCandidateData, self.myRunningData, self.myValueSetFunctor) res = ReturnCodes.kOk if (self.myIsActive): if (self.myValueSetFunctor): timeoutGuard = TimeoutGuard( self._log, '%s-value-set-functor-%s' % (self.myKeyPath, phase), self.getFunctorTimeoutForPhase(self.VALUE_SET_FUNCTOR, phase), self.getFunctorMildTimeoutForPhase(self.VALUE_SET_FUNCTOR, phase)) try: res = self.myValueSetFunctor(phase, data) except: for logFunc in self._log( "activate-value-set-functor-functor-exception" ).exceptionFunc(): logFunc( "functor raised an exception. phase=%s, data=%s", phase, data) raise timeoutGuard.checkAndLog("application problem: functor=%s" % self.myValueSetFunctor.__name__) if (res != ReturnCodes.kOk): if (phase.getConfdPhase() == TrxPhase.kPrepare): for logFunc in self._log( "activate-value-set-functor-failed-prepare" ).noticeFunc(): logFunc( "activateValueSetFunctor(): functor failed, phase=%s, data=%s, res=%s", phase, data, res) self.myDomain.setConfigErrorStr(self.myConfigErrorStr) else: for logFunc in self._log( "activate-value-set-functor-failed").errorFunc( ): logFunc( "activateValueSetFunctor(): functor failed, phase=%s, data=%s, res=%s", phase, data, res) return ReturnCodes.kGeneralError return res
def activateDeleteExportListFunctor(self, phase): for logFunc in self._log( "activate-delete-exportlist-functor").debug3Func(): logFunc("activateDeleteExportListFunctor(): called, phase=%s", phase) if (self.myIsActive): if (self.myDeleteExportListFunctor): timeoutGuard = TimeoutGuard( self._log, '%s-delete-exportlist-functor-%s' % (self.myKeyPath, phase), self.getFunctorTimeoutForPhase( self.EXPORTLIST_DELETE_FUNCTOR, phase), self.getFunctorMildTimeoutForPhase( self.EXPORTLIST_DELETE_FUNCTOR, phase)) try: res = self.myDeleteExportListFunctor(phase) except: for logFunc in self._log( "activate-delete-exportlist-functor-exception" ).exceptionFunc(): logFunc( "ExportList's delete functor raised an exception. phase=%s", phase) raise timeoutGuard.checkAndLog( "application problem: functor=%s" % self.myDeleteExportListFunctor.__name__) if (res != ReturnCodes.kOk): if (phase.getConfdPhase() == TrxPhase.kPrepare): for logFunc in self._log( "activate-delete-exportlist-functor-functor-failed-prepare" ).noticeFunc(): logFunc( "activateDeleteExportListFunctor(): functor failed, phase=%s", phase) self.myDomain.setConfigErrorStr(self.myConfigErrorStr) else: for logFunc in self._log( "activate-delete-exportlist-functor-functor-failed" ).errorFunc(): logFunc( "activateDeleteExportListFunctor(): functor failed, phase=%s", phase) return ReturnCodes.kGeneralError return ReturnCodes.kOk
def handleGetRequest (self, trxContext, keyPath, operData): for logFunc in self._log("handle-get-request").debug3Func(): logFunc("called. trxContext=%s, keyPath=%s", trxContext, keyPath) res = self.setOperDataRequestedFields(operData, keyPath) if res != ReturnCodes.kOk: for logFunc in self._log("handle-get-request-set-oper-data-requested-fields-failed").errorFunc(): logFunc( "setOperDataRequestedFields() failed. keyPath=%s, trxContext=%s", keyPath, trxContext) return ReturnCodes.kGeneralError if self.myIsActive: if self.myGetObjectFunctor: timeoutGuardName = str(self.myKeyPath) + "-" + "get-object-functor"; timeoutGuard = TimeoutGuard(self._log, timeoutGuardName, self.getFunctorTimeout(self.GET_OBJ_FUNCTOR), self.getFunctorMildTimeout(self.GET_OBJ_FUNCTOR)) index = self.myKeyPath.getLen() - 0 for logFunc in self._log("handle-get-request-extracting-data").debug3Func(): logFunc( "index=%d, keyPath[index]=%s", index, keyPath.getAt(index)) keyPathValue = keyPath.getAt(index).getValue() if not AlarmNameType.isValidValue(keyPathValue): self._log("handle-get-request-extracting-key-illegal-enum-keyPathValue-failed")\ .error("illegal enum value %s for registered", keyPathValVarName) a.infra.process.processFatal("AlarmNameType.handle-get-request-extracting-key: illegal enum") registered = AlarmNameType.getByValue(keyPathValue) res = self.myGetObjectFunctor(trxContext, registered, operData) timeoutGuard.checkAndLog("application problem: functor=%s" % self.myGetObjectFunctor.__name__) if res != ReturnCodes.kOk: for logFunc in self._log("handle-get-request-functor-failed").errorFunc(): logFunc( "functor failed. keyPath=%s, trxContext=%s", keyPath, trxContext) return ReturnCodes.kGeneralError return ReturnCodes.kOk
def validateTrx(self, tctx, validationPoint, keypath, val): for logFunc in self._log("validate-trx").debug3Func(): logFunc("called. validationPoint=%s, keypath=%s, val=%s", validationPoint, keypath, val) if self.myIsActive: if self.validateTrxFunctor: timeoutGuard = TimeoutGuard( self._log, '%s-validate-trx-functor-%s' % (keypath, validationPoint), self.getFunctorTimeout(self.VALIDATE_TRX_FUNCTOR), self.getFunctorMildTimeout(self.VALIDATE_TRX_FUNCTOR)) try: res = self.validateTrxFunctor(tctx) except: for logFunc in self._log( "validate-trx-functor-exception").exceptionFunc(): logFunc( "functor raised an exception. tctx=%s, validationPoint=%s, keypath=%s", tctx, validationPoint, keypath) raise timeoutGuard.checkAndLog("application problem: functor=%s" % self.validateTrxFunctor.__name__) if res != ReturnCodes.kOk: for logFunc in self._log( "validate-trx-functor-failed").errorFunc(): logFunc( "functor failed. res=%s, validationPoint=%s, keypath=%s", res, validationPoint, keypath) return ReturnCodes.kGeneralError else: for logFunc in self._log( "validate-trx-functor-unset").errorFunc(): logFunc( "no validation functor set. rejecting the transaction. validationPoint=%s, keypath=%s", validationPoint, keypath) return ReturnCodes.kGeneralError return ReturnCodes.kOk else: #TODO (naamas) - add error string for logFunc in self._log("validate-trx-inactive").errorFunc(): logFunc( "Blinky node is inactive. validationPoint=%s, keypath=%s", validationPoint, keypath) return ReturnCodes.kGeneralError
def getCounters(self, tctx, operData): self._log("device-counters").debug3( "device %s: get counters was called. tctx=%s", self.runningOsName, tctx) if (time.time() - self.countersLastUpdateTime) < 1: # less than 1 sec # read from cache operData.copyDataFrom(self.countersOperData) self._log("device-counters-results-cache").debug3( "device %s: counters results=%s", self.runningOsName, operData) return ReturnCodes.kOk if self.parent.isLineEnabled(): rc = self.getLineCounters(tctx, operData) else: timeoutGuard = TimeoutGuard( self._log, '%s-get-os-counters' % (self.runningOsName), Device.TIMEOUT_MILI_SEC) rc = self.getOsCounters(tctx, operData) timeoutGuard.checkAndLog(self.getOsCounters) if rc != ReturnCodes.kOk: self._log("device-get-counters-fail").debug3( "%s: failed retrieve device counters", self.runningOsName) return ReturnCodes.kGeneralError # substract counters on clear if self.isFirstTrx is False: self._log("device-counters-original-data").debug4( "%s: get original counters oper data=%s", self.runningOsName, operData) for key, value in self.countersOnClear.__dict__.iteritems(): if type(value) is int: operData.__dict__[key] -= value # cache the counters self.countersLastUpdateTime = time.time() self.countersOperData.copyDataFrom(operData) self._log("device-counters-results").debug3( "device %s: counters results=%s", self.runningOsName, operData) return ReturnCodes.kOk
def handleGetRequest(self, trxContext, keyPath, operData): for logFunc in self._log("handle-get-request").debug3Func(): logFunc("called. trxContext=%s, keyPath=%s", trxContext, keyPath) res = self.setOperDataRequestedFields(operData, keyPath) if res != ReturnCodes.kOk: for logFunc in self._log( "handle-get-request-set-oper-data-requested-fields-failed" ).errorFunc(): logFunc( "setOperDataRequestedFields() failed. keyPath=%s, trxContext=%s", keyPath, trxContext) return ReturnCodes.kGeneralError if self.myIsActive: if self.myGetObjectFunctor: timeoutGuardName = str( self.myKeyPath) + "-" + "get-object-functor" timeoutGuard = TimeoutGuard( self._log, timeoutGuardName, self.getFunctorTimeout(self.GET_OBJ_FUNCTOR), self.getFunctorMildTimeout(self.GET_OBJ_FUNCTOR)) index = self.myKeyPath.getLen() - 0 for logFunc in self._log( "handle-get-request-extracting-data").debug3Func(): logFunc("index=%d, keyPath[index]=%s", index, keyPath.getAt(index)) keyPathValue = keyPath.getAt(index).getValue() list = keyPathValue res = self.myGetObjectFunctor(trxContext, list, operData) timeoutGuard.checkAndLog("application problem: functor=%s" % self.myGetObjectFunctor.__name__) if res != ReturnCodes.kOk: for logFunc in self._log( "handle-get-request-functor-failed").errorFunc(): logFunc("functor failed. keyPath=%s, trxContext=%s", keyPath, trxContext) return ReturnCodes.kGeneralError return ReturnCodes.kOk
def handleTrxElementCreate(self, trxElement, keyDepth, phase): for logFunc in self._log("handle-trx-element-create-details").debug3Func(): logFunc("handleTrxElementCreate(): called, element-key-path=%s, element-op-code=%s, keyDepth=%s, phase=%s", trxElement.getKeyPath(), trxElement.getOpCode(), keyDepth, phase) if (self.myIsActive): if (trxElement.getKeyPath().isTagEqual(keyDepth, self.ourNamespace, self.ourXmlTagHosts)): if (self.myCreateHostsFunctor): if (not self.myHosts): for logFunc in self._log("handle-trx-element-create-hosts-not-exist").debug3Func(): logFunc("handleTrxElementCreate(): hosts not exists, trxElement=%s, keyDepth=%s, phase=%s", trxElement, keyDepth, phase) return ReturnCodes.kGeneralError timeoutGuard = TimeoutGuard(self._log, '%s-create-hosts-functor-%s' % (self.myKeyPath, phase), self.getFunctorTimeoutForPhase(self.HOSTS_CREATE_FUNCTOR, phase), self.getFunctorMildTimeoutForPhase(self.HOSTS_CREATE_FUNCTOR, phase)) try: res = self.myCreateHostsFunctor(phase, self.myHosts) except: for logFunc in self._log("handle-trx-element-create-hosts-functor-exception").exceptionFunc(): logFunc("Hosts's create functor raised an exception. trxElement=%s, keyDepth=%s, phase=%s", trxElement, keyDepth, phase) raise timeoutGuard.checkAndLog("application problem: functor=%s" % self.myCreateHostsFunctor.__name__) if (res != ReturnCodes.kOk): if (phase.getConfdPhase() == TrxPhase.kPrepare): for logFunc in self._log("handle-trx-element-create-hosts-functor-failed-prepare").noticeFunc(): logFunc("handleTrxElementCreate(): hosts functor-failed-prepare, trxElement=%s, keyDepth=%s, phase=%s", trxElement, keyDepth, phase) self.myDomain.setConfigErrorStr(self.myConfigErrorStr) else: for logFunc in self._log("handle-trx-element-create-hosts-functor-failed").errorFunc(): logFunc("handleTrxElementCreate(): hosts functor-failed, trxElement=%s, keyDepth=%s, phase=%s", trxElement, keyDepth, phase) return ReturnCodes.kGeneralError pass return ReturnCodes.kOk
def activateNotifyTrxProgressFunctor(self, progress): for logFunc in self._log( "activate-notify-trx-progress-functor").debug2Func(): logFunc("Called, progress=%s", progress) if self.myIsActive: if self.myNotifyTrxProgressFunctor != None: timeoutGuard = TimeoutGuard( self._log, '%s-activate-notify-trx-progress-functor-%s' % (self.myKeyPath, progress), self.getFunctorTimeoutForProgress( self.TRX_PROGRESS_FUNCTOR, progress), self.getFunctorMildTimeoutForProgress( self.TRX_PROGRESS_FUNCTOR, progress)) res = self.myNotifyTrxProgressFunctor(progress) timeoutGuard.checkAndLog( "application problem: functor=%s" % self.myNotifyTrxProgressFunctor.__name__) if (res != ReturnCodes.kOk): if (not progress.isPrepare()): for logFunc in self._log( "activate-notify-trx-progress-functor-failed-prepare" ).errorFunc(): logFunc( "activateNotifyTrxProgressFunctor - functor failed - fatal. progress=%s, myConfigErrorStr=%s", progress, self.myConfigErrorStr) a.infra.process.processFatal( "notify trx progress functor failed during non-prepare progress" ) for logFunc in self._log( "activate-notify-trx-progress-functor-failed" ).noticeFunc(): logFunc( "activateNotifyTrxProgressFunctor - functor failed. progress=%s, myConfigErrorStr=%s", progress, self.myConfigErrorStr) self.myDomain.setConfigErrorStr(self.myConfigErrorStr) return ReturnCodes.kGeneralError for logFunc in self._log( "activate-notify-trx-progress-functor-done").debug2Func(): logFunc("Done, progress=%s", progress) return ReturnCodes.kOk
def activateDestroySelfFunctor(self, phase): for logFunc in self._log("activate-destroy-self-functor").debug2Func(): logFunc("Called, phase=%s", phase) if self.myIsActive: if self.myDestroySelfFunctor != None: timeoutGuard = TimeoutGuard( self._log, '%s-destroy-self-functor-functor-%s' % (self.myKeyPath, phase), self.getFunctorTimeoutForPhase(self.DESTROY_SELF_FUNCTOR, phase), self.getFunctorMildTimeoutForPhase( self.DESTROY_SELF_FUNCTOR, phase)) res = self.myDestroySelfFunctor(phase) timeoutGuard.checkAndLog("application problem: functor=%s" % self.myDestroySelfFunctor.__name__) if (res != ReturnCodes.kOk): if (phase.getConfdPhase() != TrxPhase.kPrepare): for logFunc in self._log( "activate-destroy-self-functor-failed-prepare" ).errorFunc(): logFunc( "activateDestroySelfFunctor - functor failed - fatal. phase=%s, myConfigErrorStr=%s", phase, self.myConfigErrorStr) a.infra.process.processFatal( "destroy self functor failed during non-prepare phase" ) for logFunc in self._log( "activate-destroy-self-functor-failed").noticeFunc( ): logFunc( "activateDestroySelfFunctor - functor failed. phase=%s, myConfigErrorStr=%s", phase, self.myConfigErrorStr) self.myDomain.setConfigErrorStr(self.myConfigErrorStr) return ReturnCodes.kGeneralError for logFunc in self._log( "activate-destroy-self-functor-done").debug2Func(): logFunc("Done, phase=%s", phase) return ReturnCodes.kOk
def getOsCounters(self, tctx, operData): if self.runningOsName is not None: self._log("eth-tool-show-statistics").debug3( "%s: show ethernet card statistics", self.runningOsName) timeoutGuard = TimeoutGuard( self._log, '%s-show-eth-statistics' % (self.runningOsName), Device.TIMEOUT_MILI_SEC) rc = EthTool.showEthStatistics(self._log, self.runningOsName) timeoutGuard.checkAndLog(EthTool.showEthStatistics) if not a.sys.net.lnx.common.Command.isReturnOk(rc): self._log("device-fail").error( "%s: failed getting ethernet card statistics", self.runningOsName) self.setOperErrorStr( tctx, "cannot get counters information: operation not permitted") return ReturnCodes.kGeneralError output = rc[1].splitlines() unsupportedFields = [] counterToSetDict = { "rx_pkts_nic": operData.setRxPktsNic, "tx_pkts_nic": operData.setTxPktsNic, "rx_bytes_nic": operData.setRxBytesNic, "tx_bytes_nic": operData.setTxBytesNic, "lsc_int": operData.setLscInt, "tx_busy": operData.setTxBusy, "non_eop_descs": operData.setNonEopDescs, "rx_no_buffer_count": operData.setRxNoBufferCount, "collisions": operData.setCollisions, "rx_over_errors": operData.setRxOverErrors, "rx_crc_errors": operData.setRxCrcErrors, "rx_frame_errors": operData.setRxFrameErrors, "hw_rsc_aggregated": operData.setHwRscAggregated, "hw_rsc_flushed": operData.setHwRscFlushed, "fdir_match": operData.setFdirMatch, "fdir_miss": operData.setFdirMiss, "rx_fifo_errors": operData.setRxFifoErrors, "rx_missed_errors": operData.setRxMissedErrors, "tx_aborted_errors": operData.setTxAbortedErrors, "tx_carrier_errors": operData.setTxCarrierErrors, "tx_fifo_errors": operData.setTxFifoErrors, "tx_heartbeat_errors": operData.setTxHeartbeatErrors, "tx_timeout_count": operData.setTxTimeoutCount, "tx_restart_queue": operData.setTxRestartQueue, "rx_long_length_errors": operData.setRxLongLengthErrors, "rx_short_length_errors": operData.setRxShortLengthErrors, "tx_flow_control_xon": operData.setTxFlowControlXon, "rx_flow_control_xon": operData.setRxFlowControlXon, "tx_flow_control_xoff": operData.setTxFlowControlXoff, "rx_flow_control_xoff": operData.setRxFlowControlXoff, "rx_csum_offload_errors": operData.setRxCsumOffloadErrors, "alloc_rx_page_failed": operData.setAllocRxPageFailed, "alloc_rx_buff_failed": operData.setAllocRxBuffFailed, "rx_no_dma_resources": operData.setRxNoDmaResources, "fcoe_bad_fccrc": operData.setFcoeBadFccrc, "rx_fcoe_dropped": operData.setRxFcoeDropped, "rx_fcoe_packets": operData.setRxFcoePackets, "rx_fcoe_dwords": operData.setRxFcoeDwords, "tx_fcoe_packets": operData.setTxFcoePackets, "tx_fcoe_dwords": operData.setTxFcoeDwords } # set eth tool counters for line in output[1:]: (key, value) = line.split(":", 1) key = key.strip() value = value.strip() self._log("device-new-field").debug4("%s: set new field - %s", self.runningOsName, key) setFunctor = counterToSetDict.get(key, None) if setFunctor is not None: intValue = int(value) setFunctor(intValue) self._log("device-set-field").debug4( "%s: set field - %s=%s", self.runningOsName, key, intValue) else: unsupportedFields.append(key) if len(unsupportedFields) > 0: self._log("device-field-unsupported").debug2( "%s: contains unsupported fields - %s", self.runningOsName, unsupportedFields) return ReturnCodes.kOk