Add registeredAt to ecs container instance (#3358)

This commit is contained in:
Anton Grübel 2020-10-05 16:39:59 +02:00 committed by GitHub
parent 08da2c92d9
commit 349b9a990d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -1,18 +1,18 @@
from __future__ import unicode_literals
import re
import uuid
from copy import copy
from datetime import datetime
from random import random, randint
import pytz
from boto3 import Session
from moto.core.exceptions import JsonRESTError
from moto.core import BaseBackend, BaseModel, CloudFormationModel
from moto.core.exceptions import JsonRESTError
from moto.core.utils import unix_time
from moto.ec2 import ec2_backends
from copy import copy
from .exceptions import (
ServiceNotFoundException,
TaskDefinitionNotFoundException,
@ -481,6 +481,7 @@ class ContainerInstance(BaseObject):
if ec2_instance.platform == "windows"
else "linux", # options are windows and linux, linux is default
}
self.registered_at = datetime.now(pytz.utc)
@property
def response_object(self):
@ -489,6 +490,10 @@ class ContainerInstance(BaseObject):
self._format_attribute(name, value)
for name, value in response_object["attributes"].items()
]
if isinstance(response_object["registeredAt"], datetime):
response_object["registeredAt"] = unix_time(
response_object["registeredAt"].replace(tzinfo=None)
)
return response_object
def _format_attribute(self, name, value):

View File

@ -950,6 +950,7 @@ def test_describe_container_instances():
for instance in response["containerInstances"]:
instance.keys().should.contain("runningTasksCount")
instance.keys().should.contain("pendingTasksCount")
instance["registeredAt"].should.be.a("datetime.datetime")
with assert_raises(ClientError) as e:
ecs_client.describe_container_instances(