1 from MassPnfSim import MassPnfSim
4 from yaml import load, SafeLoader
5 from ipaddress import ip_address
6 from test_settings import *
10 # These test routines perform functional testing in current file tree context
11 # thus they require that no simulator instances are bootstrapped and running
12 # prior to running tests
14 @pytest.mark.parametrize("action", ['start', 'stop', 'trigger', 'status'])
15 def test_not_bootstrapped(action, caplog, args_start, args_stop, args_trigger, args_status): # pylint: disable=W0613
17 m = getattr(MassPnfSim(eval(f'args_{action}')), action)
19 except SystemExit as e:
21 assert 'No bootstrapped instance found' in caplog.text
24 def test_bootstrap(args_bootstrap, parser, caplog):
26 MassPnfSim(args_bootstrap).bootstrap()
27 for instance in range(SIM_INSTANCES):
28 assert f'Creating pnf-sim-lw-{instance}' in caplog.text
29 assert f'Done setting up instance #{instance}' in caplog.text
32 # Verify bootstrap idempotence
34 MassPnfSim(args_bootstrap).bootstrap()
35 except SystemExit as e:
37 assert 'Bootstrapped instances detected, not overwiriting, clean first' in caplog.text
40 # Verify simulator dirs created
41 sim_dirname_pattern = MassPnfSim(parser.parse_args([])).sim_dirname_pattern
42 assert len(glob(f"{sim_dirname_pattern}*")) == SIM_INSTANCES
44 # Verify ROP_file_creator.sh running
45 for instance in range(SIM_INSTANCES):
46 assert f"ROP_file_creator.sh {instance}" in popen('ps afx').read()
48 # Verify simulators configs content is valid
50 for instance in range(SIM_INSTANCES):
51 instance_ip_offset = instance * 16
53 with open(f"{sim_dirname_pattern}{instance}/{INSTANCE_CONFIG}") as f:
54 yml = load(f, Loader=SafeLoader)
55 assert URLVES == yml['urlves']
56 assert TYPEFILESERVER == yml['typefileserver']
57 assert f'sftp://onap:pano@{IPFILESERVER}:{start_port + 1}' in yml['urlsftp']
58 assert f'ftps://onap:pano@{IPFILESERVER}:{start_port + 2}' in yml['urlftps']
59 assert str(ip_address(IPSTART) + ip_offset + instance_ip_offset) == yml['ippnfsim']
61 print(yml['ippnfsim'])
63 def test_start(args_start, caplog, capfd):
64 MassPnfSim(args_start).start()
65 msg = capfd.readouterr()
66 for instance in range(SIM_INSTANCES):
67 instance_ip_offset = instance * 16
69 assert f'Starting pnf-sim-lw-{instance} instance:' in caplog.text
70 assert f'PNF-Sim IP: {str(ip_address(IPSTART) + ip_offset + instance_ip_offset)}' in msg.out
71 assert 'Starting simulator containers' in msg.out
74 def test_start_idempotence(args_start, capfd):
75 '''Verify start idempotence'''
76 MassPnfSim(args_start).start()
77 msg = capfd.readouterr()
78 assert 'Simulator containers are already up' in msg.out
79 assert 'Starting simulator containers' not in msg.out
81 def test_trigger(args_trigger, caplog, capfd):
82 sleep(5) # Wait for the simulator to settle
83 MassPnfSim(args_trigger).trigger()
84 msg = capfd.readouterr()
85 for instance in range(SIM_INSTANCES):
86 instance_ip_offset = instance * 16
88 assert f'Triggering pnf-sim-lw-{instance} instance:' in caplog.text
89 assert f'PNF-Sim IP: {str(ip_address(IPSTART) + ip_offset + instance_ip_offset)}' in msg.out
90 assert 'Simulator started' in msg.out
92 def test_trigger_idempotence(args_trigger, capfd):
93 MassPnfSim(args_trigger).trigger()
94 msg = capfd.readouterr()
95 assert "Cannot start simulator since it's already running" in msg.out
96 assert 'Simulator started' not in msg.out