From 96843fdfe8083f69dc5b10533691e7dd6839827b Mon Sep 17 00:00:00 2001 From: Christian Wittwer Date: Thu, 5 Jun 2014 10:51:45 +0200 Subject: [PATCH 1/2] Attribute instance-id added to filter dict --- moto/ec2/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/moto/ec2/utils.py b/moto/ec2/utils.py index b41d172f5..0e3d30990 100644 --- a/moto/ec2/utils.py +++ b/moto/ec2/utils.py @@ -175,7 +175,8 @@ def keypair_names_from_querystring(querystring_dict): filter_dict_attribute_mapping = { - 'instance-state-name': 'state' + 'instance-state-name': 'state', + 'instance-id': 'id' } From 6f3a0561715134a43a7b1dbf847d1752b67a36d7 Mon Sep 17 00:00:00 2001 From: Christian Wittwer Date: Thu, 5 Jun 2014 11:12:42 +0200 Subject: [PATCH 2/2] add test for instance filtering by instance-id --- tests/test_ec2/test_instances.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 9a0cd19be..3ee2a2796 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -106,6 +106,23 @@ def test_get_instances_filtering_by_state(): conn.get_all_instances.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError) +@mock_ec2 +def test_get_instances_filtering_by_instance_id(): + conn = boto.connect_ec2() + reservation = conn.run_instances('ami-1234abcd', min_count=3) + instance1, instance2, instance3 = reservation.instances + + reservations = conn.get_all_instances(filters={'instance-id': instance1.id}) + # get_all_instances should return just instance1 + reservations[0].instances.should.have.length_of(1) + reservations[0].instances[0].id.should.equal(instance1.id) + + reservations = conn.get_all_instances(filters={'instance-id': [instance1.id, instance2.id]}) + # get_all_instances should return two + reservations[0].instances.should.have.length_of(2) + + reservations = conn.get_all_instances(filters={'instance-id': 'non-existing-id'}) + reservations.should.have.length_of(0) @mock_ec2 def test_instance_start_and_stop():