83 lines
2.7 KiB
Python
Raw Normal View History

2015-05-19 14:05:20 -07:00
from mock import MagicMock
from collections import OrderedDict
import charmhelpers.contrib.openstack.templating as templating
templating.OSConfigRenderer = MagicMock()
import pg_dir_utils as nutils
from test_utils import (
CharmTestCase,
)
import charmhelpers.core.hookenv as hookenv
TO_PATCH = [
'os_release',
'neutron_plugin_attribute',
]
class DummyContext():
def __init__(self, return_value):
self.return_value = return_value
def __call__(self):
return self.return_value
class TestPGDirUtils(CharmTestCase):
def setUp(self):
super(TestPGDirUtils, self).setUp(nutils, TO_PATCH)
#self.config.side_effect = self.test_config.get
def tearDown(self):
# Reset cached cache
hookenv.cache = {}
def test_register_configs(self):
class _mock_OSConfigRenderer():
def __init__(self, templates_dir=None, openstack_release=None):
self.configs = []
self.ctxts = []
def register(self, config, ctxt):
self.configs.append(config)
self.ctxts.append(ctxt)
self.os_release.return_value = 'trusty'
templating.OSConfigRenderer.side_effect = _mock_OSConfigRenderer
_regconfs = nutils.register_configs()
2015-08-09 08:43:08 -07:00
confs = ['/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/keepalived.conf',
'/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/plumgrid.conf',
'/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/nginx.conf',
2015-05-19 14:05:20 -07:00
'/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hostname',
'/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hosts',
'/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/ifcs.conf']
self.assertItemsEqual(_regconfs.configs, confs)
def test_resource_map(self):
_map = nutils.resource_map()
svcs = ['plumgrid']
2015-08-09 08:43:08 -07:00
confs = [nutils.PG_KA_CONF]
2015-05-19 14:05:20 -07:00
[self.assertIn(q_conf, _map.keys()) for q_conf in confs]
2015-08-09 08:43:08 -07:00
self.assertEqual(_map[nutils.PG_KA_CONF]['services'], svcs)
2015-05-19 14:05:20 -07:00
def test_restart_map(self):
_restart_map = nutils.restart_map()
2015-08-09 08:43:08 -07:00
PG_KA_CONF = '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/keepalived.conf'
2015-05-19 14:05:20 -07:00
expect = OrderedDict([
(nutils.PG_CONF, ['plumgrid']),
2015-08-09 08:43:08 -07:00
(PG_KA_CONF, ['plumgrid']),
(nutils.PG_DEF_CONF, ['plumgrid']),
(nutils.PG_HN_CONF, ['plumgrid']),
(nutils.PG_HS_CONF, ['plumgrid']),
(nutils.PG_IFCS_CONF, []),
2015-05-19 14:05:20 -07:00
])
self.assertEqual(expect, _restart_map)
for item in _restart_map:
self.assertTrue(item in _restart_map)
self.assertTrue(expect[item] == _restart_map[item])