Integration test: update host + metrics name
Change-Id: I2f369300562882f3db880241cb6463b8fbe6c9ea
This commit is contained in:
parent
1cb311b96a
commit
78f8e4e6e2
@ -12,3 +12,4 @@ influxdb==2.6.0
|
|||||||
pika
|
pika
|
||||||
python-surveilclient==0.10.0
|
python-surveilclient==0.10.0
|
||||||
six
|
six
|
||||||
|
docker-py
|
||||||
|
@ -18,6 +18,7 @@ import time
|
|||||||
from compose.cli import docker_client
|
from compose.cli import docker_client
|
||||||
from compose import config as compose_config
|
from compose import config as compose_config
|
||||||
from compose import project as compose_project
|
from compose import project as compose_project
|
||||||
|
import docker
|
||||||
from surveilclient import client as sclient
|
from surveilclient import client as sclient
|
||||||
|
|
||||||
|
|
||||||
@ -83,6 +84,19 @@ class DockerBackend():
|
|||||||
else:
|
else:
|
||||||
raise Exception("Surveil could not start")
|
raise Exception("Surveil could not start")
|
||||||
|
|
||||||
|
def execute_command(self, commands, container_name):
|
||||||
|
dclient = docker.Client()
|
||||||
|
if container_name is not None:
|
||||||
|
containers = dclient.containers()
|
||||||
|
for container in containers:
|
||||||
|
count = container.get('Image').count(container_name)
|
||||||
|
if ((count == 1 and container_name != 'surveil') or
|
||||||
|
(count == 2 and container_name == 'surveil')):
|
||||||
|
for command in commands:
|
||||||
|
id = dclient.exec_create(container.get('Id')[:12],
|
||||||
|
command)
|
||||||
|
dclient.exec_start(id['Id'])
|
||||||
|
|
||||||
def tearDownClass(self):
|
def tearDownClass(self):
|
||||||
self.project.kill()
|
self.project.kill()
|
||||||
self.project.remove_stopped()
|
self.project.remove_stopped()
|
@ -5,7 +5,7 @@ surveil:
|
|||||||
- influxdb
|
- influxdb
|
||||||
- alignak
|
- alignak
|
||||||
ports:
|
ports:
|
||||||
- "8999:8080"
|
- "8999:5311"
|
||||||
command: bash -c "cd /opt/surveil && ./setup.sh && /opt/surveil/env/bin/python setup.py develop && ((sleep 40 && surveil-init --influxdb --packs --mongodb --demo) &) && sleep 20 && surveil-api --reload"
|
command: bash -c "cd /opt/surveil && ./setup.sh && /opt/surveil/env/bin/python setup.py develop && ((sleep 40 && surveil-init --influxdb --packs --mongodb --demo) &) && sleep 20 && surveil-api --reload"
|
||||||
|
|
||||||
alignak:
|
alignak:
|
||||||
|
@ -18,7 +18,7 @@ import os
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from surveil.tests import base
|
from surveil.tests import base
|
||||||
from surveil.tests.integration.backend import docker
|
from surveil.tests.integration.backend import docker_backend
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(os.environ.get('SURVEIL_INTEGRATION_TESTS', None) != 'True',
|
@unittest.skipIf(os.environ.get('SURVEIL_INTEGRATION_TESTS', None) != 'True',
|
||||||
@ -33,7 +33,7 @@ class MergedIntegrationTest(base.BaseTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if test_backend == 'DOCKER':
|
if test_backend == 'DOCKER':
|
||||||
MergedIntegrationTest.backend = docker.DockerBackend()
|
MergedIntegrationTest.backend = docker_backend.DockerBackend()
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Could not identify tests backend: '%s'" % test_backend
|
"Could not identify tests backend: '%s'" % test_backend
|
||||||
@ -47,6 +47,9 @@ class MergedIntegrationTest(base.BaseTestCase):
|
|||||||
def get_surveil_client(self):
|
def get_surveil_client(self):
|
||||||
return MergedIntegrationTest.backend.get_surveil_client()
|
return MergedIntegrationTest.backend.get_surveil_client()
|
||||||
|
|
||||||
|
def execute_command(self, command, container):
|
||||||
|
MergedIntegrationTest.backend.execute_command(command, container)
|
||||||
|
|
||||||
|
|
||||||
class SeparatedIntegrationTests(MergedIntegrationTest):
|
class SeparatedIntegrationTests(MergedIntegrationTest):
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ class TestSeparatedIntegrationSurveil(
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_delete_host(self):
|
def test_delete_host(self):
|
||||||
|
"""Delete a host and asserts that is is not monitored by Alignak."""
|
||||||
self.test_create_host()
|
self.test_create_host()
|
||||||
|
|
||||||
self.get_surveil_client().config.hosts.delete(
|
self.get_surveil_client().config.hosts.delete(
|
||||||
@ -90,16 +91,41 @@ class TestSeparatedIntegrationSurveil(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_passive_check(self):
|
def test_update_host(self):
|
||||||
self.get_surveil_client().config.hosts.create(
|
"""Update a host and asserts that is is monitored by Alignak."""
|
||||||
|
self.test_create_host()
|
||||||
|
|
||||||
|
self.get_surveil_client().config.hosts.update(
|
||||||
host_name='integrationhosttest',
|
host_name='integrationhosttest',
|
||||||
address='127.0.0.1',
|
host={'host_name': 'host_name_up',
|
||||||
use='generic-host',
|
'address': '127.0.1.1'}
|
||||||
)
|
)
|
||||||
self.get_surveil_client().config.commands.create(
|
|
||||||
command_name='check_integrationhosttest',
|
self.get_surveil_client().config.reload_config()
|
||||||
command_line='/usr/lib/monitoring/plugins/sfl/check_example'
|
|
||||||
|
def function():
|
||||||
|
status_host = (self.get_surveil_client().
|
||||||
|
config.hosts.get(host_name='host_name_up'))
|
||||||
|
self.assertTrue(
|
||||||
|
status_host['host_name'].decode() == 'host_name_up' and
|
||||||
|
status_host['address'].decode() == '127.0.1.1' and
|
||||||
|
status_host['use'].decode() == 'generic-host'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
self.try_for_x_seconds(
|
||||||
|
function,
|
||||||
|
time_to_wait=180,
|
||||||
|
cooldown=10,
|
||||||
|
exception=AssertionError,
|
||||||
|
message="Host is not updated."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_passive_check(self):
|
||||||
|
"""Test monitoring a host with passive checks."""
|
||||||
|
self.test_create_host()
|
||||||
|
|
||||||
self.get_surveil_client().config.services.create(
|
self.get_surveil_client().config.services.create(
|
||||||
check_command="check_integrationhosttest",
|
check_command="check_integrationhosttest",
|
||||||
check_interval="5",
|
check_interval="5",
|
||||||
@ -145,14 +171,24 @@ class TestSeparatedIntegrationSurveil(
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_custom_plugins(self):
|
def test_custom_plugins(self):
|
||||||
self.get_surveil_client().config.hosts.create(
|
"""Test documentation tutorial monitoring with your custom plugins."""
|
||||||
host_name='integrationhosttest',
|
commands = [
|
||||||
address='127.0.0.1',
|
"mkdir /usr/lib/monitoring/plugins/custom/",
|
||||||
use='generic-host',
|
"echo -e '#!/bin/bash\necho " +
|
||||||
)
|
"DISK $1 OK - free space: / 3326 MB (56%);"
|
||||||
|
" | /=2643MB;5948;5958;0;5968" +
|
||||||
|
"' | sudo tee /usr/lib/monitoring/plugins/"
|
||||||
|
"custom/check_example",
|
||||||
|
'chmod +x /usr/lib/monitoring/plugins/custom/'
|
||||||
|
'check_example'
|
||||||
|
]
|
||||||
|
|
||||||
|
self.execute_command(commands, 'alignak')
|
||||||
|
|
||||||
|
self.test_create_host()
|
||||||
self.get_surveil_client().config.commands.create(
|
self.get_surveil_client().config.commands.create(
|
||||||
command_name='check_integrationhosttest',
|
command_name='check_integrationhosttest',
|
||||||
command_line='/usr/lib/monitoring/plugins/sfl/check_example'
|
command_line='$CUSTOMPLUGINSDIR$/check_example $HOSTADDRESS$'
|
||||||
)
|
)
|
||||||
self.get_surveil_client().config.services.create(
|
self.get_surveil_client().config.services.create(
|
||||||
check_command="check_integrationhosttest",
|
check_command="check_integrationhosttest",
|
||||||
@ -165,8 +201,7 @@ class TestSeparatedIntegrationSurveil(
|
|||||||
notification_interval="30",
|
notification_interval="30",
|
||||||
notification_period="24x7",
|
notification_period="24x7",
|
||||||
retry_interval="3",
|
retry_interval="3",
|
||||||
service_description="check_integrationhosttest",
|
service_description="check_integrationhosttest"
|
||||||
passive_checks_enabled="1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.get_surveil_client().config.reload_config()
|
self.get_surveil_client().config.reload_config()
|
||||||
@ -178,8 +213,8 @@ class TestSeparatedIntegrationSurveil(
|
|||||||
service['service_description'].decode() ==
|
service['service_description'].decode() ==
|
||||||
'check_integrationhosttest' and
|
'check_integrationhosttest' and
|
||||||
service['plugin_output'].decode() ==
|
service['plugin_output'].decode() ==
|
||||||
"DISK OK - free space: / 3326 MB (56%);"
|
"DISK 127.0.1.1 OK - free space: / 3326 MB (56%);"
|
||||||
" | /=2643MB;5948;5958;0;5968"
|
"| /=2643MB;5948;5958;0;5968"
|
||||||
for service in status_services)
|
for service in status_services)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -192,3 +227,27 @@ class TestSeparatedIntegrationSurveil(
|
|||||||
message="Custom Plugins is not used"
|
message="Custom Plugins is not used"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_list_metrics_name_host(self):
|
||||||
|
"""Test if a host with use=generic-host have the good metrics name."""
|
||||||
|
self.test_create_host()
|
||||||
|
|
||||||
|
def function():
|
||||||
|
metrics_name_hosts = (
|
||||||
|
self.get_surveil_client().status.hosts.metrics.get(
|
||||||
|
host_name='integrationhosttest')
|
||||||
|
)
|
||||||
|
self.assertTrue(
|
||||||
|
any(metric_name['metric_name'].decode() == 'rtmin'
|
||||||
|
for metric_name in metrics_name_hosts)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(
|
||||||
|
self.try_for_x_seconds(
|
||||||
|
function,
|
||||||
|
time_to_wait=360,
|
||||||
|
cooldown=10,
|
||||||
|
exception=AssertionError,
|
||||||
|
message="No metric name for host created"
|
||||||
|
)
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user