Skip to content

Commit e895a2a

Browse files
committed
Fix broken Travis tests - get test setup from mod-livestatus
Scheduler broks is an array not a dict
1 parent 1fae6b6 commit e895a2a

File tree

4 files changed

+79
-30
lines changed

4 files changed

+79
-30
lines changed

.travis.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
language: python
22
python:
33
- "2.7"
4-
- "2.6"
54

65
install:
6+
- sudo apt-get update && sudo apt-get install -y python-pip libgnutls28-dev libssl-dev
7+
# python-pycurl python-cherrypy3
78
- ./test/setup_module_test.sh
89
- pip install importlib # this is a requirement of shinken
9-
- export PYTHONPATH=$PYTHONPATH:~/shinken # we need shinken..
10-
- export PYTHONPATH=$PYTHONPATH:~/shinken/test
11-
- export PYTHONPATH=$PYTHONPATH:~/mod-livestatus/test # we also need mock_livestatus from mod-livestatus..
1210

1311
script:
14-
- mongodir=$(pwd)
15-
# tests need to run from shinken test directory for access to test config files
16-
# (as long as the test config files are referenced with a relative path)
17-
- cd ~/shinken/test
18-
- nosetests -vx --with-coverage --cover-package=modules $mongodir/test
12+
- cur_dir=$PWD
13+
- export PYTHONPATH=$PYTHONPATH:$PWD/test/tmp/shinken # we need shinken..
14+
# - export PYTHONPATH=$PYTHONPATH:$PWD/test/tmp/shinken/test
15+
# - export PYTHONPATH=$PYTHONPATH:$PWD/test/tmp/shinken/test/modules
16+
- export PYTHONPATH=$PYTHONPATH:$PWD/test/tmp/shinken/test/modules/livestatus # we also need mock_livestatus from mod-livestatus..
17+
- echo $PYTHONPATH
18+
- cd test/tmp/shinken/test
19+
- nosetests -vx --process-restartworker --processes=1 --process-timeout=1800 "$cur_dir/test"
20+
- coverage combine
1921

2022
after_success:
2123
coveralls

test/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
-r ../requirements.txt
22
unittest2
3+
coveralls

test/setup_module_test.sh

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,84 @@
11
#!/bin/bash
22

3+
set -e
4+
set -xv
5+
6+
py_version_short=$(python -c "import sys; print(''.join(str(x) for x in sys.version_info[:2]))")
7+
# -> 26 or 27 or 34 or ..
8+
39
get_name (){
410
echo $(python -c 'import json; print json.load(open("'$1'package.json"))["name"]')
511
}
612

13+
SHI_DST=test/tmp/shinken
14+
715
setup_submodule (){
16+
local dep
17+
local mname
18+
local mpath
819
for dep in $(cat test/dep_modules.txt); do
920
mname=$(basename $dep | sed 's/.git//g')
10-
git clone --depth=15 $dep ~/$mname
11-
rmname=$(get_name ~/$mname/)
12-
cp -r ~/$mname/module ~/shinken/modules/$rmname
13-
[ -f ~/$mname/requirements.txt ] && pip install -r ~/$mname/requirements.txt
21+
mpath="test/tmp/$mname"
22+
git clone --depth 10 "$dep" "$mpath"
23+
( cd $mpath && git status && git log -1)
24+
rmname=$(get_name "$mpath/")
25+
ln -s "$PWD/$mpath/module" "$PWD/$SHI_DST/test/modules/$rmname"
26+
27+
if [ -f "$PWD/$mpath/test/mock_livestatus.py" ]
28+
then
29+
ln -s "$PWD/$mpath/test/mock_livestatus.py" "$PWD/$SHI_DST/test/modules/$rmname/mock_livestatus.py"
30+
fi
31+
32+
if [ -f "$PWD/$mpath/test/etc" ]
33+
then
34+
cp -r "$PWD/$mpath/test/etc" "$PWD/$SHI_DST/test/etc"
35+
fi
36+
37+
if [ -f "$mpath/requirements.txt" ]
38+
then
39+
pip install -r "$mpath/requirements.txt"
40+
fi
41+
42+
ls -alH "$PWD/$SHI_DST/test/modules/$rmname"
1443
done
15-
# we need the livestatus test config files to be in shinken test config dir:
16-
cp -r ~/mod-livestatus/test/etc/* ~/shinken/test/etc/
1744
}
1845

1946
name=$(get_name)
2047

2148
pip install pycurl
2249
pip install coveralls
23-
git clone https://github.com/naparuba/shinken.git ~/shinken
2450

25-
[ -f test/dep_modules.txt ] && setup_submodule
26-
[ -f requirements.txt ] && pip install -r requirements.txt
27-
[ -f test/requirements.txt ] && pip install -r test/requirements.txt
51+
rm -rf test/tmp
52+
mkdir -p test/tmp/
53+
54+
git clone --depth 10 https://github.com/naparuba/shinken.git "$SHI_DST"
55+
( cd "$SHI_DST" && git status && git log -1)
56+
57+
spec_requirement="requirements-${py_version_short}.txt"
58+
59+
(
60+
cd "$SHI_DST"
61+
pip install -r test/requirements.txt
62+
if [ -f "test/${spec_requirement}" ]
63+
then
64+
pip install -r "test/${spec_requirement}"
65+
fi
66+
)
67+
68+
if [ -f test/dep_modules.txt ]
69+
then
70+
setup_submodule
71+
fi
2872

29-
# if we have test config files we probably also need them in the shinken/test directory :
30-
[ -d test/etc ] && cp -r test/etc ~/shinken/test/
73+
test_requirement="test/requirements.txt"
74+
if [ -f "$test_requirement" ]
75+
then
76+
pip install -r "$test_requirement"
77+
fi
78+
test_requirement="test/$spec_requirement"
79+
if [ -f "$test_requirement" ]
80+
then
81+
pip install -r "$test_requirement"
82+
fi
3183

32-
# copy our module package to the shinken modules directory:
33-
cp -r module ~/shinken/modules/$name
34-
# and make a link to it from the test/modules directory:
35-
ln -sf ~/shinken/modules/ ~/shinken/test/modules
84+
ln -s "$PWD/module" "$SHI_DST/test/modules/$name"

test/test_livestatus_mongodb.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def tearDownClass(cls):
141141
mp.wait()
142142
os.system('/bin/rm -rf %r' % cls._mongo_tmp_path)
143143

144-
145144
def tearDown(self):
146145
self.livestatus_broker.db.commit()
147146
self.livestatus_broker.db.close()
@@ -162,7 +161,6 @@ def tearDown(self):
162161
self.livestatus_broker = None
163162

164163

165-
166164
@mock_livestatus_handle_request
167165
class TestConfigSmall(TestConfig):
168166
def setUp(self):
@@ -549,9 +547,8 @@ def test_max_logs_age(self):
549547
self.assertEqual(7*365, livestatus_broker.max_logs_age)
550548

551549

552-
553550
if __name__ == '__main__':
554-
#import cProfile
551+
# import cProfile
555552
command = """unittest.main()"""
556553
unittest.main()
557-
#cProfile.runctx( command, globals(), locals(), filename="/tmp/livestatus.profile" )
554+
# cProfile.runctx( command, globals(), locals(), filename="/tmp/livestatus.profile" )

0 commit comments

Comments
 (0)