def on_mdp_request(self, msg): """ Handle Requests over MQ @param msg : MQ req message """ try: with self._db.session_scope(): # Plugin handles MQ Req/rep also Plugin.on_mdp_request(self, msg) # configuration if msg.get_action() == "config.get": self._mdp_reply_config_get(msg) elif msg.get_action() == "config.set": self._mdp_reply_config_set(msg) elif msg.get_action() == "config.delete": self._mdp_reply_config_delete(msg) # devices list elif msg.get_action() == "device.get": self._mdp_reply_devices_result(msg) # device get params elif msg.get_action() == "device.params": self._mdp_reply_devices_params_result(msg) # device create elif msg.get_action() == "device.create": self._mdp_reply_devices_create_result(msg) # device delete elif msg.get_action() == "device.delete": self._mdp_reply_devices_delete_result(msg) except: msg = "Error while processing request. Message is : {0}. Error is : {1}".format(msg, traceback.format_exc()) self.log.error(msg)
def __init__(self): Plugin.__init__(self, name='scenario', log_prefix='core_') ### check that needed services are up on MQ side cli = MQSyncReq(zmq.Context()) mq_services = None while mq_services == None or 'xplgw' not in mq_services: mq_services_raw = cli.rawrequest('mmi.services', '', timeout=10) if mq_services_raw != None: mq_services = str(mq_services_raw[0]).replace(" ", "").split(",") self.log.info("Checking for MQ services : {0}".format(mq_services)) if mq_services == None or 'xplgw' not in mq_services: self.log.debug( "Needed MQ services not yet available : waiting") time.sleep(3) self.log.info("Needed MQ services available : continuing startup") ### start the scenario stuff self._backend = ScenarioManager(self.log) self.add_stop_cb(self.end) self.add_stop_cb(self.shutdown) self.log.info( u"Scenario Frontend and Manager initialized, let's wait for some work." ) self.ready()
def __init__(self): Plugin.__init__(self, name = 'scenario') self._backend = ScenarioManager(self.log) self.add_stop_cb(self.end) self.add_stop_cb(self.shutdown) self.log.info(u"Scenario Frontend and Manager initialized, let's wait for some work.") self.ready()
def __init__(self): Plugin.__init__(self, name='scenario') self._backend = ScenarioManager(self.log) self.add_stop_cb(self.end) self.add_stop_cb(self.shutdown) self.log.info( u"Scenario Frontend and Manager initialized, let's wait for some work." ) self.ready()
def __init__(self): ''' Initialize database and xPL connection ''' Plugin.__init__(self, 'dbmgr', log_prefix='core_') # Already done in Plugin #MQRep.__init__(self, zmq.Context(), 'dbmgr') self.log.debug(u"Init database_manager instance") # Check for database connexion self._db = DbHelper() with self._db.session_scope(): # TODO : move in a function and use it (also used in dbmgr) nb_test = 0 db_ok = False while not db_ok and nb_test < DATABASE_CONNECTION_NUM_TRY: nb_test += 1 try: self._db.list_user_accounts() db_ok = True except: msg = "The database is not responding. Check your configuration of if the database is up. Test {0}/{1}. The error while trying to connect to the database is : {2}".format( nb_test, DATABASE_CONNECTION_NUM_TRY, traceback.format_exc()) self.log.error(msg) msg = "Waiting for {0} seconds".format( DATABASE_CONNECTION_WAIT) self.log.info(msg) time.sleep(DATABASE_CONNECTION_WAIT) if nb_test >= DATABASE_CONNECTION_NUM_TRY: msg = "Exiting dbmgr!" self.log.error(msg) self.force_leave() return msg = "Connected to the database" self.log.info(msg) try: self._engine = self._db.get_engine() except: self.log.error( u"Error while starting database engine : {0}".format( traceback.format_exc())) self.force_leave() return self.ready()
def __init__(self): ''' Initialize database and xPL connection ''' Plugin.__init__(self, 'dbmgr', log_prefix='core_') # Already done in Plugin #MQRep.__init__(self, zmq.Context(), 'dbmgr') self.log.debug(u"Init database_manager instance") # Check for database connexion self._db = DbHelper() with self._db.session_scope(): # TODO : move in a function and use it (also used in dbmgr) nb_test = 0 db_ok = False while not db_ok and nb_test < DATABASE_CONNECTION_NUM_TRY: nb_test += 1 try: self._db.list_user_accounts() db_ok = True except: msg = "The database is not responding. Check your configuration of if the database is up. Test {0}/{1}. The error while trying to connect to the database is : {2}".format(nb_test, DATABASE_CONNECTION_NUM_TRY, traceback.format_exc()) self.log.error(msg) msg = "Waiting for {0} seconds".format(DATABASE_CONNECTION_WAIT) self.log.info(msg) time.sleep(DATABASE_CONNECTION_WAIT) if nb_test >= DATABASE_CONNECTION_NUM_TRY: msg = "Exiting dbmgr!" self.log.error(msg) self.force_leave() return msg = "Connected to the database" self.log.info(msg) try: self._engine = self._db.get_engine() except: self.log.error(u"Error while starting database engine : {0}".format(traceback.format_exc())) self.force_leave() return self.ready()
def __init__(self): Plugin.__init__(self, name = 'scenario') ### check that needed services are up on MQ side cli = MQSyncReq(zmq.Context()) mq_services = None while mq_services == None or 'xplgw' not in mq_services: mq_services_raw = cli.rawrequest('mmi.services', '', timeout=10) if mq_services_raw != None: mq_services = mq_services_raw[0].replace(" ", "").split(",") self.log.info("Checking for MQ services : {0}".format(mq_services)) if mq_services == None or 'xplgw' not in mq_services: self.log.debug("Needed MQ services not yet available : waiting") time.sleep(3) self.log.info("Needed MQ services available : continuing startup") ### start the scenario stuff self._backend = ScenarioManager(self.log) self.add_stop_cb(self.end) self.add_stop_cb(self.shutdown) self.log.info(u"Scenario Frontend and Manager initialized, let's wait for some work.") self.ready()
except: Printc.err(u"Error while creating the test devices {0} : {1}".format( device, traceback.format_exc())) return False, td if __name__ == "__main__": test_folder = os.path.dirname(os.path.realpath(__file__)) ### global variables device = "/dev/rfplayer" timer_status = 30 # set up the features plugin = Plugin(name='test', daemonize=False, parser=None, test=True) # set up the plugin name name = "rfplayer" # set up the configuration of the plugin # configuration is done in test_0010_configure_the_plugin with the cfg content # notice that the old configuration is deleted before cfg = {'configured': True, 'auto_startup': 'N'} # specific configuration for test mdode (handled by the manager for plugin startup) cfg['test_mode'] = True cfg['test_option'] = "{0}/x10_protocol_data.json".format(test_folder) ### start tests # load the test devices class