def test_error_topics(self): """Test Error Topics.""" topicname = 'iot-lab/serial/grenoble' error_topic = 'iot-lab/serial/grenoble/error/' client_cb = mock.Mock() client_topics = { 'error': mqttcommon.ErrorClient(topicname, wrap_mock(client_cb)) } server_topics = {'error': mqttcommon.ErrorServer(topicname)} mqttclient_mock.MQTTClientMock('localhost', 1883, list(client_topics.values())) server = mqttclient_mock.MQTTClientMock('localhost', 1883, list(server_topics.values())) server.publish_delay = 0 err = b'error message' topic_with_error_rel = 'm3/1/line/data/in' topic_with_error = os.path.join(topicname, topic_with_error_rel) server_topics['error'].publish_error(server, topic_with_error, err) self.assertTrue(client_cb.called) err_msg = mqttclient_mock.mqttmessage( os.path.join(error_topic, topic_with_error_rel), err) client_cb.assert_called_with(err_msg, topic_with_error_rel)
def __init__(self, client, prefix, site=None): assert site is not None super().__init__() self.clientid = clientcommon.clientid('serialclient') staticfmt = {'site': site} _topics = mqttcommon.generate_topics_dict( self.SERVER.TOPICS, prefix, self.SERVER.AGENTTOPIC, staticfmt) _print_wrapper = self.async_print_handle_readlinebuff() line_cb = _print_wrapper(self.line_handler) error_cb = _print_wrapper(self.error_cb) self.topics = { 'line': mqttcommon.ChannelClient(_topics['line'], line_cb), 'linestart': mqttcommon.RequestClient( _topics['line'], 'start', clientid=self.clientid), 'linestop': mqttcommon.RequestClient( _topics['line'], 'stop', clientid=self.clientid), 'stop': mqttcommon.RequestClient( _topics['node'], 'stop', clientid=self.clientid), 'stopall': mqttcommon.RequestClient( _topics['agenttopic'], 'stopall', clientid=self.clientid), 'error': mqttcommon.ErrorClient(_topics['agenttopic'], callback=error_cb), } self.client = client self.client.topics = list(self.topics.values())
def __init__(self, client, prefix, site=None, agenttopic=None): assert site is not None or agenttopic is not None super().__init__() self.clientid = clientcommon.clientid('serialclient') _topics = self._topics_dict(prefix, site, agenttopic) _print_wrapper = self.async_print_handle_readlinebuff() stdout_cb = _print_wrapper(self.stdout_cb) stderr_cb = _print_wrapper(self.stderr_cb) returncode_cb = _print_wrapper(self.returncode_cb) error_cb = _print_wrapper(self.error_cb) self.topics = { 'new': mqttcommon.RequestClient( _topics['agenttopic'], 'new', clientid=self.clientid), 'list': mqttcommon.RequestClient( _topics['agenttopic'], 'list', clientid=self.clientid), 'free': mqttcommon.RequestClient( _topics['agenttopic'], 'free', clientid=self.clientid), 'freeall': mqttcommon.RequestClient( _topics['agenttopic'], 'freeall', clientid=self.clientid), 'procrun': mqttcommon.RequestClient( _topics['process'], 'run', clientid=self.clientid), 'procpoll': mqttcommon.RequestClient( _topics['process'], 'poll', clientid=self.clientid), 'prockill': mqttcommon.RequestClient( _topics['process'], 'kill', clientid=self.clientid), 'procrerun': mqttcommon.RequestClient( _topics['process'], 'rerun', clientid=self.clientid), 'procstdin': mqttcommon.InputClient(_topics['procstdin']), 'procstdout': mqttcommon.OutputClient(_topics['procstdout'], callback=stdout_cb), 'procstderr': mqttcommon.OutputClient(_topics['procstderr'], callback=stderr_cb), 'procret': mqttcommon.OutputClient(_topics['procret'], callback=returncode_cb), 'error': mqttcommon.ErrorClient(_topics['agenttopic'], callback=error_cb), } self.client = client self.client.topics = list(self.topics.values())
def __init__(self, client, prefix='', site=None): assert site is not None super().__init__() clientid = clientcommon.clientid('radiosnifferclient') staticfmt = {'site': site} _topics = mqttcommon.generate_topics_dict(self.SERVER.TOPICS, prefix, self.SERVER.AGENTTOPIC, staticfmt) _print_wrapper = self.async_print_handle_readlinebuff() error_cb = _print_wrapper(self.error_cb) raw_cb = _print_wrapper(self.raw_handler) self.topics = { 'raw': mqttcommon.ChannelClient(_topics['noderaw'], raw_cb), 'rawheader': mqttcommon.RequestClient(_topics['raw'], 'rawheader', clientid=clientid), 'rawstart': mqttcommon.RequestClient(_topics['noderaw'], 'start', clientid=clientid), 'stop': mqttcommon.RequestClient(_topics['node'], 'stop', clientid=clientid), 'stopall': mqttcommon.RequestClient(_topics['agenttopic'], 'stopall', clientid=clientid), 'error': mqttcommon.ErrorClient(_topics['agenttopic'], callback=error_cb), } self.pcap_files = PcapFiles() self.client = client self.client.topics = list(self.topics.values())
def __init__(self, client, prefix, site=None): assert site is not None super().__init__() clientid = clientcommon.clientid('nodeclient') staticfmt = {'site': site} _topics = mqttcommon.generate_topics_dict(self.SERVER.TOPICS, prefix, self.SERVER.AGENTTOPIC, staticfmt) _print_wrapper = self.async_print_handle_readlinebuff() error_cb = _print_wrapper(self.error_cb) self.topics = { 'reset': mqttcommon.RequestClient(_topics['node'], 'reset', clientid=clientid), 'update': mqttcommon.RequestClient(_topics['node'], 'update', clientid=clientid), 'poweron': mqttcommon.RequestClient(_topics['node'], 'poweron', clientid=clientid), 'poweroff': mqttcommon.RequestClient(_topics['node'], 'poweroff', clientid=clientid), 'error': mqttcommon.ErrorClient(_topics['agenttopic'], callback=error_cb), } self.client = client self.client.topics = list(self.topics.values())
def __init__(self, client, prefix, agenttopic): _topics = mqttcommon.generate_topics_dict(PROCESS_SERVER.TOPICS, prefix, agenttopic) clientid = clientcommon.clientid('customprocessclient') # Copied from clients/process.py self.topics = { 'new': mqttcommon.RequestClient(_topics['agenttopic'], 'new', clientid=clientid), 'list': mqttcommon.RequestClient(_topics['agenttopic'], 'list', clientid=clientid), 'free': mqttcommon.RequestClient(_topics['agenttopic'], 'free', clientid=clientid), 'freeall': mqttcommon.RequestClient(_topics['agenttopic'], 'freeall', clientid=clientid), # I use common callback for all processes 'procrun': mqttcommon.RequestClient(_topics['process'], 'run', clientid=clientid), 'procpoll': mqttcommon.RequestClient(_topics['process'], 'poll', clientid=clientid), 'prockill': mqttcommon.RequestClient(_topics['process'], 'kill', clientid=clientid), 'procrerun': mqttcommon.RequestClient(_topics['process'], 'rerun', clientid=clientid), 'procstdin': mqttcommon.InputClient(_topics['procstdin']), 'procstdout': mqttcommon.OutputClient(_topics['procstdout'], callback=self._stdout_cb), 'procstderr': mqttcommon.OutputClient(_topics['procstderr'], callback=self._stderr_cb), 'procret': mqttcommon.OutputClient(_topics['procret'], callback=self._returncode_cb), 'error': mqttcommon.ErrorClient(_topics['agenttopic'], callback=self.error_cb), } self._rlock = threading.RLock() self._process_queues = {} self.client = client self.client.topics = list(self.topics.values())