From 06675c43c9f48ffa98b2abf2ddca137f8d18f31c Mon Sep 17 00:00:00 2001 From: David Ames Date: Fri, 28 Aug 2020 09:33:57 -0700 Subject: [PATCH] Scale-in fixes Properly handle departed and broken hooks. Change-Id: Iecb1f943ffa5505617b5e5eb70f070458fc6645d Closes-Bug: #1881596 --- provides.py | 12 +++++++++--- unit_tests/test_provides.py | 5 +++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/provides.py b/provides.py index eb054e2..9576f9f 100644 --- a/provides.py +++ b/provides.py @@ -64,9 +64,7 @@ class MySQLSharedProvides(reactive.Endpoint): else: reactive.clear_flag(self.expand_name('{endpoint_name}.available')) - @reactive.when_any('endpoint.{endpoint_name}.broken', - 'endpoint.{endpoint_name}.departed') - def departed(self): + def remove(self): flags = ( self.expand_name('{endpoint_name}.connected'), self.expand_name('{endpoint_name}.available'), @@ -74,6 +72,14 @@ class MySQLSharedProvides(reactive.Endpoint): for flag in flags: reactive.clear_flag(flag) + @reactive.when('endpoint.{endpoint_name}.broken') + def broken(self): + self.remove() + + @reactive.when('endpoint.{endpoint_name}.departed') + def departed(self): + self.remove() + def set_db_connection_info( self, relation_id, db_host, password, allowed_units=None, prefix=None, wait_timeout=None, db_port=3306, diff --git a/unit_tests/test_provides.py b/unit_tests/test_provides.py index d2ea914..2ce3c81 100644 --- a/unit_tests/test_provides.py +++ b/unit_tests/test_provides.py @@ -28,8 +28,9 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): "changed": ( "endpoint.{endpoint_name}.changed",), - "departed": ("endpoint.{endpoint_name}.broken", - "endpoint.{endpoint_name}.departed",), + "departed": ("endpoint.{endpoint_name}.departed",), + + "broken": ("endpoint.{endpoint_name}.broken",), }, } # test that the hooks were registered