~ubuntuone-pqm-team/charm-haproxy/snap-store

« back to all changes in this revision

Viewing changes to hooks/tests/test_config_changed_hooks.py

[verterok, r=admcleod, a=kwmonroe] restart rsyslog if haproxy config changes; minor updates to tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import os
4
4
 
5
5
from testtools import TestCase
6
 
from mock import patch
 
6
from mock import patch, call
7
7
 
8
8
import hooks
9
9
from utils_for_tests import patch_open
92
92
        config_data = self.config_get()
93
93
        config_data.changed.return_value = True
94
94
        _notify_reverseproxy = self.patch_hook("_notify_reverseproxy")
95
 
 
96
 
        hooks.config_changed()
97
 
        config_data.changed.assert_called_once_with("ssl_cert")
98
 
        _notify_reverseproxy.assert_called_once()
 
95
        service_restart = self.patch_hook('service_restart')
 
96
 
 
97
        hooks.config_changed()
 
98
        self.assertIn(call('ssl_cert'), config_data.changed.mock_calls)
 
99
        _notify_reverseproxy.assert_called_once_with()
 
100
        service_restart.assert_called_once_with('rsyslog')
 
101
 
 
102
    def test_config_changed_restart_rsyslog(self):
 
103
        """
 
104
        If the gloabl_log or source config value changes, rsyslog is
 
105
        restarted
 
106
        """
 
107
        config_data = self.config_get()
 
108
        called = []
 
109
 
 
110
        def changed(a):
 
111
            if a in called or a == 'ssl_cert':
 
112
                return False
 
113
            called.append(a)
 
114
            return True
 
115
 
 
116
        config_data.changed.side_effect = changed
 
117
        service_restart = self.patch_hook('service_restart')
 
118
 
 
119
        hooks.config_changed()
 
120
        self.assertIn(call('global_log'), config_data.changed.mock_calls)
 
121
        service_restart.assert_called_once_with('rsyslog')
 
122
        hooks.config_changed()
 
123
        self.assertIn(call('source'), config_data.changed.mock_calls)
 
124
        service_restart.assert_called_with('rsyslog')
99
125
 
100
126
 
101
127
class HelpersTest(TestCase):