def test_user_config_file(user_home, user_entry): info("Check user config file contents") import ConfigParser config = ConfigParser.ConfigParser() config.read("/etc/domogik/domogik-mq.cfg") #check [mq] section mq = dict(config.items('mq')) ok("Config file correctly loaded") info("Parse [mq] section") import domogikmq parent_conn, child_conn = Pipe() p = Process(target=_test_user_can_write, args=(child_conn, mq['log_dir_path'],user_entry,)) p.start() p.join() assert parent_conn.recv(), "The directory %s for log does not exist or does not have right permissions" % mq['log_dir_path'] assert mq['log_level'] in ['debug','info','warning','error','critical'], "The log_level parameter does not have a good value. Must \ be one of debug,info,warning,error,critical" # Check ports info("Check ports availibility") mq_ip = mq['ip'] if mq_ip == '*': mq_ip = get_ip() _check_port_availability(mq_ip, mq['req_rep_port']) _check_port_availability(mq_ip, mq['pub_port']) _check_port_availability(mq_ip, mq['sub_port']) ok("IPs/ports needed by Domogik MQ are not bound by anything else") ok("[mq] section seems good")
def __init__(self, context, service): """Initialize the MDPWorker. context is the zmq context to create the socket from. service is a byte-string with the service name. """ if DEBUG: print("MQRep > __init__") cfg = Loader('mq').load() config = dict(cfg[1]) if config['ip'].strip() == "*": config['ip'] = get_ip() self.endpoint = "tcp://{0}:{1}".format(config['ip'], config['req_rep_port']) self.context = context self.service = service self.stream = None self._tmo = None self.need_handshake = True self.ticker = None self._delayed_cb = None self._create_stream() ### patch fritz self._reconnect_in_progress = False ### end patch fritz return
def __init__(self, context, caller_id): cfg = Loader('mq').load() self.cfg_mq = dict(cfg[1]) if self.cfg_mq['ip'].strip() == "*": self.cfg_mq['ip'] = get_ip() pub_addr = "tcp://{0}:{1}".format(self.cfg_mq['ip'], self.cfg_mq['pub_port']) self.caller_id = caller_id self.s_send = context.socket(zmq.PUB) self.s_send.connect(pub_addr)
def __init__(self, context): """Initialize the MDPClient. """ cfg = Loader('mq').load() config = dict(cfg[1]) if config['ip'].strip() == "*": config['ip'] = get_ip() endpoint = "tcp://{0}:{1}".format(config['ip'], config['req_rep_port']) self.socket = ZmqSocket(context, zmq.REQ) self.socket.connect(endpoint) return
def __init__(self, context, caller_id, category_filters): cfg = Loader('mq').load() self.cfg_mq = dict(cfg[1]) if self.cfg_mq['ip'].strip() == "*": self.cfg_mq['ip'] = get_ip() sub_addr = "tcp://{0}:{1}".format(self.cfg_mq['ip'], self.cfg_mq['sub_port']) self.s_recv = context.socket(zmq.SUB) self.caller_id = caller_id self.s_recv.connect(sub_addr) for category_filter in category_filters: self.s_recv.setsockopt(zmq.SUBSCRIBE, category_filter) if len(category_filters) == 0: self.s_recv.setsockopt(zmq.SUBSCRIBE, '')
def main(): with daemon.DaemonContext( stderr=sys.stderr, stdin=sys.stdin, stdout=sys.stdout): cfg = Loader('mq') my_conf = cfg.load() config = dict(my_conf[1]) context = zmq.Context() if config['ip'].strip() == "*": config['ip'] = get_ip() print(("tcp://{0}:{1}".format(config['ip'], config['req_rep_port']))) broker = MDPBroker(context, "tcp://{0}:{1}".format(config['ip'], config['req_rep_port'])) IOLoop.instance().start() broker.shutdown()
def __init__(self, context, caller_id, category_filters): cfg = Loader('mq').load() self.cfg_mq = dict(cfg[1]) if self.cfg_mq['ip'].strip() == "*": self.cfg_mq['ip'] = get_ip() sub_addr = "tcp://{0}:{1}".format(self.cfg_mq['ip'], self.cfg_mq['sub_port']) self.caller_id = caller_id self.s_recv = context.socket(zmq.SUB) self.s_recv.connect(sub_addr) if len(category_filters) == 0: self.s_recv.setsockopt(zmq.SUBSCRIBE, '') else: for category_filter in category_filters: self.s_recv.setsockopt(zmq.SUBSCRIBE, category_filter) ioloop = IOLoop.instance() self.stream_asyncmq = ZMQStream(self.s_recv, ioloop) self.stream_asyncmq.on_recv(self._on_message)
def __init__(self, context, service): """Initialize the MDPClient. """ cfg = Loader('mq').load() config = dict(cfg[1]) if config['ip'].strip() == "*": config['ip'] = get_ip() self.endpoint = "tcp://{0}:{1}".format(config['ip'], config['req_rep_port']) socket = ZmqSocket(context, zmq.REQ) ioloop = IOLoop.instance() self.service = service self.stream = ZMQStream(socket, ioloop) self.stream.on_recv(self._on_message) self.can_send = True self._proto_prefix = [ PROTO_VERSION, service] self._tmo = None self.timed_out = False socket.connect(self.endpoint) return