diff --git a/pyros.py b/pyros.py index b26f811..8e35c79 100755 --- a/pyros.py +++ b/pyros.py @@ -721,8 +721,7 @@ def test(module, function): if module is None: # apps = ['obs_config','scp_mgmt','common', 'scheduling', 'seq_submit', 'user_mgmt', 'alert_mgmt.tests.TestStrategyChange'] # Removing alert_mgmt, scheduler from tests - apps = ['obs_config', "scp_mgmt", - 'dashboard', 'user_mgmt', 'seq_submit','api'] + apps = ['obs_config', "scp_mgmt", 'dashboard', 'user_mgmt', 'seq_submit', 'api'] else: os.environ["PATH_TO_OBSCONF_FILE"] = os.path.join(os.path.abspath( PYROS_DJANGO_BASE_DIR), "obs_config/fixtures/observatory_configuration_ok_simple.yml") @@ -754,7 +753,7 @@ def test(module, function): # execProcessFromVenv('manage.py test ' + app) or die() # KEEP test_pyros database after tests # execProcessFromVenv('manage.py test --keep ' + app) or die() - execProcessFromVenv('manage.py test --keep --noinput ' + app,foreground=True) or die() + execProcessFromVenv('manage.py test --keep --noinput ' + app, foreground=True) or die() change_dir("PREVIOUS") # execProcess("python install.py install") return True diff --git a/src/core/pyros_django/majordome/agent/A_Basic.py b/src/core/pyros_django/majordome/agent/A_Basic.py index a1791d9..78fee19 100755 --- a/src/core/pyros_django/majordome/agent/A_Basic.py +++ b/src/core/pyros_django/majordome/agent/A_Basic.py @@ -43,13 +43,13 @@ from typing import List, Tuple, Union, Any class A_Basic(Agent): # FOR TEST ONLY - # Run this agent in simulator mode + # - Run this agent in simulator mode TEST_MODE = False - # Run the assertion tests at the end + # - Run the assertion tests at the end TEST_WITH_FINAL_TEST = False #TEST_MAX_DURATION_SEC = None TEST_MAX_DURATION_SEC = 400 - # Who should I send commands to ? + # - Who should I send commands to ? TEST_COMMANDS_DEST = "myself" #TEST_COMMANDS_DEST = "AgentB" # Scenario to be executed diff --git a/src/core/pyros_django/majordome/agent/Agent.py b/src/core/pyros_django/majordome/agent/Agent.py index ab71831..0ccdc99 100755 --- a/src/core/pyros_django/majordome/agent/Agent.py +++ b/src/core/pyros_django/majordome/agent/Agent.py @@ -160,6 +160,7 @@ from vendor.guitastro.src.guitastro import Ephemeris import pickle +# Aliases for Cmd exceptions CmdException = AgentCmd.CmdException CmdExceptionUnknown = AgentCmd.CmdExceptionUnknown CmdExceptionUnimplemented = AgentCmd.CmdExceptionUnimplemented @@ -218,7 +219,7 @@ class Colors: BOLD = "\033[1m" UNDERLINE = "\033[4m" -def printColor(color: Colors, message, file=sys.stdout, eol=os.linesep, forced=False): +def print_colored(color: Colors, message, file=sys.stdout, eol=os.linesep, forced=False): #system = platform.system() """ if (self.disp == False and forced == False): @@ -237,10 +238,10 @@ def printFullTerm(color: Colors, string: str): row = 1000 disp = True value = int(columns / 2 - len(string) / 2) - printColor(color, "-" * value, eol="") - printColor(color, string, eol="") + print_colored(color, "-" * value, eol="") + print_colored(color, string, eol="") value += len(string) - printColor(color, "-" * (columns - value)) + print_colored(color, "-" * (columns - value)) return 0 @@ -301,23 +302,22 @@ class Agent: # --- - INSTANCE attributes are accessible via agent.__dict__ # --- - class EXEC_MODE(Enum): SEQUENTIAL = 0 THREAD = 1 PROCESS = 2 # Default modes - DEBUG_MODE:bool = False + DEBUG_MODE: bool = False #TEST_MODE = False # By default, a command is valid during 5s (and then perempted) - DEFAULT_CMD_VALIDITY_DURATION:int = 5 + DEFAULT_CMD_VALIDITY_DURATION: int = 5 # Wait a fixed number of seconds before each loop ? #WITH_RANDOM_WAIT = False # 1 sec by default - __DELAY_NB_SEC:int = 1 + __DELAY_NB_SEC: int = 1 # - YES if TEST mode (in init()) # Default LOG level is INFO @@ -332,7 +332,7 @@ class Agent: - exec_mode (EXEC_MODE) : EXEC_MODE.SEQUENTIAL, EXEC_MODE.THREAD, or EXEC_MODE.PROCESS - tooltip : description text (displayed on clic) ''' - _AGENT_SPECIFIC_COMMANDS: Dict [ str, Tuple[int, EXEC_MODE, str] ] = { + _AGENT_SPECIFIC_COMMANDS: Dict[str, Tuple[int, EXEC_MODE, str]] = { # Format : “cmd_name” : (timeout, exec_mode, tooltip) #"do_specific1" : (10, EXEC_MODE.SEQUENTIAL, ''), @@ -352,14 +352,15 @@ class Agent: # Maximum duration of this agent (only for SIMULATION mode) # If set to 0, it will never exit except if asked (or CTRL-C) # If set to 20, it will exit after 20s - TEST_MAX_DURATION_SEC :int=0 + TEST_MAX_DURATION_SEC: int = 0 #TEST_MAX_DURATION_SEC = 30 # Run this agent in simulator mode #TEST_MODE = True - WITH_SIMULATOR:bool = False + WITH_SIMULATOR: bool = False # Run the assertion tests at the end - TEST_WITH_FINAL_TEST:bool = False + TEST_WITH_FINAL_TEST: bool = False + # Aliases CMD_STATUS = AgentCmd.CMD_STATUS_CODES AGT_STATUS = AgentSurvey.STATUS_CHOICES @@ -393,8 +394,8 @@ class Agent: ##_TEST_COMMANDS_LIST: List[ Tuple[ bool, str, int, Optional[str], AgentCmd.CMD_STATUS_CODES ] ] = [ # Alias type for _TEST_COMMANDS_LIST (for more readability) - TestCommand = Tuple[ bool, str, Optional[int], Optional[str], Optional[int]] - _TEST_COMMANDS_LIST: List[ TestCommand ] = [ + TestCommand = Tuple[bool, str, Optional[int], Optional[str], Optional[int]] + _TEST_COMMANDS_LIST: List[TestCommand] = [ # Format : (DO_IT, "self cmd_name cmd_args", validity, "expected_result", expected_status), #("self do_stop now", 200, '15.5', None), @@ -591,8 +592,8 @@ class Agent: ##_cmdts: AgentCmd = None ##_next_cmdts = None - __agent_survey:AgentSurvey = None - __pending_commands:QuerySet = None # [] + __agent_survey: AgentSurvey = None + __pending_commands: QuerySet = None # [] # List of agents I will send commands to _my_client_agents_aliases = [] @@ -610,28 +611,28 @@ class Agent: # new obsconfig init for agent: ##def __init__(self, RUN_IN_THREAD=True): - def __init__(self,simulated_computer=None): + def __init__(self, simulated_computer=None): # Instance attributes declaration (with default values, or None) - self.__UP_SINCE : Final = datetime.now(tz=timezone.utc) + self.__UP_SINCE: Final = datetime.now(tz=timezone.utc) #self.UP_SINCE = datetime.utcnow() - self.__ROUTINE_ITER_START_IS_RUNNING:bool = False - self.__ROUTINE_ITER_END_IS_RUNNING:bool = False - self.__test_cmd_received_num:int = 0 # only for tests + self.__ROUTINE_ITER_START_IS_RUNNING: bool = False + self.__ROUTINE_ITER_END_IS_RUNNING: bool = False + self.__test_cmd_received_num: int = 0 # only for tests # Current Command running - self.__CC :Optional[AgentCmd] #= None - self.__CC_thread :Union[StoppableThreadEvenWhenSleeping, multiprocessing.Process] #= None + self.__CC: Optional[AgentCmd] # = None + self.__CC_thread: Union[StoppableThreadEvenWhenSleeping, multiprocessing.Process] #= None # Previous Command running ##self.__CC_prev :Optional[AgentCmd] = None # Current Command exception (if occurs) - self.__CCE :Optional[Exception] #= None + self.__CCE: Optional[Exception] #= None self.name = "Generic Agent" - self.__status :str #= None - self.__mode :str #= None - self.unit :str #= None + self.__status: str # = None + self.__mode: str # = None + self.unit: str # = None #self.TEST_COMMANDS :List #= None - self.TEST_COMMANDS :Iterable[Agent.TestCommand] #= None - self.__iter_num :int = 0 + self.TEST_COMMANDS: Iterable[Agent.TestCommand] # = None + self.__iter_num: int = 0 #print(AgentSurvey.MODE_CHOICES.IDLE) #sys.exit() @@ -639,18 +640,21 @@ class Agent: #self.__mode = self.MODE_ATTENTIVE self.set_mode_attentive() #self._set_mode(MODES.) + + # Set Obs config obs_config_file_path = os.environ["PATH_TO_OBSCONF_FILE"] path_to_obs_config_folder = os.environ["PATH_TO_OBSCONF_FOLDER"] unit = os.environ["unit_name"] - oc = OBSConfig(obs_config_file_path,unit) + oc = OBSConfig(obs_config_file_path, unit) pyros_yaml_path = os.environ["pyros_config_file"] pyros_config = ConfigPyros(pyros_yaml_path) self.set_config(oc, obs_config_file_path, path_to_obs_config_folder, unit, pyros_config, pyros_yaml_path) + + # Agent 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 - else: - self.name = self.__class__.__name__ + self.name = agent_name_from_config if agent_name_from_config else self.__class__.__name__ + + # LOG log.addHandler(handler_filebyagent(logging.INFO, self.name)) #log.addHandler(handler_filebyagent(logging.INFO, self.name)) log.debug("start Agent init") @@ -670,10 +674,11 @@ class Agent: self.TEST_COMMANDS = iter(self._TEST_COMMANDS_LIST) ##self.RUN_IN_THREAD = RUN_IN_THREAD + self.__set_status(self.AGT_STATUS.LAUNCHED) ####self._set_idle() - # Create 1st survey if none + # Get survey or create 1st one if none #tmp = AgentSurvey.objects.filter(name=self.name) #if len(tmp) == 0: #nb_agents = AgentSurvey.objects.filter(name=self.name).count() @@ -857,18 +862,16 @@ class Agent: @property def ROUTINE_ITER_START_IS_RUNNING(self): return self.__ROUTINE_ITER_START_IS_RUNNING + @property def ROUTINE_ITER_END_IS_RUNNING(self): return self.__ROUTINE_ITER_END_IS_RUNNING - - - def set_config(self, oc: OBSConfig, obs_config_file_path: str, path_to_obs_config_folder: str, unit: str, pyros_config: str, pyros_yaml_path: str): self._oc = { - 'config' : oc, - 'pyros_config' : pyros_config, - 'env' : [ + 'config': oc, + 'pyros_config': pyros_config, + 'env': [ obs_config_file_path, path_to_obs_config_folder, unit, @@ -962,10 +965,6 @@ class Agent: print("\n") - - - - def get_config_filename(self, config_filename: str): if not config_filename: #config_filename = self.DEFAULT_CONFIG_FILE_NAME @@ -1013,7 +1012,7 @@ class Agent: - def _get_real_agent_name(self, agent_alias_name:str)->str: + def _get_real_agent_name(self, agent_alias_name: str) -> str: #self.printd("key is", agent_alias_name) ''' if not self._my_client_agents: return agent_alias_name @@ -1023,7 +1022,7 @@ class Agent: - def run(self, nb_iter:int=None, FOR_REAL:bool=True): + def run(self, nb_iter: int = None, FOR_REAL: bool = True): """ FOR_REAL: set to False if you don't want Agent to send commands to devices but just print messages without really doing anything """ -- libgit2 0.21.2