Exemple #1
0
    def execute(
        self,
        name,
        parameter_json,
        raise_exception=False,
        transaction_id="",
        transaction_id_key="",
    ):
        parameters = json.loads(parameter_json)
        try:
            if transaction_id_key:
                with transaction(
                        name,
                        parameters,
                        transaction_id=transaction_id,
                        transaction_id_key=transaction_id_key,
                ) as transaction_id:
                    logger.info("Dummy log inside transaction")
                    if raise_exception:
                        raise RuntimeError("Command Failed!!!")
            else:
                with transaction(
                        name, parameters,
                        transaction_id=transaction_id) as transaction_id:
                    logger.info("Dummy log inside transaction")
                    if raise_exception:
                        raise RuntimeError("Command Failed!!!")
        except RuntimeError:
            pass
        else:
            assert not raise_exception, "Expected RuntimeError propogate out of context handler."

        self.transaction_id = transaction_id
Exemple #2
0
 def CallWithLogger(self, argin):
     self.logger.info("CallWithLogger, low_level")
     argin_json = json.loads(argin)
     with transaction(
         "CallWithLogger, low_level", argin_json, logger=self.logger
     ):
         self.logger.info("CallWithLogger, low_level")
Exemple #3
0
 def CallRaisesException(self, argin):
     argin_json = json.loads(argin)
     self.logger.info("Logger %s", self.logger)
     with transaction(
         "CallRaisesException", argin_json, logger=self.logger
     ):
         self.logger.info("CallRaisesException in context")
         raise RuntimeError("An exception has occured")
Exemple #4
0
    def CallWithContext(self, argin):
        argin_json = json.loads(argin)
        self.logger.info("Logger %s", self.logger)
        with transaction(
            "CallWithContext", argin_json, logger=self.logger
        ) as transaction_id:
            self.logger.info("CallWithContext in context")
            argin_json["transaction_id"] = transaction_id
            argin = json.dumps(argin_json)
            self.child_device.Scan(argin)
        self.logger.info("CallWithContext out of context")

        with transaction("CallWithContext", argin_json) as transaction_id:
            self.logger.info("CallWithContext in context no logger")
            argin_json["transaction_id"] = transaction_id
            argin = json.dumps(argin_json)
            self.child_device.Scan(argin)
        self.logger.info("CallWithContext out of context no logger")
Exemple #5
0
 def CallWithLogger(self, argin):
     self.logger.info("CallWithLogger, mid 2")
     argin_json = json.loads(argin)
     with transaction(
         "CallWithLogger, mid 2", argin_json, logger=self.logger
     ) as transaction_id:
         self.logger.info("CallWithLogger, mid 2")
         argin_json["transaction_id"] = transaction_id
         self.low_level_device.CallWithLogger(json.dumps(argin_json))
Exemple #6
0
 def CallWithoutLogger(self, argin):
     self.logger.info("CallWithoutLogger, top_level")
     argin_json = json.loads(argin)
     with transaction(
         "CallWithoutLogger, top_level", argin_json
     ) as transaction_id:
         self.logger.info("CallWithoutLogger, top_level")
         argin_json["transaction_id"] = transaction_id
         cmd_data = DeviceData()
         cmd_data.insert(DevString, json.dumps(argin_json))
         self.mid_level_nodes.command_inout("CallWithoutLogger", cmd_data)
Exemple #7
0
        def wrapper(self, params_json="{}"):
            name = command_method.__name__
            LOG.debug("command %s device %s", name, type(self).__name__)
            params = json.loads(params_json)

            with transaction(name, params, logger=LOG) as txn_id:
                with log_transaction_id(txn_id):
                    LOG.debug("Execute command %s", name)
                    if argdesc:
                        ret = command_method(self, txn_id, params_json)
                    else:
                        ret = command_method(self, txn_id)
            return ret