test_usr1.py (1437:1990c369a0b9) test_usr1.py (1453:71af60a59338)
1import os
2import unittest
3from subprocess import call
4from unit.applications.lang.python import TestApplicationPython
5
6
7class TestUSR1(TestApplicationPython):
8 prerequisites = {'modules': ['python']}
9
10 def test_usr1_access_log(self):
11 self.load('empty')
12
13 log = 'access.log'
14 log_new = 'new.log'
15 log_path = self.testdir + '/' + log
16
17 self.assertIn(
18 'success',
19 self.conf('"' + log_path + '"', 'access_log'),
20 'access log configure',
21 )
22
23 self.assertTrue(self.waitforfiles(log_path), 'open')
24
25 os.rename(log_path, self.testdir + '/' + log_new)
26
27 self.assertEqual(self.get()['status'], 200)
28
29 self.assertIsNotNone(
30 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', log_new),
31 'rename new',
32 )
33 self.assertFalse(os.path.isfile(log_path), 'rename old')
34
35 with open(self.testdir + '/unit.pid', 'r') as f:
36 pid = f.read().rstrip()
37
38 call(['kill', '-s', 'USR1', pid])
39
40 self.assertTrue(self.waitforfiles(log_path), 'reopen')
41
42 self.assertEqual(self.get(url='/usr1')['status'], 200)
43
44 self.stop()
45
46 self.assertIsNotNone(
47 self.wait_for_record(r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"', log),
48 'reopen 2',
49 )
50 self.assertIsNone(
51 self.search_in_log(r'/usr1', log_new), 'rename new 2'
52 )
53
54 def test_usr1_unit_log(self):
55 self.load('log_body')
56
57 log_new = 'new.log'
1import os
2import unittest
3from subprocess import call
4from unit.applications.lang.python import TestApplicationPython
5
6
7class TestUSR1(TestApplicationPython):
8 prerequisites = {'modules': ['python']}
9
10 def test_usr1_access_log(self):
11 self.load('empty')
12
13 log = 'access.log'
14 log_new = 'new.log'
15 log_path = self.testdir + '/' + log
16
17 self.assertIn(
18 'success',
19 self.conf('"' + log_path + '"', 'access_log'),
20 'access log configure',
21 )
22
23 self.assertTrue(self.waitforfiles(log_path), 'open')
24
25 os.rename(log_path, self.testdir + '/' + log_new)
26
27 self.assertEqual(self.get()['status'], 200)
28
29 self.assertIsNotNone(
30 self.wait_for_record(r'"GET / HTTP/1.1" 200 0 "-" "-"', log_new),
31 'rename new',
32 )
33 self.assertFalse(os.path.isfile(log_path), 'rename old')
34
35 with open(self.testdir + '/unit.pid', 'r') as f:
36 pid = f.read().rstrip()
37
38 call(['kill', '-s', 'USR1', pid])
39
40 self.assertTrue(self.waitforfiles(log_path), 'reopen')
41
42 self.assertEqual(self.get(url='/usr1')['status'], 200)
43
44 self.stop()
45
46 self.assertIsNotNone(
47 self.wait_for_record(r'"GET /usr1 HTTP/1.1" 200 0 "-" "-"', log),
48 'reopen 2',
49 )
50 self.assertIsNone(
51 self.search_in_log(r'/usr1', log_new), 'rename new 2'
52 )
53
54 def test_usr1_unit_log(self):
55 self.load('log_body')
56
57 log_new = 'new.log'
58 log_path = self.testdir + '/' + 'unit.log'
58 log_path = self.testdir + '/unit.log'
59 log_path_new = self.testdir + '/' + log_new
60
61 os.rename(log_path, log_path_new)
62
63 body = 'body_for_a_log_new'
64 self.assertEqual(self.post(body=body)['status'], 200)
65
66 self.assertIsNotNone(
67 self.wait_for_record(body, log_new), 'rename new'
68 )
69 self.assertFalse(os.path.isfile(log_path), 'rename old')
70
71 with open(self.testdir + '/unit.pid', 'r') as f:
72 pid = f.read().rstrip()
73
74 call(['kill', '-s', 'USR1', pid])
75
76 self.assertTrue(self.waitforfiles(log_path), 'reopen')
77
78 body = 'body_for_a_log_unit'
79 self.assertEqual(self.post(body=body)['status'], 200)
80
81 self.stop()
82
83 self.assertIsNotNone(self.wait_for_record(body), 'rename new')
84 self.assertIsNone(self.search_in_log(body, log_new), 'rename new 2')
85
86 # merge two log files into unit.log to check alerts
87
88 with open(log_path, 'w') as unit_log, \
89 open(log_path_new, 'r') as unit_log_new:
90 unit_log.write(unit_log_new.read())
91
92
93if __name__ == '__main__':
94 TestUSR1.main()
59 log_path_new = self.testdir + '/' + log_new
60
61 os.rename(log_path, log_path_new)
62
63 body = 'body_for_a_log_new'
64 self.assertEqual(self.post(body=body)['status'], 200)
65
66 self.assertIsNotNone(
67 self.wait_for_record(body, log_new), 'rename new'
68 )
69 self.assertFalse(os.path.isfile(log_path), 'rename old')
70
71 with open(self.testdir + '/unit.pid', 'r') as f:
72 pid = f.read().rstrip()
73
74 call(['kill', '-s', 'USR1', pid])
75
76 self.assertTrue(self.waitforfiles(log_path), 'reopen')
77
78 body = 'body_for_a_log_unit'
79 self.assertEqual(self.post(body=body)['status'], 200)
80
81 self.stop()
82
83 self.assertIsNotNone(self.wait_for_record(body), 'rename new')
84 self.assertIsNone(self.search_in_log(body, log_new), 'rename new 2')
85
86 # merge two log files into unit.log to check alerts
87
88 with open(log_path, 'w') as unit_log, \
89 open(log_path_new, 'r') as unit_log_new:
90 unit_log.write(unit_log_new.read())
91
92
93if __name__ == '__main__':
94 TestUSR1.main()