71 lines
1.8 KiB
Python
Raw Normal View History

2015-07-29 11:12:25 -07:00
from mock import MagicMock, patch, call
2016-03-03 12:56:40 -08:00
2015-05-19 14:05:20 -07:00
from test_utils import CharmTestCase
2016-03-03 12:56:40 -08:00
2015-05-19 14:05:20 -07:00
with patch('charmhelpers.core.hookenv.config') as config:
config.return_value = 'neutron'
import pg_dir_utils as utils
_reg = utils.register_configs
_map = utils.restart_map
utils.register_configs = MagicMock()
utils.restart_map = MagicMock()
import pg_dir_hooks as hooks
utils.register_configs = _reg
utils.restart_map = _map
TO_PATCH = [
2015-07-29 11:12:25 -07:00
'remove_iovisor',
'apt_install',
2015-05-19 14:05:20 -07:00
'CONFIGS',
'log',
2015-07-29 11:12:25 -07:00
'configure_sources',
2015-05-19 14:05:20 -07:00
'stop_pg',
'restart_pg',
2015-07-29 11:12:25 -07:00
'load_iovisor',
'ensure_mtu',
'add_lcm_key',
'determine_packages',
2015-08-24 09:18:48 -07:00
'post_pg_license',
'config',
'load_iptables'
2015-05-19 14:05:20 -07:00
]
NEUTRON_CONF_DIR = "/etc/neutron"
NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
class PGDirHooksTests(CharmTestCase):
def setUp(self):
super(PGDirHooksTests, self).setUp(hooks, TO_PATCH)
2015-08-24 09:18:48 -07:00
self.config.side_effect = self.test_config.get
2015-05-19 14:05:20 -07:00
hooks.hooks._config_save = False
def _call_hook(self, hookname):
hooks.hooks.execute([
'hooks/{}'.format(hookname)])
def test_install_hook(self):
2015-07-29 11:12:25 -07:00
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
self.determine_packages.return_value = [_pkgs]
2015-05-19 14:05:20 -07:00
self._call_hook('install')
2015-07-29 11:12:25 -07:00
self.configure_sources.assert_called_with(update=True)
self.apt_install.assert_has_calls([
call(_pkgs, fatal=True,
2015-08-09 08:43:08 -07:00
options=['--force-yes']),
2015-07-29 11:12:25 -07:00
])
self.load_iovisor.assert_called_with()
self.ensure_mtu.assert_called_with()
2015-05-19 14:05:20 -07:00
2015-08-24 09:18:48 -07:00
def test_start(self):
self._call_hook('start')
self.test_config.set('plumgrid-license-key', None)
2015-05-19 14:05:20 -07:00
def test_stop(self):
self._call_hook('stop')
self.stop_pg.assert_called_with()