diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py index 5e1f772..e25770d 100755 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -21,13 +21,13 @@ from charmhelpers.core.hookenv import ( from charmhelpers.fetch import ( apt_install, - apt_purge, configure_sources, ) from pg_dir_utils import ( register_configs, restart_pg, + restart_map, stop_pg, determine_packages, load_iovisor, @@ -37,7 +37,8 @@ from pg_dir_utils import ( post_pg_license, fabric_interface_changed, load_iptables, - restart_on_change + restart_on_change, + director_cluster_ready ) hooks = Hooks() @@ -60,12 +61,14 @@ def install(): @hooks.hook('director-relation-joined') +@restart_on_change(restart_map()) def dir_joined(): ''' This hook is run when a unit of director is added. ''' - CONFIGS.write_all() - restart_pg() + if director_cluster_ready(): + ensure_mtu() + CONFIGS.write_all() @hooks.hook('plumgrid-relation-joined') @@ -154,10 +157,6 @@ def stop(): This hook is run when the charm is destroyed. ''' stop_pg() - remove_iovisor() - pkgs = determine_packages() - for pkg in pkgs: - apt_purge(pkg, fatal=False) def main(): diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py index be1dc50..6a4324d 100644 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -409,6 +409,15 @@ def get_cidr_from_iface(interface): return None +def director_cluster_ready(): + dirs_count = len(pg_dir_context._pg_dir_ips()) + log('DIR COUNT: %s' % dirs_count) + if dirs_count == 2: + return True + else: + return False + + def restart_on_change(restart_map): """ Restart services based on configuration files changing diff --git a/unit_tests/test_pg_dir_context.py b/unit_tests/test_pg_dir_context.py index 9d32722..baac434 100644 --- a/unit_tests/test_pg_dir_context.py +++ b/unit_tests/test_pg_dir_context.py @@ -59,7 +59,8 @@ class PGDirContextTest(CharmTestCase): if section == "config": return "neutron.randomconfig" - config = {'plumgrid-virtual-ip': "192.168.100.250"} + config = {'plumgrid-virtual-ip': "192.168.100.250", + 'opsvm-ip':'127.0.0.1'} def mock_config(key=None): if key: @@ -99,5 +100,6 @@ class PGDirContextTest(CharmTestCase): '192.168.100.203'], 'director_ips_string': '192.168.100.201,192.168.100.202,192.168.100.203', + 'opsvm_ip': '127.0.0.1', } self.assertEquals(expect, napi_ctxt()) diff --git a/unit_tests/test_pg_dir_hooks.py b/unit_tests/test_pg_dir_hooks.py index c453ca8..1b8e5e8 100644 --- a/unit_tests/test_pg_dir_hooks.py +++ b/unit_tests/test_pg_dir_hooks.py @@ -20,7 +20,6 @@ utils.restart_map = _map TO_PATCH = [ 'remove_iovisor', 'apt_install', - 'apt_purge', 'CONFIGS', 'log', 'configure_sources', @@ -67,8 +66,5 @@ class PGDirHooksTests(CharmTestCase): self.test_config.set('plumgrid-license-key', None) 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 diff --git a/unit_tests/test_pg_dir_utils.py b/unit_tests/test_pg_dir_utils.py index d4fe0b1..4e0741e 100644 --- a/unit_tests/test_pg_dir_utils.py +++ b/unit_tests/test_pg_dir_utils.py @@ -55,7 +55,8 @@ class TestPGDirUtils(CharmTestCase): nutils.PG_DEF_CONF, nutils.PG_HN_CONF, nutils.PG_HS_CONF, - nutils.PG_IFCS_CONF] + nutils.PG_IFCS_CONF, + nutils.OPS_CONF] self.assertItemsEqual(_regconfs.configs, confs) def test_resource_map(self): @@ -73,6 +74,7 @@ class TestPGDirUtils(CharmTestCase): (nutils.PG_DEF_CONF, ['plumgrid']), (nutils.PG_HN_CONF, ['plumgrid']), (nutils.PG_HS_CONF, ['plumgrid']), + (nutils.OPS_CONF, ['plumgrid']), (nutils.PG_IFCS_CONF, []), ]) self.assertEqual(expect, _restart_map)