From 82214d2bc2a83d17217bdac87b1207fb31e3e256 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Sat, 28 Mar 2015 14:30:30 -0400 Subject: [PATCH] Fix bug with empty string for instance vpc_id. Closes #337. --- moto/ec2/responses/instances.py | 24 ++++++++++++++++-------- tests/test_ec2/test_instances.py | 5 +++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index f7c03206d..6a3ff35f5 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -214,8 +214,10 @@ EC2_RUN_INSTANCES = """ {{ nic.id }} - {{ nic.subnet.id }} - {{ nic.subnet.vpc_id }} + {% if nic.subnet %} + {{ nic.subnet.id }} + {{ nic.subnet.vpc_id }} + {% endif %} Primary network interface 111122223333 in-use diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 640a24eaf..5ee732d5e 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -54,6 +54,7 @@ def test_instance_launch_and_terminate(): instances[0].id.should.equal(instance.id) instances[0].state.should.equal('running') instances[0].launch_time.should.equal("2014-01-01T05:00:00") + instances[0].vpc_id.should.equal(None) root_device_name = instances[0].root_device_name instances[0].block_device_mapping[root_device_name].status.should.equal('attached') @@ -155,7 +156,7 @@ def test_get_instances_filtering_by_instance_type(): reservations.should.have.length_of(2) reservations[0].instances.should.have.length_of(1) reservations[1].instances.should.have.length_of(1) - instance_ids = [ reservations[0].instances[0].id, + instance_ids = [ reservations[0].instances[0].id, reservations[1].instances[0].id ] set(instance_ids).should.equal(set([instance1.id, instance2.id])) @@ -311,7 +312,7 @@ def test_get_instances_filtering_by_tag_value(): reservations[0].instances[0].id.should.equal(instance1.id) reservations[0].instances[1].id.should.equal(instance2.id) reservations[0].instances[2].id.should.equal(instance3.id) - + reservations = conn.get_all_instances(filters={'tag-value' : ['value2', 'bogus']}) # get_all_instances should return both instances with one of the acceptable tag values reservations.should.have.length_of(1)