aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2020-05-25 06:25:15 -0700
committerMorgan Richomme <morgan.richomme@orange.com>2020-05-25 14:06:11 +0000
commitf0190dd42eb489d83270d5f698d0ab037f513db7 (patch)
tree81a4c08ac660d072937d4fc327b54b66d983f710 /test/mocks/mass-pnf-sim
parentee15fa4d68876e79e809ba6e11341e81e41fc047 (diff)
Add functional tests for verifying simulator services status
Status is verified after each lifecycle change for proper subcommand action. Change-Id: Ia1c0e1bce24ddf1ca2c805a420e4a0665412aedf Issue-ID: INT-1577 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test/mocks/mass-pnf-sim')
-rw-r--r--test/mocks/mass-pnf-sim/conftest.py9
-rw-r--r--test/mocks/mass-pnf-sim/test_lifecycle.py26
-rw-r--r--test/mocks/mass-pnf-sim/test_settings.py1
-rw-r--r--test/mocks/mass-pnf-sim/tox.ini1
4 files changed, 36 insertions, 1 deletions
diff --git a/test/mocks/mass-pnf-sim/conftest.py b/test/mocks/mass-pnf-sim/conftest.py
index 3323440da..265813331 100644
--- a/test/mocks/mass-pnf-sim/conftest.py
+++ b/test/mocks/mass-pnf-sim/conftest.py
@@ -1,6 +1,7 @@
import MassPnfSim
import pytest
from test_settings import * # pylint: disable=W0614
+from docker import from_env
@pytest.fixture(scope="module")
def parser():
@@ -36,3 +37,11 @@ def args_trigger_custom(parser):
@pytest.fixture
def args_clean(parser):
return parser.parse_args(['clean'])
+
+@pytest.fixture
+def docker_containers():
+ docker_client = from_env()
+ container_list = []
+ for container in docker_client.containers.list():
+ container_list.append(container.attrs['Name'][1:])
+ return container_list
diff --git a/test/mocks/mass-pnf-sim/test_lifecycle.py b/test/mocks/mass-pnf-sim/test_lifecycle.py
index dc1160c75..581b022b3 100644
--- a/test/mocks/mass-pnf-sim/test_lifecycle.py
+++ b/test/mocks/mass-pnf-sim/test_lifecycle.py
@@ -60,6 +60,13 @@ def test_bootstrap(args_bootstrap, parser, caplog):
start_port += 2
print(yml['ippnfsim'])
+def test_bootstrap_status(args_status, capfd):
+ MassPnfSim(args_status).status()
+ msg = capfd.readouterr()
+ for _ in range(SIM_INSTANCES):
+ assert 'Simulator containers are down' in msg.out
+ assert 'Simulator response' not in msg.out
+
def test_start(args_start, caplog, capfd):
MassPnfSim(args_start).start()
msg = capfd.readouterr()
@@ -71,6 +78,15 @@ def test_start(args_start, caplog, capfd):
assert 'Starting simulator containers' in msg.out
caplog.clear()
+def test_start_status(args_status, docker_containers, capfd):
+ sleep(5) # Wait for the simulator to settle
+ MassPnfSim(args_status).status()
+ msg = capfd.readouterr()
+ for instance in range(SIM_INSTANCES):
+ assert '"simulatorStatus":"NOT RUNNING"' in msg.out
+ assert '"simulatorStatus":"RUNNING"' not in msg.out
+ assert f"{PNF_SIM_CONTAINER_NAME}{instance}" in docker_containers
+
def test_start_idempotence(args_start, capfd):
'''Verify start idempotence'''
MassPnfSim(args_start).start()
@@ -79,7 +95,6 @@ def test_start_idempotence(args_start, capfd):
assert 'Starting simulator containers' not in msg.out
def test_trigger(args_trigger, caplog, capfd):
- sleep(5) # Wait for the simulator to settle
MassPnfSim(args_trigger).trigger()
msg = capfd.readouterr()
for instance in range(SIM_INSTANCES):
@@ -90,6 +105,15 @@ def test_trigger(args_trigger, caplog, capfd):
assert 'Simulator started' in msg.out
caplog.clear()
+def test_trigger_status(args_status, capfd):
+ MassPnfSim(args_status).status()
+ msg = capfd.readouterr()
+ for _ in range(SIM_INSTANCES):
+ assert '"simulatorStatus":"RUNNING"' in msg.out
+ assert '"simulatorStatus":"NOT RUNNING"' not in msg.out
+ assert 'Up' in msg.out
+ assert 'Exit' not in msg.out
+
def test_trigger_idempotence(args_trigger, capfd):
MassPnfSim(args_trigger).trigger()
msg = capfd.readouterr()
diff --git a/test/mocks/mass-pnf-sim/test_settings.py b/test/mocks/mass-pnf-sim/test_settings.py
index 990a915ca..a16046ce4 100644
--- a/test/mocks/mass-pnf-sim/test_settings.py
+++ b/test/mocks/mass-pnf-sim/test_settings.py
@@ -4,3 +4,4 @@ IPFILESERVER = '127.0.0.1'
TYPEFILESERVER = 'sftp'
IPSTART = '10.11.0.1'
INSTANCE_CONFIG = 'config/config.yml'
+PNF_SIM_CONTAINER_NAME = 'pnf-simulator-'
diff --git a/test/mocks/mass-pnf-sim/tox.ini b/test/mocks/mass-pnf-sim/tox.ini
index aaa0d7a07..afa54589f 100644
--- a/test/mocks/mass-pnf-sim/tox.ini
+++ b/test/mocks/mass-pnf-sim/tox.ini
@@ -6,6 +6,7 @@ basepython = python3
deps =
pytest
pyyaml
+ docker
commands = pytest -v
[testenv:MassPnfSim-runtime]