-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.py
103 lines (77 loc) · 3.87 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
from hamcrest import *
from amplify.agent.common.context import context
from amplify.agent.managers.nginx import NginxManager
from test.base import RealNginxTestCase
__author__ = "Mike Belov"
__copyright__ = "Copyright (C) Nginx, Inc. All rights reserved."
__credits__ = ["Mike Belov", "Andrei Belov", "Ivan Poluyanov", "Oleg Mamontov", "Andrew Alexeev"]
__license__ = ""
__maintainer__ = "Mike Belov"
__email__ = "dedm@nginx.com"
class ConfigCollectorTestCase(RealNginxTestCase):
def setup_method(self, method):
super(ConfigCollectorTestCase, self).setup_method(method)
self.max_test_time = context.app_config['containers']['nginx']['max_test_duration']
def teardown_method(self, method):
context.app_config['containers']['nginx']['max_test_duration'] = self.max_test_time
super(ConfigCollectorTestCase, self).teardown_method(method)
def test_collect(self):
container = NginxManager()
container._discover_objects()
nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
collectors = nginx_obj.collectors
cfg_collector = collectors[2]
# run collect
cfg_collector.collect()
assert_that(nginx_obj.configd.current, not_(equal_to({})))
def test_test_run_time(self):
container = NginxManager()
container._discover_objects()
nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
collectors = nginx_obj.collectors
cfg_collector = collectors[2]
assert_that(nginx_obj.run_config_test, equal_to(True))
# set maximum run time for test to 0.0
context.app_config['containers']['nginx']['max_test_duration'] = 0.0
# run collect
cfg_collector.collect()
assert_that(nginx_obj.run_config_test, equal_to(False))
events = nginx_obj.eventd.current.values()
messages = []
for event in events:
messages.append(event.message)
assert_that(messages, has_item(starts_with('/usr/sbin/nginx -t -c /etc/nginx/nginx.conf took')))
class ConfigCollectorSSLTestCase(RealNginxTestCase):
def setup_method(self, method):
super(ConfigCollectorSSLTestCase, self).setup_method(method)
self.original_upload_ssl = context.app_config['containers']['nginx']['upload_ssl']
def teardown_method(self, method):
context.app_config['containers']['nginx']['upload_ssl'] = self.original_upload_ssl
super(ConfigCollectorSSLTestCase, self).teardown_method(method)
def test_ssl_config_works_if_ssl_enabled(self):
# set upload_ssl to True
context.app_config['containers']['nginx']['upload_ssl'] = True
container = NginxManager()
container._discover_objects()
assert_that(container.objects.objects_by_type[container.type], has_length(1))
# get nginx object
nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
collectors = nginx_obj.collectors
cfg_collector = collectors[2]
cfg_collector.collect()
config = nginx_obj.configd.current
assert_that(config['data']['ssl_certificates'], has_length(1))
def test_ssl_config_doesnt_work_if_ssl_disabled(self):
# set upload_ssl to True
context.app_config['containers']['nginx']['upload_ssl'] = False
container = NginxManager()
container._discover_objects()
assert_that(container.objects.objects_by_type[container.type], has_length(1))
# get nginx object
nginx_obj = container.objects.objects[container.objects.objects_by_type[container.type][0]]
collectors = nginx_obj.collectors
cfg_collector = collectors[2]
cfg_collector.collect()
config = nginx_obj.configd.current
assert_that(config['data']['ssl_certificates'], has_length(0))