Deregister a launcher when removed from config

We were depending only on the ephemeralness of launcher registration
nodes to indicate when a provider goes away. That only works when
nodepool-launcher is restarted since the ZK connection is shared
among all provider threads. This adds an API method to manually
deregister and modifies a test to ensure it works.

Change-Id: I363fc4a67a83b49b515b963f5d5accdcf1cb758c
This commit is contained in:
David Shrewsbury
2019-10-02 12:07:08 -04:00
parent 5c605b3240
commit 51030bcc6f
3 changed files with 23 additions and 3 deletions
+1
View File
@@ -381,6 +381,7 @@ class PoolWorker(threading.Thread, stats.StatsReporter):
'''
self.log.info("%s received stop" % self.name)
self.running = False
self.zk.deregisterLauncher(self.launcher_id)
self.stop_event.set()
+6
View File
@@ -1482,6 +1482,9 @@ class TestLauncher(tests.DBTestCase):
self.waitForNodes('fake-label')
self.assertEqual(2, len(pool._pool_threads))
# We should have two pool workers registered
self.assertEqual(2, len(self.zk.getRegisteredLaunchers()))
self.replace_config(configfile, 'launcher_two_provider_remove.yaml')
# Our provider pool thread count should eventually be reduced to 1
@@ -1493,6 +1496,9 @@ class TestLauncher(tests.DBTestCase):
except AssertionError:
pass
# We should have one pool worker registered
self.assertEqual(1, len(self.zk.getRegisteredLaunchers()))
def test_failed_provider(self):
"""Test that broken provider doesn't fail node requests."""
configfile = self.setup_config('launcher_two_provider_max_1.yaml')
+16 -3
View File
@@ -1508,9 +1508,10 @@ class ZooKeeper(object):
'''
Register an active node launcher.
The launcher is automatically de-registered once it terminates or
otherwise disconnects from ZooKeeper. It will need to re-register
after a lost connection. This method is safe to call multiple times.
The launcher is de-registered when the launcher process terminates or
otherwise disconnects from ZooKeeper, or via deregisterLauncher().
It will need to re-register after a lost connection. This method is
safe to call multiple times.
:param Launcher launcher: Object describing the launcher.
'''
@@ -1528,6 +1529,18 @@ class ZooKeeper(object):
makepath=True, ephemeral=True)
self.log.debug("Registered launcher %s", launcher.id)
def deregisterLauncher(self, launcher_id):
'''
Deregister an active node launcher.
:param str launcher_id: ID of the launcher to deregister.
'''
path = self._launcherPath(launcher_id)
try:
self.client.delete(path, recursive=True)
except kze.NoNodeError:
pass
def getRegisteredLaunchers(self):
'''
Get a list of all launchers that have registered with ZooKeeper.