aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-06-16 16:39:44 +0200
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-06-16 16:46:59 +0200
commitcc01b3ae0b06fb12cb5a6fed672d50ca433598f5 (patch)
tree4d86211e81f95d5b6713e6317eccc380a7d7c730 /test/mocks
parent08d234170898e95096277e22b4dbbf82f576c915 (diff)
Support setting custom username/password for the file server service
Change-Id: I21964c4b8819444dd0aebdda117a11ba96f92038 Issue-ID: INT-1627 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks')
-rwxr-xr-xtest/mocks/mass-pnf-sim/MassPnfSim.py18
-rw-r--r--test/mocks/mass-pnf-sim/conftest.py3
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml8
-rwxr-xr-xtest/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms-template.sh2
-rwxr-xr-xtest/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms.sh2
-rw-r--r--test/mocks/mass-pnf-sim/test_cli.py3
-rw-r--r--test/mocks/mass-pnf-sim/test_lifecycle.py4
-rw-r--r--test/mocks/mass-pnf-sim/test_settings.py2
8 files changed, 28 insertions, 14 deletions
diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py
index 43e389420..4907755d5 100755
--- a/test/mocks/mass-pnf-sim/MassPnfSim.py
+++ b/test/mocks/mass-pnf-sim/MassPnfSim.py
@@ -4,7 +4,7 @@ from subprocess import run, CalledProcessError
import argparse
import ipaddress
from sys import exit
-from os import chdir, getcwd, path, popen, kill, getuid, stat, mkdir, getlogin
+from os import chdir, getcwd, path, popen, kill, getuid, stat, mkdir, getlogin, chmod
from shutil import copytree, rmtree, move
from json import loads, dumps
from yaml import load, SafeLoader, dump
@@ -50,6 +50,8 @@ def get_parser():
type=validate_ip, metavar='IP', required=True)
parser_bootstrap.add_argument('--typefileserver', help='Type of the file server (SFTP/FTPS) to be included in the VES event',
type=str, choices=['sftp', 'ftps'], required=True)
+ parser_bootstrap.add_argument('--user', help='File server username', type=str, metavar='USERNAME', required=True)
+ parser_bootstrap.add_argument('--password', help='File server password', type=str, metavar='PASSWORD', required=True)
parser_bootstrap.add_argument('--ipstart', help='IP address range beginning', type=validate_ip, metavar='IP', required=True)
# Start command parser
parser_start = subparsers.add_parser('start', help='Start instances')
@@ -85,6 +87,8 @@ class MassPnfSim:
sim_compose_template = 'docker-compose-template.yml'
sim_vsftpd_template = 'config/vsftpd_ssl-TEMPLATE.conf'
sim_vsftpd_config = 'config/vsftpd_ssl.conf'
+ sim_sftp_script = 'fix-sftp-perms.sh'
+ sim_sftp_script_template = 'fix-sftp-perms-template.sh'
sim_config = 'config/config.yml'
sim_msg_config = 'config/config.json'
sim_port = 5000
@@ -198,8 +202,8 @@ class MassPnfSim:
'''Writes a yaml formatted configuration file for Java simulator app'''
yml = {}
yml['urlves'] = self.args.urlves
- yml['urlsftp'] = f'sftp://onap:pano@{self.args.ipfileserver}:{port_sftp}'
- yml['urlftps'] = f'ftps://onap:pano@{self.args.ipfileserver}:{port_ftps}'
+ yml['urlsftp'] = f'sftp://{self.args.user}:{self.args.password}@{self.args.ipfileserver}:{port_sftp}'
+ yml['urlftps'] = f'ftps://{self.args.user}:{self.args.password}@{self.args.ipfileserver}:{port_ftps}'
yml['ippnfsim'] = pnf_sim_ip
yml['typefileserver'] = self.args.typefileserver
self.logger.debug(f'Generated simulator config:\n{dump(yml)}')
@@ -269,13 +273,19 @@ class MassPnfSim:
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])
+ TIMEZONE = tzname[daylight],
+ FILESERV_USER = self.args.user,
+ FILESERV_PASS = self.args.password)
# generate vsftpd config file for the simulator instance
self._generate_config_file(self.sim_vsftpd_template, self.sim_vsftpd_config,
I = i, USER = getlogin(),
FTPS_PASV_MIN = str(ftps_pasv_port_start),
FTPS_PASV_MAX = str(ftps_pasv_port_end),
IPFILESERVER = str(self.args.ipfileserver))
+ # generate sftp permission fix script
+ self._generate_config_file(self.sim_sftp_script_template, self.sim_sftp_script,
+ I = i, FILESERV_USER = self.args.user)
+ chmod(f'{self.sim_dirname_pattern}{i}/{self.sim_sftp_script}', 0o755)
# Run the 3GPP measurements file generator
self._run_cmd(f'./ROP_file_creator.sh {i} &', f"{self.sim_dirname_pattern}{i}")
diff --git a/test/mocks/mass-pnf-sim/conftest.py b/test/mocks/mass-pnf-sim/conftest.py
index 066581040..e6ee05667 100644
--- a/test/mocks/mass-pnf-sim/conftest.py
+++ b/test/mocks/mass-pnf-sim/conftest.py
@@ -12,7 +12,8 @@ def args_bootstrap(parser):
return parser.parse_args(['bootstrap', '--count', str(SIM_INSTANCES),
'--urlves', URLVES, '--ipfileserver', IPFILESERVER,
'--typefileserver', TYPEFILESERVER, '--ipstart',
- IPSTART])
+ IPSTART, '--user', FILESERVER_USER, '--password',
+ FILESERVER_PASSWORD])
@pytest.fixture(scope="module")
def args_start(parser):
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml
index 5a1bdacd4..8a59a1157 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml
@@ -34,10 +34,10 @@ services:
ports:
- "${PORTSFTP}:22"
volumes:
- - ./files/onap/:/home/onap/
+ - ./files/onap/:/home/${FILESERV_USER}/
- ./fix-sftp-perms.sh:/etc/sftp.d/fix-sftp-perms.sh
restart: on-failure
- command: onap:pano:1001
+ command: ${FILESERV_USER}:${FILESERV_PASS}:1001
ftpes-server-vsftpd-${I}:
container_name: ftpes-server-vsftpd-${I}
@@ -49,8 +49,8 @@ services:
- "${PORTFTPS}:21"
- "${FTPS_PASV_MIN}-${FTPS_PASV_MAX}:${FTPS_PASV_MIN}-${FTPS_PASV_MAX}"
environment:
- FTP_USER: onap
- FTP_PASSWORD: pano
+ FTP_USER: ${FILESERV_USER}
+ FTP_PASSWORD: ${FILESERV_PASS}
PASV_ADDRESS: localhost
PASV_MIN_PORT: ${FTPS_PASV_MIN}
PASV_MAX_PORT: ${FTPS_PASV_MAX}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms-template.sh b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms-template.sh
new file mode 100755
index 000000000..52e69b74c
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms-template.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+chmod o+w /home/${FILESERV_USER}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms.sh b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms.sh
deleted file mode 100755
index b9f4dae85..000000000
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/fix-sftp-perms.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-chmod o+w /home/onap
diff --git a/test/mocks/mass-pnf-sim/test_cli.py b/test/mocks/mass-pnf-sim/test_cli.py
index 3e4a60e45..70c9b6c4f 100644
--- a/test/mocks/mass-pnf-sim/test_cli.py
+++ b/test/mocks/mass-pnf-sim/test_cli.py
@@ -3,7 +3,8 @@ from MassPnfSim import MassPnfSim
from test_settings import SIM_INSTANCES
@pytest.mark.parametrize(('expect_string, cli_opts'), [
- ("bootstrap: error: the following arguments are required: --urlves, --ipfileserver, --typefileserver, --ipstart",
+ ("bootstrap: error: the following arguments are required: --urlves, --ipfileserver, --typefileserver, " +\
+ "--user, --password, --ipstart",
['bootstrap']),
("bootstrap: error: argument --typefileserver: invalid choice: 'dummy' (choose from 'sftp', 'ftps')",
['bootstrap', '--typefileserver', 'dummy']),
diff --git a/test/mocks/mass-pnf-sim/test_lifecycle.py b/test/mocks/mass-pnf-sim/test_lifecycle.py
index dcd89c440..d98ea48a9 100644
--- a/test/mocks/mass-pnf-sim/test_lifecycle.py
+++ b/test/mocks/mass-pnf-sim/test_lifecycle.py
@@ -54,8 +54,8 @@ def test_bootstrap(args_bootstrap, parser, caplog):
yml = load(f, Loader=SafeLoader)
assert URLVES == yml['urlves']
assert TYPEFILESERVER == yml['typefileserver']
- assert f'sftp://onap:pano@{IPFILESERVER}:{start_port + 1}' in yml['urlsftp']
- assert f'ftps://onap:pano@{IPFILESERVER}:{start_port + 2}' in yml['urlftps']
+ assert f'sftp://{FILESERVER_USER}:{FILESERVER_PASSWORD}@{IPFILESERVER}:{start_port + 1}' in yml['urlsftp']
+ assert f'ftps://{FILESERVER_USER}:{FILESERVER_PASSWORD}@{IPFILESERVER}:{start_port + 2}' in yml['urlftps']
assert str(ip_address(IPSTART) + ip_offset + instance_ip_offset) == yml['ippnfsim']
start_port += 2
print(yml['ippnfsim'])
diff --git a/test/mocks/mass-pnf-sim/test_settings.py b/test/mocks/mass-pnf-sim/test_settings.py
index a16046ce4..c8c235367 100644
--- a/test/mocks/mass-pnf-sim/test_settings.py
+++ b/test/mocks/mass-pnf-sim/test_settings.py
@@ -2,6 +2,8 @@ SIM_INSTANCES = 2
URLVES = 'http://127.0.0.1:10000/eventListener/v7'
IPFILESERVER = '127.0.0.1'
TYPEFILESERVER = 'sftp'
+FILESERVER_USER = 'testuser'
+FILESERVER_PASSWORD = 'testpassword'
IPSTART = '10.11.0.1'
INSTANCE_CONFIG = 'config/config.yml'
PNF_SIM_CONTAINER_NAME = 'pnf-simulator-'