summaryrefslogtreecommitdiff
path: root/unit_tests/test_pg_gw_hooks.py
blob: 194d0c0a054be302b78bf32fdb49fcd1eb6ca91e (plain)
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
from mock import MagicMock, patch, call
from test_utils import CharmTestCase

with patch('charmhelpers.core.hookenv.config') as config:
    config.return_value = 'neutron'
    import pg_gw_utils as utils

_reg = utils.register_configs
_map = utils.restart_map

utils.register_configs = MagicMock()
utils.restart_map = MagicMock()

import pg_gw_hooks as hooks

utils.register_configs = _reg
utils.restart_map = _map

TO_PATCH = [
    'remove_iovisor',
    'apt_install',
    'CONFIGS',
    'log',
    'configure_sources',
    'ensure_files',
    'stop_pg',
    'load_iovisor',
    'ensure_mtu',
    'add_lcm_key',
    'determine_packages',
    'load_iptables',
    'director_cluster_ready',
    'status_set'
]
NEUTRON_CONF_DIR = "/etc/neutron"

NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR


class PGGwHooksTests(CharmTestCase):

    def setUp(self):
        super(PGGwHooksTests, self).setUp(hooks, TO_PATCH)
        # self.config.side_effect = self.test_config.get
        hooks.hooks._config_save = False

    def _call_hook(self, hookname):
        hooks.hooks.execute([
            'hooks/{}'.format(hookname)])

    def test_install_hook(self):
        _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
        self.determine_packages.return_value = [_pkgs]
        self._call_hook('install')
        self.configure_sources.assert_called_with(update=True)
        self.apt_install.assert_has_calls([
            call(_pkgs, fatal=True,
                 options=['--force-yes']),
        ])
        self.load_iovisor.assert_called_with()
        self.ensure_mtu.assert_called_with()
        self.ensure_files.assert_called_with()
        self.add_lcm_key.assert_called_with()

    def test_plumgrid_changed(self):
        self._call_hook('plumgrid-relation-changed')
        self.director_cluster_ready.return_value = True
        self.ensure_mtu.assert_called_with()
        self.CONFIGS.write_all.assert_called_with()

    def test_stop(self):
        self._call_hook('stop')
        self.stop_pg.assert_called_with()