~bbaqar/charms/trusty/plumgrid-edge/charmstore

« back to all changes in this revision

Viewing changes to unit_tests/test_pg_edge_hooks.py

  • Committer: bbaqar at plumgrid
  • Date: 2015-05-19 21:06:18 UTC
  • Revision ID: bbaqar@plumgrid.com-20150519210618-lfe60xds38e9fyy8
PLUMgrid edge initial charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mock import MagicMock, patch
 
2
 
 
3
 
 
4
from test_utils import CharmTestCase
 
5
 
 
6
with patch('charmhelpers.core.hookenv.config') as config:
 
7
    config.return_value = 'neutron'
 
8
    import pg_edge_utils as utils
 
9
 
 
10
_reg = utils.register_configs
 
11
_map = utils.restart_map
 
12
 
 
13
utils.register_configs = MagicMock()
 
14
utils.restart_map = MagicMock()
 
15
 
 
16
import pg_edge_hooks as hooks
 
17
 
 
18
utils.register_configs = _reg
 
19
utils.restart_map = _map
 
20
 
 
21
TO_PATCH = [
 
22
    #'apt_update',
 
23
    #'apt_install',
 
24
    #'apt_purge',
 
25
    #'config',
 
26
    'CONFIGS',
 
27
    #'determine_packages',
 
28
    #'determine_dvr_packages',
 
29
    #'get_shared_secret',
 
30
    #'git_install',
 
31
    'log',
 
32
    #'relation_ids',
 
33
    #'relation_set',
 
34
    #'configure_ovs',
 
35
    #'use_dvr',
 
36
    'ensure_files',
 
37
    'stop_pg',
 
38
    'restart_pg',
 
39
]
 
40
NEUTRON_CONF_DIR = "/etc/neutron"
 
41
 
 
42
NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
 
43
 
 
44
 
 
45
class PGEdgeHooksTests(CharmTestCase):
 
46
 
 
47
    def setUp(self):
 
48
        super(PGEdgeHooksTests, self).setUp(hooks, TO_PATCH)
 
49
 
 
50
        #self.config.side_effect = self.test_config.get
 
51
        hooks.hooks._config_save = False
 
52
 
 
53
    def _call_hook(self, hookname):
 
54
        hooks.hooks.execute([
 
55
            'hooks/{}'.format(hookname)])
 
56
 
 
57
    def test_install_hook(self):
 
58
        self._call_hook('install')
 
59
        self.ensure_files.assert_called_with()
 
60
 
 
61
    def test_plumgrid_edge_joined(self):
 
62
        self._call_hook('plumgrid-plugin-relation-joined')
 
63
        self.ensure_files.assert_called_with()
 
64
        self.CONFIGS.write_all.assert_called_with()
 
65
        self.restart_pg.assert_called_with()
 
66
 
 
67
    def test_stop(self):
 
68
        self._call_hook('stop')
 
69
        self.stop_pg.assert_called_with()