aboutsummaryrefslogtreecommitdiffstats
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
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>
-rwxr-xr-xtest/mocks/mass-pnf-sim/MassPnfSim.py25
-rwxr-xr-xtest/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh6
-rw-r--r--test/mocks/mass-pnf-sim/requirements.txt1
3 files changed, 13 insertions, 19 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
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh
index 3b229e167..50ef3214d 100755
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh
@@ -91,9 +91,9 @@ function compose(){
write_config $URLVES $IPFILESERVER $TYPEFILESERVER $PORTSFTP $PORTFTPS $IPPNFSIM
- cd config
- envsubst < vsftpd_ssl-TEMPLATE.conf > vsftpd_ssl.conf
- cd -
+ pushd config
+ envsubst < vsftpd_ssl-TEMPLATE.conf > vsftpd_ssl.conf
+ popd
}
function build_image(){
diff --git a/test/mocks/mass-pnf-sim/requirements.txt b/test/mocks/mass-pnf-sim/requirements.txt
index 60316e13f..27dd31c35 100644
--- a/test/mocks/mass-pnf-sim/requirements.txt
+++ b/test/mocks/mass-pnf-sim/requirements.txt
@@ -2,3 +2,4 @@ argparse
ipaddress
requests
json
+shutil