aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-05-18 07:30:11 -0700
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-05-18 07:30:11 -0700
commita89abf819ed802c3aedc98eae281066d4c5b50dd (patch)
treeea751538344859fb5abc448cfe0e8b0e96447565 /test/mocks
parentbb8249ec4200471659d443bdec4befbac2ba01aa (diff)
Make the actions decorator a static method in a subclass
Change-Id: I2bd702ff1d92c80510204cb4666f6c3db7fa62e0 Issue-ID: INT-1577 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks')
-rwxr-xr-xtest/mocks/mass-pnf-sim/MassPnfSim.py55
1 files changed, 29 insertions, 26 deletions
diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py
index 966f3c887..5c01704d3 100755
--- a/test/mocks/mass-pnf-sim/MassPnfSim.py
+++ b/test/mocks/mass-pnf-sim/MassPnfSim.py
@@ -72,27 +72,30 @@ def get_parser():
type=str, default='info')
return parser
-# MassPnfSim class actions decorator
-def do_action(action_string, cmd):
- def action_decorator(method):
- def action_wrap(self):
- cmd_local = cmd
- # Append instance # if action is 'stop'
- if method.__name__ == 'stop':
- cmd_local += " {}"
- # Alter looping range if action is 'tigger_custom'
- if method.__name__ == 'trigger_custom':
- iter_range = [self.args.triggerstart, self.args.triggerend+1]
- else:
- iter_range = [self.args.count]
- method(self)
- for i in range(*iter_range):
- self.logger.info(f'{action_string} {self.sim_dirname_pattern}{i} instance:')
- self._run_cmd(cmd_local.format(i), f"{self.sim_dirname_pattern}{i}")
- return action_wrap
- return action_decorator
-
-class MassPnfSim():
+class MassPnfSim:
+
+ # MassPnfSim class actions decorator
+ class _MassPnfSim_Decorators:
+
+ @staticmethod
+ def do_action(action_string, cmd):
+ def action_decorator(method):
+ def action_wrap(self):
+ cmd_local = cmd
+ # Append instance # if action is 'stop'
+ if method.__name__ == 'stop':
+ cmd_local += " {}"
+ # Alter looping range if action is 'tigger_custom'
+ if method.__name__ == 'trigger_custom':
+ iter_range = [self.args.triggerstart, self.args.triggerend+1]
+ else:
+ iter_range = [self.args.count]
+ method(self)
+ for i in range(*iter_range):
+ self.logger.info(f'{action_string} {self.sim_dirname_pattern}{i} instance:')
+ self._run_cmd(cmd_local.format(i), f"{self.sim_dirname_pattern}{i}")
+ return action_wrap
+ return action_decorator
log_lvl = logging.INFO
@@ -195,22 +198,22 @@ class MassPnfSim():
self.logger.info('Cleaning simulators workdirs')
self._run_cmd(f"rm -rf {self.sim_dirname_pattern}*")
- @do_action('Starting', './simulator.sh start')
+ @_MassPnfSim_Decorators.do_action('Starting', './simulator.sh start')
def start(self):
pass
- @do_action('Getting', './simulator.sh status')
+ @_MassPnfSim_Decorators.do_action('Getting', './simulator.sh status')
def status(self):
pass
- @do_action('Stopping', './simulator.sh stop')
+ @_MassPnfSim_Decorators.do_action('Stopping', './simulator.sh stop')
def stop(self):
pass
- @do_action('Triggering', './simulator.sh trigger-simulator')
+ @_MassPnfSim_Decorators.do_action('Triggering', './simulator.sh trigger-simulator')
def trigger(self):
self.logger.info("Triggering VES sending:")
- @do_action('Triggering', './simulator.sh trigger-simulator')
+ @_MassPnfSim_Decorators.do_action('Triggering', './simulator.sh trigger-simulator')
def trigger_custom(self):
self.logger.info("Triggering VES sending by a range of simulators:")