From 937fe44cefb6a749ad39e2e332881b0cf32b7cf1 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Thu, 7 May 2020 04:28:13 -0700 Subject: Refactor simulator instances IP setting logic Change-Id: I5bd36b364cd033d0d468c81f345be9255e7adb85 Issue-ID: INT-1577 Signed-off-by: Bartek Grzybowski --- test/mocks/mass-pnf-sim/mass-pnf-sim.py | 68 +++++++++++++++++--------------- test/mocks/mass-pnf-sim/requirements.txt | 1 + 2 files changed, 38 insertions(+), 31 deletions(-) (limited to 'test/mocks/mass-pnf-sim') diff --git a/test/mocks/mass-pnf-sim/mass-pnf-sim.py b/test/mocks/mass-pnf-sim/mass-pnf-sim.py index a73057e3d..7358eb5c3 100755 --- a/test/mocks/mass-pnf-sim/mass-pnf-sim.py +++ b/test/mocks/mass-pnf-sim/mass-pnf-sim.py @@ -6,6 +6,7 @@ import ipaddress import time import logging from requests import get +from json import dumps from requests.exceptions import MissingSchema, InvalidSchema, InvalidURL, ConnectionError, ConnectTimeout def validate_url(url): @@ -60,7 +61,7 @@ logger = logging.getLogger(__name__) logger.setLevel(getattr(logging, args.verbose.upper())) if args.bootstrap and args.ipstart and args.urlves: - logger.info("Bootstrap:") + logger.info("Bootstrapping PNF instances") start_port = 2000 ftps_pasv_port_start = 8000 @@ -73,27 +74,27 @@ if args.bootstrap and args.ipstart and args.urlves: # The IP ranges are in distance of 16 compared to each other. # This is matching the /28 subnet mask used in the dockerfile inside. - ip_offset = i * 16 - - ip_subnet = args.ipstart + ip_offset - logger.debug(f"\tIp Subnet: {ip_subnet}") - - ip_gw = args.ipstart + 1 + ip_offset - logger.debug(f"\tIP Gateway: {ip_gw}") - - ip_PnfSim = args.ipstart + 2 + ip_offset - logger.debug(f"\tIp Pnf SIM: {ip_PnfSim}") + instance_ip_offset = i * 16 + ip_properties = [ + 'subnet', + 'gw', + 'PnfSim', + 'ftps', + 'sftp' + ] + + ip_offset = 0 + ip = {} + for prop in ip_properties: + ip.update({prop: str(args.ipstart + ip_offset + instance_ip_offset)}) + ip_offset += 1 + + logger.debug(f'Instance #{i} properties:\n {dumps(ip, indent=4)}') PortSftp = start_port + 1 PortFtps = start_port + 2 start_port += 2 - ip_ftps = args.ipstart + 3 + ip_offset - logger.debug(f"\tUrl Ftps: {ip_ftps}") - - ip_sftp = args.ipstart + 4 + ip_offset - logger.debug(f"\tUrl Sftp: {ip_sftp}") - foldername = f"pnf-sim-lw-{i}" completed = subprocess.run('mkdir ' + foldername, shell=True) logger.info(f'\tCreating folder: {completed.stdout}') @@ -103,20 +104,23 @@ if args.bootstrap and args.ipstart and args.urlves: shell=True) logger.info(f'\tCloning folder: {completed.stdout}') - composercmd = "./simulator.sh compose " + \ - str(ip_gw) + " " + \ - str(ip_subnet) + " " + \ - str(i) + " " + \ - args.urlves + " " + \ - str(ip_PnfSim) + " " + \ - str(args.ipfileserver) + " " + \ - args.typefileserver + " " + \ - str(PortSftp) + " " + \ - str(PortFtps) + " " + \ - str(ip_ftps) + " " + \ - str(ip_sftp) + " " + \ - str(ftps_pasv_port_start) + " " + \ - str(ftps_pasv_port_end) + composercmd = " ".join([ + "./simulator.sh compose", + ip['gw'], + ip['subnet'], + str(i), + args.urlves, + ip['PnfSim'], + str(args.ipfileserver), + args.typefileserver, + str(PortSftp), + str(PortFtps), + ip['ftps'], + ip['sftp'], + str(ftps_pasv_port_start), + str(ftps_pasv_port_end) + ]) + logger.debug(f"Script cmdline: {composercmd}") completed = subprocess.run( 'set -x; cd ' + @@ -129,6 +133,8 @@ if args.bootstrap and args.ipstart and args.urlves: ftps_pasv_port_start += ftps_pasv_port_num_of_ports + 1 ftps_pasv_port_end += ftps_pasv_port_num_of_ports + 1 + logger.info(f'Done setting up instance #{i}') + completed = subprocess.run('set -x; cd pnf-sim-lightweight; ./simulator.sh build ', shell=True) logger.info(f"Build docker image: {completed.stdout}") diff --git a/test/mocks/mass-pnf-sim/requirements.txt b/test/mocks/mass-pnf-sim/requirements.txt index 7e9b64bd9..60316e13f 100644 --- a/test/mocks/mass-pnf-sim/requirements.txt +++ b/test/mocks/mass-pnf-sim/requirements.txt @@ -1,3 +1,4 @@ argparse ipaddress requests +json -- cgit 1.2.3-korg