mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Merge branch 'feature/test-external-commands-5345' into next
resolves #5345
This commit is contained in:
parent
f8e6673123
commit
876587d727
@ -13,6 +13,10 @@ class icinga2 {
|
|||||||
alias => 'icinga2-doc'
|
alias => 'icinga2-doc'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package { 'mailx':
|
||||||
|
ensure => installed,
|
||||||
|
}
|
||||||
|
|
||||||
service { 'icinga2':
|
service { 'icinga2':
|
||||||
enable => true,
|
enable => true,
|
||||||
ensure => running,
|
ensure => running,
|
||||||
|
1198
test/jenkins/external_commands.test
Executable file
1198
test/jenkins/external_commands.test
Executable file
File diff suppressed because it is too large
Load Diff
33
test/jenkins/files/configs/groups.conf
Normal file
33
test/jenkins/files/configs/groups.conf
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* A new service group required by external_commands.test::test_servicegroup_commands
|
||||||
|
*/
|
||||||
|
object ServiceGroup "aservicegroup" {
|
||||||
|
display_name = "aServiceGroup"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The two default hostgroups
|
||||||
|
*/
|
||||||
|
object HostGroup "linux-servers" {
|
||||||
|
display_name = "Linux Servers"
|
||||||
|
}
|
||||||
|
|
||||||
|
object HostGroup "windows-servers" {
|
||||||
|
display_name = "Windows Servers"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This template is essentially the same as the default one but with a servicegroup added
|
||||||
|
*/
|
||||||
|
template Service "generic-service" {
|
||||||
|
max_check_attempts = 3,
|
||||||
|
check_interval = 5m,
|
||||||
|
retry_interval = 1m,
|
||||||
|
enable_perfdata = true,
|
||||||
|
groups = ["aservicegroup"],
|
||||||
|
|
||||||
|
notifications["mail-icingaadmin"] = {
|
||||||
|
templates = [ "mail-notification" ],
|
||||||
|
user_groups = [ "icingaadmins" ]
|
||||||
|
}
|
||||||
|
}
|
15
test/jenkins/files/configs/ido_checkresults.conf
Normal file
15
test/jenkins/files/configs/ido_checkresults.conf
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* This is a copy of the default configuration file "ido-mysql.conf" with the "categories" attribute added
|
||||||
|
*/
|
||||||
|
|
||||||
|
library "db_ido_mysql"
|
||||||
|
|
||||||
|
object IdoMysqlConnection "ido-mysql" {
|
||||||
|
user = "icinga",
|
||||||
|
password = "icinga",
|
||||||
|
host = "localhost",
|
||||||
|
database = "icinga",
|
||||||
|
categories = (DbCatCheck | DbCatConfig | DbCatState | DbCatAcknowledgement |
|
||||||
|
DbCatComment | DbCatDowntime | DbCatEventHandler | DbCatExternalCommand | DbCatFlapping |
|
||||||
|
DbCatLog | DbCatNotification | DbCatProgramStatus | DbCatRetention | DbCatStateHistory)
|
||||||
|
}
|
3
test/jenkins/files/configs/notifications.conf
Normal file
3
test/jenkins/files/configs/notifications.conf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
template Notification "mail-notification" {
|
||||||
|
notification_interval = 10
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -61,7 +62,8 @@ def _parse_mysql_result(resultset):
|
|||||||
if header is None:
|
if header is None:
|
||||||
header = columns
|
header = columns
|
||||||
else:
|
else:
|
||||||
result.append(dict((header[i], v) for i, v in enumerate(columns)))
|
result.append(dict((header[i], v if v != 'NULL' else None)
|
||||||
|
for i, v in enumerate(columns)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -96,6 +98,8 @@ class LiveStatusSocket(object):
|
|||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
|
self._connected = False
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.connect()
|
self.connect()
|
||||||
return self
|
return self
|
||||||
@ -106,10 +110,22 @@ class LiveStatusSocket(object):
|
|||||||
def connect(self):
|
def connect(self):
|
||||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
self.sock.connect(self.path)
|
self.sock.connect(self.path)
|
||||||
|
self._connected = True
|
||||||
|
|
||||||
|
def reconnect(self, timeout=30):
|
||||||
|
start = time.time()
|
||||||
|
while not self._connected and time.time() - start < timeout:
|
||||||
|
try:
|
||||||
|
self.connect()
|
||||||
|
except socket.error, error:
|
||||||
|
if error.errno != 111:
|
||||||
|
raise
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.sock.shutdown(socket.SHUT_RDWR)
|
if self._connected:
|
||||||
self.sock.close()
|
self.sock.shutdown(socket.SHUT_RDWR)
|
||||||
|
self.sock.close()
|
||||||
|
self._connected = False
|
||||||
|
|
||||||
def query(self, command):
|
def query(self, command):
|
||||||
self.send(command)
|
self.send(command)
|
||||||
@ -121,10 +137,16 @@ class LiveStatusSocket(object):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
def send(self, query):
|
def send(self, query):
|
||||||
|
if not self._connected:
|
||||||
|
raise RuntimeError('Tried to write to closed socket')
|
||||||
|
|
||||||
full_query = '\n'.join([query] + self.options)
|
full_query = '\n'.join([query] + self.options)
|
||||||
self.sock.sendall((full_query + '\n\n').encode('utf-8'))
|
self.sock.sendall((full_query + '\n\n').encode('utf-8'))
|
||||||
|
|
||||||
def recv(self):
|
def recv(self):
|
||||||
|
if not self._connected:
|
||||||
|
raise RuntimeError('Tried to read from closed socket')
|
||||||
|
|
||||||
response = b''
|
response = b''
|
||||||
response_header = self.sock.recv(16)
|
response_header = self.sock.recv(16)
|
||||||
response_code = int(response_header[:3])
|
response_code = int(response_header[:3])
|
||||||
|
@ -49,11 +49,31 @@
|
|||||||
},
|
},
|
||||||
"external_commands.test": {
|
"external_commands.test": {
|
||||||
"setup": {
|
"setup": {
|
||||||
"copy": ["files/utils.py >> /tmp/utils.py"]
|
"copy": [
|
||||||
|
"files/utils.py >> /tmp/utils.py",
|
||||||
|
"files/configs/notifications.conf >> /tmp/no_spam.conf",
|
||||||
|
"files/configs/ido_checkresults.conf >> /tmp/ido_checkresults.conf",
|
||||||
|
"files/configs/groups.conf >> /tmp/groups.conf"
|
||||||
|
],
|
||||||
|
"exec": [
|
||||||
|
"sudo mv /etc/icinga2/conf.d/generic-service.conf /etc/icinga2/conf.d/generic-service.conf.bak",
|
||||||
|
"sudo mv /etc/icinga2/conf.d/groups.conf /etc/icinga2/conf.d/groups.conf.bak",
|
||||||
|
"sudo mv /tmp/groups.conf /etc/icinga2/conf.d/",
|
||||||
|
"sudo mv /tmp/ido_checkresults.conf /etc/icinga2/conf.d/",
|
||||||
|
"sudo mv /tmp/no_spam.conf /etc/icinga2/conf.d/",
|
||||||
|
"sudo service icinga2 restart"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"teardown": {
|
"teardown": {
|
||||||
"clean": ["/tmp/utils.py*"],
|
"clean": ["/tmp/utils.py*"],
|
||||||
"exec": ["sudo service icinga2 restart"]
|
"exec": [
|
||||||
|
"sudo rm /etc/icinga2/conf.d/groups.conf",
|
||||||
|
"sudo mv /etc/icinga2/conf.d/groups.conf.bak /etc/icinga2/conf.d/groups.conf",
|
||||||
|
"sudo mv /etc/icinga2/conf.d/generic-service.conf.bak /etc/icinga2/conf.d/generic-service.conf",
|
||||||
|
"sudo rm /etc/icinga2/conf.d/ido_checkresults.conf",
|
||||||
|
"sudo rm /etc/icinga2/conf.d/no_spam.conf",
|
||||||
|
"sudo service icinga2 restart"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"eventhandler.test": {
|
"eventhandler.test": {
|
||||||
|
@ -68,6 +68,7 @@ class TestSuite(object):
|
|||||||
self._copy_test(path)
|
self._copy_test(path)
|
||||||
self._results[test_name] = self._run_test(path)
|
self._results[test_name] = self._run_test(path)
|
||||||
self._apply_setup_routines(test_name, 'teardown')
|
self._apply_setup_routines(test_name, 'teardown')
|
||||||
|
self._remove_test(test_name)
|
||||||
|
|
||||||
def _apply_setup_routines(self, test_name, context):
|
def _apply_setup_routines(self, test_name, context):
|
||||||
instructions = next((t[1].get(context)
|
instructions = next((t[1].get(context)
|
||||||
@ -98,6 +99,10 @@ class TestSuite(object):
|
|||||||
self._copy_file(path, os.path.join(self._config['settings']['test_root'],
|
self._copy_file(path, os.path.join(self._config['settings']['test_root'],
|
||||||
os.path.basename(path)))
|
os.path.basename(path)))
|
||||||
|
|
||||||
|
def _remove_test(self, test_name):
|
||||||
|
test_root = self._config['settings']['test_root']
|
||||||
|
self._remove_file(os.path.join(test_root, test_name))
|
||||||
|
|
||||||
def _run_test(self, path):
|
def _run_test(self, path):
|
||||||
command = self._config['commands']['exec']
|
command = self._config['commands']['exec']
|
||||||
target = os.path.join(self._config['settings']['test_root'],
|
target = os.path.join(self._config['settings']['test_root'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user