~bbaqar/charms/trusty/plumgrid-director/config-changed-fix

« back to all changes in this revision

Viewing changes to unit_tests/test_pg_dir_hooks.py

  • Committer: bbaqar at plumgrid
  • Date: 2015-07-29 18:12:25 UTC
  • Revision ID: bbaqar@plumgrid.com-20150729181225-anngkkxc18tlow63
Updated unit tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from mock import MagicMock, patch
2
 
 
3
 
 
 
1
from mock import MagicMock, patch, call
4
2
from test_utils import CharmTestCase
5
 
 
6
3
with patch('charmhelpers.core.hookenv.config') as config:
7
4
    config.return_value = 'neutron'
8
5
    import pg_dir_utils as utils
19
16
utils.restart_map = _map
20
17
 
21
18
TO_PATCH = [
22
 
    #'apt_update',
23
 
    #'apt_install',
24
 
    #'apt_purge',
25
 
    'config',
 
19
    'remove_iovisor',
 
20
    'apt_install',
 
21
    'apt_purge',
26
22
    'CONFIGS',
27
 
    #'determine_packages',
28
 
    #'determine_dvr_packages',
29
 
    #'get_shared_secret',
30
 
    #'git_install',
31
23
    'log',
32
 
    #'relation_ids',
33
 
    'relation_set',
34
 
    #'configure_ovs',
35
 
    #'use_dvr',
 
24
    'configure_sources',
36
25
    'ensure_files',
37
26
    'stop_pg',
38
27
    'restart_pg',
 
28
    'load_iovisor',
 
29
    'ensure_mtu',
 
30
    'add_lcm_key',
 
31
    'determine_packages',
39
32
]
40
33
NEUTRON_CONF_DIR = "/etc/neutron"
41
34
 
46
39
 
47
40
    def setUp(self):
48
41
        super(PGDirHooksTests, self).setUp(hooks, TO_PATCH)
49
 
 
50
 
        self.config.side_effect = self.test_config.get
51
42
        hooks.hooks._config_save = False
52
43
 
53
44
    def _call_hook(self, hookname):
55
46
            'hooks/{}'.format(hookname)])
56
47
 
57
48
    def test_install_hook(self):
 
49
        _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
 
50
        self.determine_packages.return_value = [_pkgs]
58
51
        self._call_hook('install')
59
 
        self.ensure_files.assert_called_with()
60
 
 
61
 
    def test_plumgrid_edge_joined(self):
 
52
        self.configure_sources.assert_called_with(update=True)
 
53
        self.apt_install.assert_has_calls([
 
54
            call(_pkgs, fatal=True,
 
55
                 options=['--force-yes',
 
56
                          '--option=Dpkg::Options::=--force-confold']),
 
57
        ])
 
58
        self.load_iovisor.assert_called_with()
 
59
        self.ensure_mtu.assert_called_with()
 
60
        self.ensure_files.assert_called_with()
 
61
        self.add_lcm_key.assert_called_with()
 
62
 
 
63
    def test_config_changed_hook(self):
 
64
        _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
 
65
        self.determine_packages.return_value = [_pkgs]
 
66
        self._call_hook('config-changed')
 
67
        self.stop_pg.assert_called_with()
 
68
        self.configure_sources.assert_called_with(update=True)
 
69
        self.apt_install.assert_has_calls([
 
70
            call(_pkgs, fatal=True,
 
71
                 options=['--force-yes',
 
72
                          '--option=Dpkg::Options::=--force-confold']),
 
73
        ])
 
74
        self.load_iovisor.assert_called_with()
 
75
        self.ensure_mtu.assert_called_with()
 
76
        self.ensure_files.assert_called_with()
 
77
        self.add_lcm_key.assert_called_with()
 
78
        self.CONFIGS.write_all.assert_called_with()
 
79
        self.restart_pg.assert_called_with()
 
80
 
 
81
    def test_neutron_joined(self):
62
82
        self._call_hook('plumgrid-plugin-relation-joined')
 
83
        self.ensure_mtu.assert_called_with()
63
84
        self.ensure_files.assert_called_with()
 
85
        self.add_lcm_key.assert_called_with()
64
86
        self.CONFIGS.write_all.assert_called_with()
65
87
        self.restart_pg.assert_called_with()
66
88
 
67
 
    def test_plumgrid_joined(self):
68
 
        relation_data = {
69
 
            'pg_virtual_ip': '192.168.100.250',
70
 
        }
71
 
        self._call_hook('plumgrid-relation-joined')
72
 
        self.relation_set.assert_called_with(relation_id=None, **relation_data)
73
 
 
74
89
    def test_stop(self):
 
90
        _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
75
91
        self._call_hook('stop')
76
92
        self.stop_pg.assert_called_with()
 
93
        self.remove_iovisor.assert_called_with()
 
94
        self.determine_packages.return_value = _pkgs