Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APPSRE-10796] fix rds blue green validation #4654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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