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,7 +603,7 @@ class Agent: | ||
603 | 603 | ||
604 | # new obsconfig init for agent: | 604 | # new obsconfig init for agent: |
605 | ##def __init__(self, RUN_IN_THREAD=True): | 605 | ##def __init__(self, RUN_IN_THREAD=True): |
606 | - def __init__(self): | 606 | + def __init__(self,simulated_computer=None): |
607 | 607 | ||
608 | # Declaration of Instance attributes, default values | 608 | # Declaration of Instance attributes, default values |
609 | #self.UP_SINCE = datetime.utcnow() | 609 | #self.UP_SINCE = datetime.utcnow() |
@@ -624,7 +624,6 @@ class Agent: | @@ -624,7 +624,6 @@ class Agent: | ||
624 | self.unit = None | 624 | self.unit = None |
625 | self.TEST_COMMANDS = None | 625 | self.TEST_COMMANDS = None |
626 | self.__iter_num :int = 0 | 626 | self.__iter_num :int = 0 |
627 | - | ||
628 | #print(AgentSurvey.MODE_CHOICES.IDLE) | 627 | #print(AgentSurvey.MODE_CHOICES.IDLE) |
629 | #sys.exit() | 628 | #sys.exit() |
630 | 629 | ||
@@ -645,7 +644,7 @@ class Agent: | @@ -645,7 +644,7 @@ class Agent: | ||
645 | # set real unit name (the current unit used) | 644 | # set real unit name (the current unit used) |
646 | if unit == "": | 645 | if unit == "": |
647 | unit = oc.unit_name | 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 | if agent_name_from_config: | 648 | if agent_name_from_config: |
650 | self.name = agent_name_from_config | 649 | self.name = agent_name_from_config |
651 | self.unit = unit | 650 | self.unit = unit |
@@ -3439,6 +3438,7 @@ def build_agent(Agent_type:Agent,param_constr=None) -> Agent : | @@ -3439,6 +3438,7 @@ def build_agent(Agent_type:Agent,param_constr=None) -> Agent : | ||
3439 | #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) | 3438 | #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) |
3440 | #agent = Agent_type(RUN_IN_THREAD) | 3439 | #agent = Agent_type(RUN_IN_THREAD) |
3441 | if param_constr: | 3440 | if param_constr: |
3441 | + agent = Agent_type(simulated_computer=param_constr.get("computer")) | ||
3442 | if "AgentSST" in str(Agent_type): | 3442 | if "AgentSST" in str(Agent_type): |
3443 | agent = Agent_type(agent=param_constr.get("agent"),simulated_computer=param_constr.get("computer")) | 3443 | agent = Agent_type(agent=param_constr.get("agent"),simulated_computer=param_constr.get("computer")) |
3444 | else: | 3444 | else: |
src/core/pyros_django/agent/AgentSST.py
@@ -25,6 +25,7 @@ class AgentSST(Agent): | @@ -25,6 +25,7 @@ class AgentSST(Agent): | ||
25 | VENV_PYTHON = "" | 25 | VENV_PYTHON = "" |
26 | subprocess_dict = {} | 26 | subprocess_dict = {} |
27 | agent_in_mode_test = {} | 27 | agent_in_mode_test = {} |
28 | + simulated_computer = None | ||
28 | 29 | ||
29 | _AGENT_SPECIFIC_COMMANDS = { | 30 | _AGENT_SPECIFIC_COMMANDS = { |
30 | # Format : “cmd_name” : (timeout, exec_mode) | 31 | # Format : “cmd_name” : (timeout, exec_mode) |
@@ -50,6 +51,7 @@ class AgentSST(Agent): | @@ -50,6 +51,7 @@ class AgentSST(Agent): | ||
50 | self.computer = socket.gethostname() | 51 | self.computer = socket.gethostname() |
51 | if simulated_computer != None: | 52 | if simulated_computer != None: |
52 | self.computer = simulated_computer | 53 | self.computer = simulated_computer |
54 | + self.simulated_computer = simulated_computer | ||
53 | name_from_config = self.get_config().get_agent_sst_of_computer(self.computer) | 55 | name_from_config = self.get_config().get_agent_sst_of_computer(self.computer) |
54 | if name_from_config != None: | 56 | if name_from_config != None: |
55 | name = name_from_config | 57 | name = name_from_config |
@@ -60,8 +62,8 @@ class AgentSST(Agent): | @@ -60,8 +62,8 @@ class AgentSST(Agent): | ||
60 | self._agent_survey = AgentSurvey.objects.create( | 62 | self._agent_survey = AgentSurvey.objects.create( |
61 | name=self.name, | 63 | name=self.name, |
62 | validity_duration=60, | 64 | validity_duration=60, |
63 | - mode=self.mode, | ||
64 | - status=self.status, | 65 | + mode=self.__get_mode(), |
66 | + status=self.get_status(), | ||
65 | iteration=-1 | 67 | iteration=-1 |
66 | ) | 68 | ) |
67 | WITH_DOCKER = False | 69 | WITH_DOCKER = False |
@@ -136,6 +138,8 @@ class AgentSST(Agent): | @@ -136,6 +138,8 @@ class AgentSST(Agent): | ||
136 | self.agent_in_mode_test[agent] = self.TEST_MODE | 138 | self.agent_in_mode_test[agent] = self.TEST_MODE |
137 | if self.agent_in_mode_test[agent]: | 139 | if self.agent_in_mode_test[agent]: |
138 | cmd += test_mode | 140 | cmd += test_mode |
141 | + if self.simulated_computer: | ||
142 | + cmd += f" --computer {self.simulated_computer}" | ||
139 | process = subprocess.Popen(f"{cmd}",shell=True) | 143 | process = subprocess.Popen(f"{cmd}",shell=True) |
140 | process.poll() | 144 | process.poll() |
141 | if agent not in self.subprocess_dict: | 145 | if agent not in self.subprocess_dict: |
@@ -173,6 +177,8 @@ class AgentSST(Agent): | @@ -173,6 +177,8 @@ class AgentSST(Agent): | ||
173 | self.agent_in_mode_test[agent] = self.TEST_MODE | 177 | self.agent_in_mode_test[agent] = self.TEST_MODE |
174 | if self.agent_in_mode_test[agent]: | 178 | if self.agent_in_mode_test[agent]: |
175 | cmd += test_mode | 179 | cmd += test_mode |
180 | + if self.simulated_computer: | ||
181 | + cmd += f" --computer {self.simulated_computer}" | ||
176 | # process = subprocess.Popen(f"{cmd}", shell=True, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) | 182 | # process = subprocess.Popen(f"{cmd}", shell=True, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) |
177 | process = subprocess.Popen(f"{cmd}", shell=True) | 183 | process = subprocess.Popen(f"{cmd}", shell=True) |
178 | self.subprocess_dict[agent] = {} | 184 | self.subprocess_dict[agent] = {} |
src/core/pyros_django/observation_manager/AgentImagesProcessor.py
@@ -49,7 +49,7 @@ class AgentImagesProcessor(Agent): | @@ -49,7 +49,7 @@ class AgentImagesProcessor(Agent): | ||
49 | _TEST_COMMANDS_LIST = [ | 49 | _TEST_COMMANDS_LIST = [ |
50 | # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status), | 50 | # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status), |
51 | (True, "self do_create_test_images_1", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), | 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,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 | if name is None: | 62 | if name is None: |
63 | name = self.__class__.__name__ | 63 | name = self.__class__.__name__ |
64 | - super().__init__() | 64 | + super().__init__(simulated_computer=simulated_computer) |
65 | 65 | ||
66 | def _init(self): | 66 | def _init(self): |
67 | super()._init() | 67 | super()._init() |
@@ -320,7 +320,9 @@ class AgentImagesProcessor(Agent): | @@ -320,7 +320,9 @@ class AgentImagesProcessor(Agent): | ||
320 | return s | 320 | return s |
321 | 321 | ||
322 | if __name__ == "__main__": | 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 | print(agent) | 327 | print(agent) |
326 | agent.run() | 328 | agent.run() |