Commit 607a71315f330472fb5b62d77932bfef74e236ab

Authored by Etienne Pallier
1 parent eb6649f7
Exists in dev

validity and timeout in test

src/core/pyros_django/agent/Agent.py
... ... @@ -364,7 +364,7 @@ class Agent:
364 364 # - cmd : the command name
365 365 # - args : (optional) the list of command arguments, separated by blanks : arg1 arg2 arg3 ...
366 366 #
367   - # - timeout : the command timeout (max time allowed for execution, else it is aborted)
  367 + # - validity : the command is valid for this duration, afterwards you can forget it
368 368 #
369 369 # - expected_res : the expected result
370 370 #
... ... @@ -396,34 +396,34 @@ class Agent:
396 396 # -------------------------------
397 397  
398 398 # Agent general command
399   - ("self set_mode ATTENTIVE", 2, "MODE = ATTENTIVE"),
  399 + ("self set_mode ATTENTIVE", 200, "MODE = ATTENTIVE"),
400 400 # => should get "ATTENTIVE"
401   - ("self get_mode", 1, "MODE = ATTENTIVE"),
  401 + ("self get_mode", 100, "MODE = ATTENTIVE"),
402 402  
403 403 # => should get "7"
404   - ("self do_eval 3+5-1", 2, 7),
  404 + ("self do_eval 3+5-1", 200, 7),
405 405  
406 406 # END, will not go further
407 407 #("self do_exit", 2, "STOPPING"),
408 408  
409 409 # Agent specific commands => should be executed
410   - ("self do_specific3", 2, None),
411   - ("self do_exit", 5, "STOPPING"),
412   - ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 2, 7),
  410 + ("self do_specific3", 200, None),
  411 + ("self do_exit", 500, "STOPPING"),
  412 + ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, 7),
413 413  
414   - ("self set_mode ROUTINE", 2, "MODE = ROUTINE"),
  414 + ("self set_mode ROUTINE", 200, "MODE = ROUTINE"),
415 415 # => should get "ROUTINE"
416   - ("self get_mode", 2, "MODE = ROUTINE"),
  416 + ("self get_mode", 200, "MODE = ROUTINE"),
417 417 # Agent specific command => should be skipped (because not ATTENTIVE)
418   - ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 2, "SKIPPED"),
  418 + ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, "SKIPPED"),
419 419  
420 420 # From now on, should not run anymore process_before/after
421 421 # => and should skip next specific commands
422   - ("self set_mode IDLE", 2, "MODE = IDLE"),
  422 + ("self set_mode IDLE", 200, "MODE = IDLE"),
423 423 # => should get "IDLE"
424   - ("self get_mode", 2, "MODE = IDLE"),
  424 + ("self get_mode", 200, "MODE = IDLE"),
425 425 # Agent specific command => should be skipped (because not ATTENTIVE)
426   - ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 2, 'SKIPPED'),
  426 + ("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]", 200, 'SKIPPED'),
427 427  
428 428 # TODO: test priority commands : do_abort, do_flush_cmds, ...
429 429 # - Stop executing new commands (just let them accumulate)
... ... @@ -440,10 +440,10 @@ class Agent:
440 440 ##("self do_resume_exec",),
441 441  
442 442 # Restart the restart loop (from init())
443   - ("self do_restart_loop", 2, "RESTARTING"),
  443 + ("self do_restart_loop", 200, "RESTARTING"),
444 444  
445 445 # Now stop
446   - ("self do_exit", 2, "STOPPING"),
  446 + ("self do_exit", 200, "STOPPING"),
447 447  
448 448 '''
449 449 # specific0 not_executed_because_idle
... ... @@ -1588,17 +1588,18 @@ class Agent:
1588 1588 AgentCmd.objects.create(sender=self.name, recipient=recipient_agent, name=cmd_name)
1589 1589 """
1590 1590 #def send_command(self, to_agent, cmd_type, cmd_name, cmd_args=None):
1591   - def send_cmd_to(self, to_agent, cmd_name, cmd_args=None):
  1591 + def send_cmd_to(self, to_agent:str, cmd_name:str, cmd_args:str=None, validity:int=None, timeout:int=None):
1592 1592 """
1593 1593 #ex: send_command(“AgentX”,”GENERIC”,”EVAL”,“3+4”)
1594 1594 ex: send_command(“AgentX”,"EVAL”,“3+4”)
1595 1595 """
1596 1596 #return AgentCmd.send_cmd_from_to(self.name, self._get_real_agent_name_for_alias(to_agent), cmd_name, cmd_args)
1597   - cmd = self.create_cmd_for(to_agent, cmd_name, cmd_args).send()
  1597 + cmd = self.create_cmd_for(to_agent, cmd_name, cmd_args, validity, timeout).send()
1598 1598 #cmd.send()
1599 1599 return cmd
1600 1600  
1601   - def create_cmd_for(self, to_agent, cmd_name, cmd_args=None) -> AgentCmd:
  1601 + def create_cmd_for(self, to_agent:str, cmd_name:str, cmd_args:str=None, validity:int=None, timeout:int=None) -> AgentCmd:
  1602 +
1602 1603 '''
1603 1604 real_agent_name = self._get_real_agent_name(to_agent)
1604 1605 real_cmd_name = cmd_name
... ... @@ -1610,7 +1611,7 @@ class Agent:
1610 1611 real_agent_name = self._get_real_agent_name(to_agent)
1611 1612 except KeyError as e:
1612 1613 '''
1613   - return AgentCmd.create(self.name, to_agent, cmd_name, cmd_args)
  1614 + return AgentCmd.create(self.name, to_agent, cmd_name, cmd_args, validity, timeout)
1614 1615 '''
1615 1616 real_agent_name = self._get_real_agent_name(to_agent)
1616 1617 if not real_agent_name:
... ... @@ -2070,10 +2071,18 @@ class Agent:
2070 2071  
2071 2072 # Stop agent asap or now
2072 2073 def do_stop(self, when:str):
  2074 +
  2075 + # PRIO
2073 2076 if when == "asap":
2074 2077 pass
2075 2078 if when == "now":
2076 2079 pass
  2080 +
  2081 + # NOT PRIO
  2082 + if when == "noprio":
  2083 + pass
  2084 +
  2085 + # Bad arg
2077 2086 raise AgentCmdBadArgsException(self.CURRENT_CMD)
2078 2087  
2079 2088  
... ... @@ -2160,7 +2169,7 @@ class Agent:
2160 2169 if self.TEST_MODE: log.info("in TEST MODE")
2161 2170  
2162 2171 def _TEST_get_next_command_to_send(self)->AgentCmd:
2163   - cmd_full_name, timeout, res_expected = next(self.TEST_COMMANDS, (None,None,None))
  2172 + cmd_full_name, validity, res_expected = next(self.TEST_COMMANDS, (None,None,None))
2164 2173 #print(cmd_full_name, res_expected)
2165 2174 #return cmd_name
2166 2175 if cmd_full_name is None: return None
... ...
src/core/pyros_django/common/models.py
... ... @@ -773,7 +773,7 @@ class AgentCmd(models.Model):
773 773 def __str__(self):
774 774 # return (f"Commmand '{self.name}' ({self.state}) sent by agent {self.sender} to agent {self.recipient} at {self.s_deposit_time}")
775 775 cmd_sent_time = f" at {self.s_deposit_time}" if self.s_deposit_time else ''
776   - return (f"Commmand '{self.full_name}' ({self.state}) sent to agent {self.recipient}{cmd_sent_time} [by agent {self.sender}]")
  776 + return (f"Commmand '{self.full_name}' ({self.state}) sent to agent {self.recipient}{cmd_sent_time} (validity={self.validity_duration}s,timeout={self.exec_timeout}s) [by agent {self.sender}]")
777 777  
778 778 @property
779 779 def device_command(self) -> DeviceCmd :
... ...