Skip to content
Snippets Groups Projects
test_rspec.py 2.31 KiB
#!/usr/bin/python3
"""
## © University of Southampton IT Innovation Centre, 2018
##
## Copyright in this software belongs to University of Southampton
## IT Innovation Centre of Gamma House, Enterprise Road, 
## Chilworth Science Park, Southampton, SO16 7NS, UK.
##
## This software may not be used, sold, licensed, transferred, copied
## or reproduced in whole or in part in any manner or form or in or
## on any media by any person other than in accordance with the terms
## of the Licence Agreement supplied with the software, or otherwise
## without the prior written consent of the copyright owners.
##
## This software is distributed WITHOUT ANY WARRANTY, without even the
## implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE, except where stated in the Licence Agreement supplied with
## the software.
##
##      Created By :            Michael Boniface
##      Created Date :          25-02-2018
##      Created for Project :   FLAME
"""

from subprocess import run
from platform import system
import pytest


@pytest.mark.parametrize("service_name", [
    'clmc-service',
    'ipendpoint1',
    'ipendpoint2'
])
def test_service_names(streaming_sim_config, service_name):
    """
    Tests the service names in the configuration.

    :param streaming_sim_config: the configuration fixture collected from conftest.py
    :param service_name the service name to test
    """

    assert any(s['name'] == service_name for s in streaming_sim_config['hosts']), "{0} not in list of hosts".format(service_name)
    print("\nSuccessfully passed configuration test for service name {0}\n".format(service_name))


def test_ping(streaming_sim_config):
    """
    Pings each service to test for liveliness

    :param streaming_sim_config: the configuration fixture collected from conftest.py
    """

    print("\n")  # blank line printed for formatting purposes

    ping_count = 1
    system_dependent_param = "-n" if system().lower() == "windows" else "-c"

    for service in streaming_sim_config['hosts']:
        command = ["ping", system_dependent_param, str(ping_count), service['ip_address']]
        assert run(command).returncode == 0, "Service ping test failed for {0} with ip address {1}".format(service['name'], service['ip_address'])
        print("\nSuccessfully passed ping test for service: {0}\n".format(service['name']))