Skip to content

Commit

Permalink
Tests: pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
Grégory Starck committed Jan 28, 2015
1 parent d96edfe commit 790d565
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions test/test_livestatus_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def setUpClass(cls):
port = sock.getsockname()[1]
sock.close()
cls.mongo_db_uri = "mongodb://127.0.0.1:%s" % port
mongo_args = ['/usr/bin/mongod', '--dbpath', mongo_db, '--port',
str(port), '--logpath', mongo_log, '--smallfiles']
mp = cls._mongo_proc = subprocess.Popen(
(['/usr/bin/mongod', '--dbpath', mongo_db, '--port', str(port), '--logpath', mongo_log, '--smallfiles']),
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False
)
mongo_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)
print('Giving it some secs to correctly start..')
time_hacker.set_real_time()
# mongo takes some time to startup as it creates freshly new database files
Expand All @@ -109,7 +109,8 @@ def setUpClass(cls):
time.sleep(1)
mp.poll()
if mp.returncode is not None:
cls._read_mongolog_and_raise(mongo_log, mp, "Launched mongod but it's directly died")
cls._read_mongolog_and_raise(mongo_log, mp,
"Launched mongod but it's directly died")

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
errno = sock.connect_ex(('127.0.0.1', port))
Expand All @@ -118,8 +119,9 @@ def setUpClass(cls):
break
else:
mp.kill()
cls._read_mongolog_and_raise(mongo_log, mp,
"could not connect to port %s : mongod failed to correctly start?" % port)
cls._read_mongolog_and_raise(
mongo_log, mp,
"could not connect to port %s : mongod failed to correctly start?" % port)

time_hacker.set_my_time()

Expand Down Expand Up @@ -216,7 +218,9 @@ def test_one_log(self):
print("-------------------------------------------")

print("request logs from", int(now - 3600), int(now + 3600))
print("request logs from", time.asctime(time.localtime(int(now - 3600))), time.asctime(time.localtime(int(now + 3600))))
print("request logs from",
time.asctime(time.localtime(int(now - 3600))),
time.asctime(time.localtime(int(now + 3600))))
request = """GET log
Filter: time >= """ + str(int(now - 3600)) + """
Filter: time <= """ + str(int(now + 3600)) + """
Expand Down Expand Up @@ -269,11 +273,12 @@ def test_a_long_history(self):
# copied from test_livestatus_cache
test_host_005 = self.sched.hosts.find_by_name("test_host_005")
test_host_099 = self.sched.hosts.find_by_name("test_host_099")
test_ok_00 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_00")
test_ok_01 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_01")
test_ok_04 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_04")
test_ok_16 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_16")
test_ok_99 = self.sched.services.find_srv_by_name_and_hostname("test_host_099", "test_ok_01")
find = self.sched.services.find_srv_by_name_and_hostname
test_ok_00 = find("test_host_005", "test_ok_00")
test_ok_01 = find("test_host_005", "test_ok_01")
test_ok_04 = find("test_host_005", "test_ok_04")
test_ok_16 = find("test_host_005", "test_ok_16")
test_ok_99 = find("test_host_099", "test_ok_01")

days = 4
etime = time.time()
Expand Down Expand Up @@ -309,7 +314,8 @@ def test_a_long_history(self):
sys.stdout = open(os.devnull, "w")
should_be = 0
for day in xrange(days):
sys.stderr.write("day %d now it is %s i run %d loops\n" % (day, time.ctime(time.time()), loops))
sys.stderr.write("day %d now it is %s i run %d loops\n" % (
day, time.ctime(time.time()), loops))
self.scheduler_loop(2, [
[test_ok_00, 0, "OK"],
[test_ok_01, 0, "OK"],
Expand All @@ -330,7 +336,7 @@ def test_a_long_history(self):
[test_ok_16, 1, "WARN"],
[test_ok_99, 2, "CRIT"],
])
if int(time.time()) >= query_start and int(time.time()) <= query_end:
if query_start <= int(time.time()) <= query_end:
should_be += 3
sys.stderr.write("now it should be %s\n" % should_be)
time.sleep(62)
Expand All @@ -342,7 +348,7 @@ def test_a_long_history(self):
[test_ok_16, 0, "OK"],
[test_ok_99, 0, "OK"],
])
if int(time.time()) >= query_start and int(time.time()) <= query_end:
if query_start <= int(time.time()) <= query_end:
should_be += 1
sys.stderr.write("now it should be %s\n" % should_be)
time.sleep(2)
Expand Down Expand Up @@ -392,8 +398,12 @@ def test_a_long_history(self):

# now we have a lot of events
# find type = HOST ALERT for test_host_005
columns = (
"class time type state host_name service_description plugin_output message options "
"contact_name command_name state_type current_host_groups current_service_groups"
)
request = """GET log
Columns: class time type state host_name service_description plugin_output message options contact_name command_name state_type current_host_groups current_service_groups
Columns: """ + columns + """
Filter: time >= """ + str(int(query_start)) + """
Filter: time <= """ + str(int(query_end)) + """
Filter: type = SERVICE ALERT
Expand Down

0 comments on commit 790d565

Please sign in to comment.