diff options
author | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-05-07 04:28:13 -0700 |
---|---|---|
committer | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-05-08 06:50:13 +0000 |
commit | 937fe44cefb6a749ad39e2e332881b0cf32b7cf1 (patch) | |
tree | 2f1ad5566e4e32562f70403520a367bccf719700 /test/mocks/mass-pnf-sim/mass-pnf-sim.py | |
parent | c9514c7869532caafdcbaabdfb837d2cf30edab1 (diff) |
Refactor simulator instances IP setting logic
Change-Id: I5bd36b364cd033d0d468c81f345be9255e7adb85
Issue-ID: INT-1577
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks/mass-pnf-sim/mass-pnf-sim.py')
-rwxr-xr-x | test/mocks/mass-pnf-sim/mass-pnf-sim.py | 68 |
1 files changed, 37 insertions, 31 deletions
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}") |