Skip to content

Commit

Permalink
fix rds blue green validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabauer committed Sep 6, 2024
1 parent 9b66b27 commit e1bb5c2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 29 deletions.
33 changes: 33 additions & 0 deletions reconcile/test/utils/test_terraform_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,39 @@ def test_validate_blue_green_update_requirements_with_storage_type_change(
)


def test_validate_db_upgrade_blue_green_update_no_version_change(
mocker: MockerFixture, aws_api: AWSApi, tf: tfclient.TerraformClient
) -> None:
aws_api.get_db_valid_upgrade_target.return_value = [ # type: ignore[attr-defined]
{"Engine": "postgres", "EngineVersion": "11.12", "IsMajorVersionUpgrade": False}
]
aws_api.describe_db_parameter_group.return_value = {"rds.logical_replication": "1"} # type: ignore[attr-defined]

mocked_logging = mocker.patch("reconcile.utils.terraform_client.logging")

tf.validate_db_upgrade(
account_name="a1",
resource_name="test-database-1",
resource_change={
"before": {
"engine": "postgres",
"engine_version": "11.12",
"availability_zone": "us-east-1a",
"parameter_group_name": "test-pg",
"replicas": [],
"replicate_source_db": "",
},
"after": {
"engine": "postgres",
"engine_version": "11.12",
"blue_green_update": [{"enabled": True}],
},
},
)

mocked_logging.error.assert_not_called()


def test_check_output_debug(
tf: tfclient.TerraformClient,
mocker: MockerFixture,
Expand Down
57 changes: 28 additions & 29 deletions reconcile/utils/terraform_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,38 +771,37 @@ def validate_db_upgrade(
before_version = before["engine_version"]
after = resource_change["after"]
after_version = after["engine_version"]
if after_version == before_version:
return

region_name = get_region_from_availability_zone(before["availability_zone"])
if self._aws_api is not None:
valid_upgrade_target = self._aws_api.get_db_valid_upgrade_target(
account_name, engine, before_version, region_name=region_name
)
target = next(
(
t
for t in valid_upgrade_target
if t["EngineVersion"] == after_version
),
None,
)
if target is None:
logging.error(
f"Cannot upgrade RDS instance: {resource_name} "
f"from {before_version} to {after_version}"
if after_version != before_version:
region_name = get_region_from_availability_zone(before["availability_zone"])
if self._aws_api is not None:
valid_upgrade_target = self._aws_api.get_db_valid_upgrade_target(
account_name, engine, before_version, region_name=region_name
)
return
allow_major_version_upgrade = after.get(
"allow_major_version_upgrade",
False,
)
if target["IsMajorVersionUpgrade"] and not allow_major_version_upgrade:
logging.error(
"allow_major_version_upgrade is not enabled for upgrading RDS instance: "
f"{resource_name} to a new major version."
target = next(
(
t
for t in valid_upgrade_target
if t["EngineVersion"] == after_version
),
None,
)
return
if target is None:
logging.error(
f"Cannot upgrade RDS instance: {resource_name} "
f"from {before_version} to {after_version}"
)
return
allow_major_version_upgrade = after.get(
"allow_major_version_upgrade",
False,
)
if target["IsMajorVersionUpgrade"] and not allow_major_version_upgrade:
logging.error(
"allow_major_version_upgrade is not enabled for upgrading RDS instance: "
f"{resource_name} to a new major version."
)
return

blue_green_update = after.get("blue_green_update", [])
if blue_green_update and blue_green_update[0]["enabled"]:
Expand Down

0 comments on commit e1bb5c2

Please sign in to comment.