diff --git a/test/telegraf-agents/test_rspec.py b/test/telegraf-agents/test_rspec.py index 7a7c7ee441210077edbd4d455427ce0d47e152a1..5442eed2d366f64c32e8896f87de02f662e21dae 100644 --- a/test/telegraf-agents/test_rspec.py +++ b/test/telegraf-agents/test_rspec.py @@ -11,7 +11,7 @@ import pytest 'nginx', 'mongo', 'ffmpeg', - 'ipendpoint' + 'host' ]) def test_service_name(telegraf_agent_config, service_name): """ diff --git a/test/telegraf-agents/test_telegraf_agents.py b/test/telegraf-agents/test_telegraf_agents.py index b55f46a515940c7d6ab109fb7ea4caba7f0ff3ee..b2e8ce59e229dc1862f200e833e946c6c6272d2e 100644 --- a/test/telegraf-agents/test_telegraf_agents.py +++ b/test/telegraf-agents/test_telegraf_agents.py @@ -1,6 +1,8 @@ #!/usr/bin/python3 import pytest +from subprocess import run +from platform import system from influxdb import InfluxDBClient @pytest.mark.parametrize("service_name", [ @@ -15,10 +17,22 @@ def test_service_name(telegraf_agent_config, service_name): assert any(s['name'] == service_name for s in telegraf_agent_config['hosts']), "{0} not in list of hosts".format(service_name) def test_ping(telegraf_agent_config): - """This test will only run on linux as the process call is not portable, there's a better way""" - for host in telegraf_agent_config['hosts']: - response = os.system("ping -c 1 " + host['ip_address']) - assert response == 0, "Could not ping {0} on ip address {1}".format(host['name'], host['ip_address']) + """ + 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 telegraf_agent_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'])) + @pytest.mark.parametrize("measurement, query, expected_result", [ ('nginx', 'SELECT mean("requests") AS "mean" FROM "CLMCMetrics"."autogen"."nginx"', 0),