From 5717b5ee81cedfb3c1361cad6683cf585c90ae31 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Tue, 19 May 2020 04:50:51 -0700 Subject: Iterate over all bootstrapped instances by default Commands that support '--count' option now iterate over all autodetected bootstrapped simulator instances by default, not just the first one. Change-Id: Ia5703047447b4da98d775636fe38911f81520848 Issue-ID: INT-1577 Signed-off-by: Bartek Grzybowski --- test/mocks/mass-pnf-sim/MassPnfSim.py | 41 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py index 2bbb1aa1e..dde622ac9 100755 --- a/test/mocks/mass-pnf-sim/MassPnfSim.py +++ b/test/mocks/mass-pnf-sim/MassPnfSim.py @@ -50,13 +50,13 @@ def get_parser(): parser_bootstrap.add_argument('--ipstart', help='IP address range beginning', type=validate_ip, metavar='IP', required=True) # Start command parser parser_start = subparsers.add_parser('start', help='Start instances') - parser_start.add_argument('--count', help='Instance count to start', type=int, metavar='INT', default=1) + parser_start.add_argument('--count', help='Instance count to start', type=int, metavar='INT', default=0) # Stop command parser parser_stop = subparsers.add_parser('stop', help='Stop instances') - parser_stop.add_argument('--count', help='Instance count to stop', type=int, metavar='INT', default=1) + parser_stop.add_argument('--count', help='Instance count to stop', type=int, metavar='INT', default=0) # Trigger command 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) + parser_trigger.add_argument('--count', help='Instance count to trigger', type=int, metavar='INT', default=0) # Trigger-custom command parser 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, @@ -65,7 +65,7 @@ def get_parser(): metavar='INT', required=True) # Status command parser parser_status = subparsers.add_parser('status', help='Status') - parser_status.add_argument('--count', help='Instance count to show status for', type=int, metavar='INT', default=1) + parser_status.add_argument('--count', help='Instance count to show status for', type=int, metavar='INT', default=0) # Clean command parser subparsers.add_parser('clean', help='Clean work-dirs') # General options parser @@ -90,7 +90,12 @@ class MassPnfSim: if method.__name__ == 'trigger_custom': iter_range = [self.args.triggerstart, self.args.triggerend+1] else: - iter_range = [self.args.count] + if not self.args.count: + # If no instance count set explicitly via --count + # option + iter_range = [self.existing_sim_instances] + 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:') @@ -108,6 +113,26 @@ class MassPnfSim: self.mvn_build_cmd = 'mvn clean package docker:build -Dcheckstyle.skip' self.existing_sim_instances = self._enum_sim_instances() + # Validate 'trigger_custom' subcommand options + if self.args.subcommand == 'trigger_custom': + if (self.args.triggerend + 1) > self.existing_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']: + if self.args.count > self.existing_sim_instances: + self.logger.error('--count value greater that existing instance count') + exit(1) + if not self.existing_sim_instances: + self.logger.error('No bootstrapped instance found') + exit(1) + + # Validate 'bootstrap' subcommand + if (self.args.subcommand == 'bootstrap') and self.existing_sim_instances: + self.logger.error('Bootstrapped instances detected, not overwiriting, clean first') + exit(1) + def _run_cmd(self, cmd, dir_context='.'): if self.args.verbose == 'debug': cmd='bash -x ' + cmd @@ -161,11 +186,7 @@ class MassPnfSim: start_port += 2 self.logger.info(f'\tCreating {self.sim_dirname_pattern}{i}') - try: - copytree('pnf-sim-lightweight', f'{self.sim_dirname_pattern}{i}') - except FileExistsError: - self.logger.error(f'Directory {self.sim_dirname_pattern}{i} already exists, cannot overwrite.') - exit(1) + copytree('pnf-sim-lightweight', f'{self.sim_dirname_pattern}{i}') composercmd = " ".join([ "./simulator.sh compose", -- cgit 1.2.3-korg