From cf7869d0e2a3e011ec168d561b9de21158a2be94 Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Sat, 21 Nov 2020 23:43:38 -0800 Subject: [PATCH] Add check for `UnknownSnapshotCopyRegionFault` error --- moto/redshift/exceptions.py | 7 +++++++ moto/redshift/models.py | 5 +++++ tests/test_redshift/test_redshift.py | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/moto/redshift/exceptions.py b/moto/redshift/exceptions.py index c071d19da..eb6cea99e 100644 --- a/moto/redshift/exceptions.py +++ b/moto/redshift/exceptions.py @@ -150,3 +150,10 @@ class InvalidParameterCombinationError(RedshiftClientError): super(InvalidParameterCombinationError, self).__init__( "InvalidParameterCombination", message ) + + +class UnknownSnapshotCopyRegionFaultError(RedshiftClientError): + def __init__(self, message): + super(UnknownSnapshotCopyRegionFaultError, self).__init__( + "UnknownSnapshotCopyRegionFault", message + ) diff --git a/moto/redshift/models.py b/moto/redshift/models.py index 2fc73b8f6..bb28af029 100644 --- a/moto/redshift/models.py +++ b/moto/redshift/models.py @@ -26,6 +26,7 @@ from .exceptions import ( SnapshotCopyDisabledFaultError, SnapshotCopyGrantAlreadyExistsFaultError, SnapshotCopyGrantNotFoundFaultError, + UnknownSnapshotCopyRegionFaultError, ) @@ -577,6 +578,10 @@ class RedshiftBackend(BaseBackend): raise InvalidParameterValueError( "SnapshotCopyGrantName is required for Snapshot Copy on KMS encrypted clusters." ) + if kwargs["destination_region"] == self.region: + raise UnknownSnapshotCopyRegionFaultError( + "Invalid region {}".format(self.region) + ) status = { "DestinationRegion": kwargs["destination_region"], "RetentionPeriod": kwargs["retention_period"], diff --git a/tests/test_redshift/test_redshift.py b/tests/test_redshift/test_redshift.py index e2be4e75a..c9f0e3572 100644 --- a/tests/test_redshift/test_redshift.py +++ b/tests/test_redshift/test_redshift.py @@ -1268,6 +1268,15 @@ def test_enable_snapshot_copy(): ex.value.response["Error"]["Message"].should.contain( "SnapshotCopyGrantName is required for Snapshot Copy on KMS encrypted clusters." ) + with pytest.raises(ClientError) as ex: + client.enable_snapshot_copy( + ClusterIdentifier="test", + DestinationRegion="us-east-1", + RetentionPeriod=3, + SnapshotCopyGrantName="invalid-us-east-1-to-us-east-1", + ) + ex.value.response["Error"]["Code"].should.equal("UnknownSnapshotCopyRegionFault") + ex.value.response["Error"]["Message"].should.contain("Invalid region us-east-1") client.enable_snapshot_copy( ClusterIdentifier="test", DestinationRegion="us-west-2",