MQ: Rabbits can now be configured (#6962)

This commit is contained in:
Bert Blommers 2023-10-28 20:15:42 +00:00 committed by GitHub
parent 42ecdccea7
commit c242b78ce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 47 deletions

View File

@ -52,21 +52,6 @@ class UnknownUser(MQError):
return json.dumps(body)
class UnsupportedEngineType(MQError):
def __init__(self, engine_type: str):
super().__init__("BadRequestException", "")
self.engine_type = engine_type
def get_body(
self, *args: Any, **kwargs: Any
) -> str: # pylint: disable=unused-argument
body = {
"errorAttribute": "engineType",
"message": f"Broker engine type [{self.engine_type}] does not support configuration.",
}
return json.dumps(body)
class UnknownEngineType(MQError):
def __init__(self, engine_type: str):
super().__init__("BadRequestException", "")

View File

@ -12,7 +12,6 @@ from .exceptions import (
UnknownBroker,
UnknownConfiguration,
UnknownUser,
UnsupportedEngineType,
UnknownEngineType,
)
@ -236,14 +235,7 @@ class Broker(BaseModel):
console_access=user.get("consoleAccess", False),
)
if self.engine_type.upper() == "RABBITMQ":
self.configurations: Optional[Dict[str, Any]] = None
else:
current_config = configuration or {
"id": f"c-{mock_random.get_random_hex(6)}",
"revision": 1,
}
self.configurations = {"current": current_config, "history": []}
self.configurations: Dict[str, Any] = {"current": configuration, "history": []}
if self.engine_type.upper() == "RABBITMQ":
console_url = f"https://0000.mq.{region}.amazonaws.com"
endpoints = ["amqps://mockmq:5671"]
@ -290,8 +282,8 @@ class Broker(BaseModel):
if auto_minor_version_upgrade is not None:
self.auto_minor_version_upgrade = auto_minor_version_upgrade
if configuration:
self.configurations["history"].append(self.configurations["current"]) # type: ignore[index]
self.configurations["current"] = configuration # type: ignore[index]
self.configurations["history"].append(self.configurations["current"])
self.configurations["current"] = configuration
if engine_version:
self.engine_version = engine_version
if host_instance_type:
@ -386,7 +378,7 @@ class MQBackend(BaseBackend):
authentication_strategy: str,
auto_minor_version_upgrade: bool,
broker_name: str,
configuration: Dict[str, Any],
configuration: Optional[Dict[str, Any]],
deployment_mode: str,
encryption_options: Dict[str, Any],
engine_type: str,
@ -402,6 +394,15 @@ class MQBackend(BaseBackend):
tags: Dict[str, str],
users: List[Dict[str, Any]],
) -> Tuple[str, str]:
if configuration is None:
# create default configuration
default_config = self.create_configuration(
name=f"{broker_name}-configuration",
engine_type=engine_type,
engine_version=engine_version,
tags={},
)
configuration = {"id": default_config.id, "revision": 1}
broker = Broker(
name=broker_name,
account_id=self.account_id,
@ -471,9 +472,7 @@ class MQBackend(BaseBackend):
def create_configuration(
self, name: str, engine_type: str, engine_version: str, tags: Dict[str, str]
) -> Configuration:
if engine_type.upper() == "RABBITMQ":
raise UnsupportedEngineType(engine_type)
if engine_type.upper() != "ACTIVEMQ":
if engine_type.upper() not in ["ACTIVEMQ", "RABBITMQ"]:
raise UnknownEngineType(engine_type)
config = Configuration(
account_id=self.account_id,

View File

@ -25,6 +25,11 @@ def test_create_broker_minimal():
assert "BrokerId" in resp
assert resp["BrokerArn"].startswith("arn:aws")
# Should create default Configuration, if not specified
broker = client.describe_broker(BrokerId=resp["BrokerId"])
assert "Current" in broker["Configurations"]
assert "Id" in broker["Configurations"]["Current"]
@mock_mq
def test_create_with_tags():
@ -269,7 +274,6 @@ def test_describe_multiple_rabbits():
== "https://0000.mq.us-east-2.amazonaws.com"
)
assert len(resp["BrokerInstances"][0]["Endpoints"]) == 1
assert "Configurations" not in resp
assert resp["Logs"] == {"General": False}
assert len(resp["SubnetIds"]) == 4

View File

@ -35,22 +35,6 @@ def test_create_configuration_minimal():
assert revision["Revision"] == 1
@mock_mq
def test_create_configuration_for_rabbitmq():
client = boto3.client("mq", region_name="us-east-1")
with pytest.raises(ClientError) as exc:
client.create_configuration(
EngineType="RABBITMQ", EngineVersion="rabbit1", Name="myconfig"
)
err = exc.value.response["Error"]
assert err["Code"] == "BadRequestException"
assert (
err["Message"]
== "Broker engine type [RABBITMQ] does not support configuration."
)
@mock_mq
def test_create_configuration_for_unknown_engine():
client = boto3.client("mq", region_name="us-east-1")