Merge pull request #2818 from bblommers/cloudformation_stack_creation_time

Cloudformation - Stack creation time
This commit is contained in:
Steve Pulec 2020-03-19 19:38:46 -05:00 committed by GitHub
commit b0ea0aa162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -8,6 +8,7 @@ from boto3 import Session
from moto.compat import OrderedDict from moto.compat import OrderedDict
from moto.core import BaseBackend, BaseModel from moto.core import BaseBackend, BaseModel
from moto.core.utils import iso_8601_datetime_without_milliseconds
from .parsing import ResourceMap, OutputMap from .parsing import ResourceMap, OutputMap
from .utils import ( from .utils import (
@ -240,6 +241,7 @@ class FakeStack(BaseModel):
self.output_map = self._create_output_map() self.output_map = self._create_output_map()
self._add_stack_event("CREATE_COMPLETE") self._add_stack_event("CREATE_COMPLETE")
self.status = "CREATE_COMPLETE" self.status = "CREATE_COMPLETE"
self.creation_time = datetime.utcnow()
def _create_resource_map(self): def _create_resource_map(self):
resource_map = ResourceMap( resource_map = ResourceMap(
@ -259,6 +261,10 @@ class FakeStack(BaseModel):
output_map.create() output_map.create()
return output_map return output_map
@property
def creation_time_iso_8601(self):
return iso_8601_datetime_without_milliseconds(self.creation_time)
def _add_stack_event( def _add_stack_event(
self, resource_status, resource_status_reason=None, resource_properties=None self, resource_status, resource_status_reason=None, resource_properties=None
): ):

View File

@ -662,7 +662,7 @@ DESCRIBE_STACKS_TEMPLATE = """<DescribeStacksResponse>
<member> <member>
<StackName>{{ stack.name }}</StackName> <StackName>{{ stack.name }}</StackName>
<StackId>{{ stack.stack_id }}</StackId> <StackId>{{ stack.stack_id }}</StackId>
<CreationTime>2010-07-27T22:28:28Z</CreationTime> <CreationTime>{{ stack.creation_time_iso_8601 }}</CreationTime>
<StackStatus>{{ stack.status }}</StackStatus> <StackStatus>{{ stack.status }}</StackStatus>
{% if stack.notification_arns %} {% if stack.notification_arns %}
<NotificationARNs> <NotificationARNs>
@ -803,7 +803,7 @@ LIST_STACKS_RESPONSE = """<ListStacksResponse>
<StackId>{{ stack.stack_id }}</StackId> <StackId>{{ stack.stack_id }}</StackId>
<StackStatus>{{ stack.status }}</StackStatus> <StackStatus>{{ stack.status }}</StackStatus>
<StackName>{{ stack.name }}</StackName> <StackName>{{ stack.name }}</StackName>
<CreationTime>2011-05-23T15:47:44Z</CreationTime> <CreationTime>{{ stack.creation_time_iso_8601 }}</CreationTime>
<TemplateDescription>{{ stack.description }}</TemplateDescription> <TemplateDescription>{{ stack.description }}</TemplateDescription>
</member> </member>
{% endfor %} {% endfor %}

View File

@ -2,6 +2,8 @@ from __future__ import unicode_literals
import json import json
from collections import OrderedDict from collections import OrderedDict
from datetime import datetime, timedelta
import pytz
import boto3 import boto3
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
@ -911,6 +913,10 @@ def test_describe_stack_by_name():
stack = cf_conn.describe_stacks(StackName="test_stack")["Stacks"][0] stack = cf_conn.describe_stacks(StackName="test_stack")["Stacks"][0]
stack["StackName"].should.equal("test_stack") stack["StackName"].should.equal("test_stack")
two_secs_ago = datetime.now(tz=pytz.UTC) - timedelta(seconds=2)
assert (
two_secs_ago < stack["CreationTime"] < datetime.now(tz=pytz.UTC)
), "Stack should have been created recently"
@mock_cloudformation @mock_cloudformation