Colin Watson has proposed merging ~cjwatson/launchpad-layers:rabbitmq-optional-relation into launchpad-layers:main.
Commit message: Allow non-relation-driven RabbitMQ configuration Requested reviews: Launchpad code reviewers (launchpad-reviewers) For more details, see: https://code.launchpad.net/~cjwatson/launchpad-layers/+git/launchpad-layers/+merge/439193 This makes it easier to migrate a non-charmed Launchpad environment to a charmed deployment: everything in a given environment should use the same RabbitMQ server, so we probably want to start by using the existing one rather than demanding that the broker URLs be provided using a Juju relation. -- Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-layers:rabbitmq-optional-relation into launchpad-layers:main.
diff --git a/launchpad-base/config.yaml b/launchpad-base/config.yaml index 4f2b83b..868c93b 100644 --- a/launchpad-base/config.yaml +++ b/launchpad-base/config.yaml @@ -206,6 +206,11 @@ options: type: string description: External base URL for private PPAs. default: http://private-ppa.launchpad.test/ + rabbitmq_broker_urls: + type: string + description: > + Space-separated list of RabbitMQ broker URLs. If unset, rely on the + rabbitmq relation instead. rabbitmq_user: type: string description: Username to use with RabbitMQ. diff --git a/launchpad-base/reactive/launchpad-base.py b/launchpad-base/reactive/launchpad-base.py index b3bd439..bf26b8b 100644 --- a/launchpad-base/reactive/launchpad-base.py +++ b/launchpad-base/reactive/launchpad-base.py @@ -18,6 +18,8 @@ from charms.reactive import ( remove_state, set_state, when, + when_any, + when_none, when_not, ) from ols import base, postgres @@ -44,19 +46,34 @@ def prepare_rabbitmq(): def get_rabbitmq_uris(rabbitmq): - for conversation in rabbitmq.conversations(): - for relation_id in conversation.relation_ids: - for unit in hookenv.related_units(relation_id): - hostname = hookenv.relation_get( - "private-address", unit, relation_id - ) - vhost = rabbitmq.vhost() - username = rabbitmq.username() - password = rabbitmq.password() - yield f"amqp://{username}:{password}@{hostname}/{vhost}" - - -@when("ols.configured", "db.master.available", "rabbitmq.available") + config = hookenv.config() + if config["rabbitmq_broker_urls"]: + for url in config["rabbitmq_broker_urls"].split(): + yield url + else: + for conversation in rabbitmq.conversations(): + for relation_id in conversation.relation_ids: + for unit in hookenv.related_units(relation_id): + hostname = hookenv.relation_get( + "private-address", unit, relation_id + ) + vhost = rabbitmq.vhost() + username = rabbitmq.username() + password = rabbitmq.password() + yield f"amqp://{username}:{password}@{hostname}/{vhost}" + + +@when_any("rabbitmq.available", "config.set.rabbitmq_broker_urls") +def rabbitmq_available(): + set_state("launchpad.rabbitmq.available") + + +@when_none("rabbitmq.available", "config.set.rabbitmq_broker_urls") +def rabbitmq_unavailable(): + remove_state("launchpad.rabbitmq.available") + + +@when("ols.configured", "db.master.available", "launchpad.rabbitmq.available") @when_not("launchpad.base.configured") def configure(): db = endpoint_from_flag("db.master.available") @@ -119,6 +136,6 @@ def config_changed(): @hook("{requires:rabbitmq}-relation-changed") -def rabbitmq_relation_changed(): +def rabbitmq_relation_changed(*args): remove_state("launchpad.base.configured") remove_state("service.configured")
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp