Commit 69077052ade0093d70fdcbcd9552458dafd9f220

Authored by Alexis Koralewski
1 parent b18e2c67
Exists in dev

Change algo to find agent script (first search in obs folder then in pyros')

Showing 2 changed files with 42 additions and 40 deletions   Show diff stats
1 -01-09-2023 (AKo): V0.6.30.0 1 +13-09-2023 (AKo): V0.6.31.0
  2 + - Change algo to find agent script (first search in obs folder then in pyros')
  3 + - Change DATA path in obsconfig FileName
  4 +
  5 +13-09-2023 (AKo): V0.6.30.0
2 - Add install-dependecies command 6 - Add install-dependecies command
3 - Move obsconfig/config folder into obsconfig 7 - Move obsconfig/config folder into obsconfig
4 - Rename default obsconfig file 8 - Rename default obsconfig file
src/core/pyros_django/majordome/agent/A_SST.py
@@ -125,6 +125,38 @@ class A_SST(Agent): @@ -125,6 +125,38 @@ class A_SST(Agent):
125 125
126 def set_computer(self,computer): 126 def set_computer(self,computer):
127 self.computer = computer 127 self.computer = computer
  128 +
  129 +
  130 + def find_agent_script(self, agent_name):
  131 + obs_config = self.get_config()
  132 + agent_informations = obs_config.get_agent_information(obs_config.unit_name, agent_name)
  133 + protocol = agent_informations.get("protocol")
  134 + observatory_agent_folder = os.path.join(os.environ.get("PATH_TO_OBSCONF_FOLDER"), "agents")
  135 + if protocol:
  136 + protocol_script_name = protocol
  137 + protocol = os.path.join(observatory_agent_folder, protocol_script_name)
  138 + else:
  139 + observatory_agents = glob.glob(os.path.join(observatory_agent_folder, "*.py"))
  140 + for agent in observatory_agents:
  141 + filename, _ = os.path.splitext(os.path.basename(agent))
  142 + if filename in agent_name:
  143 + protocol_folder_abs_path = os.path.abspath(os.path.dirname(agent))
  144 + protocol_script_name = os.path.basename(agent)
  145 + protocol = os.path.join(protocol_folder_abs_path, protocol_script_name)
  146 + break
  147 + # If agent protocol isn't found in pyros_observatory_<obs>/agents folder, search in pyros folders
  148 + if not protocol:
  149 + # general agent of PyROS
  150 + for general_agent in self._general_agents:
  151 + general_agent_name = os.path.splitext(os.path.basename(general_agent))
  152 + if general_agent_name[0] in agent:
  153 + protocol_folder_abs_path = os.path.abspath(os.path.dirname(general_agent))
  154 + protocol_script_name = os.path.basename(general_agent)
  155 + protocol = os.path.join(protocol_folder_abs_path, protocol_script_name)
  156 + break
  157 + return protocol
  158 +
  159 +
128 def start_agents(self,agent_name=None): 160 def start_agents(self,agent_name=None):
129 """ 161 """
130 Start all agents or one agent of obs_config 162 Start all agents or one agent of obs_config
@@ -146,26 +178,9 @@ class A_SST(Agent): @@ -146,26 +178,9 @@ class A_SST(Agent):
146 log.info(f"Agents associated to this computer : {agents}") 178 log.info(f"Agents associated to this computer : {agents}")
147 exit(1) 179 exit(1)
148 # Start a specific agent of obs_config (restart) 180 # Start a specific agent of obs_config (restart)
149 - agent_informations = obs_config.get_agent_information(obs_config.unit_name,agent)  
150 - protocol = agent_informations.get("protocol")  
151 - if protocol:  
152 - protocol_folder_abs_path = os.path.join(os.environ.get("PATH_TO_OBSCONF_FOLDER"), "agents")  
153 - protocol_script_name = protocol  
154 - protocol = os.path.join(protocol_folder_abs_path, protocol_script_name)  
155 - else:  
156 - # general agent of PyROS  
157 - for general_agent in self._general_agents:  
158 - general_agent_name = os.path.splitext(os.path.basename(general_agent))  
159 - if general_agent_name[0] in agent:  
160 - protocol_folder_abs_path = os.path.abspath(os.path.dirname(general_agent))  
161 - protocol_script_name = os.path.basename(general_agent)  
162 - print(protocol_folder_abs_path)  
163 - print(protocol_script_name)  
164 - protocol = os.path.join(protocol_folder_abs_path, protocol_script_name)  
165 - break  
166 - print(protocol) 181 + protocol = self.find_agent_script(agent)
167 if os.path.exists(protocol): 182 if os.path.exists(protocol):
168 - cmd = self.VENV_PYTHON +" "+ protocol_folder_abs_path + os.sep + protocol_script_name 183 + cmd = self.VENV_PYTHON +" "+ protocol
169 if not agent in self.agent_in_mode_test: 184 if not agent in self.agent_in_mode_test:
170 self.agent_in_mode_test[agent] = self.TEST_MODE 185 self.agent_in_mode_test[agent] = self.TEST_MODE
171 if self.agent_in_mode_test[agent]: 186 if self.agent_in_mode_test[agent]:
@@ -200,25 +215,8 @@ class A_SST(Agent): @@ -200,25 +215,8 @@ class A_SST(Agent):
200 for agent in agents: 215 for agent in agents:
201 if "A_SST" in agent: 216 if "A_SST" in agent:
202 continue 217 continue
203 - agent_informations = obs_config.get_agent_information(obs_config.unit_name,agent)  
204 - protocol = agent_informations.get("protocol")  
205 - is_active = agent_informations.get("is_active",True)  
206 - protocol_script_name = ""  
207 - protocol_folder_abs_path = ""  
208 - if protocol and is_active == True:  
209 - protocol_folder_abs_path = os.path.join(os.environ.get("PATH_TO_OBSCONF_FOLDER"), "agents")  
210 - protocol_script_name = protocol  
211 - protocol = os.path.join(protocol_folder_abs_path, protocol_script_name)  
212 - else:  
213 - # general agent of PyROS  
214 - for general_agent in self._general_agents:  
215 - general_agent_name = os.path.splitext(os.path.basename(general_agent))  
216 - print("GENERAL AGENT NAME , AGENT : ",general_agent_name[0], agent)  
217 - if general_agent_name[0] in agent:  
218 - protocol = os.path.join(os.getcwd(),general_agent)  
219 - protocol_script_name = os.path.basename(general_agent)  
220 - protocol = os.path.join(protocol_folder_abs_path, protocol_script_name)  
221 - break 218 + print(agent)
  219 + protocol = self.find_agent_script(agent)
222 if protocol and os.path.exists(protocol): 220 if protocol and os.path.exists(protocol):
223 221
224 cmd = self.VENV_PYTHON +" "+ protocol 222 cmd = self.VENV_PYTHON +" "+ protocol
@@ -403,7 +401,7 @@ class A_SST(Agent): @@ -403,7 +401,7 @@ class A_SST(Agent):
403 nb_stopped_agent +=1 401 nb_stopped_agent +=1
404 if self.TEST_MODE: 402 if self.TEST_MODE:
405 if nb_stopped_agent == len(self.subprocess_dict.keys()): 403 if nb_stopped_agent == len(self.subprocess_dict.keys()):
406 - print("All launched agents have finished their test modes, A_SST will stop") 404 + print("A_SST TEST MODE BEHAVIOR : All launched agents have finished their test modes, A_SST will stop")
407 self.do_stop("asap") 405 self.do_stop("asap")
408 406
409 407