Skip to content

Commit cfcde85

Browse files
committed
Fix pycodestyle / pylint
1 parent a6997ae commit cfcde85

14 files changed

+73
-94
lines changed

alignak/daemons/arbiterdaemon.py

-1
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,6 @@ def get_livesynthesis(self):
18111811
'hosts_acknowledged': 0,
18121812
'hosts_in_downtime': 0,
18131813
'hosts_flapping': 0,
1814-
18151814
'services_total': 0,
18161815
'services_not_monitored': 0,
18171816
'services_ok_hard': 0,

alignak/dispatcher.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ def check_status(self):
304304

305305
try:
306306
daemon_link.statistics = daemon_link.get_daemon_stats(details=True)
307-
daemon_link.statistics['_freshness'] = int(time.time())
308-
statistics[daemon_link.name] = daemon_link.statistics
309-
logger.debug("Daemon %s statistics: %s" % (daemon_link.name,
310-
daemon_link.statistics))
307+
if daemon_link.statistics:
308+
daemon_link.statistics['_freshness'] = int(time.time())
309+
statistics[daemon_link.name] = daemon_link.statistics
310+
logger.debug("Daemon %s statistics: %s", daemon_link.name, daemon_link.statistics)
311311
except LinkError:
312312
logger.warning("Daemon connection failed, I could not get statistics.")
313313

alignak/macroresolver.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def init(self, conf):
169169
self.contactgroups = self.my_conf.contactgroups
170170
self.lists_on_demand.append(self.contactgroups)
171171
self.illegal_macro_output_chars = self.my_conf.illegal_macro_output_chars
172+
self.env_prefix = self.my_conf.env_variables_prefix
172173

173174
@staticmethod
174175
def _get_macros(chain):
@@ -298,11 +299,13 @@ def get_env_macros(self, data):
298299

299300
prop = macros[macro]
300301
value = self._get_value_from_element(obj, prop)
301-
env['NAGIOS_%s' % macro] = value
302+
env['%s%s' % (self.env_prefix, macro)] = value
302303
if hasattr(obj, 'customs'):
303304
# make NAGIOS__HOSTMACADDR from _MACADDR
304305
for cmacro in obj.customs:
305-
new_env_name = 'NAGIOS__' + obj.__class__.__name__.upper() + cmacro[1:].upper()
306+
new_env_name = '%s_%s%s' % (self.env_prefix,
307+
obj.__class__.__name__.upper(),
308+
cmacro[1:].upper())
306309
env[new_env_name] = obj.customs[cmacro]
307310

308311
return env

alignak/objects/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ class Config(Item): # pylint: disable=R0904,R0902
639639
'illegal_macro_output_chars':
640640
StringProp(default='',
641641
class_inherit=[(Host, None), (Service, None), (Contact, None)]),
642+
'env_variables_prefix':
643+
StringProp(default='ALIGNAK_'),
642644

643645
'use_regexp_matching':
644646
BoolProp(managed=False,

alignak/scheduler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ def get_objects_from_from_queues(self):
20712071
return self.my_daemon.get_objects_from_from_queues()
20722072

20732073
def get_scheduler_stats(self, details=False): # pylint: disable=unused-argument
2074-
# pylint: disable=too-many-locals
2074+
# pylint: disable=too-many-locals, too-many-branches
20752075
"""Get the scheduler statistics
20762076
20772077
:return: A dict with the following structure

setup.cfg

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
[bdist_wheel]
22
universal = 1
33

4+
[metadata]
5+
license_file = LICENSE
6+
47
[build_sphinx]
58
source-dir = doc/source
69
build-dir = doc/build
710
all_files = 1
8-
9-
[files]
10-
data_files =
11-
etc/alignak = etc/*
12-
13-
[entry_points]
14-
console_scripts =
15-
alignak-environment = alignak.bin.alignak_environment:main
16-
alignak-arbiter = alignak.bin.alignak_arbiter:main
17-
alignak-broker = alignak.bin.alignak_broker:main
18-
alignak-receiver = alignak.bin.alignak_receiver:main
19-
alignak-reactionner = alignak.bin.alignak_reactionner:main
20-
alignak-poller = alignak.bin.alignak_poller:main
21-
alignak-scheduler = alignak.bin.alignak_scheduler:main

setup.py

+33-61
Original file line numberDiff line numberDiff line change
@@ -18,50 +18,37 @@
1818
pass
1919

2020
# Define the list of requirements with specified versions
21-
requirements = [
22-
# Still needing future for the CarbonIFace lib and some other stuff (queues, ...)
23-
# Needing six for python 2.7/3 compatibility
24-
'future==0.16.0',
25-
'six==1.11.0',
26-
27-
# Alignak supports the most recent CherryPy
28-
'CherryPy==15.0.0',
29-
30-
# Requests to communicate between the daemons
31-
'requests==2.18.4',
32-
33-
# importlib is used to import modules used by the daemons
34-
'importlib' if sys.version_info <= (2,7) else '',
35-
36-
# Colored console log
37-
'termcolor==1.1.0',
38-
39-
# Set process titles
40-
'setproctitle==1.1.10',
41-
42-
# ujson is used for the internal objects serialization
43-
'ujson==1.35',
44-
45-
# numpy for date and percentile computation - needs a compiler on the installation target system!
46-
# Comment to use an internal implementation of percentile function
47-
'numpy==1.14.3',
48-
49-
# SSL between the daemons
50-
# This requirement is only a requirement if you intend to use SLL for the inter-daemons
51-
# communication. As such, to avoid installing this library per default, commenting this line!
52-
# Uncomment or `pip install pyopenssl` if SSL must be used between the Alignak daemons
53-
# pyopenssl
54-
55-
# configparser is used to parse command line of the daemons
56-
'configparser' if sys.version_info <= (2,7) else '',
57-
# docopt is used by the alignak_environment script
58-
'docopt==0.6.2',
59-
60-
# Use psutil for daemons memory monitoring (env ALIGNAK_DAEMONS_MONITORING)
61-
# Use psutil for scheduler ALIGNAK_LOG_MONITORING
62-
# Use psutil for launching daemons from the Arbiter
63-
'psutil==5.4.5'
64-
]
21+
def read_requirements(filename='requirements.txt'):
22+
"""Reads the list of requirements from given file.
23+
24+
:param filename: Filename to read the requirements from.
25+
Uses ``'requirements.txt'`` by default.
26+
27+
:return: Requirments as list of strings.
28+
"""
29+
# allow for some leeway with the argument
30+
if not filename.startswith('requirements'):
31+
filename = 'requirements-' + filename
32+
if not os.path.splitext(filename)[1]:
33+
filename += '.txt' # no extension, add default
34+
35+
def valid_line(line):
36+
line = line.strip()
37+
return line and not any(line.startswith(p) for p in ('#', '-'))
38+
39+
def extract_requirement(line):
40+
egg_eq = '#egg='
41+
if egg_eq in line:
42+
_, requirement = line.split(egg_eq, 1)
43+
return requirement
44+
return line
45+
46+
with open(filename) as f:
47+
lines = f.readlines()
48+
return list(map(extract_requirement, filter(valid_line, lines)))
49+
requirements = read_requirements()
50+
print(requirements)
51+
# exit()
6552

6653
# Better to use exec to load the VERSION from alignak/version.py
6754
# so to not have to import the alignak package:
@@ -138,23 +125,8 @@
138125
zip_safe=False,
139126
platforms='any',
140127

141-
# Dependencies (if some) ...
142-
install_requires=[
143-
# Do not set specific versions - for development purposes, use the most recent versions
144-
# More about this: https://packaging.python.org/discussions/
145-
# install-requires-vs-requirements/#install-requires-vs-requirements-files
146-
'future',
147-
'six',
148-
'importlib' if sys.version_info <= (2,7) else '',
149-
'CherryPy',
150-
'requests',
151-
'termcolor',
152-
'setproctitle',
153-
'ujson',
154-
'numpy',
155-
'docopt',
156-
'psutil'
157-
],
128+
# Dependencies...
129+
install_requires=requirements,
158130
dependency_links=[
159131
# Use the standard PyPi repository
160132
"https://pypi.python.org/simple/",

test/cfg/cfg_macroresolver.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cfg_dir=default
22

33
; Configure specific Alignak parameters
44
illegal_macro_output_chars=`~\$&|'"<>
5+
#env_variables_prefix=NAGIOS_
56
enable_environment_macros=0
67
78
$USER1$=plugins

test/cfg/cfg_macroresolver_environment.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cfg_dir=default
22

33
; Configure specific Alignak parameters
44
illegal_macro_output_chars=`~\$&|'"<>
5+
env_variables_prefix=NAGIOS_
56
enable_environment_macros=1
67
78
$USER1$=plugins

test/setup_test.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ pip install --upgrade pip
2929
sudo addgroup --system alignak
3030
sudo adduser --system alignak --ingroup alignak
3131

32-
# install prog AND tests requirements :
33-
pip install --upgrade -r requirements.txt
34-
pip install -e .
32+
# install application AND tests requirements :
3533
pip install --upgrade -r test/requirements.txt
34+
pip install -e .
3635

3736
pyversion=$(python -c "import sys; print(''.join(map(str, sys.version_info[:2])))")
3837
if test -e "test/requirements.py${pyversion}.txt"

test/test_a_properties_default.py

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class TestConfig(PropertiesTester, AlignakTest):
233233
('date_format', None),
234234
('use_timezone', ''),
235235
('illegal_object_name_chars', '`~!$%^&*"|\'<>?,()='),
236+
('env_variables_prefix', 'ALIGNAK_'),
236237
('illegal_macro_output_chars', ''),
237238
('use_regexp_matching', False),
238239
('use_true_regexp_matching', None),

test/test_macros_resolver.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,17 @@ def test_env_macros(self):
513513
data = [hst, svc]
514514
data.append(self._arbiter.conf)
515515

516+
# Macros are existing in the environment with a prefix which defaults to ALIGNAK_
517+
# but this prefix may be overriden in the configuration
518+
# assert mr.env_prefix == 'ALIGNAK_'
519+
516520
env = mr.get_env_macros(data)
517521
assert env != {}
518-
assert 'test_host_0' == env['NAGIOS_HOSTNAME']
519-
assert 0.0 == env['NAGIOS_SERVICEPERCENTCHANGE']
520-
assert 'custvalue' == env['NAGIOS__SERVICECUSTNAME']
521-
assert 'gnulinux' == env['NAGIOS__HOSTOSTYPE']
522-
assert 'NAGIOS_USER1' not in env
522+
assert 'test_host_0' == env['%sHOSTNAME' % mr.env_prefix]
523+
assert 0.0 == env['%sSERVICEPERCENTCHANGE' % mr.env_prefix]
524+
assert 'custvalue' == env['%s_SERVICECUSTNAME' % mr.env_prefix]
525+
assert 'gnulinux' == env['%s_HOSTOSTYPE' % mr.env_prefix]
526+
assert '%sUSER1' % mr.env_prefix not in env
523527

524528
def test_resource_file(self):
525529
"""
@@ -925,6 +929,9 @@ def setUp(self):
925929
self.setup_with_file(self.setup_file)
926930
assert self.conf_is_correct
927931

932+
mr = self.get_mr()
933+
assert mr.env_prefix == 'ALIGNAK_'
934+
928935

929936
class TestMacroResolverWithoutEnv(MacroResolverTester, AlignakTest):
930937
"""Test without enabled environment macros"""
@@ -936,3 +943,6 @@ def setUp(self):
936943
self.setup_file = 'cfg/cfg_macroresolver_environment.cfg'
937944
self.setup_with_file(self.setup_file)
938945
assert self.conf_is_correct
946+
947+
mr = self.get_mr()
948+
assert mr.env_prefix == 'NAGIOS_'

tests_integ/test_daemons_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ def test_get_stats(self):
13881388
# 2/ get the daemons statistics - no details
13891389
self._get_stats(req, satellite_map, False)
13901390

1391-
time.sleep(5)
1391+
time.sleep(1)
13921392

13931393
# -----
13941394
# 3/ once again, get the daemons statistics - with more details

tests_integ/test_launch_arbiter.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _stop_daemons(self, daemon_names=None):
9191
for name, port in list(satellite_map.items()):
9292
if daemon_names and name not in daemon_names:
9393
continue
94-
print("- stopping %s: http://127.0.0.1:%s/stop_request" % (name, port))
94+
print("- stopping (now) %s: http://127.0.0.1:%s/stop_request" % (name, port))
9595
raw_data = self.req.get("http://127.0.0.1:%s/stop_request?stop_now=1" % (port))
9696
data = raw_data.json()
9797
print("- response = %s" % data)
@@ -328,7 +328,7 @@ def test_arbiter_daemons_kill_one_daemon(self):
328328
cfg.read(['/tmp/alignak/etc/alignak.ini', '/tmp/alignak/etc/alignak.d/daemons.ini'])
329329
cfg.set('alignak-configuration', 'launch_missing_daemons', '1')
330330
cfg.set('alignak-configuration', 'polling_interval', '1')
331-
cfg.set('alignak-configuration', 'daemons_check_period', '1')
331+
cfg.set('alignak-configuration', 'daemons_check_period', '3')
332332
cfg.set('alignak-configuration', 'daemons_stop_timeout', '1')
333333
cfg.set('alignak-configuration', 'daemons_start_timeout', '1')
334334
cfg.set('alignak-configuration', 'daemons_new_conf_timeout', '1')
@@ -361,9 +361,11 @@ def test_arbiter_daemons_kill_one_daemon(self):
361361
print("Started...")
362362

363363
self._ping_daemons()
364+
sleep(1)
364365

365366
print("Killing one daemon process...")
366367
self._stop_daemons(['receiver'])
368+
sleep(1)
367369
self._ping_daemons()
368370
sleep(2)
369371

0 commit comments

Comments
 (0)