From 7a7141536a196d1edbd322d59ab02979dd4c54ae Mon Sep 17 00:00:00 2001 From: "marius.crisan" Date: Wed, 20 Dec 2023 15:46:38 +0100 Subject: [PATCH 1/4] Add INSTALL doc --- devops/INSTALL.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 devops/INSTALL.md diff --git a/devops/INSTALL.md b/devops/INSTALL.md new file mode 100644 index 00000000..273d84c0 --- /dev/null +++ b/devops/INSTALL.md @@ -0,0 +1,32 @@ +# INSTALL + +1. Create a wattrex user to execute cyclers and change password +```bash + +su - +# Create user, group and change password +groupadd -g 69976 wattrex +useradd -u 69976 -g wattrex wattrex +mkhomedir_helper wattrex +passwd wattrex + +# Add new user to docker group +usermod -aG docker wattrex +exit + +# Login to new user +su - wattrex +``` + +2. Execute deploy script to deploy containers for db synchronizer and CAN and SCPI sniffers +```bash +./devops/deploy.sh +``` + +NOTE: **make sure that all files in the `devops` and `config` folders belong to** +**the wattrex group and have write permissions** + +3. Export config file path +```bash +export CONFIG_FILE_PATH=$(pwd)/config/config_params.yaml +``` \ No newline at end of file From 6d8abebc09e78195874b7fdbb7b1e7c5aef42fb8 Mon Sep 17 00:00:00 2001 From: "marius.crisan" Date: Wed, 20 Dec 2023 15:48:36 +0100 Subject: [PATCH 2/4] Update INSTALL doc --- devops/INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devops/INSTALL.md b/devops/INSTALL.md index 273d84c0..5f2ecc8b 100644 --- a/devops/INSTALL.md +++ b/devops/INSTALL.md @@ -17,7 +17,7 @@ exit # Login to new user su - wattrex ``` - +2. Change system queue sizes. For this, follow this guide: [](https://github.com/WattRex/System-Tools/tree/develop/code/sys_shd) 2. Execute deploy script to deploy containers for db synchronizer and CAN and SCPI sniffers ```bash ./devops/deploy.sh @@ -29,4 +29,4 @@ NOTE: **make sure that all files in the `devops` and `config` folders belong to* 3. Export config file path ```bash export CONFIG_FILE_PATH=$(pwd)/config/config_params.yaml -``` \ No newline at end of file +``` From 32f5f6433b0f39fa95ffb2e98a5ee2bb03968307 Mon Sep 17 00:00:00 2001 From: Marius Crisan Date: Thu, 21 Dec 2023 09:39:33 +0100 Subject: [PATCH 3/4] Fix stop for cu_manager --- .../src/wattrex_cycler_cu_manager/cu_manager.py | 11 ++++------- .../src/wattrex_cycler_cu_manager/detect.py | 14 ++++++++++---- devops/cu_manager/run_cu_node.py | 17 +++++++++++++++++ devops/cycler/run_cycler.py | 5 +++-- devops/deploy.sh | 7 ++++--- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py b/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py index e586989d..da358ce5 100644 --- a/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py +++ b/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py @@ -198,15 +198,12 @@ def process_iteration(self) -> None: self.process_heartbeat() self.process_cycler_deploy_processes() - - def sync_shd_data(self) -> None: - '''Sync shared data with the sync node. - ''' - - def stop(self) -> None: - '''Stop the stream . ''' + Stop the stream . + ''' + log.critical(f"Stopping CU_Manager...") self.client_mqtt.close() + self.detector.close() ####################### FUNCTIONS ####################### diff --git a/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py b/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py index c6c4ce3f..ec7015a7 100644 --- a/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py +++ b/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py @@ -124,10 +124,6 @@ def process_detection(self) -> List[CommDataDeviceC]: self.__tx_can.send_data(DrvCanCmdDataC(data_type= DrvCanCmdTypeE.REMOVE_FILTER, payload= DrvCanFilterC(addr= 0x000, mask= 0x000, chan_name=DEFAULT_RX_CAN_NAME))) - ## Closing conections with queues - self.__tx_can.close() - self.__tx_scpi.close() - self.__rx_can.terminate() return self.det_bms + self.det_epc + self.det_ea + self.det_rs + self.det_flow def __reset_detected(self) -> None: @@ -271,3 +267,13 @@ def __parse_epc_msg(self, msg: DrvCanMessageC) -> Tuple[int, str, bitarray]: # The last bits correspond to the serial number serial_number = str(ba2int(msg_bits[24:32])) return can_id, serial_number, hw_ver + + def close(self) -> None: + ## Closing conections with queues + if isinstance(self.__tx_can, SysShdIpcChanC): + self.__tx_can.close() + if isinstance(self.__tx_scpi, SysShdIpcChanC): + self.__tx_scpi.close() + if isinstance(self.__rx_can, SysShdIpcChanC): + self.__rx_can.terminate() + log.critical("Closing channels used by detector") \ No newline at end of file diff --git a/devops/cu_manager/run_cu_node.py b/devops/cu_manager/run_cu_node.py index 7b10b32c..f0843b40 100644 --- a/devops/cu_manager/run_cu_node.py +++ b/devops/cu_manager/run_cu_node.py @@ -7,6 +7,7 @@ ####################### GENERIC IMPORTS ####################### import sys, os import threading +from signal import signal, SIGINT ####################### THIRD PARTY IMPORTS ####################### @@ -19,6 +20,8 @@ log: Logger = sys_log_logger_get_module_logger(__name__) ####################### MODULE IMPORTS ####################### +# sys.path.append(os.getcwd()+'/code/cu_manager/') +# from src.wattrex_cycler_cu_manager import CuManagerNodeC from wattrex_cycler_cu_manager import CuManagerNodeC ####################### PROJECT IMPORTS ####################### @@ -28,6 +31,19 @@ ####################### CLASSES ####################### ####################### FUNCTIONS ####################### +cu_manager_node = None + +def signal_handler(sig, frame) -> None: #pylint: disable= unused-argument + """Called when the user presses Ctrl + C to stop test. + + Args: + sig ([type]): [description] + frame ([type]): [description] + """ + if isinstance(cu_manager_node, CuManagerNodeC): + log.critical(msg='You pressed Ctrl+C! Stopping test...') + cu_manager_node.stop() + sys.exit(0) if __name__ == '__main__': working_flag_event : threading.Event = threading.Event() @@ -35,4 +51,5 @@ cu_manager_node = CuManagerNodeC(working_flag=working_flag_event, cycle_period=1000, cu_id_file_path='./devops/cu_manager/.cu_id') + signal(SIGINT, signal_handler) cu_manager_node.run() diff --git a/devops/cycler/run_cycler.py b/devops/cycler/run_cycler.py index 6fdc66b1..694e0eaa 100644 --- a/devops/cycler/run_cycler.py +++ b/devops/cycler/run_cycler.py @@ -23,8 +23,9 @@ log.critical(f'CS_ID: {CS_ID}') ####################### MODULE IMPORTS ####################### -sys.path.append(os.getcwd()+'/code/cycler/') -from src.wattrex_battery_cycler.app.app_man import AppManNodeC +# sys.path.append(os.getcwd()+'/code/cycler/') +# from src.wattrex_battery_cycler.app.app_man import AppManNodeC +from wattrex_battery_cycler.app.app_man import AppManNodeC ####################### PROJECT IMPORTS ####################### diff --git a/devops/deploy.sh b/devops/deploy.sh index c1ff86ad..e83355e2 100755 --- a/devops/deploy.sh +++ b/devops/deploy.sh @@ -18,8 +18,9 @@ export GROUP_ID=$(id -g) initial_deploy () { force_stop - python3 -m pip install can-sniffer - python3 -m pip install SCPI-sniffer + python3 -m pip install --upgrade can-sniffer + python3 -m pip install --upgrade SCPI-sniffer + python3 -m pip install --upgrade wattrex-cycler-cu-manager mkdir -p "${REPO_ROOT_DIR}/log" docker compose ${DOCKER_COMPOSE_ARGS} up cache_db db_sync -d @@ -33,7 +34,7 @@ instance_new_cycler () { check_sniffer "scpi" export CYCLER_TARGET=cycler_prod - docker compose ${DOCKER_COMPOSE_ARGS} build --build-arg UPDATE_REQS=$(date +%s) cycler + #docker compose ${DOCKER_COMPOSE_ARGS} build --build-arg UPDATE_REQS=$(date +%s) cycler docker compose ${DOCKER_COMPOSE_ARGS} run -d -e CSID=${1} --name wattrex_cycler_node_${1} cycler } From 33320b9b5778affe7f6ab7e74ea03af6ceac6e52 Mon Sep 17 00:00:00 2001 From: Marius Crisan Date: Thu, 21 Dec 2023 09:46:27 +0100 Subject: [PATCH 4/4] Pylint fixes --- .../src/wattrex_cycler_cu_manager/cu_manager.py | 9 +++++++-- code/cu_manager/src/wattrex_cycler_cu_manager/detect.py | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py b/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py index da358ce5..38f576b7 100644 --- a/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py +++ b/code/cu_manager/src/wattrex_cycler_cu_manager/cu_manager.py @@ -35,7 +35,8 @@ ####################### ENUMS ####################### ####################### CLASSES ####################### -class CuManagerNodeC(SysShdNodeC): # pylint: disable=too-many-instance-attributes +# pylint: disable=too-many-instance-attributes +class CuManagerNodeC(SysShdNodeC): ''' Cu Manager Class to instanciate a CU Manager Node ''' @@ -198,11 +199,15 @@ def process_iteration(self) -> None: self.process_heartbeat() self.process_cycler_deploy_processes() + def sync_shd_data(self) -> None: + '''Sync shared data with the sync node. + ''' + def stop(self) -> None: ''' Stop the stream . ''' - log.critical(f"Stopping CU_Manager...") + log.critical("Stopping CU_Manager...") self.client_mqtt.close() self.detector.close() diff --git a/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py b/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py index ec7015a7..c5bb6ca7 100644 --- a/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py +++ b/code/cu_manager/src/wattrex_cycler_cu_manager/detect.py @@ -269,6 +269,9 @@ def __parse_epc_msg(self, msg: DrvCanMessageC) -> Tuple[int, str, bitarray]: return can_id, serial_number, hw_ver def close(self) -> None: + ''' + Close used ipc channels + ''' ## Closing conections with queues if isinstance(self.__tx_can, SysShdIpcChanC): self.__tx_can.close() @@ -276,4 +279,4 @@ def close(self) -> None: self.__tx_scpi.close() if isinstance(self.__rx_can, SysShdIpcChanC): self.__rx_can.terminate() - log.critical("Closing channels used by detector") \ No newline at end of file + log.critical("Closing channels used by detector")