MQ: Rabbits can now be configured (#6962)
This commit is contained in:
parent
42ecdccea7
commit
c242b78ce0
@ -52,21 +52,6 @@ class UnknownUser(MQError):
|
|||||||
return json.dumps(body)
|
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):
|
class UnknownEngineType(MQError):
|
||||||
def __init__(self, engine_type: str):
|
def __init__(self, engine_type: str):
|
||||||
super().__init__("BadRequestException", "")
|
super().__init__("BadRequestException", "")
|
||||||
|
@ -12,7 +12,6 @@ from .exceptions import (
|
|||||||
UnknownBroker,
|
UnknownBroker,
|
||||||
UnknownConfiguration,
|
UnknownConfiguration,
|
||||||
UnknownUser,
|
UnknownUser,
|
||||||
UnsupportedEngineType,
|
|
||||||
UnknownEngineType,
|
UnknownEngineType,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -236,14 +235,7 @@ class Broker(BaseModel):
|
|||||||
console_access=user.get("consoleAccess", False),
|
console_access=user.get("consoleAccess", False),
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.engine_type.upper() == "RABBITMQ":
|
self.configurations: Dict[str, Any] = {"current": configuration, "history": []}
|
||||||
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": []}
|
|
||||||
if self.engine_type.upper() == "RABBITMQ":
|
if self.engine_type.upper() == "RABBITMQ":
|
||||||
console_url = f"https://0000.mq.{region}.amazonaws.com"
|
console_url = f"https://0000.mq.{region}.amazonaws.com"
|
||||||
endpoints = ["amqps://mockmq:5671"]
|
endpoints = ["amqps://mockmq:5671"]
|
||||||
@ -290,8 +282,8 @@ class Broker(BaseModel):
|
|||||||
if auto_minor_version_upgrade is not None:
|
if auto_minor_version_upgrade is not None:
|
||||||
self.auto_minor_version_upgrade = auto_minor_version_upgrade
|
self.auto_minor_version_upgrade = auto_minor_version_upgrade
|
||||||
if configuration:
|
if configuration:
|
||||||
self.configurations["history"].append(self.configurations["current"]) # type: ignore[index]
|
self.configurations["history"].append(self.configurations["current"])
|
||||||
self.configurations["current"] = configuration # type: ignore[index]
|
self.configurations["current"] = configuration
|
||||||
if engine_version:
|
if engine_version:
|
||||||
self.engine_version = engine_version
|
self.engine_version = engine_version
|
||||||
if host_instance_type:
|
if host_instance_type:
|
||||||
@ -386,7 +378,7 @@ class MQBackend(BaseBackend):
|
|||||||
authentication_strategy: str,
|
authentication_strategy: str,
|
||||||
auto_minor_version_upgrade: bool,
|
auto_minor_version_upgrade: bool,
|
||||||
broker_name: str,
|
broker_name: str,
|
||||||
configuration: Dict[str, Any],
|
configuration: Optional[Dict[str, Any]],
|
||||||
deployment_mode: str,
|
deployment_mode: str,
|
||||||
encryption_options: Dict[str, Any],
|
encryption_options: Dict[str, Any],
|
||||||
engine_type: str,
|
engine_type: str,
|
||||||
@ -402,6 +394,15 @@ class MQBackend(BaseBackend):
|
|||||||
tags: Dict[str, str],
|
tags: Dict[str, str],
|
||||||
users: List[Dict[str, Any]],
|
users: List[Dict[str, Any]],
|
||||||
) -> Tuple[str, str]:
|
) -> 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(
|
broker = Broker(
|
||||||
name=broker_name,
|
name=broker_name,
|
||||||
account_id=self.account_id,
|
account_id=self.account_id,
|
||||||
@ -471,9 +472,7 @@ class MQBackend(BaseBackend):
|
|||||||
def create_configuration(
|
def create_configuration(
|
||||||
self, name: str, engine_type: str, engine_version: str, tags: Dict[str, str]
|
self, name: str, engine_type: str, engine_version: str, tags: Dict[str, str]
|
||||||
) -> Configuration:
|
) -> Configuration:
|
||||||
if engine_type.upper() == "RABBITMQ":
|
if engine_type.upper() not in ["ACTIVEMQ", "RABBITMQ"]:
|
||||||
raise UnsupportedEngineType(engine_type)
|
|
||||||
if engine_type.upper() != "ACTIVEMQ":
|
|
||||||
raise UnknownEngineType(engine_type)
|
raise UnknownEngineType(engine_type)
|
||||||
config = Configuration(
|
config = Configuration(
|
||||||
account_id=self.account_id,
|
account_id=self.account_id,
|
||||||
|
@ -25,6 +25,11 @@ def test_create_broker_minimal():
|
|||||||
assert "BrokerId" in resp
|
assert "BrokerId" in resp
|
||||||
assert resp["BrokerArn"].startswith("arn:aws")
|
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
|
@mock_mq
|
||||||
def test_create_with_tags():
|
def test_create_with_tags():
|
||||||
@ -269,7 +274,6 @@ def test_describe_multiple_rabbits():
|
|||||||
== "https://0000.mq.us-east-2.amazonaws.com"
|
== "https://0000.mq.us-east-2.amazonaws.com"
|
||||||
)
|
)
|
||||||
assert len(resp["BrokerInstances"][0]["Endpoints"]) == 1
|
assert len(resp["BrokerInstances"][0]["Endpoints"]) == 1
|
||||||
assert "Configurations" not in resp
|
|
||||||
assert resp["Logs"] == {"General": False}
|
assert resp["Logs"] == {"General": False}
|
||||||
assert len(resp["SubnetIds"]) == 4
|
assert len(resp["SubnetIds"]) == 4
|
||||||
|
|
||||||
|
@ -35,22 +35,6 @@ def test_create_configuration_minimal():
|
|||||||
assert revision["Revision"] == 1
|
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
|
@mock_mq
|
||||||
def test_create_configuration_for_unknown_engine():
|
def test_create_configuration_for_unknown_engine():
|
||||||
client = boto3.client("mq", region_name="us-east-1")
|
client = boto3.client("mq", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user