From 37d63886406cb12fff7792ed87b3cb6f2364818c Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Thu, 19 Apr 2018 20:21:27 -0700 Subject: [PATCH] Fix rds.describe_db_snapshots bugs * Correctly return all snapshots for a given DBInstanceIdentifier. * If an invalid DBInstanceIdentifier is passed in, return an empty array instead of raising a ClientError (which is what AWS actually does). Fixes #1569 --- moto/rds2/models.py | 5 +++-- tests/test_rds2/test_rds2.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/moto/rds2/models.py b/moto/rds2/models.py index 268ae5af2..eb0c0387a 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -722,10 +722,11 @@ class RDS2Backend(BaseBackend): def describe_snapshots(self, db_instance_identifier, db_snapshot_identifier): if db_instance_identifier: + db_instance_snapshots = [] for snapshot in self.snapshots.values(): if snapshot.database.db_instance_identifier == db_instance_identifier: - return [snapshot] - raise DBSnapshotNotFoundError() + db_instance_snapshots.append(snapshot) + return db_instance_snapshots if db_snapshot_identifier: if db_snapshot_identifier in self.snapshots: diff --git a/tests/test_rds2/test_rds2.py b/tests/test_rds2/test_rds2.py index ea0ab378f..78ba17b53 100644 --- a/tests/test_rds2/test_rds2.py +++ b/tests/test_rds2/test_rds2.py @@ -350,8 +350,6 @@ def test_describe_db_snapshots(): MasterUserPassword='hunter2', Port=1234, DBSecurityGroups=["my_sg"]) - conn.describe_db_snapshots.when.called_with( - DBInstanceIdentifier="db-primary-1").should.throw(ClientError) created = conn.create_db_snapshot(DBInstanceIdentifier='db-primary-1', DBSnapshotIdentifier='snapshot-1').get('DBSnapshot') @@ -366,6 +364,11 @@ def test_describe_db_snapshots(): snapshot.should.equal(created) snapshot.get('Engine').should.equal('postgres') + conn.create_db_snapshot(DBInstanceIdentifier='db-primary-1', + DBSnapshotIdentifier='snapshot-2') + snapshots = conn.describe_db_snapshots(DBInstanceIdentifier='db-primary-1').get('DBSnapshots') + snapshots.should.have.length_of(2) + @mock_rds2 def test_delete_db_snapshot():