Example #1
0
    def send_client_reboot(self, client_id: str):
        """
        Triggers the reboot of the specified client

        :param client_id: ID of the client
        :return: None
        :raises UnknownClientException: If client id is unknown to the system
        :raises NoClientResponseException: If client did not respond to the request
        :raises ClientRebootError: If client could not be rebooted for aby reason
        """
        if client_id not in [x.get_name() for x in self._delegate.get_client_info()]:
            raise UnknownClientException(client_id)
        writer = ClientController(client_id, self._network)
        writer.reboot_client()
Example #2
0
    def _erase_config(self):
        print()
        print("Overwriting EEPROM:")

        erase_controller = ClientController(self._client_name, self._network)

        try:
            erase_controller.erase_config()
            print("Config was successfully erased\n")

        except NoClientResponseException:
            print("Received no Response to Reset Request\n")
            return
        except ConfigEraseError:
            print("Failed to reset EEPROM\n")
Example #3
0
    def send_client_gadget_config_write(self, client_id: str, config: dict):
        """
        Sends a request to write a gadget config to a client

        :param client_id: ID of the client to send the config to
        :param config: Config to write
        :return: None
        :raises UnknownClientException: If client id is unknown to the system
        :raises ConfigWriteError: If client did not acknowledge config writing success
        :raises ValidationError: If passed config was faulty
        """
        if client_id not in [x.get_name() for x in self._delegate.get_client_info()]:
            raise UnknownClientException(client_id)
        writer = ClientController(client_id, self._network)
        writer.write_gadget_config(config)
Example #4
0
    def _reboot_client(self):
        print()
        print("Rebooting Client:")

        reboot_controller = ClientController(self._client_name, self._network)

        try:
            with LoadingIndicator():
                reboot_controller.reboot_client()
            print("Client reboot successful\n")

        except NoClientResponseException:
            print("Received no response to reboot request\n")
            return
        except ClientRebootError:
            print("Failed to reboot client\n")
            return
def test_client_controller_reset_config(controller: ClientController, connector: DummyNetworkConnector,
                                        manager: ClientConfigManager):
    with pytest.raises(NoClientResponseException):
        controller.erase_config()

    connector.reset()

    connector.mock_ack(False)
    with pytest.raises(ConfigEraseError):
        controller.erase_config()

    connector.reset()

    connector.mock_ack(True)
    controller.erase_config()
Example #6
0
    def _write_config(self):

        manager = ClientConfigManager()
        config_names = manager.get_config_names()

        config_path: Optional[str]
        config_data: Optional[dict] = None

        while not config_data:

            config_index = select_option(config_names, "which config to write",
                                         "Quit")

            if config_index == -1:
                return

            config_data = manager.get_config(config_names[config_index])

            if not config_data:
                response = ask_for_continue(
                    "Config file could either not be loaded, isn no valid json file or"
                    "no valid config. Try again?")
                if not response:
                    return
                else:
                    continue

        print(f"Loaded config '{config_data['name']}'")
        print()
        print("Writing config:")

        write_controller = ClientController(self._client_name, self._network)

        w_system = False
        w_event = False
        w_gadget = False
        has_error = False

        write_option = select_option([
            "Write complete config", "System only", "Gadgets only",
            "Events only"
        ], "writing task", "back")

        if write_option == -1:
            return
        elif write_option == 0:
            w_system = True
            w_event = True
            w_gadget = True
        elif write_option == 1:
            w_system = True
        elif write_option == 2:
            w_gadget = True
        elif write_option == 3:
            w_event = True

        if w_system:
            print("Writing system config...")

            try:
                with LoadingIndicator():
                    write_controller.write_system_config(config_data["system"])
                print("Config was successfully written\n")

            except NoClientResponseException:
                print("Received no response to config write request\n")
                has_error = True
            except ConfigWriteError:
                print("Failed to write config on chip\n")
                has_error = True

        if w_gadget:
            print("Writing gadget config...")

            try:
                with LoadingIndicator():
                    write_controller.write_gadget_config(
                        config_data["gadgets"])
                print("Config was successfully written\n")

            except NoClientResponseException:
                print("Received no response to config write request\n")
                has_error = True
            except ConfigWriteError:
                print("Failed to write config on chip\n")
                has_error = True

        if w_event:
            print("Writing event config...")

            try:
                with LoadingIndicator():
                    write_controller.write_event_config(config_data["events"])
                print("Config was successfully written\n")

            except NoClientResponseException:
                print("Received no response to config write request\n")
                has_error = True
            except ConfigWriteError:
                print("Failed to write config on chip\n")
                has_error = True

        if not has_error:
            print("All writing efforts were successful\n")
        else:
            print("Completed with errors\n")
def controller(network):
    controller = ClientController(TEST_CLIENT_NAME, network)
    yield controller