diff options
author | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-06-01 12:38:49 +0200 |
---|---|---|
committer | Morgan Richomme <morgan.richomme@orange.com> | 2020-06-02 15:13:29 +0000 |
commit | 572f644a9fb2bdfc897aa03774a030e828382d3f (patch) | |
tree | 53ed406da015b62719e4df480fc320c52b36a441 /test | |
parent | 110badf8a806ced0368d970fd96def9d790fb949 (diff) |
Drop shell wrapper for getting simulators status
Change-Id: Id7c3c614d472d8ee01533e9bd146f258813e7cbe
Issue-ID: INT-1606
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'test')
-rwxr-xr-x | test/mocks/mass-pnf-sim/MassPnfSim.py | 28 | ||||
-rw-r--r-- | test/mocks/mass-pnf-sim/test_lifecycle.py | 23 |
2 files changed, 37 insertions, 14 deletions
diff --git a/test/mocks/mass-pnf-sim/MassPnfSim.py b/test/mocks/mass-pnf-sim/MassPnfSim.py index f932c8286..d10686710 100755 --- a/test/mocks/mass-pnf-sim/MassPnfSim.py +++ b/test/mocks/mass-pnf-sim/MassPnfSim.py @@ -10,7 +10,7 @@ from json import dumps from yaml import load, SafeLoader from glob import glob from docker import from_env -from requests import get +from requests import get, codes from requests.exceptions import MissingSchema, InvalidSchema, InvalidURL, ConnectionError, ConnectTimeout def validate_url(url): @@ -107,6 +107,9 @@ class MassPnfSim: log_lvl = logging.INFO sim_config = 'config/config.yml' + sim_port = 5000 + sim_base_url = 'http://{}:' + str(sim_port) + '/simulator' + sim_container_name = 'pnf-simulator' def __init__(self, args): self.args = args @@ -114,6 +117,7 @@ class MassPnfSim: self.logger.setLevel(self.log_lvl) self.sim_dirname_pattern = "pnf-sim-lw-" self.mvn_build_cmd = 'mvn clean package docker:build -Dcheckstyle.skip' + self.docker_compose_status_cmd = 'docker-compose ps' self.existing_sim_instances = self._enum_sim_instances() # Validate 'trigger_custom' subcommand options @@ -250,9 +254,27 @@ class MassPnfSim: def start(self): pass - @_MassPnfSim_Decorators.do_action('Getting', './simulator.sh status') def status(self): - pass + if not self.args.count: + iter_range = [self.existing_sim_instances] + else: + iter_range = [self.args.count] + for i in range(*iter_range): + self.logger.info(f'Getting {self.sim_dirname_pattern}{i} instance status:') + if f"{self.sim_container_name}-{i}" in self._get_docker_containers(): + try: + sim_ip = self._get_sim_instance_data(i) + self.logger.info(f' PNF-Sim IP: {sim_ip}') + self._run_cmd(self.docker_compose_status_cmd, f"{self.sim_dirname_pattern}{i}") + sim_response = get('{}/status'.format(self.sim_base_url).format(sim_ip)) + if sim_response.status_code == codes.ok: + self.logger.info(sim_response.text) + else: + self.logger.error(f'Simulator request returned http code {sim_response.status_code}') + except KeyError: + self.logger.error(f'Unable to get sim instance IP from {self.sim_config}') + else: + self.logger.info(' Simulator containers are down') @_MassPnfSim_Decorators.do_action('Stopping', './simulator.sh stop') def stop(self): diff --git a/test/mocks/mass-pnf-sim/test_lifecycle.py b/test/mocks/mass-pnf-sim/test_lifecycle.py index 581b022b3..c61b72dd1 100644 --- a/test/mocks/mass-pnf-sim/test_lifecycle.py +++ b/test/mocks/mass-pnf-sim/test_lifecycle.py @@ -60,12 +60,12 @@ def test_bootstrap(args_bootstrap, parser, caplog): start_port += 2 print(yml['ippnfsim']) -def test_bootstrap_status(args_status, capfd): +def test_bootstrap_status(args_status, caplog): 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 + assert 'Simulator containers are down' in caplog.text + assert 'Simulator response' not in caplog.text + caplog.clear() def test_start(args_start, caplog, capfd): MassPnfSim(args_start).start() @@ -78,14 +78,14 @@ 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): +def test_start_status(args_status, docker_containers, caplog): 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 '"simulatorStatus":"NOT RUNNING"' in caplog.text + assert '"simulatorStatus":"RUNNING"' not in caplog.text assert f"{PNF_SIM_CONTAINER_NAME}{instance}" in docker_containers + caplog.clear() def test_start_idempotence(args_start, capfd): '''Verify start idempotence''' @@ -105,14 +105,15 @@ def test_trigger(args_trigger, caplog, capfd): assert 'Simulator started' in msg.out caplog.clear() -def test_trigger_status(args_status, capfd): +def test_trigger_status(args_status, capfd, caplog): 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 '"simulatorStatus":"RUNNING"' in caplog.text + assert '"simulatorStatus":"NOT RUNNING"' not in caplog.text assert 'Up' in msg.out assert 'Exit' not in msg.out + caplog.clear() def test_trigger_idempotence(args_trigger, capfd): MassPnfSim(args_trigger).trigger() |