From 912ecc8facd9bfd520ad8a34f9439e927da7678a Mon Sep 17 00:00:00 2001 From: Alexis Koralewski Date: Wed, 23 Nov 2022 09:12:48 +0100 Subject: [PATCH] Change location of pyros config file --- CHANGELOG | 4 ++++ privatedev/config/pyros/__init__.py | 0 privatedev/config/pyros/config_pyros.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ privatedev/config/pyros/config_pyros.yml | 14 ++++++++++++++ privatedev/config/pyros/schema_pyros_config.yml | 31 +++++++++++++++++++++++++++++++ pyros.py | 9 +++++++-- src/core/pyros_django/scientific_program/views.py | 8 +++++--- 7 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 privatedev/config/pyros/__init__.py create mode 100644 privatedev/config/pyros/config_pyros.py create mode 100644 privatedev/config/pyros/config_pyros.yml create mode 100644 privatedev/config/pyros/schema_pyros_config.yml diff --git a/CHANGELOG b/CHANGELOG index 3948db1..17a538a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +23-11-2022 (AKo): v0.6.8.0 + - Change column order for agents commands views, add color for pending commands, fix width of table + - Change location of pyros config file + 07-11-2022 (AKo): v0.6.7.0 - Improve agents commands view (add status filter) - Add port configuration for phpmyadmin in docker-compose.yml diff --git a/privatedev/config/pyros/__init__.py b/privatedev/config/pyros/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/privatedev/config/pyros/__init__.py diff --git a/privatedev/config/pyros/config_pyros.py b/privatedev/config/pyros/config_pyros.py new file mode 100644 index 0000000..001466a --- /dev/null +++ b/privatedev/config/pyros/config_pyros.py @@ -0,0 +1,83 @@ +import yaml +import os +import time +import pykwalify.core +from pykwalify.errors import SchemaError + + +class ConfigPyros: + def check_and_return_config(self, yaml_file: str, schema_file: str) -> dict: + """ + Check if yaml_file is valid for the schema_file and return an dictionary of the config file + + Args: + yaml_file (str): Path to the config_file to be validated + schema_file (str): Path to the schema file + + Returns: + dict: dictionary of the config file (with values) + """ + # disable pykwalify error to clean the output + # logging.disable(logging.ERROR) + try: + can_yaml_file_be_read = False + while can_yaml_file_be_read != True: + if os.access(yaml_file, os.R_OK): + can_yaml_file_be_read = True + else: + print( + f"{yaml_file} can't be accessed, waiting for availability") + time.sleep(0.5) + + c = pykwalify.core.Core(source_file=yaml_file, schema_files=[ + self.config_path+"/"+schema_file]) + return c.validate(raise_exception=True) + except SchemaError: + for error in c.errors: + print("Error :", str(error).split(". Path")[0]) + print("Path to error :", error.path) + return None + except IOError: + print("Error when reading the observatory config file") + + def read_and_check_config_file(self, yaml_file: str) -> dict: + """ + Read the schema key of the config file to retrieve schema name and proceed to the checking of that config file + Call check_and_return_config function and print its return. + + Args: + yaml_file (str): path to the config file + Returns: + dict: Dictionary of the config file (with values) + """ + try: + can_config_file_be_read = False + while can_config_file_be_read != True: + + if os.access(yaml_file, os.R_OK): + can_config_file_be_read = True + else: + print( + f"{yaml_file} can't be accessed, waiting for availability") + time.sleep(0.5) + with open(yaml_file, 'r') as stream: + print(f"Reading {yaml_file}") + config_file = yaml.safe_load(stream) + result = self.check_and_return_config( + yaml_file, config_file["schema"]) + if result == None: + print( + "Error when reading and validating config file, please check the errors right above") + exit(1) + return result + + except yaml.YAMLError as exc: + print(exc) + except Exception as e: + print(e) + return None + + def __init__(self, pyros_config_file): + self.config_path = os.path.abspath(os.path.join( + os.environ.get("DJANGO_PATH"), "../../../config/pyros//")) + self.pyros_config = self.read_and_check_config_file(pyros_config_file) diff --git a/privatedev/config/pyros/config_pyros.yml b/privatedev/config/pyros/config_pyros.yml new file mode 100644 index 0000000..0bf44b4 --- /dev/null +++ b/privatedev/config/pyros/config_pyros.yml @@ -0,0 +1,14 @@ +schema: schema_pyros_config.yml +general: + logo: logo_pyros.png + color_theme: sienna + nb_element_per_page: 20 +USR: + nb_element_per_page: 10 +SCP: ~ +OCF: ~ +ENV: + time_history: 2 + time_before_plot: 10 + + \ No newline at end of file diff --git a/privatedev/config/pyros/schema_pyros_config.yml b/privatedev/config/pyros/schema_pyros_config.yml new file mode 100644 index 0000000..5eae4d2 --- /dev/null +++ b/privatedev/config/pyros/schema_pyros_config.yml @@ -0,0 +1,31 @@ +type: map +mapping: + schema: + type: str + required: True + general: + type: map + required: True + mapping: + logo: + type: str + required: True + color_theme: + type: str + required: True + nb_element_per_page: + type: int + required: True + USR: + type: any + SCP: + type: any + OCF: + type: any + ENV: + type: map + mapping: + time_history: + type: int + time_before_plot: + type: int diff --git a/pyros.py b/pyros.py index cda2392..d3e2a49 100755 --- a/pyros.py +++ b/pyros.py @@ -82,6 +82,7 @@ AGENTS = { "AgentImagesProcessor_tnc_up1": "../../../privatedev/plugin/agent", "agentBasic": "agent", "AgentTriton": "agent", + "AgentMCO":"agent", } # AGENTS = ["agentX", "webserver", "monitoring", "majordome", "scheduler", "alert_manager"] # AGENTS = ["all", "webserver", "monitoring", "majordome", "scheduler", "alert"] @@ -828,12 +829,16 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos "pykwalify package (required for obsconfig class) installation failed") if configfile: log.debug("With config file" + configfile) + # os.environ["pyros_config_file"] = os.path.join(os.path.abspath( + # PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile) os.environ["pyros_config_file"] = os.path.join(os.path.abspath( - PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile) + PYROS_DJANGO_BASE_DIR), "../../../private/config/pyros/", configfile) else: configfile = 'config_pyros.yml' + # os.environ["pyros_config_file"] = os.path.join(os.path.abspath( + # PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile) os.environ["pyros_config_file"] = os.path.join(os.path.abspath( - PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile) + PYROS_DJANGO_BASE_DIR), "../../../private/config/pyros/", configfile) logo_name = ConfigPyros( os.environ["pyros_config_file"]).pyros_config["general"]["logo"] diff --git a/src/core/pyros_django/scientific_program/views.py b/src/core/pyros_django/scientific_program/views.py index 7cc7832..cfd77a2 100644 --- a/src/core/pyros_django/scientific_program/views.py +++ b/src/core/pyros_django/scientific_program/views.py @@ -58,10 +58,10 @@ def index_scientific_program(request): # the date of today shift through the time line if previous_period: temp = today - previous_period.start_date - date_diff_today_end_of_property = temp.days / 12.5 + date_diff_today_end_of_property = temp.days * 0.85 else: temp = today - current_period.start_date - date_diff_today_end_of_property = temp.days / 12.5 + 15 + date_diff_today_end_of_property = (temp.days / 8) + 15 CAN_VALIDATE_SP = request.session.get("role") in ("Admin","Unit-PI","Unit-board") and sp_to_be_validated CAN_EVALUATE_SP = request.session.get("role") in ("Admin","TAC") and sp_to_be_evaluated CAN_SUBMIT_SP = request.session.get("role") in ("Admin","Observer") and does_next_period_exist @@ -842,7 +842,9 @@ def create_period(request): past_periods = [] active_period = Period.objects.exploitation_period() - periods = Period.objects.all().order_by("-start_date").exclude(id=active_period.id) + periods = Period.objects.all().order_by("-start_date") + if active_period: + periods.exclude(id=active_period.id) for period in periods: if active_period != None: past_periods.append(period) -- libgit2 0.21.2