diff options
author | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-05-25 01:06:25 -0700 |
---|---|---|
committer | Morgan Richomme <morgan.richomme@orange.com> | 2020-05-25 14:06:11 +0000 |
commit | 2b709a7ffb716cb44d31c784f8dc4a9254ebebaf (patch) | |
tree | fcec89c9a027926b84316ce567c0a9bddf910262 /test/mocks | |
parent | 59aef35ebd5f345336937588cea7ddd5e2ea8cc1 (diff) |
Add functional tests for bootstrap commands
Change-Id: Idb816780206f8b3b7a14128b7fd4603c4977ce11
Issue-ID: INT-1577
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks')
-rw-r--r-- | test/mocks/mass-pnf-sim/test_lifecycle.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/mocks/mass-pnf-sim/test_lifecycle.py b/test/mocks/mass-pnf-sim/test_lifecycle.py new file mode 100644 index 000000000..c3ef1ee6f --- /dev/null +++ b/test/mocks/mass-pnf-sim/test_lifecycle.py @@ -0,0 +1,60 @@ +from MassPnfSim import MassPnfSim +from glob import glob +from os import popen +from yaml import load, SafeLoader +from ipaddress import ip_address +from test_settings import * +import pytest + +# These test routines perform functional testing in current file tree context +# thus they require that no simulator instances are bootstrapped and running +# prior to running tests + +@pytest.mark.parametrize("action", ['start', 'stop', 'trigger', 'status']) +def test_not_bootstrapped(action, caplog, args_start, args_stop, args_trigger, args_status): # pylint: disable=W0613 + try: + m = getattr(MassPnfSim(eval(f'args_{action}')), action) + m() + except SystemExit as e: + assert e.code == 1 + assert 'No bootstrapped instance found' in caplog.text + caplog.clear() + +def test_bootstrap(args_bootstrap, parser, caplog): + # Initial bootstrap + MassPnfSim(args_bootstrap).bootstrap() + for instance in range(SIM_INSTANCES): + assert f'Creating pnf-sim-lw-{instance}' in caplog.text + assert f'Done setting up instance #{instance}' in caplog.text + caplog.clear() + + # Verify bootstrap idempotence + try: + MassPnfSim(args_bootstrap).bootstrap() + except SystemExit as e: + assert e.code == 1 + assert 'Bootstrapped instances detected, not overwiriting, clean first' in caplog.text + caplog.clear() + + # Verify simulator dirs created + sim_dirname_pattern = MassPnfSim(parser.parse_args([])).sim_dirname_pattern + assert len(glob(f"{sim_dirname_pattern}*")) == SIM_INSTANCES + + # Verify ROP_file_creator.sh running + for instance in range(SIM_INSTANCES): + assert f"ROP_file_creator.sh {instance}" in popen('ps afx').read() + + # Verify simulators configs content is valid + start_port = 2000 + for instance in range(SIM_INSTANCES): + instance_ip_offset = instance * 16 + ip_offset = 2 + with open(f"{sim_dirname_pattern}{instance}/{INSTANCE_CONFIG}") as f: + 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 str(ip_address(IPSTART) + ip_offset + instance_ip_offset) == yml['ippnfsim'] + start_port += 2 + print(yml['ippnfsim']) |