From 9c844b4da6284c918655248760358bde43203244 Mon Sep 17 00:00:00 2001 From: Alexis Koralewski Date: Thu, 24 Nov 2022 14:34:46 +0100 Subject: [PATCH] AgentSST change names of agents when launched with simulated computer --- src/core/pyros_django/agent/Agent.py | 6 +++--- src/core/pyros_django/agent/AgentSST.py | 10 ++++++++-- src/core/pyros_django/observation_manager/AgentImagesProcessor.py | 12 +++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/core/pyros_django/agent/Agent.py b/src/core/pyros_django/agent/Agent.py index ac92efd..0611338 100755 --- a/src/core/pyros_django/agent/Agent.py +++ b/src/core/pyros_django/agent/Agent.py @@ -603,7 +603,7 @@ class Agent: # new obsconfig init for agent: ##def __init__(self, RUN_IN_THREAD=True): - def __init__(self): + def __init__(self,simulated_computer=None): # Declaration of Instance attributes, default values #self.UP_SINCE = datetime.utcnow() @@ -624,7 +624,6 @@ class Agent: self.unit = None self.TEST_COMMANDS = None self.__iter_num :int = 0 - #print(AgentSurvey.MODE_CHOICES.IDLE) #sys.exit() @@ -645,7 +644,7 @@ class Agent: # set real unit name (the current unit used) if unit == "": unit = oc.unit_name - agent_name_from_config = self.get_config().get_agent_name_from_config(self.__class__.__name__) + agent_name_from_config = self.get_config().get_agent_name_from_config(self.__class__.__name__,simulated_computer) if agent_name_from_config: self.name = agent_name_from_config self.unit = unit @@ -3439,6 +3438,7 @@ def build_agent(Agent_type:Agent,param_constr=None) -> Agent : #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) #agent = Agent_type(RUN_IN_THREAD) if param_constr: + agent = Agent_type(simulated_computer=param_constr.get("computer")) if "AgentSST" in str(Agent_type): agent = Agent_type(agent=param_constr.get("agent"),simulated_computer=param_constr.get("computer")) else: diff --git a/src/core/pyros_django/agent/AgentSST.py b/src/core/pyros_django/agent/AgentSST.py index 1b40349..c5ba279 100644 --- a/src/core/pyros_django/agent/AgentSST.py +++ b/src/core/pyros_django/agent/AgentSST.py @@ -25,6 +25,7 @@ class AgentSST(Agent): VENV_PYTHON = "" subprocess_dict = {} agent_in_mode_test = {} + simulated_computer = None _AGENT_SPECIFIC_COMMANDS = { # Format : “cmd_name” : (timeout, exec_mode) @@ -50,6 +51,7 @@ class AgentSST(Agent): self.computer = socket.gethostname() if simulated_computer != None: self.computer = simulated_computer + self.simulated_computer = simulated_computer name_from_config = self.get_config().get_agent_sst_of_computer(self.computer) if name_from_config != None: name = name_from_config @@ -60,8 +62,8 @@ class AgentSST(Agent): self._agent_survey = AgentSurvey.objects.create( name=self.name, validity_duration=60, - mode=self.mode, - status=self.status, + mode=self.__get_mode(), + status=self.get_status(), iteration=-1 ) WITH_DOCKER = False @@ -136,6 +138,8 @@ class AgentSST(Agent): self.agent_in_mode_test[agent] = self.TEST_MODE if self.agent_in_mode_test[agent]: cmd += test_mode + if self.simulated_computer: + cmd += f" --computer {self.simulated_computer}" process = subprocess.Popen(f"{cmd}",shell=True) process.poll() if agent not in self.subprocess_dict: @@ -173,6 +177,8 @@ class AgentSST(Agent): self.agent_in_mode_test[agent] = self.TEST_MODE if self.agent_in_mode_test[agent]: cmd += test_mode + if self.simulated_computer: + cmd += f" --computer {self.simulated_computer}" # process = subprocess.Popen(f"{cmd}", shell=True, stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) process = subprocess.Popen(f"{cmd}", shell=True) self.subprocess_dict[agent] = {} diff --git a/src/core/pyros_django/observation_manager/AgentImagesProcessor.py b/src/core/pyros_django/observation_manager/AgentImagesProcessor.py index 689e314..bddf436 100755 --- a/src/core/pyros_django/observation_manager/AgentImagesProcessor.py +++ b/src/core/pyros_django/observation_manager/AgentImagesProcessor.py @@ -49,7 +49,7 @@ class AgentImagesProcessor(Agent): _TEST_COMMANDS_LIST = [ # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status), (True, "self do_create_test_images_1", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), - (True, "self do_exit", 500, "STOPPING", Agent.CMD_STATUS.CMD_EXECUTED), + (True, "self do_stop asap", 500, "STOPPING", Agent.CMD_STATUS.CMD_EXECUTED), ] """ @@ -58,10 +58,10 @@ class AgentImagesProcessor(Agent): ================================================================= """ - def __init__(self, name:str=None): + def __init__(self, name:str=None,simulated_computer=None): if name is None: name = self.__class__.__name__ - super().__init__() + super().__init__(simulated_computer=simulated_computer) def _init(self): super()._init() @@ -320,7 +320,9 @@ class AgentImagesProcessor(Agent): return s if __name__ == "__main__": - - agent = build_agent(AgentImagesProcessor) + parser = argparse.ArgumentParser(description='Start a agentSST.') + parser.add_argument("--computer",dest="computer",help='Launch agent with simulated computer hostname',action="store") + args = vars(parser.parse_args()) + agent = build_agent(AgentImagesProcessor,param_constr=args) print(agent) agent.run() -- libgit2 0.21.2