remove merge_taglists as AWS will only take submitted tags or tags from db but not both when creating snapshot

This commit is contained in:
Jon Beilke 2018-09-21 13:28:13 -05:00
parent 6eb490ac78
commit 7daee905a5
4 changed files with 10 additions and 43 deletions

View File

@ -286,12 +286,3 @@ 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,7 +13,6 @@ 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,
@ -418,10 +417,10 @@ class Database(BaseModel):
class Snapshot(BaseModel):
def __init__(self, database, snapshot_id, tags=None):
def __init__(self, database, snapshot_id, tags):
self.database = database
self.snapshot_id = snapshot_id
self.tags = tags or []
self.tags = tags
self.created_at = iso_8601_datetime_with_milliseconds(datetime.datetime.now())
@property
@ -712,8 +711,10 @@ class RDS2Backend(BaseBackend):
raise DBSnapshotAlreadyExistsError(db_snapshot_identifier)
if len(self.snapshots) >= int(os.environ.get('MOTO_RDS_SNAPSHOT_LIMIT', '100')):
raise SnapshotQuotaExceededError()
if database.copy_tags_to_snapshot:
tags = merge_taglists(database.tags, tags)
if tags is None:
tags = list()
if database.copy_tags_to_snapshot and not tags:
tags = database.get_tags()
snapshot = Snapshot(database, db_snapshot_identifier, tags)
self.snapshots[db_snapshot_identifier] = snapshot
return snapshot
@ -810,13 +811,13 @@ class RDS2Backend(BaseBackend):
def delete_database(self, db_instance_identifier, db_snapshot_name=None):
if db_instance_identifier in self.databases:
if db_snapshot_name:
self.create_snapshot(db_instance_identifier, db_snapshot_name)
database = self.databases.pop(db_instance_identifier)
if database.is_replica:
primary = self.find_db_from_id(database.source_db_identifier)
primary.remove_replica(database)
database.status = 'deleting'
if db_snapshot_name:
self.snapshots[db_snapshot_name] = Snapshot(database, db_snapshot_name)
return database
else:
raise DBInstanceNotFoundError(db_instance_identifier)

View File

@ -160,7 +160,7 @@ class RDS2Response(BaseResponse):
def create_db_snapshot(self):
db_instance_identifier = self._get_param('DBInstanceIdentifier')
db_snapshot_identifier = self._get_param('DBSnapshotIdentifier')
tags = self._get_param('Tags', [])
tags = self.unpack_complex_list_params('Tags.Tag', ('Key', 'Value'))
snapshot = self.backend.create_snapshot(db_instance_identifier, db_snapshot_identifier, tags)
template = self.response_template(CREATE_SNAPSHOT_TEMPLATE)
return template.render(snapshot=snapshot)

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import sure # noqa
from freezegun import freeze_time
from moto.core.utils import camelcase_to_underscores, underscores_to_camelcase, unix_time, merge_taglists
from moto.core.utils import camelcase_to_underscores, underscores_to_camelcase, unix_time
def test_camelcase_to_underscores():
@ -28,28 +28,3 @@ def test_underscores_to_camelcase():
@freeze_time("2015-01-01 12:00:00")
def test_unix_time():
unix_time().should.equal(1420113600.0)
def test_merge_taglists():
taglist_a = [
{
'Key': 'foo',
'Value': 'bar',
},
{
'Key': 'foo1',
'Value': 'bar1',
},
]
taglist_b = [
{
'Key': 'foo1',
'Value': 'bar1b',
},
]
taglist_merged = merge_taglists(taglist_a, taglist_b)
len(taglist_merged).should.equal(2)
tag_foo = [t for t in taglist_merged if t['Key']=='foo']
tag_foo1 = [t for t in taglist_merged if t['Key']=='foo1']
tag_foo[0].should.equal({'Key': 'foo','Value': 'bar',})
tag_foo1[0].should.equal({'Key': 'foo1','Value': 'bar1b',})