From 062256ada323c80ec5ffe0d9656ef4cde4e394ff Mon Sep 17 00:00:00 2001 From: Chris Henry Date: Sun, 18 Jan 2015 15:53:59 -0500 Subject: [PATCH 1/6] Use the current time when launching an instance. --- moto/ec2/models.py | 1 + moto/ec2/responses/instances.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index e9246a6bf..574621001 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -299,6 +299,7 @@ class Instance(BotoInstance, TaggedEC2Resource): self.subnet_id = kwargs.get("subnet_id") self.key_name = kwargs.get("key_name") self.source_dest_check = "true" + self.launch_time = datetime.now().strftime('%y-%m-%dT%H:%M:%S%z') self.block_device_mapping = BlockDeviceMapping() self.block_device_mapping['/dev/sda1'] = BlockDeviceType(volume_id=random_volume_id()) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 7922f9d99..49b385a58 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -325,7 +325,7 @@ EC2_DESCRIBE_INSTANCES = """ Date: Sun, 18 Jan 2015 16:20:59 -0500 Subject: [PATCH 3/6] Change timestamp format to ISO 8601, as per http://docs.aws.amazon.com/cli/latest/userguide/cli-using-param.html --- moto/ec2/responses/instances.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 49b385a58..62456bc87 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -204,7 +204,7 @@ EC2_RUN_INSTANCES = """ Date: Sun, 18 Jan 2015 16:37:56 -0500 Subject: [PATCH 5/6] Fix merge conflict, --- moto/ec2/models.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index edd56f898..8fdb7444b 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -299,11 +299,8 @@ class Instance(BotoInstance, TaggedEC2Resource): self.subnet_id = kwargs.get("subnet_id") self.key_name = kwargs.get("key_name") self.source_dest_check = "true" -<<<<<<< HEAD self.launch_time = datetime.now().isoformat() -======= self.private_ip_address = kwargs.get('private_ip_address') ->>>>>>> c22ea3014b8d2068696ef246e90bd9ec8ec90b91 self.block_device_mapping = BlockDeviceMapping() self.block_device_mapping['/dev/sda1'] = BlockDeviceType(volume_id=random_volume_id()) From b1c41820f70e8d9c8464f5fc380fb8a2fae1c1d5 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Mon, 19 Jan 2015 13:44:15 -0500 Subject: [PATCH 6/6] Cleanup EC2 launch time code a bit. --- moto/ec2/models.py | 2 +- tests/test_ec2/test_instances.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 8fdb7444b..a83284ef6 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -299,7 +299,7 @@ class Instance(BotoInstance, TaggedEC2Resource): self.subnet_id = kwargs.get("subnet_id") self.key_name = kwargs.get("key_name") self.source_dest_check = "true" - self.launch_time = datetime.now().isoformat() + self.launch_time = datetime.utcnow().isoformat() self.private_ip_address = kwargs.get('private_ip_address') self.block_device_mapping = BlockDeviceMapping() diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 346eef514..95f047d5c 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -9,6 +9,7 @@ import datetime import boto from boto.ec2.instance import Reservation, InstanceAttribute from boto.exception import EC2ResponseError +from freezegun import freeze_time import sure # noqa from moto import mock_ec2 @@ -35,6 +36,7 @@ def test_add_servers(): ############################################ +@freeze_time("2014-01-01 05:00:00") @mock_ec2 def test_instance_launch_and_terminate(): conn = boto.connect_ec2('the_key', 'the_secret') @@ -51,7 +53,7 @@ def test_instance_launch_and_terminate(): instances.should.have.length_of(1) instances[0].id.should.equal(instance.id) instances[0].state.should.equal('running') - datetime.datetime.strptime(instances[0].launch_time, '%Y-%m-%dT%H:%M:%S.%f') + instances[0].launch_time.should.equal("2014-01-01T05:00:00") root_device_name = instances[0].root_device_name instances[0].block_device_mapping[root_device_name].status.should.equal('attached')