Commit 6d1f4089bab17c3502199f6ff381742ff6ffbb13
1 parent
34996a84
Exists in
dev
cleanup
Showing
5 changed files
with
51 additions
and
17 deletions
Show diff stats
CHANGELOG
1 | +21-10-2022 (EP): v0.6.4.0 | |
2 | + - Agent updates : | |
3 | + - cleanup : methods are now either private, protected, or public, according to their role | |
4 | + - CTRL-C managed sooner : no more at main_loop level but at restart_loop level | |
5 | + - Misnamed commands managed and test error cases added to AgentBasic | |
6 | + - nicer/easier reading of general algo | |
7 | + - allow to send command to AgentXY even if AgentXY running in test mode (better managed but not yet completely ok, can crash agent...) | |
8 | + - Stop : affiche le nom de l’agent qui s’arrete | |
1 | 9 | 21-10-2022 (AKo): v0.6.3.0 |
2 | 10 | - UI changes on agent detail |
3 | 11 | - Handling badly nammed commands | ... | ... |
VERSION
privatedev/plugin/agent/AgentBasic.py
... | ... | @@ -35,12 +35,18 @@ class AgentBasic(Agent): |
35 | 35 | # @override |
36 | 36 | _AGENT_SPECIFIC_COMMANDS = [ |
37 | 37 | # Format : (“cmd_name”, timeout, exec_mode) |
38 | - ("do_specific10", 10, 0), | |
38 | + | |
39 | + # Error raising commands | |
39 | 40 | ("do_cmd_unimplemented_and_declared", 3, 0), |
40 | - ("cmd_badly_named_and_declared", 3, 0), | |
41 | + ("cmd_misnamed_and_declared", 3, 0), | |
42 | + ("do_cmd_raising_error_exec", 3, 0), | |
43 | + | |
44 | + # Normal Commands | |
41 | 45 | #("set_specific2", 5, 0), |
46 | + ("do_specific10", 10, 0), | |
42 | 47 | ("do_specific30", 3, 0), |
43 | - ("do_cmd_raising_error_exec", 3, 0), | |
48 | + ("do_cmd_with_long_exec_time", 3, 0), | |
49 | + | |
44 | 50 | ] |
45 | 51 | |
46 | 52 | # Deactivate some tests, so that test scenario runs faster during DEV |
... | ... | @@ -80,9 +86,9 @@ class AgentBasic(Agent): |
80 | 86 | |
81 | 87 | |
82 | 88 | # - Error case 1 - CMD_INVALID |
83 | - # a) Badly named commands | |
84 | - (True, "self cmd_badly_named_and_declared", 200, "Command badly named, must start with do_, get_, or set_", Agent.CMD_STATUS.CMD_INVALID), | |
85 | - (COMMIT_ONLY, "self cmd_badly_named_and_undeclared", 200, None, Agent.CMD_STATUS.CMD_INVALID), | |
89 | + # a) Misnamed commands | |
90 | + (True, "self cmd_misnamed_and_declared", 200, "Command misnamed, must start with do_, get_, or set_", Agent.CMD_STATUS.CMD_INVALID), | |
91 | + (COMMIT_ONLY, "self cmd_misnamed_and_undeclared", 200, None, Agent.CMD_STATUS.CMD_INVALID), | |
86 | 92 | # b) Unknwon command |
87 | 93 | ##FIXME: ("self unexisting_cmd", 200, '', Agent.CMD_STATUS.CMD_UNKNOWN), |
88 | 94 | (COMMIT_ONLY, "self do_cmd_unexisting", 200, 'EXCEPTION on command do_cmd_unexisting: Unknown command', Agent.CMD_STATUS.CMD_INVALID), |
... | ... | @@ -348,6 +354,11 @@ class AgentBasic(Agent): |
348 | 354 | def do_cmd_raising_error_exec(self): |
349 | 355 | raise CmdExceptionExecError(self.current_cmd) |
350 | 356 | |
357 | + # Long time execution command | |
358 | + def do_cmd_with_long_exec_time(self): | |
359 | + self.waitfor(100) | |
360 | + return "took 100s to execute" | |
361 | + | |
351 | 362 | def do_specific10(self, |
352 | 363 | arg1:int, |
353 | 364 | arg2:int, | ... | ... |
src/core/pyros_django/agent/Agent.py
... | ... | @@ -1037,7 +1037,7 @@ class Agent: |
1037 | 1037 | except KeyboardInterrupt: # CTRL-C |
1038 | 1038 | # In case of CTRL-C, kill the current thread (process) before dying (in error) |
1039 | 1039 | #log.info("CTRL-C Interrupted, I kill the current thread (process) before exiting (if exists)") |
1040 | - log.info("CTRL-C Interrupted, trying to stop cleanly") | |
1040 | + log.info(f"{self.name}: CTRL-C Interrupted") | |
1041 | 1041 | break |
1042 | 1042 | #self._kill_running_device_cmd_if_exists("USER_CTRLC") |
1043 | 1043 | #self.do_things_before_exit("USER_CTRLC") |
... | ... | @@ -1196,8 +1196,8 @@ class Agent: |
1196 | 1196 | #self._set_status(self.STATUS_EXIT) |
1197 | 1197 | ##self._log_agent_state() |
1198 | 1198 | |
1199 | - log.info("Trying to stop cleanly") | |
1200 | - log.info("Before exiting, Here are (if exists) the current (still) pending commands (time ordered) :") | |
1199 | + log.info(f"{self.name}: Trying to stop cleanly") | |
1200 | + log.info(f"{self.name}: Before exiting, Here are (if exists) the current (still) pending commands (time ordered) :") | |
1201 | 1201 | #commands = AgentCmd.get_commands_sent_to_agent(self.name) |
1202 | 1202 | commands = AgentCmd.get_pending_and_running_commands_for_agent(self.name) |
1203 | 1203 | AgentCmd.show_commands(commands, True) |
... | ... | @@ -1208,6 +1208,7 @@ class Agent: |
1208 | 1208 | #self._DO_EXIT=True |
1209 | 1209 | #exit(0) |
1210 | 1210 | |
1211 | + log.info(f"{self.name}: Before exiting, calling do_things_before_exit()") | |
1211 | 1212 | self._do_things_before_exit(stopper_agent_name) |
1212 | 1213 | ##self._set_and_log_status(self.AGT_STATUS.EXITING) |
1213 | 1214 | |
... | ... | @@ -1335,7 +1336,7 @@ class Agent: |
1335 | 1336 | cmd.set_read_time() |
1336 | 1337 | |
1337 | 1338 | if not AgentCmd.is_generic(cmd.name) and not self.is_native_device_command(cmd.name): |
1338 | - cmd.set_as_invalid("Command badly named, must start with do_, get_, or set_") | |
1339 | + cmd.set_as_invalid("Command misnamed, must start with do_, get_, or set_") | |
1339 | 1340 | return cmd |
1340 | 1341 | |
1341 | 1342 | # CASE 1 - AGENT GENERAL command |
... | ... | @@ -2583,6 +2584,9 @@ class Agent: |
2583 | 2584 | |
2584 | 2585 | if not self.is_in_test_mode(): return |
2585 | 2586 | if not cmd: return |
2587 | + # Only check TEST commands (not checking commands sent by others, like via the web interface...) | |
2588 | + #print("*** TEST ***", self.name) | |
2589 | + if cmd.sender != self.name: return | |
2586 | 2590 | |
2587 | 2591 | log.debug("*** CHECK ***") |
2588 | 2592 | #if hasattr(self._cmdts,'expected_res'): | ... | ... |
src/core/pyros_django/agent/AgentBasic.py
... | ... | @@ -35,12 +35,18 @@ class AgentBasic(Agent): |
35 | 35 | # @override |
36 | 36 | _AGENT_SPECIFIC_COMMANDS = [ |
37 | 37 | # Format : (“cmd_name”, timeout, exec_mode) |
38 | - ("do_specific10", 10, 0), | |
38 | + | |
39 | + # Error raising commands | |
39 | 40 | ("do_cmd_unimplemented_and_declared", 3, 0), |
40 | - ("cmd_badly_named_and_declared", 3, 0), | |
41 | + ("cmd_misnamed_and_declared", 3, 0), | |
42 | + ("do_cmd_raising_error_exec", 3, 0), | |
43 | + | |
44 | + # Normal Commands | |
41 | 45 | #("set_specific2", 5, 0), |
46 | + ("do_specific10", 10, 0), | |
42 | 47 | ("do_specific30", 3, 0), |
43 | - ("do_cmd_raising_error_exec", 3, 0), | |
48 | + ("do_cmd_with_long_exec_time", 3, 0), | |
49 | + | |
44 | 50 | ] |
45 | 51 | |
46 | 52 | # Deactivate some tests, so that test scenario runs faster during DEV |
... | ... | @@ -80,9 +86,9 @@ class AgentBasic(Agent): |
80 | 86 | |
81 | 87 | |
82 | 88 | # - Error case 1 - CMD_INVALID |
83 | - # a) Badly named commands | |
84 | - (True, "self cmd_badly_named_and_declared", 200, "Command badly named, must start with do_, get_, or set_", Agent.CMD_STATUS.CMD_INVALID), | |
85 | - (COMMIT_ONLY, "self cmd_badly_named_and_undeclared", 200, None, Agent.CMD_STATUS.CMD_INVALID), | |
89 | + # a) Misnamed commands | |
90 | + (True, "self cmd_misnamed_and_declared", 200, "Command misnamed, must start with do_, get_, or set_", Agent.CMD_STATUS.CMD_INVALID), | |
91 | + (COMMIT_ONLY, "self cmd_misnamed_and_undeclared", 200, None, Agent.CMD_STATUS.CMD_INVALID), | |
86 | 92 | # b) Unknwon command |
87 | 93 | ##FIXME: ("self unexisting_cmd", 200, '', Agent.CMD_STATUS.CMD_UNKNOWN), |
88 | 94 | (COMMIT_ONLY, "self do_cmd_unexisting", 200, 'EXCEPTION on command do_cmd_unexisting: Unknown command', Agent.CMD_STATUS.CMD_INVALID), |
... | ... | @@ -348,6 +354,11 @@ class AgentBasic(Agent): |
348 | 354 | def do_cmd_raising_error_exec(self): |
349 | 355 | raise CmdExceptionExecError(self.current_cmd) |
350 | 356 | |
357 | + # Long time execution command | |
358 | + def do_cmd_with_long_exec_time(self): | |
359 | + self.waitfor(100) | |
360 | + return "took 100s to execute" | |
361 | + | |
351 | 362 | def do_specific10(self, |
352 | 363 | arg1:int, |
353 | 364 | arg2:int, | ... | ... |