Merge "Integration tests : passive, custom plugins"

This commit is contained in:
Jenkins 2015-07-02 15:58:55 +00:00 committed by Gerrit Code Review
commit bde01df409
3 changed files with 117 additions and 9 deletions

View File

@ -10,5 +10,5 @@ keystonemiddleware
PasteDeploy
influxdb==2.6.0
pika
python-surveilclient==0.6.0
python-surveilclient==0.8.0
six

View File

@ -6,13 +6,14 @@ surveil:
- alignak
ports:
- "8999:8080"
command: bash -c "cd /opt/surveil && ./setup.sh && python setup.py develop && ((sleep 40 && surveil-init --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:
build: tools/docker/alignak_container/
links:
- mongo
- influxdb
- redis
environment:
SURVEIL_OS_AUTH_URL: "http://keystone:5000/v2.0"
SURVEIL_OS_USERNAME: "admin"
@ -25,6 +26,9 @@ mongo:
"mongod --nojournal --smallfiles"
influxdb:
image: savoirfairelinux/influxdb
image: savoirfairelinux/influxdb:0.9.0
environment:
PRE_CREATE_DB: "db"
redis:
image: redis

View File

@ -4,7 +4,7 @@
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
@ -20,7 +20,6 @@ from surveil.tests.integration import integration_test
class TestMergedIngegrationSurveil(
integration_test.MergedIntegrationTest
):
def test_hello(self):
self.assertEqual(
requests.get("http://localhost:8999/v2/hello").text,
@ -31,7 +30,6 @@ class TestMergedIngegrationSurveil(
class TestSeparatedIntegrationSurveil(
integration_test.SeparatedIntegrationTests
):
def test_create_host(self):
"""Creates a host and asserts that is is monitored by Alignak."""
config_hosts = (TestSeparatedIntegrationSurveil.
@ -45,6 +43,7 @@ class TestSeparatedIntegrationSurveil(
TestSeparatedIntegrationSurveil.client.config.hosts.create(
host_name='integrationhosttest',
address='127.0.0.1',
use='generic-host',
)
TestSeparatedIntegrationSurveil.client.config.reload_config()
@ -55,7 +54,6 @@ class TestSeparatedIntegrationSurveil(
self.assertTrue(
any(host['host_name'].decode() == 'integrationhosttest'
for host in status_hosts)
)
self.assertTrue(
@ -72,8 +70,7 @@ class TestSeparatedIntegrationSurveil(
self.test_create_host()
TestSeparatedIntegrationSurveil.client.config.hosts.delete(
'integrationhosttest'
)
'integrationhosttest')
TestSeparatedIntegrationSurveil.client.config.reload_config()
@ -94,3 +91,110 @@ class TestSeparatedIntegrationSurveil(
message="Host was not deleted"
)
)
def test_passive_check(self):
TestSeparatedIntegrationSurveil.client.config.hosts.create(
host_name='integrationhosttest',
address='127.0.0.1',
use='generic-host',
)
TestSeparatedIntegrationSurveil.client.config.commands.create(
command_name='check_integrationhosttest',
command_line='/usr/lib/monitoring/plugins/sfl/check_example'
)
TestSeparatedIntegrationSurveil.client.config.services.create(
check_command="check_integrationhosttest",
check_interval="5",
check_period="24x7",
contact_groups="admins",
contacts="admin",
host_name="integrationhosttest",
max_check_attempts="5",
notification_interval="30",
notification_period="24x7",
retry_interval="3",
service_description="check_integrationhosttest",
passive_checks_enabled="1"
)
TestSeparatedIntegrationSurveil.client.config.reload_config()
(TestSeparatedIntegrationSurveil.client.status.services.
submit_check_result(
host_name='integrationhosttest',
service_description='check_integrationhosttest',
output="Hello",
return_code=0
)
)
def function():
status_services = (TestSeparatedIntegrationSurveil.
client.status.services.list())
self.assertFalse(
any(service['host_name'].decode() == 'integrationhosttest' and
service['service_description'].decode() ==
'check_integrationhosttest' and
service['plugin_output'].decode() == 'Hello' and
service['state'].decode() == 'OK'
for service in status_services)
)
self.assertTrue(
self.try_for_x_seconds(
function,
time_to_wait=180,
cooldown=10,
exception=AssertionError,
message="submit check result fail"
)
)
def test_custom_plugins(self):
TestSeparatedIntegrationSurveil.client.config.hosts.create(
host_name='integrationhosttest',
address='127.0.0.1',
use='generic-host',
)
TestSeparatedIntegrationSurveil.client.config.commands.create(
command_name='check_integrationhosttest',
command_line='/usr/lib/monitoring/plugins/sfl/check_example'
)
TestSeparatedIntegrationSurveil.client.config.services.create(
check_command="check_integrationhosttest",
check_interval="5",
check_period="24x7",
contact_groups="admins",
contacts="admin",
host_name="integrationhosttest",
max_check_attempts="5",
notification_interval="30",
notification_period="24x7",
retry_interval="3",
service_description="check_integrationhosttest",
passive_checks_enabled="1"
)
TestSeparatedIntegrationSurveil.client.config.reload_config()
def function():
status_services = (TestSeparatedIntegrationSurveil.
client.status.services.list())
self.assertFalse(
any(service['host_name'].decode() == 'integrationhosttest' and
service['service_description'].decode() ==
'check_integrationhosttest' and
service['plugin_output'].decode() ==
"DISK OK - free space: / 3326 MB (56%);"
" | /=2643MB;5948;5958;0;5968"
for service in status_services)
)
self.assertTrue(
self.try_for_x_seconds(
function,
time_to_wait=180,
cooldown=10,
exception=AssertionError,
message="Custom Plugins is not used"
)
)