def _send_set_log_level(self):
        level = {
            LogLevel.Debug(): 'Debug',
            LogLevel.Info(): 'Info',
            LogLevel.Warning(): 'Warning',
            LogLevel.Error(): 'Error',
        }[self.loglevel]

        self.log.log_message(LogLevel.Info(), f'set loglevel to {level}')
        self.connectionHandler.send_set_log_level(self.loglevel)
Example #2
0
    def _execute_cmd_init(self):
        self.logger.log_message(LogLevel.Debug(), 'COMMAND: init')
        # ToDo: How should we perform the selftest?
        self.logger.log_message(LogLevel.Info(), 'running self test...')
        selftest_result = self._sequencer_instance.init()
        self.logger.log_message(LogLevel.Info(), f'self test completed: {selftest_result}')

        self.send_status("IDLE")

        # TODO: how to report positive init command results? we could also write the testresult
        # self.publish_result(selftest_result, "<insert init result data here>")
        # note that currently once "init" failed the status will not be restored to ALIVE
        if not selftest_result:
            self._mqtt.publish_status(TheTestAppStatusAlive.INITFAIL, {'state': self._statemachine.state, 'payload': {'state': self._statemachine.state, 'message': 'selftest is failed'}})
    def publish_state(self, site_id=None, param_data=None):
        if self.prev_state == self.state:
            return

        self.prev_state = self.state
        self.log.log_message(LogLevel.Info(), f'Master state is {self.state}')
        self.connectionHandler.publish_state(self.external_state)
Example #4
0
    def publish_current_state(self, info):
        self._conhandler.publish_state(self.state, self._error_message)

        if self.prev_state != self.state:
            self.log.log_message(LogLevel.Info(),
                                 f'control state is: {self.state}')

        self.prev_state = self.state
 def send_load_test_to_all_sites(self, testapp_params):
     topic = f'ate/{self.device_id}/Control/cmd'
     params = {
         'type': 'cmd',
         'command': 'loadTest',
         'testapp_params': testapp_params,
         'sites': self.sites,
     }
     self.log.log_message(LogLevel.Info(), 'Send LoadLot to sites...')
     self.mqtt.publish(topic, json.dumps(params), 0, False)
Example #6
0
    def on_load(self, testapp_params: dict):
        self._error_message = ''
        self.log.log_message(
            LogLevel.Info(), f'test_program parameters: {str(testapp_params)}')
        if not self._does_test_program_exist(testapp_params):
            self.load_error(
                f'Test program could not be found: {testapp_params["cwd"]}/{testapp_params["testapp_script_path"]}'
            )
            return

        self._task = asyncio.create_task(
            self._run_testapp_task(testapp_params))
Example #7
0
 def _send_get_bin_settings(self):
     self.connectionHandler.send_get_bin_settings()
     self.arm_timeout(
         RESPONSE_TIMEOUT,
         lambda: self.timeout("not all sites send bin settings"))
     self.pendingTransitionsTest = SequenceContainer([
         TEST_STATE_IDLE
     ], self.configuredSites, lambda: None, lambda site, state: self.on_error(
         f"Bad statetransition of testapp {site} during waiting of bin settings to {state}"
     ))
     self.log.log_message(LogLevel.Info(),
                          'Master sent get_bin_settings command')
    def _on_connect_handler(self, client, userdata, flags, conect_res):
        self.log.log_message(LogLevel.Info(), 'mqtt connected')
        self.connected_flag = True

        self.mqtt.subscribe(f"ate/{self.device_id}/Master/#")
        self.mqtt.subscribe(f"ate/{self.device_id}/TestApp/#")
        self.mqtt.subscribe(f"ate/{self.device_id}/Control/#")
        self.mqtt.subscribe(f"ate/{self.handler_id}/{SUBTOPIC_HANDLER}")
        self.mqtt.subscribe(f"ate/{self.device_id}/+/log/#")

        self.status_consumer.startup_done()
        self.send_reset_to_all_sites()
    def on_testapp_status_changed(self, siteid: str, status_msg: dict):
        if self.external_state == 'softerror':
            return

        newstatus = status_msg['payload']['state']
        self.log.log_message(LogLevel.Info(),
                             f'Testapp {siteid} state is {newstatus}')
        if self.is_testing(
                allow_substates=True) and newstatus == TEST_STATE_IDLE:
            self.handle_status_idle(siteid)

        if self.pendingTransitionsTest:
            self.pendingTransitionsTest.trigger_transition(siteid, newstatus)
Example #10
0
    def _on_connect_handler(self, client, userdata, flags, conect_res):
        self.log.log_message(LogLevel.Info(), 'mqtt connected')
        self.connected_flag = True

        self.mqtt.subscribe(self._generate_base_topic_cmd())
        self.mqtt.subscribe(self._generate_base_topic_resource())
        self.mqtt.subscribe(self.__generate_sub_topic(TOPIC_CONTROLSTATUS))
        self.mqtt.subscribe(self.__generate_sub_topic(TOPIC_TESTRESULT))
        self.mqtt.subscribe(self.__generate_sub_topic(TOPIC_TESTSTATUS))
        self.mqtt.subscribe(self.__generate_sub_topic(TOPIC_TESTRESOURCE))
        self.mqtt.subscribe(self.__generate_sub_topic(TOPIC_TESTSUMMARY))
        self.mqtt.subscribe(self.__generate_sub_topic(TOPIC_TESTBINSETTINGS))
        self.mqtt.subscribe(self.__generate_log_topic())
        self.mqtt.subscribe(
            self.__generate_handler_topic(
                f"{self.handler_id}/{SUBTOPIC_HANDLER}"))
        self.status_consumer.startup_done()
        self.send_reset_to_all_sites()
    def on_control_status_changed(self, siteid: str, status_msg: dict):
        if self.external_state == 'softerror':
            return

        newstatus = status_msg['payload']['state']

        if (status_msg['interface_version'] != INTERFACE_VERSION):
            self.log.log_message(LogLevel.Error(),
                                 f'Bad interface version on site {siteid}')
            self.bad_interface_version()

        try:
            if (self.siteStates[siteid] != newstatus):
                self.log.log_message(LogLevel.Info(),
                                     f'Control {siteid} state is {newstatus}')
                self.siteStates[siteid] = newstatus
                self.pendingTransitionsControl.trigger_transition(
                    siteid, newstatus)
        except KeyError:
            self.on_error(f"Site id received: {siteid} is not configured")
Example #12
0
    def handle_message(self, message):
        message_type = message['type']
        try:
            expected_master_state = {'load': lambda: self._on_load_command_issued(),
                                     'next': lambda: self._on_next_command_issued(),
                                     'unload': lambda: self._on_unload_command_issued()}[message_type]()
        except KeyError:
            expected_master_state = [MasterStates.unknown()]
        except MachineError:
            self._log.log_message(LogLevel.Warning(), f'cannot trigger command "{message_type}" from state {self.state}')
            return self._get_error_message(message_type)
        finally:
            self._log.log_message(LogLevel.Info(), f'Handler reports message: {message}')

        if expected_master_state[0] == MasterStates.unknown():
            return {}

        self.pending_transistion_master = SequenceContainer(expected_master_state, self._device_ids, lambda: self._get_call_back(expected_master_state[0]),
                                                            lambda site, state: self._on_unexpected_master_state(site, state))

        return {}
 def publish_state(self, state, message) -> None:
     self._log.log_message(LogLevel.Info(), f'Handler state: {state}')
     self.publish(self._generate_handler_status_topic(),
                  self._generate_status_message(state, message),
                  qos=1,
                  retain=False)
Example #14
0
                    metavar="devid",
                    help="Id of the testing device this magfield should serve")
parser.add_argument("device_ip",
                    type=str,
                    metavar="devip",
                    help="Address of the STL source")
parser.add_argument(
    "device_port",
    type=int,
    metavar="devport",
    help="Port of the STL source (default configuration of device is 21324)")

args = parser.parse_args()

log = Logger('magfield-stl')
log.set_logger_level(LogLevel.Info())
comm_channel = TcpCommunicationChannel(args.device_ip, args.device_port, log)
driver = DCS6K(comm_channel)
magfield = MagFieldImpl(driver)


async def do_loop():
    mqtt = MqttBridge(args.broker_ip, args.broker_port, args.device_id,
                      magfield, log)
    mqtt.start_loop()
    while True:
        await asyncio.sleep(1)


asyncio.run(do_loop())
 def _on_disconnect_handler(self, client, userdata, distc_res):
     self.log.log_message(LogLevel.Info(),
                          f'mqtt disconnected (rc: {distc_res})')
     self.connected_flag = False
 def _handle_handler_temperature(self, param_data):
     self.log.log_message(
         LogLevel.Info(),
         f'handler temperature is : {param_data["temperature"]}')
Example #17
0
    def _on_connect_handler(self, client, userdata, flags, conect_res):
        self.log.log_message(LogLevel.Info(), 'mqtt connected')

        self.mqtt.subscribe(self._generate_base_topic_cmd())
        self.mqtt.subscribe(self._generate_base_topic_status_master())
        self._statemachine.publish_current_state(None)