← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:charm-endpoint-from-flag into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:charm-endpoint-from-flag into launchpad:master.

Commit message:
Use endpoint_from_flag rather than handler arguments

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

https://charmsreactive.readthedocs.io/en/latest/charms.reactive.decorators.html says:

  For backwards compatibility, some decorators will pass endpoint
  instances if the handler function specifies them as arguments.
  However, explicit instance access using `endpoint_from_flag` is
  recommended, because ensuring proper argument order can be confusing:
  they are passed in bottom-up, left-to-right, and no negative or
  ambiguous decorators, such as `when_not()` or `when_any()` will ever
  pass arguments.

I also ran into some weird behaviour during an `upgrade-charm` attempt where the backward-compatibility mode doesn't quite seem to work, so use the recommended explicit form instead.

This also pulls in the similar fix from https://code.launchpad.net/~cjwatson/launchpad-layers/+git/launchpad-layers/+merge/439082.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:charm-endpoint-from-flag into launchpad:master.
diff --git a/charm/launchpad-admin/charmcraft.yaml b/charm/launchpad-admin/charmcraft.yaml
index 507bbe3..6788e25 100644
--- a/charm/launchpad-admin/charmcraft.yaml
+++ b/charm/launchpad-admin/charmcraft.yaml
@@ -35,7 +35,7 @@ parts:
     after:
       - ols-layers
     source: https://git.launchpad.net/launchpad-layers
-    source-commit: "624df58b5b21a34f8931bba12931e1e3a37ac7b5"
+    source-commit: "e4d85d4993268ca4c484c3e0b2715886159c9018"
     source-submodules: []
     source-type: git
     plugin: dump
diff --git a/charm/launchpad-admin/reactive/launchpad-admin.py b/charm/launchpad-admin/reactive/launchpad-admin.py
index 0a31116..1cd9268 100644
--- a/charm/launchpad-admin/reactive/launchpad-admin.py
+++ b/charm/launchpad-admin/reactive/launchpad-admin.py
@@ -11,7 +11,7 @@ from charms.launchpad.base import (
     strip_dsn_authentication,
     update_pgpass,
 )
-from charms.reactive import set_state, when, when_not
+from charms.reactive import endpoint_from_flag, set_state, when, when_not
 from ols import base, postgres
 from psycopg2.extensions import make_dsn, parse_dsn
 
@@ -29,7 +29,10 @@ def strip_password(dsn):
     "session-db.master.available",
 )
 @when_not("service_configured")
-def configure(db, db_admin, session_db):
+def configure():
+    db = endpoint_from_flag("db.master.available")
+    db_admin = endpoint_from_flag("db-admin.master.available")
+    session_db = endpoint_from_flag("session-db.master.available")
     config = get_service_config()
     db_primary, _ = postgres.get_db_uris(db)
     db_admin_primary, _ = postgres.get_db_uris(db_admin)
diff --git a/charm/launchpad-appserver/charmcraft.yaml b/charm/launchpad-appserver/charmcraft.yaml
index 8b9bdda..497c836 100644
--- a/charm/launchpad-appserver/charmcraft.yaml
+++ b/charm/launchpad-appserver/charmcraft.yaml
@@ -35,7 +35,7 @@ parts:
     after:
       - ols-layers
     source: https://git.launchpad.net/launchpad-layers
-    source-commit: "624df58b5b21a34f8931bba12931e1e3a37ac7b5"
+    source-commit: "e4d85d4993268ca4c484c3e0b2715886159c9018"
     source-submodules: []
     source-type: git
     plugin: dump
diff --git a/charm/launchpad-appserver/reactive/launchpad-appserver.py b/charm/launchpad-appserver/reactive/launchpad-appserver.py
index 8f7d514..aea1b0a 100644
--- a/charm/launchpad-appserver/reactive/launchpad-appserver.py
+++ b/charm/launchpad-appserver/reactive/launchpad-appserver.py
@@ -16,6 +16,7 @@ from charms.launchpad.base import (
 )
 from charms.reactive import (
     clear_flag,
+    endpoint_from_flag,
     helpers,
     set_flag,
     set_state,
@@ -97,7 +98,9 @@ def config_files():
     "memcache.available",
 )
 @when_not("service.configured")
-def configure(session_db, memcache):
+def configure():
+    session_db = endpoint_from_flag("session-db.master.available")
+    memcache = endpoint_from_flag("memcache.available")
     config = get_service_config()
     session_db_primary, _ = postgres.get_db_uris(session_db)
     # XXX cjwatson 2022-09-23: Mangle the connection string into a form
@@ -149,7 +152,8 @@ def check_is_running():
 
 @when("nrpe-external-master.available", "service.configured")
 @when_not("launchpad.appserver.nrpe-external-master.published")
-def nrpe_available(nrpe):
+def nrpe_available():
+    nrpe = endpoint_from_flag("nrpe-external-master.available")
     config = hookenv.config()
     healthy_regex = (
         r"(\/\+icing\/rev[0-9a-f]+\/).*(Is your project registered yet\?)"
diff --git a/charm/launchpad/charmcraft.yaml b/charm/launchpad/charmcraft.yaml
index 0060a18..6f9625c 100644
--- a/charm/launchpad/charmcraft.yaml
+++ b/charm/launchpad/charmcraft.yaml
@@ -35,7 +35,7 @@ parts:
     after:
       - ols-layers
     source: https://git.launchpad.net/launchpad-layers
-    source-commit: "624df58b5b21a34f8931bba12931e1e3a37ac7b5"
+    source-commit: "e4d85d4993268ca4c484c3e0b2715886159c9018"
     source-submodules: []
     source-type: git
     plugin: dump