Removed package removal in stop hook

This commit is contained in:
Bilal Baqar 2016-03-26 19:43:53 +01:00
parent fa4588b0e3
commit f7ff2f8dad
5 changed files with 22 additions and 14 deletions

View File

@ -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.
'''
if director_cluster_ready():
ensure_mtu()
CONFIGS.write_all()
restart_pg()
@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():

View File

@ -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

View File

@ -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())

View File

@ -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

View File

@ -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)