Commit 975bf9f67db19fcdcdfc7a2d9047830859ea8fa1
1 parent
088d73f1
Exists in
dev
bugfix priority command read time
Showing
3 changed files
with
113 additions
and
39 deletions
Show diff stats
privatedev/plugin/agent/AgentBasic.py
@@ -46,22 +46,22 @@ class AgentBasic(Agent): | @@ -46,22 +46,22 @@ class AgentBasic(Agent): | ||
46 | 46 | ||
47 | # Normal Commands | 47 | # Normal Commands |
48 | #("set_specific2", 5, 0), | 48 | #("set_specific2", 5, 0), |
49 | - ("do_specific10", 10, Agent.EXEC_MODE.SEQUENTIAL), | ||
50 | - ("do_specific30", 3, Agent.EXEC_MODE.SEQUENTIAL), | ||
51 | - ("do_cmd_with_long_exec_time", 3, Agent.EXEC_MODE.SEQUENTIAL), | 49 | + ("do_specific10", 1, Agent.EXEC_MODE.SEQUENTIAL), |
50 | + ("do_specific30", 0, Agent.EXEC_MODE.SEQUENTIAL), | ||
51 | + ("do_cmd_with_long_exec_time", 50, Agent.EXEC_MODE.THREAD), | ||
52 | 52 | ||
53 | ] | 53 | ] |
54 | 54 | ||
55 | # Deactivate some tests, so that test scenario runs faster during DEV | 55 | # Deactivate some tests, so that test scenario runs faster during DEV |
56 | # on DEV | 56 | # on DEV |
57 | - #COMMIT_ONLY = False | 57 | + COMMIT_ONLY = False |
58 | # on commit only | 58 | # on commit only |
59 | - COMMIT_ONLY = True | 59 | + #COMMIT_ONLY = True |
60 | 60 | ||
61 | # @override | 61 | # @override |
62 | _TEST_COMMANDS_LIST = [ | 62 | _TEST_COMMANDS_LIST = [ |
63 | 63 | ||
64 | - # Format : (DO_IT, "self cmd_name cmd_args", timeout, "expected_result", expected_status), | 64 | + # Format : (DO_IT, "self cmd_name cmd_args", validity, "expected_result", expected_status), |
65 | 65 | ||
66 | #("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), | 66 | #("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), |
67 | 67 | ||
@@ -71,14 +71,16 @@ class AgentBasic(Agent): | @@ -71,14 +71,16 @@ class AgentBasic(Agent): | ||
71 | #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), | 71 | #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
72 | 72 | ||
73 | # get_specific_cmds | 73 | # get_specific_cmds |
74 | - (True, " self get_specific_cmds ", 200, | 74 | + (True, " self get_all_cmds ", 100, |
75 | None, | 75 | None, |
76 | #'do_specific10(arg1:int,arg2:int,arg3:float,arg4:str,arg5:typing.Tuple[int, str, int],arg6:typing.List[int]);do_specific30();do_cmd_raising_some_exception();do_cmd_unimplemented(U)', | 76 | #'do_specific10(arg1:int,arg2:int,arg3:float,arg4:str,arg5:typing.Tuple[int, str, int],arg6:typing.List[int]);do_specific30();do_cmd_raising_some_exception();do_cmd_unimplemented(U)', |
77 | Agent.CMD_STATUS.CMD_EXECUTED | 77 | Agent.CMD_STATUS.CMD_EXECUTED |
78 | ), | 78 | ), |
79 | 79 | ||
80 | - # do_restart | ||
81 | (COMMIT_ONLY, "self do_restart asap", 200, 'RESTARTING asap', Agent.CMD_STATUS.CMD_EXECUTED), | 80 | (COMMIT_ONLY, "self do_restart asap", 200, 'RESTARTING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
81 | + | ||
82 | + # do_restart | ||
83 | + (True, "self do_cmd_with_long_exec_time", 200, None, Agent.CMD_STATUS.CMD_EXECUTED), | ||
82 | #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), | 84 | #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
83 | 85 | ||
84 | # ---------------------------------------------------- | 86 | # ---------------------------------------------------- |
@@ -371,8 +373,39 @@ class AgentBasic(Agent): | @@ -371,8 +373,39 @@ class AgentBasic(Agent): | ||
371 | 373 | ||
372 | # Long time execution command | 374 | # Long time execution command |
373 | def do_cmd_with_long_exec_time(self): | 375 | def do_cmd_with_long_exec_time(self): |
374 | - self.waitfor(100) | ||
375 | - return "took 100s to execute" | 376 | + nbsec=8 |
377 | + | ||
378 | + res = f"1 - now sleeping {nbsec} sec" | ||
379 | + self.CC.set_result(res, True) | ||
380 | + #self.CC.get_updated_result() | ||
381 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
382 | + self.sleep(nbsec) | ||
383 | + | ||
384 | + res = f"2 - now sleeping {nbsec} sec" | ||
385 | + self.CC.set_result(res, True) | ||
386 | + #self.CC.get_updated_result() | ||
387 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
388 | + self.sleep(nbsec) | ||
389 | + | ||
390 | + res = f"3 - now sleeping {nbsec} sec" | ||
391 | + self.CC.set_result(res, True) | ||
392 | + #self.CC.get_updated_result() | ||
393 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
394 | + self.sleep(nbsec) | ||
395 | + | ||
396 | + res = f"4 - now sleeping {nbsec} sec" | ||
397 | + self.CC.set_result(res, True) | ||
398 | + #self.CC.get_updated_result() | ||
399 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
400 | + self.sleep(nbsec) | ||
401 | + | ||
402 | + res = f"5 - now sleeping {nbsec} sec" | ||
403 | + self.CC.set_result(res, True) | ||
404 | + #self.CC.get_updated_result() | ||
405 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
406 | + self.sleep(nbsec) | ||
407 | + | ||
408 | + return f"should have taken {5*nbsec}s to execute" | ||
376 | 409 | ||
377 | def do_specific10(self, | 410 | def do_specific10(self, |
378 | arg1:int, | 411 | arg1:int, |
src/core/pyros_django/agent/Agent.py
@@ -327,6 +327,7 @@ class Agent: | @@ -327,6 +327,7 @@ class Agent: | ||
327 | #_AGENT_SPECIFIC_COMMANDS: List[ Tuple[str, int, int] ] = [ | 327 | #_AGENT_SPECIFIC_COMMANDS: List[ Tuple[str, int, int] ] = [ |
328 | _AGENT_SPECIFIC_COMMANDS: List[ Tuple[str, int, EXEC_MODE] ] = [ | 328 | _AGENT_SPECIFIC_COMMANDS: List[ Tuple[str, int, EXEC_MODE] ] = [ |
329 | # Format : (โcmd_nameโ, timeout, exec_mode) | 329 | # Format : (โcmd_nameโ, timeout, exec_mode) |
330 | + | ||
330 | ("do_specific1", 10, EXEC_MODE.SEQUENTIAL), | 331 | ("do_specific1", 10, EXEC_MODE.SEQUENTIAL), |
331 | #("set_specific2", 5, 0), | 332 | #("set_specific2", 5, 0), |
332 | ("do_specific3", 3, EXEC_MODE.THREAD), | 333 | ("do_specific3", 3, EXEC_MODE.THREAD), |
@@ -368,7 +369,7 @@ class Agent: | @@ -368,7 +369,7 @@ class Agent: | ||
368 | # - cmd : the command name | 369 | # - cmd : the command name |
369 | # - args : (optional) the list of command arguments, separated by blanks : arg1 arg2 arg3 ... | 370 | # - args : (optional) the list of command arguments, separated by blanks : arg1 arg2 arg3 ... |
370 | # | 371 | # |
371 | - # - validity : the command is valid for this duration, afterwards you can forget it | 372 | + # - validity : the command is valid for this duration, afterwards you can skip it |
372 | # | 373 | # |
373 | # - expected_res : the expected result (set to None if not to be tested) | 374 | # - expected_res : the expected result (set to None if not to be tested) |
374 | # | 375 | # |
@@ -381,9 +382,10 @@ class Agent: | @@ -381,9 +382,10 @@ class Agent: | ||
381 | # - "self do_restart_loop" => means to send the command "do_restart_loop" to MYSELF (no args) | 382 | # - "self do_restart_loop" => means to send the command "do_restart_loop" to MYSELF (no args) |
382 | # | 383 | # |
383 | #_TEST_COMMANDS_LIST: List[ Tuple[ bool, str, int, Union[str,None], Union[int,None] ] ] = [ | 384 | #_TEST_COMMANDS_LIST: List[ Tuple[ bool, str, int, Union[str,None], Union[int,None] ] ] = [ |
384 | - _TEST_COMMANDS_LIST: List[ Tuple[ bool, str, int, Optional[str], Optional[int]] ] = [ | 385 | + ##_TEST_COMMANDS_LIST: List[ Tuple[ bool, str, int, Optional[str], AgentCmd.CMD_STATUS_CODES ] ] = [ |
386 | + _TEST_COMMANDS_LIST: List[ Tuple[ bool, str, Optional[int], Optional[str], Optional[int]] ] = [ | ||
387 | + # Format : (DO_IT, "self cmd_name cmd_args", validity, "expected_result", expected_status), | ||
385 | 388 | ||
386 | - # Format : (DO_IT, "self cmd_name cmd_args", timeout, "expected_result", expected_status), | ||
387 | #("self do_stop now", 200, '15.5', None), | 389 | #("self do_stop now", 200, '15.5', None), |
388 | (True, "self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, '15.5', None), | 390 | (True, "self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, '15.5', None), |
389 | 391 | ||
@@ -1127,7 +1129,7 @@ class Agent: | @@ -1127,7 +1129,7 @@ class Agent: | ||
1127 | ###cmd = self.__start_next_received_cmd_if_possible_and_exists() | 1129 | ###cmd = self.__start_next_received_cmd_if_possible_and_exists() |
1128 | # Better : | 1130 | # Better : |
1129 | cmd = self.__get_next_received_cmd_if_possible_and_exists() | 1131 | cmd = self.__get_next_received_cmd_if_possible_and_exists() |
1130 | - if cmd: | 1132 | + if cmd: |
1131 | self.__CC_prev = self.__CC | 1133 | self.__CC_prev = self.__CC |
1132 | # This way, started commands will be able to access the current command via self.__CC | 1134 | # This way, started commands will be able to access the current command via self.__CC |
1133 | self.__CC = cmd | 1135 | self.__CC = cmd |
@@ -1169,7 +1171,9 @@ class Agent: | @@ -1169,7 +1171,9 @@ class Agent: | ||
1169 | 1171 | ||
1170 | 1172 | ||
1171 | def __get_next_received_cmd_if_possible_and_exists(self)->Optional[AgentCmd]: | 1173 | def __get_next_received_cmd_if_possible_and_exists(self)->Optional[AgentCmd]: |
1174 | + self.__set_and_log_status(self.AGT_STATUS.IN_MAIN_LOOP_GET_NEXT_CMD) | ||
1172 | cmd = None | 1175 | cmd = None |
1176 | + | ||
1173 | # GET NEXT COMMAND if exists and if current cmd is finished | 1177 | # GET NEXT COMMAND if exists and if current cmd is finished |
1174 | #if self.__CC is None or self.__CC.is_finished() or self.__priority_cmd_received(): | 1178 | #if self.__CC is None or self.__CC.is_finished() or self.__priority_cmd_received(): |
1175 | CMD_PRIO = self.__get_received_priority_cmd_if_exists() | 1179 | CMD_PRIO = self.__get_received_priority_cmd_if_exists() |
@@ -1189,10 +1193,12 @@ class Agent: | @@ -1189,10 +1193,12 @@ class Agent: | ||
1189 | log.info("RUNNING PRIORITY COMMAND:") | 1193 | log.info("RUNNING PRIORITY COMMAND:") |
1190 | log.info(str(CMD_PRIO)) | 1194 | log.info(str(CMD_PRIO)) |
1191 | cmd = CMD_PRIO if CMD_PRIO else self.__get_next_received_cmd_if_exists() | 1195 | cmd = CMD_PRIO if CMD_PRIO else self.__get_next_received_cmd_if_exists() |
1196 | + | ||
1192 | return cmd | 1197 | return cmd |
1193 | 1198 | ||
1194 | 1199 | ||
1195 | def __start_next_received_cmd(self, cmd:AgentCmd)->None: | 1200 | def __start_next_received_cmd(self, cmd:AgentCmd)->None: |
1201 | + cmd.set_read_time() | ||
1196 | print() | 1202 | print() |
1197 | print() | 1203 | print() |
1198 | log.info("*"*10 + " NEXT CMD RECEIVED PROCESSING (START) " + "*"*10 + '\n') | 1204 | log.info("*"*10 + " NEXT CMD RECEIVED PROCESSING (START) " + "*"*10 + '\n') |
@@ -1427,7 +1433,7 @@ class Agent: | @@ -1427,7 +1433,7 @@ class Agent: | ||
1427 | def __start_cmd(self, cmd:AgentCmd)->None: | 1433 | def __start_cmd(self, cmd:AgentCmd)->None: |
1428 | ''' Processing the next pending command (self.__CC) ''' | 1434 | ''' Processing the next pending command (self.__CC) ''' |
1429 | #cmd = self.__CC | 1435 | #cmd = self.__CC |
1430 | - self.__set_and_log_status(self.AGT_STATUS.IN_MAIN_LOOP_GET_NEXT_CMD) | 1436 | + #self.__set_and_log_status(self.AGT_STATUS.IN_MAIN_LOOP_GET_NEXT_CMD) |
1431 | 1437 | ||
1432 | #print() | 1438 | #print() |
1433 | #print() | 1439 | #print() |
@@ -1640,11 +1646,11 @@ class Agent: | @@ -1640,11 +1646,11 @@ class Agent: | ||
1640 | old_commands.delete() | 1646 | old_commands.delete() |
1641 | """ | 1647 | """ |
1642 | 1648 | ||
1643 | - def sleep(self, nbsec): | 1649 | + def sleep(self, nbsec:float): |
1644 | log.info(f"Now, waiting (sleeping) for {nbsec} second(s)...") | 1650 | log.info(f"Now, waiting (sleeping) for {nbsec} second(s)...") |
1645 | time.sleep(nbsec) | 1651 | time.sleep(nbsec) |
1646 | # alias to sleep | 1652 | # alias to sleep |
1647 | - def waitfor(self, nbsec:float=2.0): | 1653 | + def waitfor(self, nbsec:float): |
1648 | ''' | 1654 | ''' |
1649 | # thread | 1655 | # thread |
1650 | if self._current_device_cmd_thread and self.RUN_IN_THREAD: | 1656 | if self._current_device_cmd_thread and self.RUN_IN_THREAD: |
@@ -1661,7 +1667,7 @@ class Agent: | @@ -1661,7 +1667,7 @@ class Agent: | ||
1661 | # MODE & STATUS | 1667 | # MODE & STATUS |
1662 | # | 1668 | # |
1663 | 1669 | ||
1664 | - def get_state(self): | 1670 | + def get_state(self)->str: |
1665 | return f"MODE is {self.__get_mode()} ; STATUS is {self.get_status()} ; ITERATION #{self.__iter_num}" | 1671 | return f"MODE is {self.__get_mode()} ; STATUS is {self.get_status()} ; ITERATION #{self.__iter_num}" |
1666 | 1672 | ||
1667 | def show_state(self): | 1673 | def show_state(self): |
@@ -1674,20 +1680,21 @@ class Agent: | @@ -1674,20 +1680,21 @@ class Agent: | ||
1674 | # | 1680 | # |
1675 | 1681 | ||
1676 | # - GET | 1682 | # - GET |
1677 | - def get_status(self): | 1683 | + def get_status(self)->AgentSurvey.STATUS_CHOICES: |
1678 | return self.__status | 1684 | return self.__status |
1679 | 1685 | ||
1680 | # - SET | 1686 | # - SET |
1681 | 1687 | ||
1682 | # Private because automatic, must not be changed, depends only on the step the Agent is currently running, used only by Agent (superclass) | 1688 | # Private because automatic, must not be changed, depends only on the step the Agent is currently running, used only by Agent (superclass) |
1683 | - def __set_status(self, status:str): | 1689 | + def __set_status(self, status:AgentSurvey.STATUS_CHOICES): |
1684 | #self.printd(f"[{status}] (switching from status {self.__status})") | 1690 | #self.printd(f"[{status}] (switching from status {self.__status})") |
1685 | log.debug(f"[{status}]") | 1691 | log.debug(f"[{status}]") |
1686 | self.__status = status | 1692 | self.__status = status |
1687 | return False | 1693 | return False |
1688 | 1694 | ||
1689 | # Private because automatic, must not be changed, used only by Agent (superclass) | 1695 | # Private because automatic, must not be changed, used only by Agent (superclass) |
1690 | - def __set_and_log_status(self, status:str): | 1696 | + ##def __set_and_log_status(self, status:str): |
1697 | + def __set_and_log_status(self, status:AgentSurvey.STATUS_CHOICES): | ||
1691 | self.__set_status(status) | 1698 | self.__set_status(status) |
1692 | self.__log_agent_state() | 1699 | self.__log_agent_state() |
1693 | 1700 | ||
@@ -1697,12 +1704,12 @@ class Agent: | @@ -1697,12 +1704,12 @@ class Agent: | ||
1697 | # | 1704 | # |
1698 | 1705 | ||
1699 | # - GET | 1706 | # - GET |
1700 | - def __get_mode(self): | 1707 | + def __get_mode(self)->AgentSurvey.MODE_CHOICES: |
1701 | return self.__mode | 1708 | return self.__mode |
1702 | # Test mode | 1709 | # Test mode |
1703 | - def IS_MODE_IDLE(self): return self.__get_mode() == AgentSurvey.MODE_CHOICES.IDLE | ||
1704 | - def IS_MODE_ROUTINE(self): return self.__get_mode() == AgentSurvey.MODE_CHOICES.ROUTINE | ||
1705 | - def IS_MODE_ATTENTIVE(self): return self.__get_mode() == AgentSurvey.MODE_CHOICES.ATTENTIVE | 1710 | + def IS_MODE_IDLE(self)->bool: return self.__get_mode() == AgentSurvey.MODE_CHOICES.IDLE |
1711 | + def IS_MODE_ROUTINE(self)->bool: return self.__get_mode() == AgentSurvey.MODE_CHOICES.ROUTINE | ||
1712 | + def IS_MODE_ATTENTIVE(self)->bool: return self.__get_mode() == AgentSurvey.MODE_CHOICES.ATTENTIVE | ||
1706 | # @deprecated | 1713 | # @deprecated |
1707 | def IS_IDLE(self): return self.IS_MODE_IDLE() | 1714 | def IS_IDLE(self): return self.IS_MODE_IDLE() |
1708 | # @deprecated | 1715 | # @deprecated |
@@ -1743,7 +1750,7 @@ class Agent: | @@ -1743,7 +1750,7 @@ class Agent: | ||
1743 | """ | 1750 | """ |
1744 | def suspend(self): | 1751 | def suspend(self): |
1745 | """ | 1752 | """ |
1746 | - TODO: | 1753 | + FIXME: |
1747 | Mode IDLE (doit rester ร l'รฉcoute d'un resume, | 1754 | Mode IDLE (doit rester ร l'รฉcoute d'un resume, |
1748 | et doit continuer ร alimenter les tables pour informer de son รฉtat via tables agents_logs, | 1755 | et doit continuer ร alimenter les tables pour informer de son รฉtat via tables agents_logs, |
1749 | et lire table agents_command pour reprendre via resume, | 1756 | et lire table agents_command pour reprendre via resume, |
@@ -1754,6 +1761,7 @@ class Agent: | @@ -1754,6 +1761,7 @@ class Agent: | ||
1754 | 1761 | ||
1755 | def resume(self): | 1762 | def resume(self): |
1756 | """ | 1763 | """ |
1764 | + FIXME: | ||
1757 | Quit suspend() mode | 1765 | Quit suspend() mode |
1758 | """ | 1766 | """ |
1759 | self._set_active() | 1767 | self._set_active() |
@@ -2105,7 +2113,7 @@ class Agent: | @@ -2105,7 +2113,7 @@ class Agent: | ||
2105 | # so return it for execution | 2113 | # so return it for execution |
2106 | #self.printd(f"Got command {cmd.name} sent by agent {cmd.sender} at {cmd.sender_deposit_time}") | 2114 | #self.printd(f"Got command {cmd.name} sent by agent {cmd.sender} at {cmd.sender_deposit_time}") |
2107 | #self.printd(f"Starting processing of this command") | 2115 | #self.printd(f"Starting processing of this command") |
2108 | - next_cmd.set_read_time() | 2116 | + ##next_cmd.set_read_time() |
2109 | return next_cmd | 2117 | return next_cmd |
2110 | 2118 | ||
2111 | 2119 | ||
@@ -2785,7 +2793,7 @@ class Agent: | @@ -2785,7 +2793,7 @@ class Agent: | ||
2785 | 2793 | ||
2786 | # To be overriden by subclass (AgentDevice...) | 2794 | # To be overriden by subclass (AgentDevice...) |
2787 | # @abstract | 2795 | # @abstract |
2788 | - def is_device_level_cmd(self, cmd): | 2796 | + def is_device_level_cmd(self, cmd)->bool: |
2789 | return False | 2797 | return False |
2790 | 2798 | ||
2791 | ''' | 2799 | ''' |
@@ -2802,7 +2810,7 @@ class Agent: | @@ -2802,7 +2810,7 @@ class Agent: | ||
2802 | ''' | 2810 | ''' |
2803 | 2811 | ||
2804 | 2812 | ||
2805 | - def __cmd_was_sent_before_my_start(self, cmd:AgentCmd): | 2813 | + def __cmd_was_sent_before_my_start(self, cmd:AgentCmd)->bool: |
2806 | return cmd.s_deposit_time < self.__UP_SINCE | 2814 | return cmd.s_deposit_time < self.__UP_SINCE |
2807 | 2815 | ||
2808 | 2816 |
src/core/pyros_django/agent/AgentBasic.py
@@ -46,22 +46,22 @@ class AgentBasic(Agent): | @@ -46,22 +46,22 @@ class AgentBasic(Agent): | ||
46 | 46 | ||
47 | # Normal Commands | 47 | # Normal Commands |
48 | #("set_specific2", 5, 0), | 48 | #("set_specific2", 5, 0), |
49 | - ("do_specific10", 10, Agent.EXEC_MODE.SEQUENTIAL), | ||
50 | - ("do_specific30", 3, Agent.EXEC_MODE.SEQUENTIAL), | ||
51 | - ("do_cmd_with_long_exec_time", 3, Agent.EXEC_MODE.SEQUENTIAL), | 49 | + ("do_specific10", 1, Agent.EXEC_MODE.SEQUENTIAL), |
50 | + ("do_specific30", 0, Agent.EXEC_MODE.SEQUENTIAL), | ||
51 | + ("do_cmd_with_long_exec_time", 50, Agent.EXEC_MODE.THREAD), | ||
52 | 52 | ||
53 | ] | 53 | ] |
54 | 54 | ||
55 | # Deactivate some tests, so that test scenario runs faster during DEV | 55 | # Deactivate some tests, so that test scenario runs faster during DEV |
56 | # on DEV | 56 | # on DEV |
57 | - #COMMIT_ONLY = False | 57 | + COMMIT_ONLY = False |
58 | # on commit only | 58 | # on commit only |
59 | - COMMIT_ONLY = True | 59 | + #COMMIT_ONLY = True |
60 | 60 | ||
61 | # @override | 61 | # @override |
62 | _TEST_COMMANDS_LIST = [ | 62 | _TEST_COMMANDS_LIST = [ |
63 | 63 | ||
64 | - # Format : (DO_IT, "self cmd_name cmd_args", timeout, "expected_result", expected_status), | 64 | + # Format : (DO_IT, "self cmd_name cmd_args", validity, "expected_result", expected_status), |
65 | 65 | ||
66 | #("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), | 66 | #("self do_stop now", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), |
67 | 67 | ||
@@ -71,14 +71,16 @@ class AgentBasic(Agent): | @@ -71,14 +71,16 @@ class AgentBasic(Agent): | ||
71 | #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), | 71 | #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
72 | 72 | ||
73 | # get_specific_cmds | 73 | # get_specific_cmds |
74 | - (True, " self get_specific_cmds ", 200, | 74 | + (True, " self get_all_cmds ", 100, |
75 | None, | 75 | None, |
76 | #'do_specific10(arg1:int,arg2:int,arg3:float,arg4:str,arg5:typing.Tuple[int, str, int],arg6:typing.List[int]);do_specific30();do_cmd_raising_some_exception();do_cmd_unimplemented(U)', | 76 | #'do_specific10(arg1:int,arg2:int,arg3:float,arg4:str,arg5:typing.Tuple[int, str, int],arg6:typing.List[int]);do_specific30();do_cmd_raising_some_exception();do_cmd_unimplemented(U)', |
77 | Agent.CMD_STATUS.CMD_EXECUTED | 77 | Agent.CMD_STATUS.CMD_EXECUTED |
78 | ), | 78 | ), |
79 | 79 | ||
80 | - # do_restart | ||
81 | (COMMIT_ONLY, "self do_restart asap", 200, 'RESTARTING asap', Agent.CMD_STATUS.CMD_EXECUTED), | 80 | (COMMIT_ONLY, "self do_restart asap", 200, 'RESTARTING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
81 | + | ||
82 | + # do_restart | ||
83 | + (True, "self do_cmd_with_long_exec_time", 200, None, Agent.CMD_STATUS.CMD_EXECUTED), | ||
82 | #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), | 84 | #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
83 | 85 | ||
84 | # ---------------------------------------------------- | 86 | # ---------------------------------------------------- |
@@ -371,8 +373,39 @@ class AgentBasic(Agent): | @@ -371,8 +373,39 @@ class AgentBasic(Agent): | ||
371 | 373 | ||
372 | # Long time execution command | 374 | # Long time execution command |
373 | def do_cmd_with_long_exec_time(self): | 375 | def do_cmd_with_long_exec_time(self): |
374 | - self.waitfor(100) | ||
375 | - return "took 100s to execute" | 376 | + nbsec=8 |
377 | + | ||
378 | + res = f"1 - now sleeping {nbsec} sec" | ||
379 | + self.CC.set_result(res, True) | ||
380 | + #self.CC.get_updated_result() | ||
381 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
382 | + self.sleep(nbsec) | ||
383 | + | ||
384 | + res = f"2 - now sleeping {nbsec} sec" | ||
385 | + self.CC.set_result(res, True) | ||
386 | + #self.CC.get_updated_result() | ||
387 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
388 | + self.sleep(nbsec) | ||
389 | + | ||
390 | + res = f"3 - now sleeping {nbsec} sec" | ||
391 | + self.CC.set_result(res, True) | ||
392 | + #self.CC.get_updated_result() | ||
393 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
394 | + self.sleep(nbsec) | ||
395 | + | ||
396 | + res = f"4 - now sleeping {nbsec} sec" | ||
397 | + self.CC.set_result(res, True) | ||
398 | + #self.CC.get_updated_result() | ||
399 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
400 | + self.sleep(nbsec) | ||
401 | + | ||
402 | + res = f"5 - now sleeping {nbsec} sec" | ||
403 | + self.CC.set_result(res, True) | ||
404 | + #self.CC.get_updated_result() | ||
405 | + while self.CC.get_updated_result() != res: self.sleep(1) | ||
406 | + self.sleep(nbsec) | ||
407 | + | ||
408 | + return f"should have taken {5*nbsec}s to execute" | ||
376 | 409 | ||
377 | def do_specific10(self, | 410 | def do_specific10(self, |
378 | arg1:int, | 411 | arg1:int, |