Juju Charm - PLUMgrid Gateway
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_pg_gw_hooks.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from mock import MagicMock, patch, call
  2. from test_utils import CharmTestCase
  3. with patch('charmhelpers.core.hookenv.config') as config:
  4. config.return_value = 'neutron'
  5. import pg_gw_utils as utils
  6. _reg = utils.register_configs
  7. _map = utils.restart_map
  8. utils.register_configs = MagicMock()
  9. utils.restart_map = MagicMock()
  10. import pg_gw_hooks as hooks
  11. utils.register_configs = _reg
  12. utils.restart_map = _map
  13. TO_PATCH = [
  14. 'remove_iovisor',
  15. 'apt_install',
  16. 'CONFIGS',
  17. 'log',
  18. 'configure_sources',
  19. 'ensure_files',
  20. 'stop_pg',
  21. 'load_iovisor',
  22. 'ensure_mtu',
  23. 'add_lcm_key',
  24. 'determine_packages',
  25. 'load_iptables',
  26. 'director_cluster_ready',
  27. 'status_set'
  28. ]
  29. NEUTRON_CONF_DIR = "/etc/neutron"
  30. NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
  31. class PGGwHooksTests(CharmTestCase):
  32. def setUp(self):
  33. super(PGGwHooksTests, self).setUp(hooks, TO_PATCH)
  34. # self.config.side_effect = self.test_config.get
  35. hooks.hooks._config_save = False
  36. def _call_hook(self, hookname):
  37. hooks.hooks.execute([
  38. 'hooks/{}'.format(hookname)])
  39. def test_install_hook(self):
  40. _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
  41. self.determine_packages.return_value = [_pkgs]
  42. self._call_hook('install')
  43. self.configure_sources.assert_called_with(update=True)
  44. self.apt_install.assert_has_calls([
  45. call(_pkgs, fatal=True,
  46. options=['--force-yes']),
  47. ])
  48. self.load_iovisor.assert_called_with()
  49. self.ensure_mtu.assert_called_with()
  50. self.ensure_files.assert_called_with()
  51. self.add_lcm_key.assert_called_with()
  52. def test_plumgrid_changed(self):
  53. self._call_hook('plumgrid-relation-changed')
  54. self.director_cluster_ready.return_value = True
  55. self.ensure_mtu.assert_called_with()
  56. self.CONFIGS.write_all.assert_called_with()
  57. def test_stop(self):
  58. self._call_hook('stop')
  59. self.stop_pg.assert_called_with()