diff options
author | 2020-06-17 12:28:45 +0200 | |
---|---|---|
committer | 2020-06-17 12:28:45 +0200 | |
commit | 90d6d7ff2abc2047d1b95fab651647d9f5ce4d9c (patch) | |
tree | 2bca9f1e8697787869087a14c4e046e9be1c1c86 /test/mocks/mass-pnf-sim | |
parent | 4d5f4e0c53b068fcdb1aff5aefb94a8c6a097bea (diff) |
Validate the subcommands on each instance method invocation
Change-Id: I22d6d6ef47ae99a7b2ad7f3e1407e0a49c48c953
Issue-ID: INT-1629
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks/mass-pnf-sim')
-rwxr-xr-x | test/mocks/mass-pnf-sim/MassPnfSim.py | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py index c7886d3d3..d6972d978 100755 --- a/test/mocks/mass-pnf-sim/MassPnfSim.py +++ b/test/mocks/mass-pnf-sim/MassPnfSim.py @@ -83,6 +83,33 @@ def get_parser(): class MassPnfSim: + # MassPnfSim class actions decorator + class _MassPnfSim_Decorators: + @staticmethod + def validate_subcommand(method): + def wrapper(self): + # Validate 'trigger_custom' subcommand options + if self.args.subcommand == 'trigger_custom': + if (self.args.triggerend + 1) > self._enum_sim_instances(): + self.logger.error('--triggerend value greater than existing instance count.') + exit(1) + + # Validate --count option for subcommands that support it + if self.args.subcommand in ['start', 'stop', 'trigger', 'status', 'stop_simulator']: + if self.args.count > self._enum_sim_instances(): + self.logger.error('--count value greater that existing instance count') + exit(1) + if not self._enum_sim_instances(): + self.logger.error('No bootstrapped instance found') + exit(1) + + # Validate 'bootstrap' subcommand + if (self.args.subcommand == 'bootstrap') and self._enum_sim_instances(): + self.logger.error('Bootstrapped instances detected, not overwiriting, clean first') + exit(1) + method(self) + return wrapper + log_lvl = logging.INFO sim_compose_template = 'docker-compose-template.yml' sim_vsftpd_template = 'config/vsftpd_ssl-TEMPLATE.conf' @@ -107,26 +134,6 @@ class MassPnfSim: self.mvn_build_cmd = 'mvn clean package docker:build -Dcheckstyle.skip' self.docker_compose_status_cmd = 'docker-compose ps' - # Validate 'trigger_custom' subcommand options - if self.args.subcommand == 'trigger_custom': - if (self.args.triggerend + 1) > self._enum_sim_instances(): - self.logger.error('--triggerend value greater than existing instance count.') - exit(1) - - # Validate --count option for subcommands that support it - if self.args.subcommand in ['start', 'stop', 'trigger', 'status', 'stop_simulator']: - if self.args.count > self._enum_sim_instances(): - self.logger.error('--count value greater that existing instance count') - exit(1) - if not self._enum_sim_instances(): - self.logger.error('No bootstrapped instance found') - exit(1) - - # Validate 'bootstrap' subcommand - if (self.args.subcommand == 'bootstrap') and self._enum_sim_instances(): - self.logger.error('Bootstrapped instances detected, not overwiriting, clean first') - exit(1) - def _run_cmd(self, cmd, dir_context='.'): old_pwd = getcwd() try: @@ -224,6 +231,7 @@ class MassPnfSim: f.write(template) chdir(old_pwd) + @_MassPnfSim_Decorators.validate_subcommand def bootstrap(self): self.logger.info("Bootstrapping PNF instances") @@ -311,6 +319,7 @@ class MassPnfSim: for sim_id in range(self._enum_sim_instances()): rmtree(f"{self.sim_dirname_pattern}{sim_id}") + @_MassPnfSim_Decorators.validate_subcommand def start(self): for i in range(*self._get_iter_range()): # If container is not running @@ -324,6 +333,7 @@ class MassPnfSim: else: self.logger.warning(f'Instance {self.sim_dirname_pattern}{i} containers are already up') + @_MassPnfSim_Decorators.validate_subcommand def status(self): for i in range(*self._get_iter_range()): self.logger.info(f'Getting {self.sim_dirname_pattern}{i} instance status:') @@ -342,6 +352,7 @@ class MassPnfSim: else: self.logger.info(' Simulator containers are down') + @_MassPnfSim_Decorators.validate_subcommand def stop(self): for i in range(*self._get_iter_range()): self.logger.info(f'Stopping {self.sim_dirname_pattern}{i} instance:') @@ -373,6 +384,7 @@ class MassPnfSim: else: self.logger.warning(" Simulator containers are already down") + @_MassPnfSim_Decorators.validate_subcommand def trigger(self): self.logger.info("Triggering VES sending:") for i in range(*self._get_iter_range()): @@ -403,6 +415,7 @@ class MassPnfSim: # Make the 'trigger_custom' an alias to the 'trigger' method trigger_custom = trigger + @_MassPnfSim_Decorators.validate_subcommand def stop_simulator(self): self.logger.info("Stopping sending PNF registration messages:") for i in range(*self._get_iter_range()): |