From 349b9a990daf17cb1ff5cf74c54c9521ad2f0c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Gr=C3=BCbel?= Date: Mon, 5 Oct 2020 16:39:59 +0200 Subject: [PATCH] Add registeredAt to ecs container instance (#3358) --- moto/ecs/models.py | 11 ++++++++--- tests/test_ecs/test_ecs_boto3.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/moto/ecs/models.py b/moto/ecs/models.py index 7041a322b..210344f10 100644 --- a/moto/ecs/models.py +++ b/moto/ecs/models.py @@ -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): diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py index c528349f5..919124c6e 100644 --- a/tests/test_ecs/test_ecs_boto3.py +++ b/tests/test_ecs/test_ecs_boto3.py @@ -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(