Commit b82752ac55c4d171722834edb46927c3380b3165

Authored by Alexis Koralewski
1 parent b4df3bc3
Exists in dev

Move obsconfig/config folder into obsconfig

  1 +01-09-2023 (AKo): V0.6.30.0
  2 + - Add install-dependecies command
  3 + - Move obsconfig/config folder into obsconfig
  4 +
1 01-09-2023 (AKo): V0.6.29.0 5 01-09-2023 (AKo): V0.6.29.0
2 - Add fn context to channels in obsconfig class 6 - Add fn context to channels in obsconfig class
3 - 7 + - Add makedirs in fn_context definition
  8 + - Fix agent protocol path in A_SST
  9 +
4 28-07-2023 (AKo): V0.6.28.0 10 28-07-2023 (AKo): V0.6.28.0
5 - Add command in A_SCP_Manager to generate ephemeris files of sun & moon for a period 11 - Add command in A_SCP_Manager to generate ephemeris files of sun & moon for a period
6 - Fix AgentSST start one agent 12 - Fix AgentSST start one agent
@@ -60,8 +60,8 @@ AGENTS = { @@ -60,8 +60,8 @@ AGENTS = {
60 "AgentM": "env_monitor", 60 "AgentM": "env_monitor",
61 "AgentSP": "scientific_programs", 61 "AgentSP": "scientific_programs",
62 "AgentScheduler": "scheduling", 62 "AgentScheduler": "scheduling",
63 - "AgentImagesProcessor": "observation_manager",  
64 - "AgentImagesCalibrator": "observation_manager", 63 + "AgentImagesProcessor": "img_process",
  64 + "AgentImagesCalibrator": "img_analysis",
65 "A_SST": "majordome/agent", 65 "A_SST": "majordome/agent",
66 "Agent": "majordome/agent", 66 "Agent": "majordome/agent",
67 "Agent2": "majordome/agent", 67 "Agent2": "majordome/agent",
@@ -815,6 +815,84 @@ def initdb(): @@ -815,6 +815,84 @@ def initdb():
815 return True 815 return True
816 816
817 817
  818 +
  819 +@pyros_launcher.command(help="Install dependencies")
  820 +# @global_test_options
  821 +@click.option('--observatory', '-o', help='the observatory name to be used')
  822 +@click.option('--unit', '-u', help='the unit name to be used')
  823 +@click.option("--foreground","-fg", is_flag=True, help="Print stdout and error in terminal")
  824 +def install_dependencies(observatory: str, unit: str, foreground: bool):
  825 + if observatory == None or len(observatory) == 0:
  826 + observatory = "default"
  827 + default_obsconfig_folder = os.path.join(
  828 + os.path.abspath(PYROS_DJANGO_BASE_DIR), "../../../config/pyros_observatory/")
  829 + path_to_obs_config_folder = default_obsconfig_folder+"pyros_observatory_"+observatory+"/"
  830 + else:
  831 + observatories_configuration_folder = os.path.join(
  832 + os.path.abspath(PYROS_DJANGO_BASE_DIR), "../../../../PYROS_OBSERVATORY/")
  833 + if len(glob.glob(observatories_configuration_folder+"pyros_observatory_"+observatory+"/")) != 1:
  834 + # Observatory configuration folder not found
  835 + print(
  836 + f"Observatory configuration folder for observatory '{observatory}' not found in {observatories_configuration_folder}")
  837 + print("Available observatories configuration :")
  838 + for obs_conf_folder in os.listdir(observatories_configuration_folder):
  839 + print(obs_conf_folder)
  840 + exit(1)
  841 +
  842 + path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory
  843 + obs_config_file_name = ""
  844 + # Search for observatory config file
  845 + obs_config_file_name = glob.glob(
  846 + path_to_obs_config_folder+"/observatory*.yml")[0]
  847 +
  848 + obs_config_file_path = os.path.join(
  849 + path_to_obs_config_folder, obs_config_file_name)
  850 + os.environ["PATH_TO_OBSCONF_FILE"] = obs_config_file_path
  851 + os.environ["PATH_TO_OBSCONF_FOLDER"] = path_to_obs_config_folder
  852 + os.environ["unit_name"] = unit if unit else ''
  853 +
  854 + # add path to pyros_django folder as the config class is supposed to work within this folder
  855 + cmd_test_obs_config = f"-c \"from src.core.pyros_django.obs_config.obsconfig_class import OBSConfig\nOBSConfig('{obs_config_file_path}')\""
  856 + if not execProcessFromVenv(cmd_test_obs_config,foreground=True):
  857 + # Observatory configuration has an issue
  858 + exit(1)
  859 + else:
  860 + from src.core.pyros_django.obs_config.obsconfig_class import OBSConfig
  861 + try:
  862 + from git import Repo, GitError
  863 + except:
  864 + pip = "pip" if IS_WINDOWS else "pip3"
  865 + if WITH_DOCKER:
  866 + process = subprocess.Popen(
  867 + pip + " install --user --upgrade GitPython", shell=True)
  868 + else:
  869 + process = subprocess.Popen(
  870 + pip + " install --upgrade GitPython", shell=True)
  871 + process.wait()
  872 + if process.returncode == 0:
  873 + # self.addExecuted(self.current_command, command)
  874 + from git import Repo, GitError
  875 + else:
  876 + log.error("GitPython package (required for obsconfig class) installation failed")
  877 + VENDOR_PATH = os.path.join(os.getcwd(), "./vendor/")
  878 + import socket
  879 + obsconfig = OBSConfig(obs_config_file_path)
  880 + computer_hostname = socket.gethostname()
  881 + dependencies = obsconfig.get_dependencies()
  882 + for computer_name in obsconfig.get_computers().keys():
  883 + if computer_hostname == obsconfig.get_computers().get(computer_name).get("computer_config").get("hostname"):
  884 + computer = computer_name
  885 + os.chdir("vendor")
  886 + for dependency in dependencies:
  887 + if computer in dependency["computers"]:
  888 + for cmd in dependency["commands"]:
  889 + print(cmd)
  890 + process = subprocess.Popen(cmd, shell=True)
  891 + process.wait()
  892 + if process.returncode == 0:
  893 + continue
  894 +
  895 +
818 @pyros_launcher.command(help="Launch an agent") 896 @pyros_launcher.command(help="Launch an agent")
819 # @global_test_options 897 # @global_test_options
820 @click.argument('agent') 898 @click.argument('agent')
@@ -881,7 +959,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos @@ -881,7 +959,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos
881 print(obs_conf_folder) 959 print(obs_conf_folder)
882 exit(1) 960 exit(1)
883 961
884 - path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory+"/config/" 962 + path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory
885 obs_config_file_name = "" 963 obs_config_file_name = ""
886 # Search for observatory config file 964 # Search for observatory config file
887 obs_config_file_name = glob.glob( 965 obs_config_file_name = glob.glob(
@@ -1096,7 +1174,7 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s @@ -1096,7 +1174,7 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s
1096 print(obs_conf_folder) 1174 print(obs_conf_folder)
1097 exit(1) 1175 exit(1)
1098 1176
1099 - path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory+"/config/" 1177 + path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory
1100 obs_config_file_name = "" 1178 obs_config_file_name = ""
1101 # Search for observatory config file 1179 # Search for observatory config file
1102 obs_config_file_name = glob.glob( 1180 obs_config_file_name = glob.glob(
src/core/pyros_django/obs_config/obsconfig_class.py
@@ -901,11 +901,13 @@ class OBSConfig: @@ -901,11 +901,13 @@ class OBSConfig:
901 agents = self.get_agents(self.unit_name) 901 agents = self.get_agents(self.unit_name)
902 for agent in agents: 902 for agent in agents:
903 computer_name = agents[agent]["computer"] 903 computer_name = agents[agent]["computer"]
904 - computer_hostname = self.get_computers().get(computer_name).get("computer_config").get("hostname")  
905 - if(computer_hostname not in agents_per_computer.keys()):  
906 - agents_per_computer[computer_hostname] = [agent]  
907 - else:  
908 - agents_per_computer[computer_hostname].append(agent) 904 + # computer_name is a string so we have to check if it's different of string None
  905 + if computer_name != "None":
  906 + computer_hostname = self.get_computers().get(computer_name).get("computer_config").get("hostname")
  907 + if(computer_hostname not in agents_per_computer.keys()):
  908 + agents_per_computer[computer_hostname] = [agent]
  909 + else:
  910 + agents_per_computer[computer_hostname].append(agent)
909 return agents_per_computer 911 return agents_per_computer
910 912
911 def get_agents_per_device(self, unit_name: str) -> dict: 913 def get_agents_per_device(self, unit_name: str) -> dict:
@@ -1319,22 +1321,26 @@ class OBSConfig: @@ -1319,22 +1321,26 @@ class OBSConfig:
1319 dependencies = self.get_unit_by_name(unit).get("DEPENDENCIES") 1321 dependencies = self.get_unit_by_name(unit).get("DEPENDENCIES")
1320 dependencies_return = [] 1322 dependencies_return = []
1321 for dependency in dependencies: 1323 for dependency in dependencies:
  1324 + dependency = dependency.get("DEPENDENCY")
1322 computers = dependency.get("computers") 1325 computers = dependency.get("computers")
1323 commands = [] 1326 commands = []
1324 for link in dependency.get("links"): 1327 for link in dependency.get("links"):
  1328 + link = link.get("link")
1325 type = link.get("type") 1329 type = link.get("type")
1326 url = link.get("url") 1330 url = link.get("url")
  1331 + name = link.get("name")
1327 cmd = "" 1332 cmd = ""
1328 if type == "git": 1333 if type == "git":
1329 - cmd += f"git clone {url}" 1334 + cmd += f"git clone {url}.git {name}"
1330 elif type == "wget": 1335 elif type == "wget":
1331 cmd += f"wget {url}" 1336 cmd += f"wget {url}"
1332 commands.append(cmd) 1337 commands.append(cmd)
1333 path_projet_root = os.environ['PROJECT_ROOT_PATH'] 1338 path_projet_root = os.environ['PROJECT_ROOT_PATH']
1334 install_section = link.get("install") 1339 install_section = link.get("install")
1335 - install_cmd = f"{install_section.get('shell')} {path_projet_root}{install_section.get('script')}"  
1336 - cmd.append(install_cmd)  
1337 - dependencies_return.append((computers,commands)) 1340 + #script_path = os.path.join(path_projet_root, "vendor", name, install_section.get('script'))
  1341 + install_cmd = f"{install_section.get('shell')} {install_section.get('script')}"
  1342 + commands.append(install_cmd)
  1343 + dependencies_return.append({"computers":computers, "commands":commands})
1338 return dependencies_return 1344 return dependencies_return
1339 1345
1340 1346