Commit 3edb50a607d4042f3044099df0e733fc60c537ce
1 parent
2ca198f4
Exists in
dev
bugfix simulateur et test
Showing
6 changed files
with
85 additions
and
59 deletions
Show diff stats
src/core/pyros_django/agent/Agent.py
... | ... | @@ -232,6 +232,9 @@ class Agent: |
232 | 232 | WITH_SIMULATOR = False |
233 | 233 | TEST_MODE = False |
234 | 234 | |
235 | + # Default LOG level is INFO | |
236 | + PYROS_DEFAULT_GLOBAL_LOG_LEVEL = LogPyros.LOG_LEVEL_INFO # INFO | |
237 | + | |
235 | 238 | # To be overriden by subclasses (empty by default, no agent specific command) |
236 | 239 | AGENT_SPECIFIC_COMMANDS = [ |
237 | 240 | #"do_eval", |
... | ... | @@ -404,13 +407,17 @@ class Agent: |
404 | 407 | printd("*** ENVIRONMENT VARIABLE PYROS_DEBUG is:", os.environ.get('PYROS_DEBUG'), '***') |
405 | 408 | ##self.DEBUG_MODE = DEBUG_MODE |
406 | 409 | self.DEBUG_MODE = os.environ.get('PYROS_DEBUG', '0')=='1' |
407 | - self._log = LogPyros(self.name, AgentLogs) | |
408 | - ##self._log.debug_level = DEBUG_MODE | |
410 | + self.log = LogPyros(self.name, AgentLogs) | |
411 | + ##self.log.debug_level = DEBUG_MODE | |
412 | + ''' | |
409 | 413 | # Default LOG level is INFO |
410 | 414 | log_level = LogPyros.LOG_LEVEL_INFO # INFO |
411 | - self._log.set_global_log_level(LogPyros.LOG_LEVEL_DEBUG) if self.DEBUG_MODE else self._log.set_global_log_level(log_level) | |
412 | - ##self.printd("LOG LEVEL IS:", self._log.debug_level) | |
413 | - self.print("LOG LEVEL IS:", self._log.get_global_log_level()) | |
415 | + self.log.set_global_log_level(LogPyros.LOG_LEVEL_DEBUG) if self.DEBUG_MODE else self.log.set_global_log_level(log_level) | |
416 | + ''' | |
417 | + global_log_level = LogPyros.LOG_LEVEL_DEBUG if self.DEBUG_MODE else self.PYROS_DEFAULT_GLOBAL_LOG_LEVEL | |
418 | + self.log.set_global_log_level(global_log_level) | |
419 | + ##self.printd("LOG LEVEL IS:", self.log.debug_level) | |
420 | + self.print("LOG LEVEL IS:", self.log.get_global_log_level()) | |
414 | 421 | |
415 | 422 | # New way with PathLib |
416 | 423 | my_parent_abs_dir = Path(__file__).resolve().parent |
... | ... | @@ -500,7 +507,7 @@ class Agent: |
500 | 507 | #return "I am agent " + self.name |
501 | 508 | |
502 | 509 | # Normal print |
503 | - def print(self, *args, **kwargs): self._log.print(*args, **kwargs) | |
510 | + def print(self, *args, **kwargs): self.log.print(*args, **kwargs) | |
504 | 511 | """ |
505 | 512 | if args: |
506 | 513 | self.printd(f"({self.name}): ", *args, **kwargs) |
... | ... | @@ -508,11 +515,16 @@ class Agent: |
508 | 515 | self.printd() |
509 | 516 | """ |
510 | 517 | # DEBUG print shortcut |
511 | - def printd(self, *args, **kwargs): self._log.printd(*args, **kwargs) | |
518 | + def printd(self, *args, **kwargs): self.log.printd(*args, **kwargs) | |
512 | 519 | """ |
513 | 520 | if DEBUG: self.printd(d(*args, **kwargs) |
514 | 521 | """ |
515 | - def printdb(self, *args, **kwargs): self._log.db( *args, **kwargs) | |
522 | + def log_d(self, *args, **kwargs): self.log.log_d(*args, **kwargs) | |
523 | + def log_i(self, *args, **kwargs): self.log.log_i(*args, **kwargs) | |
524 | + def log_w(self, *args, **kwargs): self.log.log_w(*args, **kwargs) | |
525 | + def log_e(self, *args, **kwargs): self.log.log_e(*args, **kwargs) | |
526 | + def log_c(self, *args, **kwargs): self.log.log_c(*args, **kwargs) | |
527 | + def printdb(self, *args, **kwargs): self.log.db( *args, **kwargs) | |
516 | 528 | |
517 | 529 | def sleep(self, nbsec:float=2.0): |
518 | 530 | ''' |
... | ... | @@ -565,9 +577,9 @@ class Agent: |
565 | 577 | self.print_TEST_MODE() |
566 | 578 | |
567 | 579 | self.init() |
568 | - self._log.log_w("WARNING", "watch your step !") | |
569 | - self._log.log_e("ERROR") | |
570 | - self._log.log_c("FATAL critical ERROR") | |
580 | + self.log_w("WARNING", "watch your step !") | |
581 | + self.log_e("ERROR") | |
582 | + self.log_c("FATAL critical ERROR") | |
571 | 583 | |
572 | 584 | # Avoid blocking on false "running" commands |
573 | 585 | # (old commands that stayed with "running" status when agent was killed) |
... | ... | @@ -701,8 +713,8 @@ class Agent: |
701 | 713 | try: |
702 | 714 | self._exec_agent_cmd(cmd) |
703 | 715 | except AttributeError as e: |
704 | - self.print(f"EXCEPTION: Agent level specific command '{cmd.name}' unknown (not implemented as a function) :", e) | |
705 | - self.print("Thus => I ignore this command...") | |
716 | + self.log_e(f"EXCEPTION: Agent level specific command '{cmd.name}' unknown (not implemented as a function) :", e) | |
717 | + self.log_e("Thus => I ignore this command...") | |
706 | 718 | cmd.set_result("ERROR: INVALID AGENT LEVEL SPECIFIC COMMAND") |
707 | 719 | cmd.set_as_pending() |
708 | 720 | cmd.set_as_skipped() |
... | ... | @@ -738,8 +750,8 @@ class Agent: |
738 | 750 | try: |
739 | 751 | self.exec_device_cmd_if_possible(cmd) |
740 | 752 | except (UnimplementedGenericCmdException, UnknownNativeCmdException) as e: |
741 | - self.print(f"EXCEPTION caught by {type(self).__name__} (from Agent mainloop) for command '{cmd.name}'", e) | |
742 | - self.print("Thus ==> ignore this command") | |
753 | + self.log_e(f"EXCEPTION caught by {type(self).__name__} (from Agent mainloop) for command '{cmd.name}'", e) | |
754 | + self.log_e("Thus ==> ignore this command") | |
743 | 755 | cmd.set_result(e) |
744 | 756 | #cmd.set_as_killed_by(type(self).__name__) |
745 | 757 | cmd.set_as_skipped() |
... | ... | @@ -988,11 +1000,11 @@ class Agent: |
988 | 1000 | self.printd("------------------------------------------") |
989 | 1001 | |
990 | 1002 | # --- update the log parameters |
991 | - ##self._log.path_data = self._path_data | |
992 | - ##print("new self._log.path_data is", self._log.path_data) | |
993 | - self._log.set_global_path_data(self._path_data) | |
994 | - print("new self._log.global_path_data is", self._log.get_global_path_data()) | |
995 | - self._log.home = home | |
1003 | + ##self.log.path_data = self._path_data | |
1004 | + ##print("new self.log.path_data is", self.log.path_data) | |
1005 | + self.log.set_global_path_data(self._path_data) | |
1006 | + print("new self.log.global_path_data is", self.log.get_global_path_data()) | |
1007 | + self.log.home = home | |
996 | 1008 | |
997 | 1009 | |
998 | 1010 | #def update_survey(self): |
... | ... | @@ -1040,9 +1052,9 @@ class Agent: |
1040 | 1052 | try: |
1041 | 1053 | real_agent_name = self._get_real_agent_name(to_agent) |
1042 | 1054 | except KeyError as e: |
1043 | - self.print("UNKNOWN AgentDevice ALIAS", to_agent) | |
1044 | - self.print("Exception raised", e) | |
1045 | - self.print(f"=> Thus, I do not send this command '{cmd_name}'") | |
1055 | + self.log_e("UNKNOWN AgentDevice ALIAS", to_agent) | |
1056 | + self.log_e("Exception raised", e) | |
1057 | + self.log_e(f"=> Thus, I do not send this command '{cmd_name}'") | |
1046 | 1058 | return None |
1047 | 1059 | return Command.create(self.name, real_agent_name, cmd_name, cmd_args) |
1048 | 1060 | ''' | ... | ... |
src/core/pyros_django/agent/AgentDevice.py
... | ... | @@ -327,7 +327,7 @@ class AgentDevice(Agent): |
327 | 327 | try: |
328 | 328 | self._device_ctrl.close() |
329 | 329 | except AttributeError as e: |
330 | - self.print("Error on closing the socket (TBC):", e) | |
330 | + self.log_e("Error on closing the socket (TBC):", e) | |
331 | 331 | ''' |
332 | 332 | # Stop device simulator (only if used) |
333 | 333 | if self.is_using_simulator(): |
... | ... | @@ -380,12 +380,12 @@ class AgentDevice(Agent): |
380 | 380 | try: |
381 | 381 | res = self.exec_device_cmd(cmd) |
382 | 382 | except (DCCNotFoundException, UnimplementedGenericCmdException, UnknownNativeCmdException) as e: |
383 | - self.tprintd(f"EXCEPTION caught by {type(self).__name__} (from thread)", e) | |
383 | + self.log_e(f"THREAD EXCEPTION caught by {type(self).__name__} (from thread)", e) | |
384 | 384 | #raise |
385 | 385 | cmd.set_result(e) |
386 | 386 | cmd.set_as_killed_by(type(self).__name__) |
387 | 387 | #time.sleep(2) |
388 | - self.tprintd(">>>>> Thread: execution of command", cmd.name, "is now aborted") | |
388 | + self.log_e(">>>>> Thread: execution of command", cmd.name, "is now aborted") | |
389 | 389 | self._current_device_cmd = None |
390 | 390 | self._current_device_cmd_thread.terminate() |
391 | 391 | # (EP) ...NOT SURE THAT BELOW THIS LINE, SOMETHING WILL BE EXECUTED, because THIS current thread is being killed... |
... | ... | @@ -554,7 +554,7 @@ class AgentDevice(Agent): |
554 | 554 | try: |
555 | 555 | res = self._device_ctrl.exec_cmd(cmd.full_name) |
556 | 556 | except (DCCNotFoundException, UnimplementedGenericCmdException) as e: |
557 | - self.tprintd(f"EXCEPTION caught by {type(self).__name__} (from AD)", e) | |
557 | + self.log_e(f"THREAD EXCEPTION caught by {type(self).__name__} (from AD)", e) | |
558 | 558 | raise |
559 | 559 | self.tprintd("result is", str(res)) |
560 | 560 | if res.ok: self.tprintd("OK") | ... | ... |
src/device_controller/abstract_component/device_controller.py
... | ... | @@ -438,7 +438,7 @@ class DeviceController(): |
438 | 438 | ##self.Protoc.encap(self) |
439 | 439 | ##return self._protoc.encap(self, data) |
440 | 440 | return self._protoc.encap(data) |
441 | - self._log.log_w("WARNING", "watch your step !!!") | |
441 | + self.log_w("WARNING", "watch your step !!!") | |
442 | 442 | |
443 | 443 | ##def uncap(self, data:str): |
444 | 444 | def uncap(self, stamp:str, data:str): |
... | ... | @@ -463,7 +463,7 @@ class DeviceController(): |
463 | 463 | self.DEBUG_MODE = os.environ.get('PYROS_DEBUG', '0') == '1' |
464 | 464 | ##set_logger(self.DEBUG_MODE) |
465 | 465 | ##log_d("Logger configured") |
466 | - self._log = LogPyros(self.__class__.__name__) | |
466 | + self.log = LogPyros(self.__class__.__name__) | |
467 | 467 | self.print("coucou") |
468 | 468 | |
469 | 469 | |
... | ... | @@ -518,7 +518,7 @@ class DeviceController(): |
518 | 518 | self._thread_device_simulator = threading.Thread(target=self.device_simulator_run) |
519 | 519 | self._thread_device_simulator.start() |
520 | 520 | |
521 | - self._log.log_w("WARNING", "watch your step !!") | |
521 | + self.log_w("WARNING", "watch your step !!") | |
522 | 522 | |
523 | 523 | |
524 | 524 | |
... | ... | @@ -540,15 +540,16 @@ class DeviceController(): |
540 | 540 | self._my_channel.set_logger(DEBUG) |
541 | 541 | ''' |
542 | 542 | |
543 | - def print(self, *args, **kwargs): self._log.print(*args, **kwargs) | |
544 | - | |
545 | - # DEBUG print | |
543 | + def print(self, *args, **kwargs): self.log.print(*args, **kwargs) | |
546 | 544 | def printd(self, *args, **kwargs): |
547 | - self._log.printd(*args, **kwargs) | |
548 | - #if self.DEBUG_MODE: printd(*args, **kwargs) | |
549 | - | |
545 | + self.log.printd(*args, **kwargs) | |
550 | 546 | def tprintd(self, *args, **kwargs): |
551 | 547 | self.printd('(THREAD):', *args, *kwargs) |
548 | + def log_d(self, *args, **kwargs): self.log.log_d(*args, **kwargs) | |
549 | + def log_i(self, *args, **kwargs): self.log.log_i(*args, **kwargs) | |
550 | + def log_w(self, *args, **kwargs): self.log.log_w(*args, **kwargs) | |
551 | + def log_e(self, *args, **kwargs): self.log.log_e(*args, **kwargs) | |
552 | + def log_c(self, *args, **kwargs): self.log.log_c(*args, **kwargs) | |
552 | 553 | |
553 | 554 | def device_simulator_run(self): |
554 | 555 | #HOST, PORT = "localhost", 11110 |
... | ... | @@ -911,7 +912,7 @@ class DeviceController(): |
911 | 912 | try: |
912 | 913 | res = self.exec_generic_cmd(cmd.name, cmd.args, cmd.devtype) |
913 | 914 | except (UnimplementedGenericCmdException, DCCNotFoundException) as e: |
914 | - self.tprintd(f"EXCEPTION caught by {type(self).__name__} (from DC)", e) | |
915 | + self.log_e(f"THREAD EXCEPTION caught by {type(self).__name__} (from DC)", e) | |
915 | 916 | raise |
916 | 917 | return res |
917 | 918 | |
... | ... | @@ -934,7 +935,7 @@ class DeviceController(): |
934 | 935 | try: |
935 | 936 | res_native = self.exec_native_cmd(cmd.name_and_args) |
936 | 937 | except UnknownNativeCmdException as e: |
937 | - self.tprintd(f"EXCEPTION caught by {type(self).__name__} (from DC)", e) | |
938 | + self.log_e(f"THREAD EXCEPTION caught by {type(self).__name__} (from DC)", e) | |
938 | 939 | raise |
939 | 940 | return GenericResult(res_native) |
940 | 941 | |
... | ... | @@ -1045,7 +1046,7 @@ class DeviceController(): |
1045 | 1046 | dcc = self.get_dc_component_for_type(dcc_type) |
1046 | 1047 | self.tprintd("*** EXECUTร PAR COMPONENT", dcc) |
1047 | 1048 | except DCCNotFoundException as e: |
1048 | - self.tprintd(f"EXCEPTION caught by {type(self).__name__} (from dcc)", e) | |
1049 | + self.log_e(f"THREAD EXCEPTION caught by {type(self).__name__} (from dcc)", e) | |
1049 | 1050 | raise |
1050 | 1051 | #return (DCC)(self.exec_generic_cmd(generic_cmd, values_to_set, None)) |
1051 | 1052 | |
... | ... | @@ -1053,7 +1054,7 @@ class DeviceController(): |
1053 | 1054 | try: |
1054 | 1055 | return dcc.exec_generic_cmd(generic_cmd, values_to_set, None) |
1055 | 1056 | except UnimplementedGenericCmdException as e: |
1056 | - self.tprintd(f"EXCEPTION caught by {type(self).__name__} (from dcc)", e) | |
1057 | + self.log_e(f"THREAD EXCEPTION caught by {type(self).__name__} (from dcc)", e) | |
1057 | 1058 | raise |
1058 | 1059 | # not executed ? |
1059 | 1060 | return None | ... | ... |
src/device_controller/abstract_component/device_simulator.py
... | ... | @@ -198,6 +198,11 @@ class DeviceSimulator: |
198 | 198 | # TYPE1 |
199 | 199 | if command not in (cls.protoc.COMMAND5, cls.protoc.COMMAND6): |
200 | 200 | # TYPE2 or 3 |
201 | + ''' | |
202 | + if len(command) < 3: raise UnknownCommandException() | |
203 | + if not (command[-1]=='#'): raise UnknownCommandException() | |
204 | + if not (command[0]==':') and command not in ('bC#','bW#','bR#'): raise UnknownCommandException() | |
205 | + ''' | |
201 | 206 | if ( |
202 | 207 | (len(command) < 3) |
203 | 208 | or |
... | ... | @@ -208,22 +213,26 @@ class DeviceSimulator: |
208 | 213 | ): |
209 | 214 | raise UnknownCommandException() |
210 | 215 | |
211 | - command_start = command[1:3] | |
212 | 216 | |
213 | - # If "set_xxx" command, update related "get_xxx" command simulated answer in the commands dictionary | |
214 | - #if command_start in ('SC', 'SL', 'Sg', 'St'): | |
215 | - if command_start[0] == 'S': | |
216 | - #Memo.set(command_start[1],command[3:]) | |
217 | - #related_get_cmd_name = 'G'+ command_start[1] | |
218 | - related_get_cmd_name = cls.my_dc.get_related_native_get_cmd_name_for_set_cmd(command_start) | |
219 | - #printd('(SIM) related_get_cmd_name:', related_get_cmd_name) | |
220 | - if related_get_cmd_name: | |
221 | - cls.my_dc.set_simulated_answer_for_native_get_cmd(related_get_cmd_name, command) | |
222 | - | |
223 | - ##answer = cls.get_simulated_answer_for_native_cmd(command_start) | |
224 | - answer = cls.my_dc.get_simulated_answer_for_native_cmd(command_start) | |
225 | - if answer is None: answer='NO ANSWER IMPLEMENTED FOR COMMAND '+command | |
226 | - printd("****** (SIM) answer for native cmd", command_start, "is:", answer) | |
217 | + # TODO: GEMINI SPECIFIC => move from this default method | |
218 | + if command in (cls.protoc.COMMAND6, cls.protoc.COMMAND5): | |
219 | + if command == cls.protoc.COMMAND6: answer = "G" | |
220 | + elif command == cls.protoc.COMMAND5: answer = cls.protoc.COMMAND5 | |
221 | + else: | |
222 | + command_start = command[1:3] | |
223 | + # If "set_xxx" command, update related "get_xxx" command simulated answer in the commands dictionary | |
224 | + #if command_start in ('SC', 'SL', 'Sg', 'St'): | |
225 | + if command_start[0] == 'S': | |
226 | + #Memo.set(command_start[1],command[3:]) | |
227 | + #related_get_cmd_name = 'G'+ command_start[1] | |
228 | + related_get_cmd_name = cls.my_dc.get_related_native_get_cmd_name_for_set_cmd(command_start) | |
229 | + #printd('(SIM) related_get_cmd_name:', related_get_cmd_name) | |
230 | + if related_get_cmd_name: | |
231 | + cls.my_dc.set_simulated_answer_for_native_get_cmd(related_get_cmd_name, command) | |
232 | + ##answer = cls.get_simulated_answer_for_native_cmd(command_start) | |
233 | + answer = cls.my_dc.get_simulated_answer_for_native_cmd(command_start) | |
234 | + if answer is None: answer='NO ANSWER IMPLEMENTED FOR COMMAND '+command | |
235 | + printd("****** (SIM) answer for native cmd", command_start, "is:", answer) | |
227 | 236 | |
228 | 237 | ''' |
229 | 238 | if command == cls.protoc.COMMAND6: answer = "G" | ... | ... |
src/device_controller/channels/client_channel.py
... | ... | @@ -42,7 +42,7 @@ class ClientChannel(): |
42 | 42 | self.PROTOCOL = PROTOCOL |
43 | 43 | self.buf = buffer_size |
44 | 44 | |
45 | - self._log = LogPyros(self.__class__.__name__) | |
45 | + self.log = LogPyros(self.__class__.__name__) | |
46 | 46 | |
47 | 47 | # Logger configuration |
48 | 48 | #self.set_logger() |
... | ... | @@ -61,8 +61,8 @@ class ClientChannel(): |
61 | 61 | print("Client channel killed") |
62 | 62 | |
63 | 63 | # LOG methods |
64 | - def print(self, *args, **kwargs): self._log.print(*args, **kwargs) | |
65 | - def printd(self, *args, **kwargs): self._log.printd(*args, **kwargs) | |
64 | + def print(self, *args, **kwargs): self.log.print(*args, **kwargs) | |
65 | + def printd(self, *args, **kwargs): self.log.printd(*args, **kwargs) | |
66 | 66 | |
67 | 67 | |
68 | 68 | def send_data(self, data:str): | ... | ... |
src/device_controller/test/test_client_gemini.py
... | ... | @@ -36,9 +36,12 @@ class TestClient(unittest.TestCase): |
36 | 36 | def test_run_unittests(self): |
37 | 37 | |
38 | 38 | q_a = [ |
39 | - (':toto#', 'TOTO'), | |
39 | + #(':toto#', 'TOTO'), | |
40 | + (':toto#', 'NO ANSWER IMPLEMENTED FOR COMMAND :toto#'), | |
41 | + #(':GD#', '+12:30'), | |
40 | 42 | (':GD#', '+12:29'), |
41 | 43 | #(':GD#', '+12:28') |
44 | + # Command SIX (6) | |
42 | 45 | ('6', 'G'), |
43 | 46 | ] |
44 | 47 | |
... | ... | @@ -72,6 +75,7 @@ class TestClient(unittest.TestCase): |
72 | 75 | print("ra-dec is", radec) |
73 | 76 | #self.assertEqual(radec, ('15:01:48', '+12:28')) |
74 | 77 | self.assertEqual(radec.txt, '15:01:49,+12:29') |
78 | + #self.assertEqual(radec.txt, '15:01:50,+12:30') | |
75 | 79 | |
76 | 80 | #tele_client.close() |
77 | 81 | ... | ... |