Get the routine name to call with getattr 51/107451/2
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Mon, 11 May 2020 13:00:00 +0000 (06:00 -0700)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 12 May 2020 05:50:41 +0000 (05:50 +0000)
Each subcommand has a corresponding method in
MassPnfSim class hence it can be called directly
by it's name.

Change-Id: Id7139a5f96cceac89559bd68d89085130703f4bd
Issue-ID: INT-1577
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
test/mocks/mass-pnf-sim/MassPnfSim.py
test/mocks/mass-pnf-sim/mass-pnf-sim.py

index 48b1d74..1a6ae8a 100755 (executable)
@@ -53,7 +53,7 @@ def get_parser():
     parser_trigger = subparsers.add_parser('trigger', help='Trigger one single VES event from each simulator')
     parser_trigger.add_argument('--count', help='Instance count to trigger', type=int, metavar='INT', default=1)
     # Trigger-custom command parser
-    parser_triggerstart = subparsers.add_parser('trigger-custom', help='Trigger one single VES event from specific simulators')
+    parser_triggerstart = subparsers.add_parser('trigger_custom', help='Trigger one single VES event from specific simulators')
     parser_triggerstart.add_argument('--triggerstart', help='First simulator id to trigger', type=int,
                                      metavar='INT', required=True)
     parser_triggerstart.add_argument('--triggerend', help='Last simulator id to trigger', type=int,
index 1a57cbe..fe60626 100755 (executable)
@@ -18,20 +18,7 @@ if __name__ == '__main__':
     MassPnfSim.log_lvl = log_lvl
 
     if args.subcommand is not None:
-        sim = MassPnfSim(args)
-        if args.subcommand == 'bootstrap' :
-            sim.bootstrap()
-        if args.subcommand == 'clean':
-            sim.clean()
-        if args.subcommand == 'start':
-            sim.start()
-        if args.subcommand == 'status':
-            sim.status()
-        if args.subcommand == 'stop':
-            sim.stop()
-        if args.subcommand == 'trigger':
-            sim.trigger()
-        if args.subcommand == 'trigger-custom':
-            sim.trigger_custom()
+        sim_routine = getattr(MassPnfSim(args), args.subcommand)
+        sim_routine()
     else:
         parser.print_usage()