Commit 5acb05d27aae84c8a210910f93fa5be5f47e3caf
1 parent
670b526c
Exists in
dev
SAFE TEST MODE
Suppression commandes dangereuses quand mode TEST et REAL (no simulator)
Showing
2 changed files
with
38 additions
and
23 deletions
Show diff stats
src/core/pyros_django/agent/Agent.py
... | ... | @@ -452,6 +452,7 @@ class Agent: |
452 | 452 | self._agent_survey = AgentSurvey.objects.create(name=self.name, validity_duration=60, mode=self.mode, status=self.status, iteration=-1) |
453 | 453 | self.printd("Agent survey is", self._agent_survey) |
454 | 454 | |
455 | + | |
455 | 456 | def get_config_filename(self, config_filename: str): |
456 | 457 | if not config_filename: |
457 | 458 | config_filename = self.DEFAULT_CONFIG_FILE_NAME |
... | ... | @@ -519,6 +520,20 @@ class Agent: |
519 | 520 | FOR_REAL: set to False if you don't want Agent to send commands to devices but just print messages without really doing anything |
520 | 521 | """ |
521 | 522 | |
523 | + # TEST MODE ONLY | |
524 | + # IF in test mode but with REAL devices (no SIMULATOR), delete all dangerous commands from the test commands list scenario: | |
525 | + if self.TEST_MODE: | |
526 | + print("\n!!! In TEST mode !!! => preparing to run a scenario of test commands") | |
527 | + print("- Current test commands list scenario is:\n", self.TEST_COMMANDS_LIST) | |
528 | + if not self.WITH_SIMULATOR: | |
529 | + print("\n!!! In TEST but no SIMULATOR mode (using REAL device) !!! => removing dangerous commands for real devices... :") | |
530 | + TEST_COMMANDS_LIST_copy = self.TEST_COMMANDS_LIST.copy() | |
531 | + for cmd in TEST_COMMANDS_LIST_copy: | |
532 | + cmd_key = cmd.split()[1] | |
533 | + if ("set_" in cmd_key) or ("do_start" in cmd_key) or cmd_key in ["do_init", "do_goto", "do_open", "do_close"]: | |
534 | + self.TEST_COMMANDS_LIST.remove(cmd) | |
535 | + print("- NEW test commands list scenario is:\n", self.TEST_COMMANDS_LIST, '\n') | |
536 | + | |
522 | 537 | self._DO_EXIT = False |
523 | 538 | self._DO_RESTART = True |
524 | 539 | |
... | ... | @@ -551,7 +566,7 @@ class Agent: |
551 | 566 | self._kill_running_device_cmd_if_exists("USER_CTRLC") |
552 | 567 | exit(1) |
553 | 568 | |
554 | - if self.TEST_MODE and self.TEST_WITH_FINAL_TEST: self._simulator_test_results() | |
569 | + if self.TEST_MODE and self.TEST_WITH_FINAL_TEST: self._TEST_test_results() | |
555 | 570 | #if self._DO_EXIT: exit(0) |
556 | 571 | |
557 | 572 | |
... | ... | @@ -622,7 +637,7 @@ class Agent: |
622 | 637 | if self.TEST_MAX_DURATION_SEC and (time.time()-self.start_time > self.TEST_MAX_DURATION_SEC): |
623 | 638 | self.print("Exit because of max duration set to ", self.TEST_MAX_DURATION_SEC, "s") |
624 | 639 | self._kill_running_device_cmd_if_exists(self.name) |
625 | - #if self.TEST_MODE and self.TEST_WITH_FINAL_TEST: self._simulator_test_results() | |
640 | + #if self.TEST_MODE and self.TEST_WITH_FINAL_TEST: self._TEST_test_results() | |
626 | 641 | self._DO_MAIN_LOOP = False |
627 | 642 | return |
628 | 643 | |
... | ... | @@ -716,7 +731,7 @@ class Agent: |
716 | 731 | |
717 | 732 | def print_TEST_MODE(self): |
718 | 733 | if self.TEST_MODE: |
719 | - self._log.print("[IN SIMULATOR MODE]") | |
734 | + self._log.print("[IN TEST MODE]") | |
720 | 735 | self.print("flush previous commands to be sure to start in clean state") |
721 | 736 | Command.delete_pending_commands_for_agent(self.name) |
722 | 737 | else: |
... | ... | @@ -738,7 +753,7 @@ class Agent: |
738 | 753 | """ |
739 | 754 | self.printd("\n\n--------- START ROUTINE PROCESSING ---------") |
740 | 755 | self._set_status(self.STATUS_ROUTINE_PROCESS) |
741 | - if self.TEST_MODE: self._simulator_routine_process() | |
756 | + if self.TEST_MODE: self._test_routine_process() | |
742 | 757 | self.printd("\n--------- END ROUTINE PROCESSING ---------\n") |
743 | 758 | |
744 | 759 | |
... | ... | @@ -1168,7 +1183,7 @@ class Agent: |
1168 | 1183 | commands = Command.get_pending_and_running_commands_for_agent(self.name) |
1169 | 1184 | Command.show_commands(commands) |
1170 | 1185 | #if self.TEST_MODE and self.TEST_WITH_FINAL_TEST and self.TEST_COMMANDS_DEST == "myself": self.simulator_test_results() |
1171 | - if self.TEST_MODE and self.TEST_WITH_FINAL_TEST: self._simulator_test_results() | |
1186 | + if self.TEST_MODE and self.TEST_WITH_FINAL_TEST: self._TEST_test_results() | |
1172 | 1187 | #self._DO_EXIT=True |
1173 | 1188 | #exit(0) |
1174 | 1189 | |
... | ... | @@ -1253,17 +1268,17 @@ class Agent: |
1253 | 1268 | |
1254 | 1269 | """ |
1255 | 1270 | ================================================================= |
1256 | - SIMULATOR DEDICATED FUNCTIONS | |
1271 | + TEST DEDICATED FUNCTIONS | |
1257 | 1272 | ================================================================= |
1258 | 1273 | """ |
1259 | 1274 | |
1260 | 1275 | #def setSimulatorMode(self, mode): |
1261 | - def _set_test_mode(self, mode): | |
1276 | + def _set_test_mode(self, mode:bool): | |
1262 | 1277 | self.TEST_MODE=mode |
1263 | - def _set_with_simulator(self, mode): | |
1278 | + def _set_with_simulator(self, mode:bool): | |
1264 | 1279 | self.WITH_SIMULATOR=mode |
1265 | 1280 | |
1266 | - def _simulator_get_next_command_to_send(self)->Command: | |
1281 | + def _TEST_get_next_command_to_send(self)->Command: | |
1267 | 1282 | cmd_full_name = next(self.TEST_COMMANDS, None) |
1268 | 1283 | #return cmd_name |
1269 | 1284 | if cmd_full_name is None: return None |
... | ... | @@ -1273,7 +1288,7 @@ class Agent: |
1273 | 1288 | #return Command(sender=self.name, recipient=recipient_agent, name=cmd_name) |
1274 | 1289 | cmd = self.create_cmd_for(agent_recipient, cmd_name) |
1275 | 1290 | # If no cmd created (because of error, bad AgentDevice name), call again this method for next cmd |
1276 | - if cmd is None: return self._simulator_get_next_command_to_send() | |
1291 | + if cmd is None: return self._TEST_get_next_command_to_send() | |
1277 | 1292 | return cmd |
1278 | 1293 | |
1279 | 1294 | """ |
... | ... | @@ -1287,13 +1302,13 @@ class Agent: |
1287 | 1302 | recipient_agent = self.name if self.TEST_COMMANDS_DEST=="myself" else self.TEST_COMMANDS_DEST |
1288 | 1303 | Command.objects.create(sender=self.name, recipient=recipient_agent, name=cmd_name) |
1289 | 1304 | #time.sleep(1) |
1290 | - #self._simulator_current_cmd_idx += 1 | |
1305 | + #self._TEST_current_cmd_idx += 1 | |
1291 | 1306 | #self._nb_test_cmds += 1 |
1292 | 1307 | """ |
1293 | 1308 | |
1294 | - def _simulator_routine_process(self): | |
1309 | + def _test_routine_process(self): | |
1295 | 1310 | """ |
1296 | - SIMULATOR MODE ONLY | |
1311 | + TEST MODE ONLY | |
1297 | 1312 | """ |
1298 | 1313 | |
1299 | 1314 | # There is a current command being processed |
... | ... | @@ -1306,7 +1321,7 @@ class Agent: |
1306 | 1321 | if self._cmdts.is_pending() or self._cmdts.is_running(): |
1307 | 1322 | if self._next_cmdts is None: |
1308 | 1323 | # If next command is "do_abort" then abort becomes the new current command (to be sent) |
1309 | - self._next_cmdts = self._simulator_get_next_command_to_send() | |
1324 | + self._next_cmdts = self._TEST_get_next_command_to_send() | |
1310 | 1325 | if self._next_cmdts and self._next_cmdts.name == "do_abort": |
1311 | 1326 | # Wait a little to give a chance to agentB to start execution of current command, |
1312 | 1327 | # so that we can abort it then (otherwise it won't be aborted!!) |
... | ... | @@ -1358,7 +1373,7 @@ class Agent: |
1358 | 1373 | self._cmdts = self._next_cmdts |
1359 | 1374 | self._next_cmdts = None |
1360 | 1375 | else: |
1361 | - self._cmdts = self._simulator_get_next_command_to_send() | |
1376 | + self._cmdts = self._TEST_get_next_command_to_send() | |
1362 | 1377 | # No more command to send (from simulator) => return and EXIT |
1363 | 1378 | if self._cmdts is None: |
1364 | 1379 | self._DO_MAIN_LOOP = False |
... | ... | @@ -1374,10 +1389,10 @@ class Agent: |
1374 | 1389 | #cmdts_is_processed = False |
1375 | 1390 | #cmdts_res = None |
1376 | 1391 | |
1377 | - def _simulator_test_results(self): | |
1392 | + def _TEST_test_results(self): | |
1378 | 1393 | if self.TEST_COMMANDS_LIST == [] : return |
1379 | 1394 | nb_commands_to_send = len(self.TEST_COMMANDS_LIST) |
1380 | - nb_commands_sent, commands = self._simulator_test_results_start() | |
1395 | + nb_commands_sent, commands = self._TEST_test_results_start() | |
1381 | 1396 | #nb_commands_to_send = len(self.TEST_COMMANDS_LIST) |
1382 | 1397 | |
1383 | 1398 | # General (default) test |
... | ... | @@ -1416,10 +1431,10 @@ class Agent: |
1416 | 1431 | print("-", nb_unknown, "unknown command(s) => skipped") |
1417 | 1432 | |
1418 | 1433 | # Specific (detailed) test (to be overriden by subclass) |
1419 | - nb_asserted2 = self.simulator_test_results_main(commands) | |
1420 | - self._simulator_test_results_end(nb_asserted) | |
1434 | + nb_asserted2 = self.TEST_test_results_main(commands) | |
1435 | + self._TEST_test_results_end(nb_asserted) | |
1421 | 1436 | |
1422 | - def _simulator_test_results_start(self): | |
1437 | + def _TEST_test_results_start(self): | |
1423 | 1438 | self.print("\n--- Testing if the commands I SENT had the awaited result") |
1424 | 1439 | self.print("Here are the last commands I sent:") |
1425 | 1440 | #commands = list(Command.get_last_N_commands_for_agent(self.name, 16)) |
... | ... | @@ -1457,7 +1472,7 @@ class Agent: |
1457 | 1472 | """ |
1458 | 1473 | |
1459 | 1474 | # To be overriden by subclass |
1460 | - def simulator_test_results_main(self, commands): | |
1475 | + def TEST_test_results_main(self, commands): | |
1461 | 1476 | return 0 |
1462 | 1477 | ''' |
1463 | 1478 | nb_asserted = 0 |
... | ... | @@ -1468,7 +1483,7 @@ class Agent: |
1468 | 1483 | return nb_asserted |
1469 | 1484 | ''' |
1470 | 1485 | |
1471 | - def _simulator_test_results_end(self, nb_asserted): | |
1486 | + def _TEST_test_results_end(self, nb_asserted): | |
1472 | 1487 | #nb_commands_to_send = len(self.TEST_COMMANDS_LIST) |
1473 | 1488 | #print(nb_asserted, "vs", nb_commands_to_send) |
1474 | 1489 | #assert nb_asserted == nb_commands_to_send | ... | ... |
src/core/pyros_django/agent/AgentMultiRequester.py
... | ... | @@ -355,7 +355,7 @@ class AgentMultiRequester(Agent): |
355 | 355 | ''' |
356 | 356 | |
357 | 357 | # @override |
358 | - def simulator_test_results_main(self, commands): | |
358 | + def TEST_test_results_main(self, commands): | |
359 | 359 | #nb_asserted = super().simulator_test_results_main(commands) |
360 | 360 | nb_asserted = 0 |
361 | 361 | ''' | ... | ... |