Add Redshift.ClusterAlreadyExists Error

Closes #2967
This commit is contained in:
Brian Pandola 2020-05-06 14:28:40 -07:00
commit 55f207050e
3 changed files with 32 additions and 0 deletions

View file

@ -136,3 +136,10 @@ class SnapshotCopyAlreadyEnabledFaultError(RedshiftClientError):
cluster_identifier
),
)
class ClusterAlreadyExistsFaultError(RedshiftClientError):
def __init__(self):
super(ClusterAlreadyExistsFaultError, self).__init__(
"ClusterAlreadyExists", "Cluster already exists"
)

View file

@ -10,6 +10,7 @@ from moto.core import BaseBackend, BaseModel
from moto.core.utils import iso_8601_datetime_with_milliseconds
from moto.ec2 import ec2_backends
from .exceptions import (
ClusterAlreadyExistsFaultError,
ClusterNotFoundError,
ClusterParameterGroupNotFoundError,
ClusterSecurityGroupNotFoundError,
@ -580,6 +581,8 @@ class RedshiftBackend(BaseBackend):
def create_cluster(self, **cluster_kwargs):
cluster_identifier = cluster_kwargs["cluster_identifier"]
if cluster_identifier in self.clusters:
raise ClusterAlreadyExistsFaultError()
cluster = Cluster(self, **cluster_kwargs)
self.clusters[cluster_identifier] = cluster
return cluster