[1009] Converts ECS Instance full arn to instance_id for storage
This commit is contained in:
parent
71a054af92
commit
090cad8c88
@ -769,6 +769,8 @@ class EC2ContainerServiceBackend(BaseBackend):
|
|||||||
Container instances status should be one of [ACTIVE,DRAINING]")
|
Container instances status should be one of [ACTIVE,DRAINING]")
|
||||||
failures = []
|
failures = []
|
||||||
container_instance_objects = []
|
container_instance_objects = []
|
||||||
|
list_container_instance_ids = [x.split('/')[-1]
|
||||||
|
for x in list_container_instance_ids]
|
||||||
for container_instance_id in list_container_instance_ids:
|
for container_instance_id in list_container_instance_ids:
|
||||||
container_instance = self.container_instances[cluster_name].get(container_instance_id, None)
|
container_instance = self.container_instances[cluster_name].get(container_instance_id, None)
|
||||||
if container_instance is not None:
|
if container_instance is not None:
|
||||||
|
@ -910,6 +910,65 @@ def test_update_container_instances_state():
|
|||||||
status='test_status').should.throw(Exception)
|
status='test_status').should.throw(Exception)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
@mock_ecs
|
||||||
|
def test_update_container_instances_state_by_arn():
|
||||||
|
ecs_client = boto3.client('ecs', region_name='us-east-1')
|
||||||
|
ec2 = boto3.resource('ec2', region_name='us-east-1')
|
||||||
|
|
||||||
|
test_cluster_name = 'test_ecs_cluster'
|
||||||
|
_ = ecs_client.create_cluster(
|
||||||
|
clusterName=test_cluster_name
|
||||||
|
)
|
||||||
|
|
||||||
|
instance_to_create = 3
|
||||||
|
test_instance_arns = []
|
||||||
|
for i in range(0, instance_to_create):
|
||||||
|
test_instance = ec2.create_instances(
|
||||||
|
ImageId="ami-1234abcd",
|
||||||
|
MinCount=1,
|
||||||
|
MaxCount=1,
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
instance_id_document = json.dumps(
|
||||||
|
ec2_utils.generate_instance_identity_document(test_instance)
|
||||||
|
)
|
||||||
|
|
||||||
|
response = ecs_client.register_container_instance(
|
||||||
|
cluster=test_cluster_name,
|
||||||
|
instanceIdentityDocument=instance_id_document)
|
||||||
|
|
||||||
|
test_instance_arns.append(response['containerInstance']['containerInstanceArn'])
|
||||||
|
|
||||||
|
response = ecs_client.update_container_instances_state(cluster=test_cluster_name,
|
||||||
|
containerInstances=test_instance_arns,
|
||||||
|
status='DRAINING')
|
||||||
|
len(response['failures']).should.equal(0)
|
||||||
|
len(response['containerInstances']).should.equal(instance_to_create)
|
||||||
|
response_statuses = [ci['status'] for ci in response['containerInstances']]
|
||||||
|
for status in response_statuses:
|
||||||
|
status.should.equal('DRAINING')
|
||||||
|
response = ecs_client.update_container_instances_state(cluster=test_cluster_name,
|
||||||
|
containerInstances=test_instance_arns,
|
||||||
|
status='DRAINING')
|
||||||
|
len(response['failures']).should.equal(0)
|
||||||
|
len(response['containerInstances']).should.equal(instance_to_create)
|
||||||
|
response_statuses = [ci['status'] for ci in response['containerInstances']]
|
||||||
|
for status in response_statuses:
|
||||||
|
status.should.equal('DRAINING')
|
||||||
|
response = ecs_client.update_container_instances_state(cluster=test_cluster_name,
|
||||||
|
containerInstances=test_instance_arns,
|
||||||
|
status='ACTIVE')
|
||||||
|
len(response['failures']).should.equal(0)
|
||||||
|
len(response['containerInstances']).should.equal(instance_to_create)
|
||||||
|
response_statuses = [ci['status'] for ci in response['containerInstances']]
|
||||||
|
for status in response_statuses:
|
||||||
|
status.should.equal('ACTIVE')
|
||||||
|
ecs_client.update_container_instances_state.when.called_with(cluster=test_cluster_name,
|
||||||
|
containerInstances=test_instance_arns,
|
||||||
|
status='test_status').should.throw(Exception)
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
@mock_ecs
|
@mock_ecs
|
||||||
def test_run_task():
|
def test_run_task():
|
||||||
|
Loading…
Reference in New Issue
Block a user