From b6f4584737d2472a9457c2d499bafdc481e79ae6 Mon Sep 17 00:00:00 2001 From: steffyP Date: Thu, 24 Feb 2022 15:18:43 +0100 Subject: [PATCH] RDS: enable add and remove tag for resources (#4882) --- moto/rds2/models.py | 14 ++++++---- tests/test_rds2/test_rds2.py | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index 740cae63b..beccfdfeb 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -1971,14 +1971,16 @@ class RDS2Backend(BaseBackend): resource_name = arn_breakdown[len(arn_breakdown) - 1] if resource_type == "db": # Database if resource_name in self.databases: - self.databases[resource_name].remove_tags(tag_keys) + return self.databases[resource_name].remove_tags(tag_keys) elif resource_type == "es": # Event Subscription - return None + if resource_name in self.event_subscriptions: + return self.event_subscriptions[resource_name].remove_tags(tag_keys) elif resource_type == "og": # Option Group if resource_name in self.option_groups: return self.option_groups[resource_name].remove_tags(tag_keys) elif resource_type == "pg": # Parameter Group - return None + if resource_name in self.db_parameter_groups: + return self.db_parameter_groups[resource_name].remove_tags(tag_keys) elif resource_type == "ri": # Reserved DB instance return None elif resource_type == "secgrp": # DB security group @@ -2007,12 +2009,14 @@ class RDS2Backend(BaseBackend): if resource_name in self.databases: return self.databases[resource_name].add_tags(tags) elif resource_type == "es": # Event Subscription - return [] + if resource_name in self.event_subscriptions: + return self.event_subscriptions[resource_name].add_tags(tags) elif resource_type == "og": # Option Group if resource_name in self.option_groups: return self.option_groups[resource_name].add_tags(tags) elif resource_type == "pg": # Parameter Group - return [] + if resource_name in self.db_parameter_groups: + return self.db_parameter_groups[resource_name].add_tags(tags) elif resource_type == "ri": # Reserved DB instance return [] elif resource_type == "secgrp": # DB security group diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index 5b98c7e68..b70e70f1c 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -1568,6 +1568,57 @@ def test_list_tags_database_subnet_group(): ) +@mock_rds2 +def test_modify_tags_parameter_group(): + conn = boto3.client("rds", region_name="us-west-2") + client_tags = [{"Key": "character_set_client", "Value": "utf-8"}] + result = conn.create_db_parameter_group( + DBParameterGroupName="test-sqlserver-2017", + DBParameterGroupFamily="mysql5.6", + Description="MySQL Group", + Tags=client_tags, + ) + resource = result["DBParameterGroup"]["DBParameterGroupArn"] + result = conn.list_tags_for_resource(ResourceName=resource) + result["TagList"].should.equal(client_tags) + server_tags = [{"Key": "character_set_server", "Value": "utf-8"}] + conn.add_tags_to_resource(ResourceName=resource, Tags=server_tags) + combined_tags = client_tags + server_tags + result = conn.list_tags_for_resource(ResourceName=resource) + result["TagList"].should.equal(combined_tags) + + conn.remove_tags_from_resource( + ResourceName=resource, TagKeys=["character_set_client"] + ) + result = conn.list_tags_for_resource(ResourceName=resource) + result["TagList"].should.equal(server_tags) + + +@mock_rds2 +def test_modify_tags_event_subscription(): + conn = boto3.client("rds", region_name="us-west-2") + tags = [{"Key": "hello", "Value": "world"}] + result = conn.create_event_subscription( + SubscriptionName="my-instance-events", + SourceType="db-instance", + EventCategories=["backup", "recovery"], + SnsTopicArn="arn:aws:sns:us-east-1:123456789012:interesting-events", + Tags=tags, + ) + resource = result["EventSubscription"]["EventSubscriptionArn"] + result = conn.list_tags_for_resource(ResourceName=resource) + result["TagList"].should.equal(tags) + new_tags = [{"Key": "new_key", "Value": "new_value"}] + conn.add_tags_to_resource(ResourceName=resource, Tags=new_tags) + combined_tags = tags + new_tags + result = conn.list_tags_for_resource(ResourceName=resource) + result["TagList"].should.equal(combined_tags) + + conn.remove_tags_from_resource(ResourceName=resource, TagKeys=["new_key"]) + result = conn.list_tags_for_resource(ResourceName=resource) + result["TagList"].should.equal(tags) + + @mock_ec2 @mock_rds2 def test_add_tags_database_subnet_group():