From 820e5db56b695e04a6c6738173700d320e42c37c Mon Sep 17 00:00:00 2001 From: Alexis Koralewski Date: Thu, 23 Jun 2022 10:36:08 +0200 Subject: [PATCH] Adding new methods to get unit home and agent path_data_root. Adding data folder and his README file, git will ignore all content inside this folder --- .gitignore | 4 ++++ CHANGELOG | 4 ++++ data/README.md | 1 + src/core/pyros_django/obsconfig/obsconfig_class.py | 26 +++++++++++++++++++++++++- src/core/pyros_django/observation_manager/AgentImagesProcessor.py | 23 +++++++---------------- 5 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 data/README.md diff --git a/.gitignore b/.gitignore index 1833f77..a1b3f95 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,10 @@ client.log docker/*.env +# Agents data +# Ignore everthing outside of README.md +data/* +!data/README.md private/* privatedev/config/*/history/ diff --git a/CHANGELOG b/CHANGELOG index f66db42..b365ff7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +23-06-2022 (AKo): v0.4.14.0 + - Adding methods in obsconfig class to get home of unit and path_data_root of agent + - Adding data folder at root of project with an README. Git will ignore all content outside of this file in this folder + 20-06-2022 (AKo): v0.4.14.0 - Fixing issues for PYROSW with Windows OS, Adding venv option actions (running pyros in actual venv) if there is one and we're not within docker's pyros container - Fixing AgentSST (renaming method properly) diff --git a/data/README.md b/data/README.md new file mode 100644 index 0000000..b31f693 --- /dev/null +++ b/data/README.md @@ -0,0 +1 @@ +Folder to place Agents data \ No newline at end of file diff --git a/src/core/pyros_django/obsconfig/obsconfig_class.py b/src/core/pyros_django/obsconfig/obsconfig_class.py index 42f21a0..655ae1e 100644 --- a/src/core/pyros_django/obsconfig/obsconfig_class.py +++ b/src/core/pyros_django/obsconfig/obsconfig_class.py @@ -590,9 +590,10 @@ class OBSConfig: computers = {} for computer_id in range(len(self.obs_config["OBSERVATORY"]["INVENTORY"]["COMPUTERS"])): computer = self.obs_config["OBSERVATORY"]["INVENTORY"]["COMPUTERS"][computer_id]["COMPUTER"] - if("file" in computer.keys()): + if "file" in computer.keys(): computer["computer_config"] = self.read_and_check_config_file( self.CONFIG_PATH+computer["file"])["COMPUTER"] + print(computer) computers[computer["name"]] = computer return computers @@ -1116,6 +1117,29 @@ class OBSConfig: horizon = self.get_unit_by_name(unit_name).get("horizon") return horizon.get("line") + def getHome(self): + """ + Return home of current unit + + Returns: + str: string reprensenting home of unit + """ + home = self.get_unit_by_name(self.unit_name).get("home") + return home + + def get_agent_path_data_root(self, agent_name:str): + """ + Return agent path_data_root + + Args: + agent_name (str): _description_ + + Returns: + str|None: String reprensenting path_data_root + """ + agent = self.get_agent_information(self.unit_name, agent_name) + path_data_root = agent.get(path_data_root,None) + return path_data_root class MissingMandatoryAgentException(Exception): """ diff --git a/src/core/pyros_django/observation_manager/AgentImagesProcessor.py b/src/core/pyros_django/observation_manager/AgentImagesProcessor.py index 4bd1c57..b17525b 100755 --- a/src/core/pyros_django/observation_manager/AgentImagesProcessor.py +++ b/src/core/pyros_django/observation_manager/AgentImagesProcessor.py @@ -91,28 +91,19 @@ class AgentImagesProcessor(Agent): agent_alias = self.__class__.__name__ log.info(f"agent_alias = {agent_alias}") config = self._oc['config'] - units = config.get_units() - kunits = list(units.keys()) - kunit = kunits[0] - log.info(f"unit key = {kunit}") - unit = units[kunit] - self._unit = unit + unit = self.config.unit_name # log.info(f"unit = {unit}") - agents = config.get_agents(kunit) + agents = config.get_agents(unit) # log.info(f"agents = {agents}") - attrs = agents[agent_alias] - key = 'path_data_root' - if key in attrs: - self._path_data_root = attrs['path_data_root'] - else: + # get_agent_path_data_root return str value if path_data_root exists in obsconfig for this agent or None if not + self._path_data_root = self.config.get_agent_path_data_root(agent_alias) + if self.path_data_root = None: # default with docker should be /home/pyros_user/app self._path_data_root = os.environ['PROJECT_ROOT_PATH'] - if self._path_data_root == None: - self._path_data_root = os.environ['PROJECT_ROOT_PATH'] log.info(f"path_data_root = {self._path_data_root}") # - prepare the variables to return - path_data_root = self._path_data_root - home = self._unit['home'] + # Return home of current unit + home = self.config.getHome() # return path_data_root, home # === Define and create the directories for the images to process -- libgit2 0.21.2