Skip to content

Commit e00316d

Browse files
committed
Closes #1035 - configuring events log
Clean default shipped configuration Closes #1036 - Remove _Thread__stop deprecated function
1 parent 46b367a commit e00316d

File tree

9 files changed

+156
-34
lines changed

9 files changed

+156
-34
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ jobs:
4343
# -- pycodestyle (former pep8)
4444
- pycodestyle --max-line-length=100 --exclude='*.pyc,carboniface.py' alignak/*
4545
# -- pylint
46-
# - unset PYTHONWARNINGS
4746
- pylint --rcfile=.pylintrc -r no alignak
48-
# - export PYTHONWARNINGS=all
4947
# -- pep257
5048
- pep257 --select=D300 alignak
5149
- stage: Pypi deployment

alignak/daemon.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,10 @@ def do_stop(self):
859859
self.http_thread.join(timeout=3)
860860
if self.http_thread.is_alive(): # pragma: no cover, should never happen...
861861
logger.warning("HTTP thread did not terminated. Force stopping the thread..")
862-
try:
863-
self.http_thread._Thread__stop() # pylint: disable=E1101
864-
except Exception as exp: # pylint: disable=broad-except
865-
print("Exception: %s" % exp)
862+
# try:
863+
# self.http_thread._Thread__stop() # pylint: disable=E1101
864+
# except Exception as exp: # pylint: disable=broad-except
865+
# print("Exception: %s" % exp)
866866
else:
867867
logger.debug("HTTP thread exited")
868868
self.http_thread = None

etc/sample/demo/readme.cfg

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Demo configuration
2+
# ---
3+
4+
# Copy the files and directories into the default shipped *alignak/etc* directory
5+
# to use this saemple configuration
6+
7+
# Extra features:
8+
# - some realms are defined

tests/alignak_test.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def _stop_alignak_daemons(self, arbiter_only=True, request_stop_uri=''):
364364
for name, proc in list(self.procs.items()):
365365
if arbiter_only and name not in ['arbiter-master']:
366366
continue
367-
if proc.pid == self.my_pid:
367+
if getattr(self, 'my_pid', None) and proc.pid == self.my_pid:
368368
print("- do not kill myself!")
369369
continue
370370
print("Asking %s (pid=%d) to end..." % (name, proc.pid))
@@ -404,11 +404,14 @@ def _stop_alignak_daemons(self, arbiter_only=True, request_stop_uri=''):
404404
daemon_process = psutil.Process(proc.pid)
405405
daemon_process.terminate()
406406
daemon_process.wait(10)
407+
except psutil.AccessDenied:
408+
print("-> access denied...")
409+
continue
407410
except psutil.NoSuchProcess:
408-
print("not existing!")
411+
print("-> not existing!")
409412
continue
410413
except psutil.TimeoutExpired:
411-
print("***** timeout 10 seconds, force-killing the daemon...")
414+
print("-> timeout 10 seconds, force-killing the daemon...")
412415
daemon_process.kill()
413416

414417
def _run_command_with_timeout(self, cmd, timeout_sec):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
define hostgroup {
3+
hostgroup_name router
4+
alias All Router Hosts
5+
}
6+
7+
define hostgroup {
8+
hostgroup_name allhosts
9+
alias All Hosts
10+
members localhost
11+
}
12+
13+
define hostgroup{
14+
hostgroup_name test
15+
alias Test hosts
16+
}

tests_integ/alignak_test.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def _stop_alignak_daemons(self, arbiter_only=True, request_stop_uri=''):
364364
for name, proc in list(self.procs.items()):
365365
if arbiter_only and name not in ['arbiter-master']:
366366
continue
367-
if proc.pid == self.my_pid:
367+
if getattr(self, 'my_pid', None) and proc.pid == self.my_pid:
368368
print("- do not kill myself!")
369369
continue
370370
print("Asking %s (pid=%d) to end..." % (name, proc.pid))
@@ -404,11 +404,14 @@ def _stop_alignak_daemons(self, arbiter_only=True, request_stop_uri=''):
404404
daemon_process = psutil.Process(proc.pid)
405405
daemon_process.terminate()
406406
daemon_process.wait(10)
407+
except psutil.AccessDenied:
408+
print("-> access denied...")
409+
continue
407410
except psutil.NoSuchProcess:
408-
print("not existing!")
411+
print("-> not existing!")
409412
continue
410413
except psutil.TimeoutExpired:
411-
print("***** timeout 10 seconds, force-killing the daemon...")
414+
print("-> timeout 10 seconds, force-killing the daemon...")
412415
daemon_process.kill()
413416

414417
def _run_command_with_timeout(self, cmd, timeout_sec):

tests_integ/test_daemons_api.py

+115-22
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@
2020
#
2121

2222
import os
23-
import sys
2423
import time
2524
import signal
2625
import json
2726

28-
from pprint import pprint
29-
30-
import subprocess
31-
from time import sleep
3227
import requests
3328
import shutil
3429
import psutil
@@ -97,7 +92,8 @@ def _prepare_my_configuration(self, daemons_list=None, remove_daemons=None,
9792
shutil.rmtree('%s/etc/arbiter' % self.cfg_folder)
9893
shutil.copytree('./cfg/%s/arbiter' % cfg_dir, '%s/etc/arbiter' % self.cfg_folder)
9994

100-
self._prepare_hosts_configuration(cfg_folder='%s/etc/arbiter/objects/hosts' % self.cfg_folder,
95+
self._prepare_hosts_configuration(cfg_folder='%s/etc/arbiter/objects/hosts'
96+
% self.cfg_folder,
10197
hosts_count=hosts_count, target_file_name='hosts.cfg',
10298
realms=realms)
10399

@@ -115,9 +111,9 @@ def _prepare_my_configuration(self, daemons_list=None, remove_daemons=None,
115111

116112
cfg.set('alignak-configuration', 'daemons_check_period', '5')
117113
cfg.set('alignak-configuration', 'daemons_stop_timeout', '3')
118-
cfg.set('alignak-configuration', 'daemons_start_timeout', '1')
119-
cfg.set('alignak-configuration', 'daemons_new_conf_timeout', '1')
120-
cfg.set('alignak-configuration', 'daemons_dispatch_timeout', '1')
114+
cfg.set('alignak-configuration', 'daemons_start_timeout', '5')
115+
cfg.set('alignak-configuration', 'daemons_new_conf_timeout', '5')
116+
cfg.set('alignak-configuration', 'daemons_dispatch_timeout', '5')
121117
cfg.set('alignak-configuration', 'min_workers', '1')
122118
cfg.set('alignak-configuration', 'max_workers', '1')
123119

@@ -209,12 +205,12 @@ def _run_daemons_and_test_api(self, ssl=False):
209205

210206
# -----
211207
print("Testing api...")
212-
name_to_interface = {'arbiter': ArbiterInterface,
213-
'scheduler': SchedulerInterface,
214-
'broker': BrokerInterface,
215-
'poller': GenericInterface,
216-
'reactionner': GenericInterface,
217-
'receiver': GenericInterface}
208+
# name_to_interface = {'arbiter': ArbiterInterface,
209+
# 'scheduler': SchedulerInterface,
210+
# 'broker': BrokerInterface,
211+
# 'poller': GenericInterface,
212+
# 'reactionner': GenericInterface,
213+
# 'receiver': GenericInterface}
218214
doc = []
219215
doc.append(".. _alignak_features/daemons_api:")
220216
doc.append("")
@@ -325,7 +321,7 @@ def _run_daemons_and_test_api(self, ssl=False):
325321
assert "long_output" in livestate
326322
assert "perf_data" in livestate
327323

328-
doc = []
324+
doc = list()
329325
doc.append(".. _alignak_features/alignak_status:")
330326
doc.append(".. Built from the test_daemons_api.py unit test last run!")
331327
doc.append("")
@@ -394,11 +390,7 @@ def _run_daemons_and_test_api(self, ssl=False):
394390
assert "livestate" in data
395391
livestate = data['livestate']
396392
print("Livestate: %s" % livestate)
397-
l = {
398-
'daemons': {'reactionner-master': 1, 'poller-master': 1, 'broker-master': 1,
399-
'receiver-master': 1, 'scheduler-master': 1},
400-
'state': 1, 'timestamp': 1531487166,
401-
'output': 'warning because some daemons are not reachable.'}
393+
402394
assert "timestamp" in livestate
403395
assert "state" in livestate
404396
assert "output" in livestate
@@ -1791,7 +1783,7 @@ def test_get_stats(self):
17911783
self._stop_alignak_daemons(request_stop_uri='http://127.0.0.1:7770')
17921784

17931785
def test_get_realms(self):
1794-
""" Running all the Alignak daemons - get realmss organization
1786+
""" Running all the Alignak daemons - get realms organization
17951787
17961788
:return:
17971789
"""
@@ -1831,6 +1823,107 @@ def test_get_realms(self):
18311823
print("Alignak realms: %s" % (raw_data.text))
18321824
assert raw_data.status_code == 200
18331825
data = raw_data.json()
1826+
r = {
1827+
"All": dict(name="All", level=0, hosts=[
1828+
"host-all-7", "host-all-6", "host-all-3", "host-all-2", "host-all-0", "host-all-1",
1829+
"localhost", "host-all-8", "host-all-9", "host-all-5", "host-all-4"
1830+
], hostgroups=["monitoring_servers"], children={
1831+
"Asia": dict(name="Asia", level=1,
1832+
hosts=["host-asia-3", "host-asia-7", "host-asia-9", "host-asia-4",
1833+
"host-asia-8", "host-asia-1", "host-asia-2", "host-asia-0",
1834+
"host-asia-5", "host-asia-6"], hostgroups=[], children={
1835+
"Japan": {"name": "Japan", "level": 2,
1836+
"hosts": ["host-japan-8", "host-japan-7", "host-japan-3",
1837+
"host-japan-4", "host-japan-0", "host-japan-5",
1838+
"host-japan-1", "host-japan-2", "host-japan-9",
1839+
"host-japan-6"],
1840+
"hostgroups": [], "children": {
1841+
"Osaka": {"name": "Osaka", "level": 3, "hosts": [],
1842+
"hostgroups": [], "children": {},
1843+
"satellites": {"schedulers": ["scheduler-master"],
1844+
"reactionners": ["reactionner-master"],
1845+
"brokers": ["broker-master"],
1846+
"receivers": ["receiver-master"],
1847+
"pollers": ["poller-master"]}},
1848+
"Tokyo": {"name": "Tokyo", "level": 3, "hosts": ["h_Tokyo"],
1849+
"hostgroups": [], "children": {},
1850+
"satellites": {"schedulers": ["scheduler-master"],
1851+
"reactionners": ["reactionner-master"],
1852+
"brokers": ["broker-master"],
1853+
"receivers": ["receiver-master"],
1854+
"pollers": ["poller-master"]}}
1855+
},
1856+
"satellites": dict(schedulers=["scheduler-master"],
1857+
reactionners=["reactionner-master"],
1858+
brokers=["broker-master"],
1859+
receivers=["receiver-master"],
1860+
pollers=["poller-master"])}
1861+
}, satellites={"schedulers": ["scheduler-master"],
1862+
"reactionners": ["reactionner-master"],
1863+
"brokers": ["broker-master"],
1864+
"receivers": ["receiver-master"],
1865+
"pollers": ["poller-master"]}),
1866+
"Europe": dict(name="Europe", level=1,
1867+
hosts=["host-europe-8", "host-europe-0", "host-europe-2",
1868+
"host-europe-3", "host-europe-9", "host-europe-1",
1869+
"host-europe-5", "host-europe-7", "host-europe-6",
1870+
"host-europe-4"], hostgroups=[], children={
1871+
"France": {"name": "France", "level": 2,
1872+
"hosts": ["host-france-4", "h_France", "host-france-0",
1873+
"host-france-1", "host-france-8", "host-france-5",
1874+
"host-france-7", "host-france-9", "host-france-6",
1875+
"host-france-3", "host-france-2"],
1876+
"hostgroups": [], "children": {
1877+
"Lyon": {"name": "Lyon", "level": 3, "hosts": ["h_Lyon"],
1878+
"hostgroups": [], "children": {},
1879+
"satellites": {"schedulers": ["scheduler-master"],
1880+
"reactionners": ["reactionner-master"],
1881+
"brokers": ["broker-master"],
1882+
"receivers": ["receiver-master"],
1883+
"pollers": ["poller-master"]}},
1884+
"Paris": {"name": "Paris", "level": 3, "hosts": ["h_Paris"],
1885+
"hostgroups": [], "children": {},
1886+
"satellites": {"schedulers": ["scheduler-master"],
1887+
"reactionners": ["reactionner-master"],
1888+
"brokers": ["broker-master"],
1889+
"receivers": ["receiver-master"],
1890+
"pollers": ["poller-master"]}}},
1891+
"satellites": {"schedulers": ["scheduler-master"],
1892+
"reactionners": ["reactionner-master"],
1893+
"brokers": ["broker-master"],
1894+
"receivers": ["receiver-master"],
1895+
"pollers": ["poller-master"]}},
1896+
"Italy": {"name": "Italy", "level": 2, "hosts": [], "hostgroups": [],
1897+
"children": {
1898+
"Roma": {"name": "Roma", "level": 3, "hosts": ["h_Roma"],
1899+
"hostgroups": [], "children": {}, "satellites": {
1900+
"schedulers": ["scheduler-master"],
1901+
"reactionners": ["reactionner-master"],
1902+
"brokers": ["broker-master"],
1903+
"receivers": ["receiver-master"],
1904+
"pollers": ["poller-master"]}},
1905+
"Torino": {"name": "Torino", "level": 3, "hosts": [],
1906+
"hostgroups": [], "children": {},
1907+
"satellites": {
1908+
"schedulers": ["scheduler-master"],
1909+
"reactionners": ["reactionner-master"],
1910+
"brokers": ["broker-master"],
1911+
"receivers": ["receiver-master"],
1912+
"pollers": ["poller-master"]}}},
1913+
"satellites": {"schedulers": ["scheduler-master"],
1914+
"reactionners": ["reactionner-master"],
1915+
"brokers": ["broker-master"],
1916+
"receivers": ["receiver-master"],
1917+
"pollers": ["poller-master"]}}},
1918+
satellites={"schedulers": ["scheduler-master"],
1919+
"reactionners": ["reactionner-master"],
1920+
"brokers": ["broker-master"],
1921+
"receivers": ["receiver-master"],
1922+
"pollers": ["poller-master"]})
1923+
}, satellites={"schedulers": ["scheduler-master"],
1924+
"reactionners": ["reactionner-master"], "brokers": ["broker-master"],
1925+
"receivers": ["receiver-master"], "pollers": ["poller-master"]})
1926+
}
18341927
assert 'All' in data
18351928
assert data['All']['name'] == 'All'
18361929
assert data['All']['level'] == 0

tests_integ/test_launch_arbiter.py

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def _run_arbiter_no_configured_daemons(self, alignak_launched):
123123
cfg_folder = '/tmp/alignak'
124124
print("Copy default configuration (../etc) to %s..." % cfg_folder)
125125
if os.path.exists('%s/etc' % cfg_folder):
126+
print("deleting existing configuration in %s/etc..." % cfg_folder)
126127
shutil.rmtree('%s/etc' % cfg_folder)
127128
shutil.copytree('../etc', '%s/etc' % cfg_folder)
128129
# Remove the daemons configuration part!

0 commit comments

Comments
 (0)