added new merge_taglists() to moto.core.utils for merging lists of tags with precedence (ie. during rds2.create_snapshot)

This commit is contained in:
Jon Beilke 2018-09-21 10:39:42 -05:00
commit 276da06168
3 changed files with 38 additions and 3 deletions

View file

@ -286,3 +286,12 @@ def amzn_request_id(f):
return status, headers, body
return _wrapper
def merge_taglists(taglist_a, taglist_b):
''' Merges two tag lists into a single tag list with Keys in the second list taking precedence'''
tags_a = {t['Key']:t for t in taglist_a}
tags_b = {t['Key']:t for t in taglist_b}
merged_tags = tags_a.copy()
merged_tags.update(tags_b)
return merged_tags.values()

View file

@ -13,6 +13,7 @@ from moto.compat import OrderedDict
from moto.core import BaseBackend, BaseModel
from moto.core.utils import get_random_hex
from moto.core.utils import iso_8601_datetime_with_milliseconds
from moto.core.utils import merge_taglists
from moto.ec2.models import ec2_backends
from .exceptions import (RDSClientError,
DBInstanceNotFoundError,
@ -697,8 +698,8 @@ class RDS2Backend(BaseBackend):
raise DBSnapshotAlreadyExistsError(db_snapshot_identifier)
if len(self.snapshots) >= int(os.environ.get('MOTO_RDS_SNAPSHOT_LIMIT', '100')):
raise SnapshotQuotaExceededError()
if not database.copy_tags_to_snapshot:
tags = None
if database.copy_tags_to_snapshot:
tags = merge_taglists(database.tags, tags)
snapshot = Snapshot(database, db_snapshot_identifier, tags)
self.snapshots[db_snapshot_identifier] = snapshot
return snapshot