Commit 9c844b4da6284c918655248760358bde43203244
1 parent
baada9d5
Exists in
dev
AgentSST change names of agents when launched with simulated computer
Showing
3 changed files
with
18 additions
and
10 deletions
Show diff stats
src/core/pyros_django/agent/Agent.py
... | ... | @@ -603,7 +603,7 @@ class Agent: |
603 | 603 | |
604 | 604 | # new obsconfig init for agent: |
605 | 605 | ##def __init__(self, RUN_IN_THREAD=True): |
606 | - def __init__(self): | |
606 | + def __init__(self,simulated_computer=None): | |
607 | 607 | |
608 | 608 | # Declaration of Instance attributes, default values |
609 | 609 | #self.UP_SINCE = datetime.utcnow() |
... | ... | @@ -624,7 +624,6 @@ class Agent: |
624 | 624 | self.unit = None |
625 | 625 | self.TEST_COMMANDS = None |
626 | 626 | self.__iter_num :int = 0 |
627 | - | |
628 | 627 | #print(AgentSurvey.MODE_CHOICES.IDLE) |
629 | 628 | #sys.exit() |
630 | 629 | |
... | ... | @@ -645,7 +644,7 @@ class Agent: |
645 | 644 | # set real unit name (the current unit used) |
646 | 645 | if unit == "": |
647 | 646 | unit = oc.unit_name |
648 | - agent_name_from_config = self.get_config().get_agent_name_from_config(self.__class__.__name__) | |
647 | + agent_name_from_config = self.get_config().get_agent_name_from_config(self.__class__.__name__,simulated_computer) | |
649 | 648 | if agent_name_from_config: |
650 | 649 | self.name = agent_name_from_config |
651 | 650 | self.unit = unit |
... | ... | @@ -3439,6 +3438,7 @@ def build_agent(Agent_type:Agent,param_constr=None) -> Agent : |
3439 | 3438 | #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) |
3440 | 3439 | #agent = Agent_type(RUN_IN_THREAD) |
3441 | 3440 | if param_constr: |
3441 | + agent = Agent_type(simulated_computer=param_constr.get("computer")) | |
3442 | 3442 | if "AgentSST" in str(Agent_type): |
3443 | 3443 | agent = Agent_type(agent=param_constr.get("agent"),simulated_computer=param_constr.get("computer")) |
3444 | 3444 | else: | ... | ... |
src/core/pyros_django/agent/AgentSST.py
... | ... | @@ -25,6 +25,7 @@ class AgentSST(Agent): |
25 | 25 | VENV_PYTHON = "" |
26 | 26 | subprocess_dict = {} |
27 | 27 | agent_in_mode_test = {} |
28 | + simulated_computer = None | |
28 | 29 | |
29 | 30 | _AGENT_SPECIFIC_COMMANDS = { |
30 | 31 | # Format : “cmd_name” : (timeout, exec_mode) |
... | ... | @@ -50,6 +51,7 @@ class AgentSST(Agent): |
50 | 51 | self.computer = socket.gethostname() |
51 | 52 | if simulated_computer != None: |
52 | 53 | self.computer = simulated_computer |
54 | + self.simulated_computer = simulated_computer | |
53 | 55 | name_from_config = self.get_config().get_agent_sst_of_computer(self.computer) |
54 | 56 | if name_from_config != None: |
55 | 57 | name = name_from_config |
... | ... | @@ -60,8 +62,8 @@ class AgentSST(Agent): |
60 | 62 | self._agent_survey = AgentSurvey.objects.create( |
61 | 63 | name=self.name, |
62 | 64 | validity_duration=60, |
63 | - mode=self.mode, | |
64 | - status=self.status, | |
65 | + mode=self.__get_mode(), | |
66 | + status=self.get_status(), | |
65 | 67 | iteration=-1 |
66 | 68 | ) |
67 | 69 | WITH_DOCKER = False |
... | ... | @@ -136,6 +138,8 @@ class AgentSST(Agent): |
136 | 138 | self.agent_in_mode_test[agent] = self.TEST_MODE |
137 | 139 | if self.agent_in_mode_test[agent]: |
138 | 140 | cmd += test_mode |
141 | + if self.simulated_computer: | |
142 | + cmd += f" --computer {self.simulated_computer}" | |
139 | 143 | process = subprocess.Popen(f"{cmd}",shell=True) |
140 | 144 | process.poll() |
141 | 145 | if agent not in self.subprocess_dict: |
... | ... | @@ -173,6 +177,8 @@ class AgentSST(Agent): |
173 | 177 | self.agent_in_mode_test[agent] = self.TEST_MODE |
174 | 178 | if self.agent_in_mode_test[agent]: |
175 | 179 | cmd += test_mode |
180 | + if self.simulated_computer: | |
181 | + cmd += f" --computer {self.simulated_computer}" | |
176 | 182 | # process = subprocess.Popen(f"{cmd}", shell=True, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) |
177 | 183 | process = subprocess.Popen(f"{cmd}", shell=True) |
178 | 184 | self.subprocess_dict[agent] = {} | ... | ... |
src/core/pyros_django/observation_manager/AgentImagesProcessor.py
... | ... | @@ -49,7 +49,7 @@ class AgentImagesProcessor(Agent): |
49 | 49 | _TEST_COMMANDS_LIST = [ |
50 | 50 | # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status), |
51 | 51 | (True, "self do_create_test_images_1", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), |
52 | - (True, "self do_exit", 500, "STOPPING", Agent.CMD_STATUS.CMD_EXECUTED), | |
52 | + (True, "self do_stop asap", 500, "STOPPING", Agent.CMD_STATUS.CMD_EXECUTED), | |
53 | 53 | ] |
54 | 54 | |
55 | 55 | """ |
... | ... | @@ -58,10 +58,10 @@ class AgentImagesProcessor(Agent): |
58 | 58 | ================================================================= |
59 | 59 | """ |
60 | 60 | |
61 | - def __init__(self, name:str=None): | |
61 | + def __init__(self, name:str=None,simulated_computer=None): | |
62 | 62 | if name is None: |
63 | 63 | name = self.__class__.__name__ |
64 | - super().__init__() | |
64 | + super().__init__(simulated_computer=simulated_computer) | |
65 | 65 | |
66 | 66 | def _init(self): |
67 | 67 | super()._init() |
... | ... | @@ -320,7 +320,9 @@ class AgentImagesProcessor(Agent): |
320 | 320 | return s |
321 | 321 | |
322 | 322 | if __name__ == "__main__": |
323 | - | |
324 | - agent = build_agent(AgentImagesProcessor) | |
323 | + parser = argparse.ArgumentParser(description='Start a agentSST.') | |
324 | + parser.add_argument("--computer",dest="computer",help='Launch agent with simulated computer hostname',action="store") | |
325 | + args = vars(parser.parse_args()) | |
326 | + agent = build_agent(AgentImagesProcessor,param_constr=args) | |
325 | 327 | print(agent) |
326 | 328 | agent.run() | ... | ... |