Commit d6441fe977a6bdaa733f039db7d212673ee777cd

Authored by Etienne Pallier
1 parent 9fa0958e
Exists in dev

new methods is_xxx for AgentCmd

privatedev/plugin/agent/AgentBasic.py
... ... @@ -36,7 +36,7 @@ class AgentBasic(Agent):
36 36 ("do_specific10", 10, 0),
37 37 #("set_specific2", 5, 0),
38 38 ("do_specific30", 3, 0),
39   - ("existing_but_unimplemented_cmd", 3, 0),
  39 + ####("existing_but_unimplemented_cmd", 3, 0),
40 40 ]
41 41  
42 42 # @override
... ... @@ -44,6 +44,18 @@ class AgentBasic(Agent):
44 44  
45 45 # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status),
46 46 #("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED),
  47 +
  48 + # do_stop
  49 + #("self do_stop now", 200, 'STOPPING now', Agent.CMD_STATUS.CMD_EXECUTED),
  50 + #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED),
  51 + #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED),
  52 +
  53 + ("self do_restart now", 200, 'RESTARTING now', Agent.CMD_STATUS.CMD_EXECUTED),
  54 + #("self get_specific_cmds", 200, 'EXCEPTION - One specific cmd is unimplemented: existing_but_unimplemented_cmd', Agent.CMD_STATUS.CMD_EXEC_ERROR),
  55 + ("self get_specific_cmds", 200, 'do_specific10(arg1:int,arg2:int,arg3:float,arg4:str,arg5:typing.Tuple[int, str, int],arg6:typing.List[int]);do_specific30()', Agent.CMD_STATUS.CMD_EXECUTED),
  56 + ("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED),
  57 +
  58 +
47 59 ("self do_specific10 2 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, '16.5', None),
48 60  
49 61 # bad parameters (missing or too many, or bad type)=> CMD_INVALID
... ... @@ -125,11 +137,11 @@ class AgentBasic(Agent):
125 137  
126 138 # @override
127 139 def main_loop_start(self):
128   - print("LOOP START")
  140 + print("AgentBasic LOOP START")
129 141  
130 142 # @override
131 143 def main_loop_end(self):
132   - print("LOOP END");
  144 + print("AgentBasic LOOP END");
133 145  
134 146 # @override
135 147 def routine_process_before_body(self):
... ...
src/core/pyros_django/agent/AgentBasic.py
... ... @@ -36,7 +36,7 @@ class AgentBasic(Agent):
36 36 ("do_specific10", 10, 0),
37 37 #("set_specific2", 5, 0),
38 38 ("do_specific30", 3, 0),
39   - ("existing_but_unimplemented_cmd", 3, 0),
  39 + ####("existing_but_unimplemented_cmd", 3, 0),
40 40 ]
41 41  
42 42 # @override
... ... @@ -45,15 +45,14 @@ class AgentBasic(Agent):
45 45 # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status),
46 46 #("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED),
47 47  
48   -
49   -
50 48 # do_stop
51 49 #("self do_stop now", 200, 'STOPPING now', Agent.CMD_STATUS.CMD_EXECUTED),
52 50 #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED),
53 51 #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED),
54 52  
55 53 ("self do_restart now", 200, 'RESTARTING now', Agent.CMD_STATUS.CMD_EXECUTED),
56   - ("self get_specific_cmds", 200, 'EXCEPTION - One specific cmd is unimplemented: existing_but_unimplemented_cmd', Agent.CMD_STATUS.CMD_EXEC_ERROR),
  54 + #("self get_specific_cmds", 200, 'EXCEPTION - One specific cmd is unimplemented: existing_but_unimplemented_cmd', Agent.CMD_STATUS.CMD_EXEC_ERROR),
  55 + ("self get_specific_cmds", 200, 'do_specific10(arg1:int,arg2:int,arg3:float,arg4:str,arg5:typing.Tuple[int, str, int],arg6:typing.List[int]);do_specific30()', Agent.CMD_STATUS.CMD_EXECUTED),
57 56 ("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED),
58 57  
59 58  
... ...
src/core/pyros_django/common/models.py
... ... @@ -929,30 +929,16 @@ class AgentCmd(models.Model):
929 929 def is_read(self):
930 930 return self.r_read_time is not None
931 931  
  932 + # CMD status
  933 +
  934 + # 1 - pending
932 935 def is_pending(self):
933 936 return self.state == self.CMD_STATUS_CODES.CMD_PENDING
934 937  
935   - def is_running(self):
936   - return self.state == self.CMD_STATUS_CODES.CMD_RUNNING
937   -
938   - # execution finished without error
939   - def is_executed(self):
940   - return self.state == self.CMD_STATUS_CODES.CMD_EXECUTED
941   -
942   - # Cmd is finished if not pending or running
943   - def is_finished(self):
944   - return not (self.is_pending() or self.is_running())
945   -
946   - # Cmd is finished with error : finished but NOT executed
947   - def is_finished_with_error(self):
948   - return self.is_finished() and not self.is_executed()
949   -
950   - def is_skipped(self):
951   - return self.state == self.CMD_STATUS_CODES.CMD_SKIPPED
952   -
953   - def is_killed(self):
954   - return self.state == self.CMD_STATUS_CODES.CMD_EXEC_KILLED
955   -
  938 + # 2 - ERROR cases (from PENDING)
  939 + def is_invalid(self): return self.state == self.CMD_STATUS_CODES.CMD_INVALID
  940 + def is_unimplemented(self): return self.state == self.CMD_STATUS_CODES.CMD_UNIMPLEMENTED
  941 + def is_skipped(self): return self.state == self.CMD_STATUS_CODES.CMD_SKIPPED
956 942 def is_expired(self):
957 943 if self.state == self.CMD_STATUS_CODES.CMD_EXPIRED: return True
958 944 # Must NOT be running
... ... @@ -967,8 +953,21 @@ class AgentCmd(models.Model):
967 953 print(f"Elapsed time is {elapsed_time}, (max is {max_time})")
968 954 if elapsed_time > max_time:
969 955 """
  956 + # finished with issue (from pending)
  957 + def is_pending_issue(self): return self.is_invalid() or self.is_unimplemented() or self.is_skipped() or self.is_expired()
  958 +
  959 + # 3 - running
  960 + def is_running(self):
  961 + return self.state == self.CMD_STATUS_CODES.CMD_RUNNING
970 962  
971   - def is_timeout(self):
  963 + # 4 - ERROR cases (from RUNNING)
  964 + def is_exec_error(self): return self.state == self.CMD_STATUS_CODES.CMD_EXEC_ERROR
  965 + def is_exec_killed(self): return self.state == self.CMD_STATUS_CODES.CMD_EXEC_KILLED
  966 + # alias
  967 + def is_killed(self): return self.is_exec_killed()
  968 + # alias
  969 + def is_timeout(self): return self.is_exec_timeout()
  970 + def is_exec_timeout(self):
972 971 if self.state == self.CMD_STATUS_CODES.CMD_EXEC_TIMEOUT: return True
973 972 # Must be running
974 973 if not self.is_running(): return False
... ... @@ -976,6 +975,20 @@ class AgentCmd(models.Model):
976 975 elapsed_time = (datetime.utcnow().astimezone() - self.r_start_time)
977 976 printd("elapsed_time since exec", elapsed_time)
978 977 return elapsed_time > timedelta(seconds=self.exec_timeout)
  978 + # finished with any execution issue
  979 + def is_exec_issue(self): return self.state.startswith("CMD_EXEC_")
  980 +
  981 + # 5 - Execution finished
  982 + # Cmd is finished if not pending or running
  983 + def is_finished(self):
  984 + return not (self.is_pending() or self.is_running())
  985 + # Cmd is finished with error : finished but NOT executed
  986 + def is_finished_with_error(self):
  987 + return self.is_finished() and not self.is_executed()
  988 + # Cmd is finished without error (normal case)
  989 + def is_executed(self):
  990 + return self.state == self.CMD_STATUS_CODES.CMD_EXECUTED
  991 +
979 992  
980 993 # --- GETTERS/SETTERS functions ---
981 994  
... ...