~charmers/charms/trusty/plumgrid-gateway/trunk

« back to all changes in this revision

Viewing changes to unit_tests/test_pg_gw_utils.py

  • Committer: bbaqar at plumgrid
  • Date: 2015-05-19 21:07:07 UTC
  • Revision ID: bbaqar@plumgrid.com-20150519210707-r02016etu0kbmhmo
PLUMgrid gateway initial charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mock import MagicMock
 
2
from collections import OrderedDict
 
3
import charmhelpers.contrib.openstack.templating as templating
 
4
 
 
5
templating.OSConfigRenderer = MagicMock()
 
6
 
 
7
import pg_gw_utils as nutils
 
8
 
 
9
from test_utils import (
 
10
    CharmTestCase,
 
11
)
 
12
import charmhelpers.core.hookenv as hookenv
 
13
 
 
14
 
 
15
TO_PATCH = [
 
16
    'os_release',
 
17
    'neutron_plugin_attribute',
 
18
]
 
19
 
 
20
 
 
21
class DummyContext():
 
22
 
 
23
    def __init__(self, return_value):
 
24
        self.return_value = return_value
 
25
 
 
26
    def __call__(self):
 
27
        return self.return_value
 
28
 
 
29
 
 
30
class TestPGGwUtils(CharmTestCase):
 
31
 
 
32
    def setUp(self):
 
33
        super(TestPGGwUtils, self).setUp(nutils, TO_PATCH)
 
34
        #self.config.side_effect = self.test_config.get
 
35
 
 
36
    def tearDown(self):
 
37
        # Reset cached cache
 
38
        hookenv.cache = {}
 
39
 
 
40
    def test_register_configs(self):
 
41
        class _mock_OSConfigRenderer():
 
42
            def __init__(self, templates_dir=None, openstack_release=None):
 
43
                self.configs = []
 
44
                self.ctxts = []
 
45
 
 
46
            def register(self, config, ctxt):
 
47
                self.configs.append(config)
 
48
                self.ctxts.append(ctxt)
 
49
 
 
50
        self.os_release.return_value = 'trusty'
 
51
        templating.OSConfigRenderer.side_effect = _mock_OSConfigRenderer
 
52
        _regconfs = nutils.register_configs()
 
53
        confs = ['/var/lib/libvirt/filesystems/plumgrid/opt/pg/etc/plumgrid.conf',
 
54
                 '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hostname',
 
55
                 '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hosts',
 
56
                 '/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/ifcs.conf',
 
57
                 '/etc/nova/rootwrap.d/network.filters']
 
58
        self.assertItemsEqual(_regconfs.configs, confs)
 
59
 
 
60
    def test_resource_map(self):
 
61
        _map = nutils.resource_map()
 
62
        svcs = ['plumgrid']
 
63
        confs = [nutils.PG_CONF]
 
64
        [self.assertIn(q_conf, _map.keys()) for q_conf in confs]
 
65
        self.assertEqual(_map[nutils.PG_CONF]['services'], svcs)
 
66
 
 
67
    def test_restart_map(self):
 
68
        _restart_map = nutils.restart_map()
 
69
        expect = OrderedDict([
 
70
            (nutils.PG_CONF, ['plumgrid']),
 
71
            (nutils.PGHN_CONF, ['plumgrid']),
 
72
            (nutils.PGHS_CONF, ['plumgrid']),
 
73
            (nutils.PGIFCS_CONF, []),
 
74
            (nutils.FILTERS_CONF, []),
 
75
        ])
 
76
        self.assertEqual(expect, _restart_map)
 
77
        for item in _restart_map:
 
78
            self.assertTrue(item in _restart_map)
 
79
            self.assertTrue(expect[item] == _restart_map[item])