Add ec2 filtering by instance state
This commit is contained in:
parent
76ea9172da
commit
257ca9f771
5 changed files with 98 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ import base64
|
|||
|
||||
import boto
|
||||
from boto.ec2.instance import Reservation, InstanceAttribute
|
||||
from boto.exception import EC2ResponseError
|
||||
import sure # flake8: noqa
|
||||
|
||||
from moto import mock_ec2
|
||||
|
|
@ -69,6 +70,34 @@ def test_get_instances_by_id():
|
|||
instance_ids = [instance.id for instance in reservation.instances]
|
||||
instance_ids.should.equal([instance1.id, instance2.id])
|
||||
|
||||
# Call get_all_instances with a bad id should raise an error
|
||||
conn.get_all_instances.when.called_with(instance_ids=[instance1.id, "i-1234abcd"]).should.throw(
|
||||
EC2ResponseError,
|
||||
"The instance ID 'i-1234abcd' does not exist"
|
||||
)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_get_instances_filtering_by_state():
|
||||
conn = boto.connect_ec2()
|
||||
reservation = conn.run_instances('ami-1234abcd', min_count=3)
|
||||
instance1, instance2, instance3 = reservation.instances
|
||||
|
||||
conn.terminate_instances([instance1.id])
|
||||
|
||||
reservations = conn.get_all_instances(filters={'instance-state-name': 'pending'})
|
||||
reservations.should.have.length_of(1)
|
||||
# Since we terminated instance1, only instance2 and instance3 should be returned
|
||||
instance_ids = [instance.id for instance in reservations[0].instances]
|
||||
set(instance_ids).should.equal(set([instance2.id, instance3.id]))
|
||||
|
||||
reservations = conn.get_all_instances([instance2.id], filters={'instance-state-name': 'pending'})
|
||||
reservations.should.have.length_of(1)
|
||||
instance_ids = [instance.id for instance in reservations[0].instances]
|
||||
instance_ids.should.equal([instance2.id])
|
||||
|
||||
conn.get_all_instances.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_instance_start_and_stop():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue