AWS: handle 'InvalidConversionTaskId.Malformed' error
When we call the describe_import_image_tasks paginator with a task id specified and that task id does not exist, AWS can return a InvalidConversionTaskId.Malformed error instead of the expected empty list. Handle that case and add a test for it. Change-Id: I1a3a9297e123a50a4beeb7e18124b8cc17aa28bb
This commit is contained in:
@@ -824,10 +824,19 @@ class AwsAdapter(statemachine.Adapter):
|
|||||||
paginator = self.ec2_client.get_paginator(
|
paginator = self.ec2_client.get_paginator(
|
||||||
'describe_import_image_tasks')
|
'describe_import_image_tasks')
|
||||||
with self.non_mutating_rate_limiter:
|
with self.non_mutating_rate_limiter:
|
||||||
for page in paginator.paginate(ImportTaskIds=[task_id]):
|
try:
|
||||||
for task in page['ImportImageTasks']:
|
for page in paginator.paginate(ImportTaskIds=[task_id]):
|
||||||
# Return the first and only task
|
for task in page['ImportImageTasks']:
|
||||||
return task
|
# Return the first and only task
|
||||||
|
return task
|
||||||
|
except botocore.exceptions.ClientError as error:
|
||||||
|
if (error.response['Error']['Code'] ==
|
||||||
|
'InvalidConversionTaskId.Malformed'):
|
||||||
|
# In practice, this can mean that the task no
|
||||||
|
# longer exists
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _listImportSnapshotTasks(self):
|
def _listImportSnapshotTasks(self):
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ class ImportImageTaskPaginator:
|
|||||||
if 'ImportTaskIds' in kw:
|
if 'ImportTaskIds' in kw:
|
||||||
tasks = [t for t in tasks
|
tasks = [t for t in tasks
|
||||||
if t['ImportTaskId'] in kw['ImportTaskIds']]
|
if t['ImportTaskId'] in kw['ImportTaskIds']]
|
||||||
|
if not tasks:
|
||||||
|
raise botocore.exceptions.ClientError(
|
||||||
|
{'Error': {'Code': 'InvalidConversionTaskId.Malformed'}},
|
||||||
|
'DescribeImportImageTasks')
|
||||||
# A page of tasks
|
# A page of tasks
|
||||||
ret = [{'ImportImageTasks': tasks}]
|
ret = [{'ImportImageTasks': tasks}]
|
||||||
|
|
||||||
|
|||||||
@@ -1042,6 +1042,14 @@ class TestDriverAws(tests.DBTestCase):
|
|||||||
# Probably not found
|
# Probably not found
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def test_aws_get_import_image_task(self):
|
||||||
|
# A unit test of the unusual error handling for missing tasks
|
||||||
|
configfile = self.setup_config('aws/diskimage.yaml')
|
||||||
|
pool = self.useNodepool(configfile, watermark_sleep=1)
|
||||||
|
self.startPool(pool)
|
||||||
|
adapter = pool.getProviderManager('ec2-us-west-2').adapter
|
||||||
|
self.assertIsNone(adapter._getImportImageTask("fake-id"))
|
||||||
|
|
||||||
def test_aws_provisioning_spot_instances(self):
|
def test_aws_provisioning_spot_instances(self):
|
||||||
# Test creating a spot instances instead of an on-demand on.
|
# Test creating a spot instances instead of an on-demand on.
|
||||||
req = self.requestNode('aws/aws-spot.yaml', 'ubuntu1404-spot')
|
req = self.requestNode('aws/aws-spot.yaml', 'ubuntu1404-spot')
|
||||||
|
|||||||
Reference in New Issue
Block a user