aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/mocks/mass-pnf-sim/MassPnfSim.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py
index fbeec1dde..9801d8e74 100755
--- a/test/mocks/mass-pnf-sim/MassPnfSim.py
+++ b/test/mocks/mass-pnf-sim/MassPnfSim.py
@@ -204,19 +204,18 @@ class MassPnfSim:
with open(f'{self.sim_dirname_pattern}{i}/{self.sim_config}', 'w') as fout:
fout.write(dump(yml))
- def _generate_docker_compose_file(self, **kwargs):
- '''Helper private method to generate the Docker Compose file
- for a given simulator instance'''
+ def _generate_config_file(self, source, dest, **kwargs):
+ '''Helper private method to generate a file based on a template'''
old_pwd = getcwd()
chdir(self.sim_dirname_pattern + str(kwargs['I']))
- # Read the docker compose template file
- with open(self.sim_compose_template, 'r') as f:
+ # Read the template file
+ with open(source, 'r') as f:
template = f.read()
# Replace all occurences of env like variable with it's
# relevant value from a corresponding key form kwargs
for (k,v) in kwargs.items():
template = template.replace('${' + k + '}', str(v))
- with open('docker-compose.yml', 'w') as f:
+ with open(dest, 'w') as f:
f.write(template)
chdir(old_pwd)
@@ -278,14 +277,16 @@ class MassPnfSim:
self.logger.info(f"\tCreating instance #{i} configuration ")
self._run_cmd(composercmd, f"{self.sim_dirname_pattern}{i}")
self._generate_pnf_sim_config(i, PortSftp, PortFtps, ip['PnfSim'])
- self._generate_docker_compose_file(IPGW = ip['gw'], IPSUBNET = ip['subnet'],
- I = i, IPPNFSIM = ip['PnfSim'],
- PORTSFTP = str(PortSftp),
- PORTFTPS = str(PortFtps),
- IPFTPS = ip['ftps'], IPSFTP = ip['sftp'],
- FTPS_PASV_MIN = str(ftps_pasv_port_start),
- FTPS_PASV_MAX = str(ftps_pasv_port_end),
- TIMEZONE = tzname[daylight])
+ # generate docker-compose for the simulator instance
+ self._generate_config_file(self.sim_compose_template, 'docker-compose.yml',
+ IPGW = ip['gw'], IPSUBNET = ip['subnet'],
+ I = i, IPPNFSIM = ip['PnfSim'],
+ PORTSFTP = str(PortSftp),
+ PORTFTPS = str(PortFtps),
+ IPFTPS = ip['ftps'], IPSFTP = ip['sftp'],
+ FTPS_PASV_MIN = str(ftps_pasv_port_start),
+ FTPS_PASV_MAX = str(ftps_pasv_port_end),
+ TIMEZONE = tzname[daylight])
ftps_pasv_port_start += ftps_pasv_port_num_of_ports + 1
ftps_pasv_port_end += ftps_pasv_port_num_of_ports + 1