aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/MassPnfSim.py
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-06-12 10:45:42 +0200
committerMorgan Richomme <morgan.richomme@orange.com>2020-06-15 14:09:30 +0000
commite2f20d07585afd9e1826ecdb48590553e7e4566f (patch)
tree05177f717df2e70b722f3fd22223fcedcf160675 /test/mocks/mass-pnf-sim/MassPnfSim.py
parent3561d299559bc3d808eb708f2f2b05937b35c9e4 (diff)
Make the config generation private method more generic
Change-Id: I2a0b9ef8eb304cfd088cd3a7dc4c61aaf54504c4 Issue-ID: INT-1621 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks/mass-pnf-sim/MassPnfSim.py')
-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