Updated unit tests
This commit is contained in:
parent
23cc070ac4
commit
e625d03935
|
@ -1,8 +1,5 @@
|
|||
from mock import MagicMock, patch
|
||||
|
||||
|
||||
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_dir_utils as utils
|
||||
|
@ -19,23 +16,19 @@ utils.register_configs = _reg
|
|||
utils.restart_map = _map
|
||||
|
||||
TO_PATCH = [
|
||||
#'apt_update',
|
||||
#'apt_install',
|
||||
#'apt_purge',
|
||||
'config',
|
||||
'remove_iovisor',
|
||||
'apt_install',
|
||||
'apt_purge',
|
||||
'CONFIGS',
|
||||
#'determine_packages',
|
||||
#'determine_dvr_packages',
|
||||
#'get_shared_secret',
|
||||
#'git_install',
|
||||
'log',
|
||||
#'relation_ids',
|
||||
'relation_set',
|
||||
#'configure_ovs',
|
||||
#'use_dvr',
|
||||
'configure_sources',
|
||||
'ensure_files',
|
||||
'stop_pg',
|
||||
'restart_pg',
|
||||
'load_iovisor',
|
||||
'ensure_mtu',
|
||||
'add_lcm_key',
|
||||
'determine_packages',
|
||||
]
|
||||
NEUTRON_CONF_DIR = "/etc/neutron"
|
||||
|
||||
|
@ -46,8 +39,6 @@ class PGDirHooksTests(CharmTestCase):
|
|||
|
||||
def setUp(self):
|
||||
super(PGDirHooksTests, self).setUp(hooks, TO_PATCH)
|
||||
|
||||
self.config.side_effect = self.test_config.get
|
||||
hooks.hooks._config_save = False
|
||||
|
||||
def _call_hook(self, hookname):
|
||||
|
@ -55,22 +46,49 @@ class PGDirHooksTests(CharmTestCase):
|
|||
'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',
|
||||
'--option=Dpkg::Options::=--force-confold']),
|
||||
])
|
||||
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_edge_joined(self):
|
||||
self._call_hook('plumgrid-plugin-relation-joined')
|
||||
def test_config_changed_hook(self):
|
||||
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
||||
self.determine_packages.return_value = [_pkgs]
|
||||
self._call_hook('config-changed')
|
||||
self.stop_pg.assert_called_with()
|
||||
self.configure_sources.assert_called_with(update=True)
|
||||
self.apt_install.assert_has_calls([
|
||||
call(_pkgs, fatal=True,
|
||||
options=['--force-yes',
|
||||
'--option=Dpkg::Options::=--force-confold']),
|
||||
])
|
||||
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()
|
||||
self.CONFIGS.write_all.assert_called_with()
|
||||
self.restart_pg.assert_called_with()
|
||||
|
||||
def test_plumgrid_joined(self):
|
||||
relation_data = {
|
||||
'pg_virtual_ip': '192.168.100.250',
|
||||
}
|
||||
self._call_hook('plumgrid-relation-joined')
|
||||
self.relation_set.assert_called_with(relation_id=None, **relation_data)
|
||||
def test_neutron_joined(self):
|
||||
self._call_hook('plumgrid-plugin-relation-joined')
|
||||
self.ensure_mtu.assert_called_with()
|
||||
self.ensure_files.assert_called_with()
|
||||
self.add_lcm_key.assert_called_with()
|
||||
self.CONFIGS.write_all.assert_called_with()
|
||||
self.restart_pg.assert_called_with()
|
||||
|
||||
def test_stop(self):
|
||||
_pkgs = ['plumgrid-lxc', 'iovisor-dkms']
|
||||
self._call_hook('stop')
|
||||
self.stop_pg.assert_called_with()
|
||||
self.remove_iovisor.assert_called_with()
|
||||
self.determine_packages.return_value = _pkgs
|
||||
|
|
Loading…
Reference in New Issue