| 
									
										
										
										
											2014-08-27 11:17:06 -04:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | import datetime | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | import boto | 
					
						
							| 
									
										
										
										
											2016-11-07 23:08:30 -05:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | from boto.exception import EC2ResponseError | 
					
						
							|  |  |  | from botocore.exceptions import ClientError | 
					
						
							|  |  |  | import pytz | 
					
						
							| 
									
										
										
										
											2013-08-03 17:21:25 -04:00
										 |  |  | import sure  # noqa | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:08:23 +01:00
										 |  |  | from moto import mock_ec2, mock_ec2_deprecated, settings | 
					
						
							|  |  |  | from moto.ec2.models import ec2_backends | 
					
						
							| 
									
										
										
										
											2014-11-29 23:34:40 -05:00
										 |  |  | from moto.core.utils import iso_8601_datetime_with_milliseconds | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_request_spot_instances(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("ec2", "us-east-1") | 
					
						
							|  |  |  |     vpc = conn.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     subnet = conn.create_subnet( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         VpcId=vpc["VpcId"], CidrBlock="10.0.0.0/16", AvailabilityZone="us-east-1a" | 
					
						
							|  |  |  |     )["Subnet"] | 
					
						
							|  |  |  |     subnet_id = subnet["SubnetId"] | 
					
						
							| 
									
										
										
										
											2016-11-07 23:08:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.create_security_group(GroupName="group1", Description="description") | 
					
						
							|  |  |  |     conn.create_security_group(GroupName="group2", Description="description") | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |     start_dt = datetime.datetime(2013, 1, 1).replace(tzinfo=pytz.utc) | 
					
						
							|  |  |  |     end_dt = datetime.datetime(2013, 1, 2).replace(tzinfo=pytz.utc) | 
					
						
							|  |  |  |     start = iso_8601_datetime_with_milliseconds(start_dt) | 
					
						
							|  |  |  |     end = iso_8601_datetime_with_milliseconds(end_dt) | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  |         request = conn.request_spot_instances( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             SpotPrice="0.5", | 
					
						
							|  |  |  |             InstanceCount=1, | 
					
						
							|  |  |  |             Type="one-time", | 
					
						
							|  |  |  |             ValidFrom=start, | 
					
						
							|  |  |  |             ValidUntil=end, | 
					
						
							|  |  |  |             LaunchGroup="the-group", | 
					
						
							|  |  |  |             AvailabilityZoneGroup="my-group", | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |             LaunchSpecification={ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "ImageId": "ami-abcd1234", | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |                 "KeyName": "test", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "SecurityGroups": ["group1", "group2"], | 
					
						
							| 
									
										
										
										
											2017-02-23 22:28:09 -05:00
										 |  |  |                 "UserData": "some test data", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "InstanceType": "m1.small", | 
					
						
							|  |  |  |                 "Placement": {"AvailabilityZone": "us-east-1c"}, | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |                 "KernelId": "test-kernel", | 
					
						
							|  |  |  |                 "RamdiskId": "test-ramdisk", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                 "Monitoring": {"Enabled": True}, | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  |                 "SubnetId": subnet_id, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             DryRun=True, | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  |         ) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.response["Error"]["Code"].should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) | 
					
						
							|  |  |  |     ex.value.response["Error"]["Message"].should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the RequestSpotInstance operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  |     request = conn.request_spot_instances( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         SpotPrice="0.5", | 
					
						
							|  |  |  |         InstanceCount=1, | 
					
						
							|  |  |  |         Type="one-time", | 
					
						
							|  |  |  |         ValidFrom=start, | 
					
						
							|  |  |  |         ValidUntil=end, | 
					
						
							|  |  |  |         LaunchGroup="the-group", | 
					
						
							|  |  |  |         AvailabilityZoneGroup="my-group", | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |         LaunchSpecification={ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "ImageId": "ami-abcd1234", | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |             "KeyName": "test", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "SecurityGroups": ["group1", "group2"], | 
					
						
							| 
									
										
										
										
											2017-02-23 22:28:09 -05:00
										 |  |  |             "UserData": "some test data", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "InstanceType": "m1.small", | 
					
						
							|  |  |  |             "Placement": {"AvailabilityZone": "us-east-1c"}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |             "KernelId": "test-kernel", | 
					
						
							|  |  |  |             "RamdiskId": "test-ramdisk", | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |             "Monitoring": {"Enabled": True}, | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |             "SubnetId": subnet_id, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     requests = conn.describe_spot_instance_requests()["SpotInstanceRequests"] | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  |     requests.should.have.length_of(1) | 
					
						
							|  |  |  |     request = requests[0] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     request["State"].should.equal("open") | 
					
						
							|  |  |  |     request["SpotPrice"].should.equal("0.5") | 
					
						
							|  |  |  |     request["Type"].should.equal("one-time") | 
					
						
							|  |  |  |     request["ValidFrom"].should.equal(start_dt) | 
					
						
							|  |  |  |     request["ValidUntil"].should.equal(end_dt) | 
					
						
							|  |  |  |     request["LaunchGroup"].should.equal("the-group") | 
					
						
							|  |  |  |     request["AvailabilityZoneGroup"].should.equal("my-group") | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     launch_spec = request["LaunchSpecification"] | 
					
						
							|  |  |  |     security_group_names = [ | 
					
						
							|  |  |  |         group["GroupName"] for group in launch_spec["SecurityGroups"] | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     set(security_group_names).should.equal(set(["group1", "group2"])) | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     launch_spec["ImageId"].should.equal("ami-abcd1234") | 
					
						
							|  |  |  |     launch_spec["KeyName"].should.equal("test") | 
					
						
							|  |  |  |     launch_spec["InstanceType"].should.equal("m1.small") | 
					
						
							|  |  |  |     launch_spec["KernelId"].should.equal("test-kernel") | 
					
						
							|  |  |  |     launch_spec["RamdiskId"].should.equal("test-ramdisk") | 
					
						
							|  |  |  |     launch_spec["SubnetId"].should.equal(subnet_id) | 
					
						
							| 
									
										
										
										
											2013-02-21 23:13:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | def test_request_spot_instances_default_arguments(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Test that moto set the correct default arguments | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn = boto3.client("ec2", "us-east-1") | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     request = conn.request_spot_instances( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         SpotPrice="0.5", LaunchSpecification={"ImageId": "ami-abcd1234"} | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     requests = conn.describe_spot_instance_requests()["SpotInstanceRequests"] | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  |     requests.should.have.length_of(1) | 
					
						
							|  |  |  |     request = requests[0] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     request["State"].should.equal("open") | 
					
						
							|  |  |  |     request["SpotPrice"].should.equal("0.5") | 
					
						
							|  |  |  |     request["Type"].should.equal("one-time") | 
					
						
							|  |  |  |     request.shouldnt.contain("ValidFrom") | 
					
						
							|  |  |  |     request.shouldnt.contain("ValidUntil") | 
					
						
							|  |  |  |     request.shouldnt.contain("LaunchGroup") | 
					
						
							|  |  |  |     request.shouldnt.contain("AvailabilityZoneGroup") | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     launch_spec = request["LaunchSpecification"] | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     security_group_names = [ | 
					
						
							|  |  |  |         group["GroupName"] for group in launch_spec["SecurityGroups"] | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  |     security_group_names.should.equal(["default"]) | 
					
						
							| 
									
										
										
										
											2017-02-23 19:43:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     launch_spec["ImageId"].should.equal("ami-abcd1234") | 
					
						
							|  |  |  |     request.shouldnt.contain("KeyName") | 
					
						
							|  |  |  |     launch_spec["InstanceType"].should.equal("m1.small") | 
					
						
							|  |  |  |     request.shouldnt.contain("KernelId") | 
					
						
							|  |  |  |     request.shouldnt.contain("RamdiskId") | 
					
						
							|  |  |  |     request.shouldnt.contain("SubnetId") | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | def test_cancel_spot_instance_request(): | 
					
						
							|  |  |  |     conn = boto.connect_ec2() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     requests = conn.get_all_spot_instance_requests() | 
					
						
							|  |  |  |     requests.should.have.length_of(1) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(EC2ResponseError) as ex: | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  |         conn.cancel_spot_instance_requests([requests[0].id], dry_run=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     ex.value.error_code.should.equal("DryRunOperation") | 
					
						
							|  |  |  |     ex.value.status.should.equal(400) | 
					
						
							|  |  |  |     ex.value.message.should.equal( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "An error occurred (DryRunOperation) when calling the CancelSpotInstance operation: Request would have succeeded, but DryRun flag is set" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2016-10-15 23:08:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 18:11:29 -04:00
										 |  |  |     conn.cancel_spot_instance_requests([requests[0].id]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     requests = conn.get_all_spot_instance_requests() | 
					
						
							|  |  |  |     requests.should.have.length_of(0) | 
					
						
							| 
									
										
										
										
											2014-07-29 15:29:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-07-29 15:29:52 +03:00
										 |  |  | def test_request_spot_instances_fulfilled(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Test that moto correctly fullfills a spot instance request | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2014-11-15 13:50:58 -05:00
										 |  |  |     conn = boto.ec2.connect_to_region("us-east-1") | 
					
						
							| 
									
										
										
										
											2014-07-29 15:29:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     request = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") | 
					
						
							| 
									
										
										
										
											2014-07-29 15:29:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     requests = conn.get_all_spot_instance_requests() | 
					
						
							|  |  |  |     requests.should.have.length_of(1) | 
					
						
							|  |  |  |     request = requests[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     request.state.should.equal("open") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:08:23 +01:00
										 |  |  |     if not settings.TEST_SERVER_MODE: | 
					
						
							|  |  |  |         ec2_backends["us-east-1"].spot_instance_requests[request.id].state = "active" | 
					
						
							| 
									
										
										
										
											2014-07-29 15:29:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:08:23 +01:00
										 |  |  |         requests = conn.get_all_spot_instance_requests() | 
					
						
							|  |  |  |         requests.should.have.length_of(1) | 
					
						
							|  |  |  |         request = requests[0] | 
					
						
							| 
									
										
										
										
											2014-07-29 15:29:52 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:08:23 +01:00
										 |  |  |         request.state.should.equal("active") | 
					
						
							| 
									
										
										
										
											2014-09-04 12:38:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-09-04 12:38:09 -07:00
										 |  |  | def test_tag_spot_instance_request(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Test that moto correctly tags a spot instance request | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     conn = boto.connect_ec2() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     request = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") | 
					
						
							|  |  |  |     request[0].add_tag("tag1", "value1") | 
					
						
							|  |  |  |     request[0].add_tag("tag2", "value2") | 
					
						
							| 
									
										
										
										
											2014-09-04 12:38:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     requests = conn.get_all_spot_instance_requests() | 
					
						
							|  |  |  |     requests.should.have.length_of(1) | 
					
						
							|  |  |  |     request = requests[0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     tag_dict = dict(request.tags) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     tag_dict.should.equal({"tag1": "value1", "tag2": "value2"}) | 
					
						
							| 
									
										
										
										
											2014-09-04 12:39:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-09-04 12:39:14 -07:00
										 |  |  | def test_get_all_spot_instance_requests_filtering(): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Test that moto correctly filters spot instance requests | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     conn = boto.connect_ec2() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     request1 = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") | 
					
						
							|  |  |  |     request2 = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") | 
					
						
							|  |  |  |     conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") | 
					
						
							|  |  |  |     request1[0].add_tag("tag1", "value1") | 
					
						
							|  |  |  |     request1[0].add_tag("tag2", "value2") | 
					
						
							|  |  |  |     request2[0].add_tag("tag1", "value1") | 
					
						
							|  |  |  |     request2[0].add_tag("tag2", "wrong") | 
					
						
							| 
									
										
										
										
											2014-09-04 12:39:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     requests = conn.get_all_spot_instance_requests(filters={"state": "active"}) | 
					
						
							| 
									
										
										
										
											2014-09-04 12:39:14 -07:00
										 |  |  |     requests.should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     requests = conn.get_all_spot_instance_requests(filters={"state": "open"}) | 
					
						
							| 
									
										
										
										
											2014-09-04 12:39:14 -07:00
										 |  |  |     requests.should.have.length_of(3) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     requests = conn.get_all_spot_instance_requests(filters={"tag:tag1": "value1"}) | 
					
						
							| 
									
										
										
										
											2014-09-04 12:39:14 -07:00
										 |  |  |     requests.should.have.length_of(2) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 21:37:43 -05:00
										 |  |  |     requests = conn.get_all_spot_instance_requests( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         filters={"tag:tag1": "value1", "tag:tag2": "value2"} | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2014-09-04 12:39:14 -07:00
										 |  |  |     requests.should.have.length_of(1) | 
					
						
							| 
									
										
										
										
											2014-10-05 22:55:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 22:35:45 -05:00
										 |  |  | @mock_ec2_deprecated | 
					
						
							| 
									
										
										
										
											2014-10-05 22:55:36 -04:00
										 |  |  | def test_request_spot_instances_setting_instance_id(): | 
					
						
							| 
									
										
										
										
											2014-11-15 13:50:58 -05:00
										 |  |  |     conn = boto.ec2.connect_to_region("us-east-1") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     request = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") | 
					
						
							| 
									
										
										
										
											2014-10-05 22:55:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:08:23 +01:00
										 |  |  |     if not settings.TEST_SERVER_MODE: | 
					
						
							|  |  |  |         req = ec2_backends["us-east-1"].spot_instance_requests[request[0].id] | 
					
						
							|  |  |  |         req.state = "active" | 
					
						
							|  |  |  |         req.instance_id = "i-12345678" | 
					
						
							| 
									
										
										
										
											2014-10-05 22:55:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 16:08:23 +01:00
										 |  |  |         request = conn.get_all_spot_instance_requests()[0] | 
					
						
							|  |  |  |         assert request.state == "active" | 
					
						
							|  |  |  |         assert request.instance_id == "i-12345678" |