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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. 'configure_analyst_opsvm'
  29. ]
  30. NEUTRON_CONF_DIR = "/etc/neutron"
  31. NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
  32. class PGGwHooksTests(CharmTestCase):
  33. def setUp(self):
  34. super(PGGwHooksTests, self).setUp(hooks, TO_PATCH)
  35. # self.config.side_effect = self.test_config.get
  36. hooks.hooks._config_save = False
  37. def _call_hook(self, hookname):
  38. hooks.hooks.execute([
  39. 'hooks/{}'.format(hookname)])
  40. def test_install_hook(self):
  41. _pkgs = ['plumgrid-lxc', 'iovisor-dkms']
  42. self.determine_packages.return_value = [_pkgs]
  43. self._call_hook('install')
  44. self.configure_sources.assert_called_with(update=True)
  45. self.apt_install.assert_has_calls([
  46. call(_pkgs, fatal=True,
  47. options=['--force-yes']),
  48. ])
  49. self.load_iovisor.assert_called_with()
  50. self.ensure_mtu.assert_called_with()
  51. self.ensure_files.assert_called_with()
  52. self.add_lcm_key.assert_called_with()
  53. def test_plumgrid_changed(self):
  54. self._call_hook('plumgrid-relation-changed')
  55. self.director_cluster_ready.return_value = True
  56. self.ensure_mtu.assert_called_with()
  57. self.CONFIGS.write_all.assert_called_with()
  58. def test_stop(self):
  59. self._call_hook('stop')
  60. self.stop_pg.assert_called_with()