aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/MassPnfSim.py
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-05-14 07:38:54 -0700
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-05-15 06:42:14 -0700
commitbe79e4d2c5e9acacead38c264d356d4c82234342 (patch)
tree1cde25e2738438224b0d557a1a42b115a49b9879 /test/mocks/mass-pnf-sim/MassPnfSim.py
parentb61465f0662d183442eafe7bfed2f1d1061f2c09 (diff)
Leverage internal shell runner in bootstrap mode
Use native python modules for file operations Change-Id: I1ca505f9a891c722c2aace118536fa470bf50b35 Issue-ID: INT-1577 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.py25
1 files changed, 9 insertions, 16 deletions
diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py
index f782b22fb..980be1535 100755
--- a/test/mocks/mass-pnf-sim/MassPnfSim.py
+++ b/test/mocks/mass-pnf-sim/MassPnfSim.py
@@ -6,6 +6,7 @@ import argparse
import ipaddress
from sys import exit
from os import chdir, getcwd
+from shutil import copytree
from json import dumps
from requests import get
from requests.exceptions import MissingSchema, InvalidSchema, InvalidURL, ConnectionError, ConnectTimeout
@@ -130,14 +131,12 @@ class MassPnfSim():
PortFtps = start_port + 2
start_port += 2
- foldername = f"pnf-sim-lw-{i}"
- completed = subprocess.run('mkdir ' + foldername, shell=True)
- self.logger.info(f'\tCreating folder: {completed.stdout}')
- completed = subprocess.run(
- 'cp -r pnf-sim-lightweight/* ' +
- foldername,
- shell=True)
- self.logger.info(f'\tCloning folder: {completed.stdout}')
+ 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)
composercmd = " ".join([
"./simulator.sh compose",
@@ -156,14 +155,8 @@ class MassPnfSim():
str(ftps_pasv_port_end)
])
self.logger.debug(f"Script cmdline: {composercmd}")
-
- completed = subprocess.run(
- 'set -x; cd ' +
- foldername +
- '; ' +
- composercmd,
- shell=True)
- self.logger.info(f'Cloning: {completed.stdout}')
+ self.logger.info(f"\tCreating instance #{i} configuration ")
+ self._run_cmd(composercmd, f"{self.sim_dirname_pattern}{i}")
ftps_pasv_port_start += ftps_pasv_port_num_of_ports + 1
ftps_pasv_port_end += ftps_pasv_port_num_of_ports + 1