← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-layers:db-changed into launchpad-layers:main

 

Colin Watson has proposed merging ~cjwatson/launchpad-layers:db-changed into launchpad-layers:main.

Commit message:
Clear configured states on DB relation changes

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-layers/+git/launchpad-layers/+merge/441077

Otherwise we don't notice if (for example) the relation tells us that a DB password has changed, or if the relation is broken.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-layers:db-changed into launchpad-layers:main.
diff --git a/launchpad-base/reactive/launchpad-base.py b/launchpad-base/reactive/launchpad-base.py
index 4bec15d..3063019 100644
--- a/launchpad-base/reactive/launchpad-base.py
+++ b/launchpad-base/reactive/launchpad-base.py
@@ -22,6 +22,7 @@ from charms.reactive import (
     when_any,
     when_none,
     when_not,
+    when_not_all,
 )
 from ols import base, postgres
 
@@ -110,6 +111,15 @@ def configure():
     set_state("launchpad.base.configured")
 
 
+@when("launchpad.base.configured")
+@when_not_all(
+    "ols.configured", "db.master.available", "launchpad.rabbitmq.available"
+)
+def deconfigure():
+    remove_state("launchpad.base.configured")
+    remove_state("service.configured")
+
+
 @hook("upgrade-charm")
 def upgrade_charm():
     # The ols layer takes care of removing the ols.service.installed,
@@ -133,6 +143,13 @@ def config_changed():
     remove_state("service.configured")
 
 
+@when("db.database.changed", "launchpad.base.configured")
+def db_changed():
+    remove_state("launchpad.base.configured")
+    remove_state("service.configured")
+    remove_state("db.database.changed")
+
+
 @hook("{requires:rabbitmq}-relation-changed")
 def rabbitmq_relation_changed(*args):
     remove_state("launchpad.base.configured")