Commit 795c826a59469bfb1e5a4da030f44a605fa36beb
1 parent
8902a770
Exists in
dev
Ajout de la gestion des commandes badly named
Showing
4 changed files
with
54 additions
and
6 deletions
Show diff stats
privatedev/plugin/agent/AgentBasic.py
... | ... | @@ -37,7 +37,8 @@ class AgentBasic(Agent): |
37 | 37 | # Format : (“cmd_name”, timeout, exec_mode) |
38 | 38 | ("do_specific10", 10, 0), |
39 | 39 | ("do_cmd_unimplemented", 3, 0), |
40 | - ("cmd_unimplemented2", 3, 0), | |
40 | + ("cmd_badly_named_and_implemented", 3, 0), | |
41 | + ("cmd_badly_named_and_unimplemented", 3, 0), | |
41 | 42 | #("set_specific2", 5, 0), |
42 | 43 | ("do_specific30", 3, 0), |
43 | 44 | ("do_cmd_raising_error_exec", 3, 0), |
... | ... | @@ -47,7 +48,7 @@ class AgentBasic(Agent): |
47 | 48 | # on DEV |
48 | 49 | #COMMIT_ONLY = False |
49 | 50 | # on commit only |
50 | - COMMIT_ONLY = True | |
51 | + COMMIT_ONLY = False | |
51 | 52 | |
52 | 53 | # @override |
53 | 54 | _TEST_COMMANDS_LIST = [ |
... | ... | @@ -60,7 +61,12 @@ class AgentBasic(Agent): |
60 | 61 | #("self do_stop now", 200, 'STOPPING now', Agent.CMD_STATUS.CMD_EXECUTED), |
61 | 62 | #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
62 | 63 | #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
63 | - | |
64 | + | |
65 | + | |
66 | + # Badly named command (not generic) => CMD_INVAlID | |
67 | + (True, "self cmd_badly_named_and_implemented", 200, "Command badly named, must start with do_, get_, or set_", Agent.CMD_STATUS.CMD_INVALID), | |
68 | + (True, "self cmd_badly_named_and_unimplemented", 200, None, Agent.CMD_STATUS.CMD_INVALID), | |
69 | + | |
64 | 70 | # do_restart |
65 | 71 | |
66 | 72 | (COMMIT_ONLY, "self do_restart asap", 200, 'RESTARTING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
... | ... | @@ -371,6 +377,8 @@ class AgentBasic(Agent): |
371 | 377 | def do_specific30(self): |
372 | 378 | pass |
373 | 379 | |
380 | + def cmd_badly_named_and_implemented(self): | |
381 | + pass | |
374 | 382 | |
375 | 383 | """ |
376 | 384 | ================================================================= |
... | ... | @@ -388,4 +396,9 @@ if __name__ == "__main__": |
388 | 396 | agent.setSimulatorMode(TEST_MODE) |
389 | 397 | print(agent) |
390 | 398 | ''' |
399 | + | |
400 | + # Run only 4 iterations | |
401 | + #agent.run(nb_iter=4) | |
402 | + | |
403 | + # Run indefinitely | |
391 | 404 | agent.run() | ... | ... |
src/core/pyros_django/agent/Agent.py
... | ... | @@ -1334,6 +1334,10 @@ class Agent: |
1334 | 1334 | |
1335 | 1335 | cmd.set_read_time() |
1336 | 1336 | |
1337 | + if not AgentCmd.is_generic(cmd.name) and not self.is_native_device_command(cmd.name): | |
1338 | + cmd.set_as_invalid("Command badly named, must start with do_, get_, or set_") | |
1339 | + return cmd | |
1340 | + | |
1337 | 1341 | # CASE 1 - AGENT GENERAL command |
1338 | 1342 | # (DO_RESTART, DO_EXIST, DO_ABORT, DO_ABORT_COMMAND, DO_FLUSH_COMMANDS, ...) |
1339 | 1343 | # This processing can set DO_MAIN_LOOP and DO_RESTART_LOOP to False |
... | ... | @@ -1465,6 +1469,10 @@ class Agent: |
1465 | 1469 | #if self.TEST_MODE: self._TEST_test_routine_process() |
1466 | 1470 | pass |
1467 | 1471 | |
1472 | + # To be overriden by AgentDevice | |
1473 | + def is_native_device_command(self, cmd_name:str): | |
1474 | + return False | |
1475 | + | |
1468 | 1476 | """ |
1469 | 1477 | def purge_commands(self): |
1470 | 1478 | ### |
... | ... | @@ -1517,6 +1525,12 @@ class Agent: |
1517 | 1525 | #print(cmd_name) |
1518 | 1526 | specific_commands += cmd_name |
1519 | 1527 | |
1528 | + # 1) Error case 1 - Badly named command (not get, set, do) (implemented or not) | |
1529 | + if not AgentCmd.is_generic(cmd_name): | |
1530 | + specific_commands += '(I);' | |
1531 | + continue | |
1532 | + | |
1533 | + # 2) Error case 2 - Well named command (get, set, do) but not yet implemented | |
1520 | 1534 | try: |
1521 | 1535 | f = getattr(self, cmd_name) |
1522 | 1536 | # Exception if exists an unimplemented command |
... | ... | @@ -1527,6 +1541,7 @@ class Agent: |
1527 | 1541 | # next cmd |
1528 | 1542 | continue |
1529 | 1543 | |
1544 | + # 3) Normal case : well named command and implemented | |
1530 | 1545 | specific_commands += "(" |
1531 | 1546 | args = signature(f) |
1532 | 1547 | #specific_commands += str(args) | ... | ... |
src/core/pyros_django/agent/AgentBasic.py
... | ... | @@ -37,7 +37,8 @@ class AgentBasic(Agent): |
37 | 37 | # Format : (“cmd_name”, timeout, exec_mode) |
38 | 38 | ("do_specific10", 10, 0), |
39 | 39 | ("do_cmd_unimplemented", 3, 0), |
40 | - ("cmd_unimplemented2", 3, 0), | |
40 | + ("cmd_badly_named_and_implemented", 3, 0), | |
41 | + ("cmd_badly_named_and_unimplemented", 3, 0), | |
41 | 42 | #("set_specific2", 5, 0), |
42 | 43 | ("do_specific30", 3, 0), |
43 | 44 | ("do_cmd_raising_error_exec", 3, 0), |
... | ... | @@ -47,7 +48,7 @@ class AgentBasic(Agent): |
47 | 48 | # on DEV |
48 | 49 | #COMMIT_ONLY = False |
49 | 50 | # on commit only |
50 | - COMMIT_ONLY = True | |
51 | + COMMIT_ONLY = False | |
51 | 52 | |
52 | 53 | # @override |
53 | 54 | _TEST_COMMANDS_LIST = [ |
... | ... | @@ -60,7 +61,12 @@ class AgentBasic(Agent): |
60 | 61 | #("self do_stop now", 200, 'STOPPING now', Agent.CMD_STATUS.CMD_EXECUTED), |
61 | 62 | #("self do_stop", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
62 | 63 | #("self do_stop asap", 200, 'STOPPING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
63 | - | |
64 | + | |
65 | + | |
66 | + # Badly named command (not generic) => CMD_INVAlID | |
67 | + (True, "self cmd_badly_named_and_implemented", 200, "Command badly named, must start with do_, get_, or set_", Agent.CMD_STATUS.CMD_INVALID), | |
68 | + (True, "self cmd_badly_named_and_unimplemented", 200, None, Agent.CMD_STATUS.CMD_INVALID), | |
69 | + | |
64 | 70 | # do_restart |
65 | 71 | |
66 | 72 | (COMMIT_ONLY, "self do_restart asap", 200, 'RESTARTING asap', Agent.CMD_STATUS.CMD_EXECUTED), |
... | ... | @@ -371,6 +377,8 @@ class AgentBasic(Agent): |
371 | 377 | def do_specific30(self): |
372 | 378 | pass |
373 | 379 | |
380 | + def cmd_badly_named_and_implemented(self): | |
381 | + pass | |
374 | 382 | |
375 | 383 | """ |
376 | 384 | ================================================================= |
... | ... | @@ -388,4 +396,9 @@ if __name__ == "__main__": |
388 | 396 | agent.setSimulatorMode(TEST_MODE) |
389 | 397 | print(agent) |
390 | 398 | ''' |
399 | + | |
400 | + # Run only 4 iterations | |
401 | + #agent.run(nb_iter=4) | |
402 | + | |
403 | + # Run indefinitely | |
391 | 404 | agent.run() | ... | ... |
src/core/pyros_django/common/models.py
... | ... | @@ -664,6 +664,13 @@ class AgentCmd(models.Model): |
664 | 664 | |
665 | 665 | # -------------- Command CLASS (static) METHODS -------------- |
666 | 666 | |
667 | + @classmethod | |
668 | + def is_generic(self, cmd_name:str) ->bool : | |
669 | + ''' | |
670 | + Generic if starts with get_, set_, or do_ | |
671 | + ''' | |
672 | + return cmd_name.startswith( ('get_', 'set_', 'do_') ) | |
673 | + | |
667 | 674 | # Avoid to override the Model __init__ method |
668 | 675 | # See https://docs.djangoproject.com/en/stable/ref/models/instances/#creating-objects |
669 | 676 | @classmethod | ... | ... |