Merge pull request #1765 from nate/fix/double-create-queue-with-redrive-policy
Don't error on double create queue with same attrs
This commit is contained in:
commit
ec2b278fc8
@ -385,10 +385,22 @@ class SQSBackend(BaseBackend):
|
|||||||
def create_queue(self, name, **kwargs):
|
def create_queue(self, name, **kwargs):
|
||||||
queue = self.queues.get(name)
|
queue = self.queues.get(name)
|
||||||
if queue:
|
if queue:
|
||||||
# Queue already exist. If attributes don't match, throw error
|
try:
|
||||||
for key, value in kwargs.items():
|
kwargs.pop('region')
|
||||||
if getattr(queue, camelcase_to_underscores(key)) != value:
|
except KeyError:
|
||||||
raise QueueAlreadyExists("The specified queue already exists.")
|
pass
|
||||||
|
|
||||||
|
new_queue = Queue(name, region=self.region_name, **kwargs)
|
||||||
|
|
||||||
|
queue_attributes = queue.attributes
|
||||||
|
new_queue_attributes = new_queue.attributes
|
||||||
|
|
||||||
|
for key in ['CreatedTimestamp', 'LastModifiedTimestamp']:
|
||||||
|
queue_attributes.pop(key)
|
||||||
|
new_queue_attributes.pop(key)
|
||||||
|
|
||||||
|
if queue_attributes != new_queue_attributes:
|
||||||
|
raise QueueAlreadyExists("The specified queue already exists.")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
kwargs.pop('region')
|
kwargs.pop('region')
|
||||||
|
@ -40,6 +40,33 @@ def test_create_fifo_queue_fail():
|
|||||||
raise RuntimeError('Should of raised InvalidParameterValue Exception')
|
raise RuntimeError('Should of raised InvalidParameterValue Exception')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_sqs
|
||||||
|
def test_create_queue_with_same_attributes():
|
||||||
|
sqs = boto3.client('sqs', region_name='us-east-1')
|
||||||
|
|
||||||
|
dlq_url = sqs.create_queue(QueueName='test-queue-dlq')['QueueUrl']
|
||||||
|
dlq_arn = sqs.get_queue_attributes(QueueUrl=dlq_url)['Attributes']['QueueArn']
|
||||||
|
|
||||||
|
attributes = {
|
||||||
|
'DelaySeconds': '900',
|
||||||
|
'MaximumMessageSize': '262144',
|
||||||
|
'MessageRetentionPeriod': '1209600',
|
||||||
|
'ReceiveMessageWaitTimeSeconds': '20',
|
||||||
|
'RedrivePolicy': '{"deadLetterTargetArn": "%s", "maxReceiveCount": 100}' % (dlq_arn),
|
||||||
|
'VisibilityTimeout': '43200'
|
||||||
|
}
|
||||||
|
|
||||||
|
sqs.create_queue(
|
||||||
|
QueueName='test-queue',
|
||||||
|
Attributes=attributes
|
||||||
|
)
|
||||||
|
|
||||||
|
sqs.create_queue(
|
||||||
|
QueueName='test-queue',
|
||||||
|
Attributes=attributes
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@mock_sqs
|
@mock_sqs
|
||||||
def test_create_queue_with_different_attributes_fail():
|
def test_create_queue_with_different_attributes_fail():
|
||||||
sqs = boto3.client('sqs', region_name='us-east-1')
|
sqs = boto3.client('sqs', region_name='us-east-1')
|
||||||
|
Loading…
Reference in New Issue
Block a user