From 4f847cfb4bdead77114efb1d4889f433789369c8 Mon Sep 17 00:00:00 2001 From: dreadpirateshawn Date: Wed, 22 Oct 2014 15:11:37 -0700 Subject: [PATCH] ModifyInstanceAttribute: Added support for 'SourceDestCheck.Value'. --- moto/ec2/models.py | 1 + .../responses/elastic_network_interfaces.py | 8 +++-- moto/ec2/responses/instances.py | 8 ++--- tests/test_ec2/test_instances.py | 34 +++++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 5337fe563..13d70a086 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -280,6 +280,7 @@ class Instance(BotoInstance, TaggedEC2Resource): self.instance_type = kwargs.get("instance_type", "m1.small") self.subnet_id = kwargs.get("subnet_id") self.key_name = kwargs.get("key_name") + self.source_dest_check = "true" self.block_device_mapping = BlockDeviceMapping() self.block_device_mapping['/dev/sda1'] = BlockDeviceType(volume_id=random_volume_id()) diff --git a/moto/ec2/responses/elastic_network_interfaces.py b/moto/ec2/responses/elastic_network_interfaces.py index dc952cd05..d3f7388bc 100644 --- a/moto/ec2/responses/elastic_network_interfaces.py +++ b/moto/ec2/responses/elastic_network_interfaces.py @@ -72,7 +72,9 @@ CREATE_NETWORK_INTERFACE_RESPONSE = """ {% if eni.private_ip_address %} {{ eni.private_ip_address }} {% endif %} - true + {% if eni.instance %} + {{ eni.instance.source_dest_check }} + {% endif %} {% for group in eni.group_set %} @@ -114,7 +116,9 @@ DESCRIBE_NETWORK_INTERFACES_RESPONSE = """{{ eni.private_ip_address }} {% endif %} ip-10-0-0-134.us-west-2.compute.internal - true + {% if eni.instance %} + {{ eni.instance.source_dest_check }} + {% endif %} {% for group in eni.group_set %} diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 70f19a8f2..49050f9d6 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -206,7 +206,7 @@ EC2_RUN_INSTANCES = """in-use 1b:2b:3c:4d:5e:6f {{ nic.private_ip_address }} - true + {{ instance.source_dest_check }} {% for group in nic.group_set %} diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 955ce0477..98740a8ae 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -246,6 +246,40 @@ def test_instance_attribute_user_data(): instance_attribute.get("userData").should.equal("this is my user data") +@mock_ec2 +def test_instance_attribute_source_dest_check(): + conn = boto.connect_ec2('the_key', 'the_secret') + reservation = conn.run_instances('ami-1234abcd') + instance = reservation.instances[0] + + # Default value is true + instance.sourceDestCheck.should.equal('true') + + instance_attribute = instance.get_attribute("sourceDestCheck") + instance_attribute.should.be.a(InstanceAttribute) + instance_attribute.get("sourceDestCheck").should.equal(True) + + # Set to false (note: Boto converts bool to string, eg 'false') + instance.modify_attribute("sourceDestCheck", False) + + instance.update() + instance.sourceDestCheck.should.equal('false') + + instance_attribute = instance.get_attribute("sourceDestCheck") + instance_attribute.should.be.a(InstanceAttribute) + instance_attribute.get("sourceDestCheck").should.equal(False) + + # Set back to true + instance.modify_attribute("sourceDestCheck", True) + + instance.update() + instance.sourceDestCheck.should.equal('true') + + instance_attribute = instance.get_attribute("sourceDestCheck") + instance_attribute.should.be.a(InstanceAttribute) + instance_attribute.get("sourceDestCheck").should.equal(True) + + @mock_ec2 def test_user_data_with_run_instance(): user_data = b"some user data"