-
-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new option
[messaging].prefix
to configure prefix of RabbitMQ e…
…xchange/queue names (#6282)
- Loading branch information
Showing
26 changed files
with
141 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ ssh_key_file = /home/vagrant/.ssh/stanley_rsa | |
|
||
[messaging] | ||
url = amqp://guest:[email protected]:5672/ | ||
prefix = st2dev | ||
# Uncomment to test SSL options | ||
#url = amqp://guest:[email protected]:5671/ | ||
#ssl = True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
from dataclasses import dataclass | ||
from textwrap import dedent | ||
from typing import Tuple | ||
|
||
from pants.backend.python.goals.pytest_runner import ( | ||
PytestPluginSetupRequest, | ||
|
@@ -27,6 +28,8 @@ | |
VenvPexProcess, | ||
rules as pex_rules, | ||
) | ||
from pants.core.goals.test import TestExtraEnv | ||
from pants.engine.env_vars import EnvironmentVars | ||
from pants.engine.fs import CreateDigest, Digest, FileContent | ||
from pants.engine.rules import collect_rules, Get, MultiGet, rule | ||
from pants.engine.process import FallibleProcessResult, ProcessCacheScope | ||
|
@@ -54,13 +57,17 @@ class UsesRabbitMQRequest: | |
# These config opts for integration tests are in: | ||
# conf/st2.tests*.conf st2tests/st2tests/fixtures/conf/st2.tests*.conf | ||
# (changed by setting ST2_CONFIG_PATH env var inside the tests) | ||
# TODO: for unit tests: modify code to pull mq connect settings from env vars | ||
# TODO: for int tests: modify st2.tests*.conf on the fly to set the per-pantsd-slot vhost | ||
# and either add env vars for mq connect settings or modify conf files as well | ||
# These can also be updated via the ST2_MESSAGING_* env vars (which oslo_config reads). | ||
# Integration tests should pass these changes onto subprocesses via the same env vars. | ||
|
||
# with our version of oslo.config (newer are slower) we can't directly override opts w/ environment variables. | ||
mq_urls: Tuple[str] = ("amqp://guest:[email protected]:5672//",) | ||
|
||
mq_urls: tuple[str] = ("amqp://guest:[email protected]:5672//",) | ||
@classmethod | ||
def from_env(cls, env: EnvironmentVars) -> UsesRabbitMQRequest: | ||
default = cls() | ||
url = env.get("ST2_MESSAGING__URL", None) | ||
mq_urls = (url,) if url else default.mq_urls | ||
return UsesRabbitMQRequest(mq_urls=mq_urls) | ||
|
||
|
||
@dataclass(frozen=True) | ||
|
@@ -83,9 +90,12 @@ def is_applicable(cls, target: Target) -> bool: | |
) | ||
async def rabbitmq_is_running_for_pytest( | ||
request: PytestUsesRabbitMQRequest, | ||
test_extra_env: TestExtraEnv, | ||
) -> PytestPluginSetup: | ||
# this will raise an error if rabbitmq is not running | ||
_ = await Get(RabbitMQIsRunning, UsesRabbitMQRequest()) | ||
_ = await Get( | ||
RabbitMQIsRunning, UsesRabbitMQRequest.from_env(env=test_extra_env.env) | ||
) | ||
|
||
return PytestPluginSetup() | ||
|
||
|
@@ -167,6 +177,16 @@ async def rabbitmq_is_running( | |
""" | ||
), | ||
service_start_cmd_generic="systemctl start rabbitmq-server", | ||
env_vars_hint=dedent( | ||
"""\ | ||
You can also export the ST2_MESSAGING__URL env var to automatically use any | ||
RabbitMQ host, local or remote, while running unit and integration tests. | ||
If needed, you can also override the default exchange/queue name prefix | ||
by exporting ST2_MESSAGING__PREFIX. Note that tests always add a numeric | ||
suffix to the exchange/queue name prefix so that tests can safely run | ||
in parallel. | ||
""" | ||
), | ||
), | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2024 The StackStorm Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from __future__ import absolute_import | ||
|
||
import kombu | ||
from oslo_config import cfg | ||
|
||
|
||
class Exchange(kombu.Exchange): | ||
def __call__(self, *args, **kwargs): | ||
# update exchange name with prefix just before binding (as late as possible). | ||
prefix = cfg.CONF.messaging.prefix | ||
if self.name and prefix != "st2": | ||
self.name = self.name.replace("st2.", f"{prefix}.", 1) | ||
return super().__call__(*args, **kwargs) | ||
|
||
|
||
class Queue(kombu.Queue): | ||
def __call__(self, *args, **kwargs): | ||
# update queue name with prefix just before binding (as late as possible). | ||
prefix = cfg.CONF.messaging.prefix | ||
if self.name and prefix != "st2": | ||
self.name = self.name.replace("st2.", f"{prefix}.", 1) | ||
return super().__call__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.