From b5a454e0dad24c05f3a6a6290c66360965b2570f Mon Sep 17 00:00:00 2001 From: Ilya Sukhanov Date: Wed, 28 Aug 2013 10:19:12 -0400 Subject: [PATCH] When manipulating instance save end states instead of transitional When starting an instance it should eventually enter running state. At least in the normal case. So we report pending but save running, this way when client requests state of instance a second time, we reply with running. Similar thing for stop/terminate/reboot. --- moto/ec2/models.py | 18 +++++++++--------- moto/ec2/responses/amis.py | 5 ++++- moto/ec2/responses/instances.py | 20 ++++++++++---------- tests/test_ec2/test_instances.py | 11 ++++++----- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 1bcdbe5d7..ccde643e9 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -29,24 +29,24 @@ class Instance(BotoInstance): super(Instance, self).__init__() self.id = random_instance_id() self.image_id = image_id - self._state = InstanceState() + self._state = InstanceState("running", 16) self.user_data = user_data def start(self): - self._state.name = "pending" - self._state.code = 0 + self._state.name = "running" + self._state.code = 16 def stop(self): - self._state.name = "stopping" - self._state.code = 64 + self._state.name = "stopped" + self._state.code = 80 def terminate(self): - self._state.name = "shutting-down" - self._state.code = 32 + self._state.name = "terminated" + self._state.code = 48 def reboot(self): - self._state.name = "pending" - self._state.code = 0 + self._state.name = "running" + self._state.code = 16 def get_tags(self): tags = ec2_backend.describe_tags(self.id) diff --git a/moto/ec2/responses/amis.py b/moto/ec2/responses/amis.py index b95fbfab6..b6e856388 100644 --- a/moto/ec2/responses/amis.py +++ b/moto/ec2/responses/amis.py @@ -7,7 +7,10 @@ from moto.ec2.utils import instance_ids_from_querystring class AmisResponse(object): def create_image(self): name = self.querystring.get('Name')[0] - description = self.querystring.get('Description')[0] + if "Description" in self.querystring: + description = self.querystring.get('Description')[0] + else: + description = "" instance_ids = instance_ids_from_querystring(self.querystring) instance_id = instance_ids[0] image = ec2_backend.create_image(instance_id, name, description) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 68be9dafd..f230dcf49 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -95,8 +95,8 @@ EC2_RUN_INSTANCES = """