Adding server mode
This commit is contained in:
parent
c6f5afff75
commit
a728b2581a
31 changed files with 489 additions and 66 deletions
|
|
@ -1,14 +1,34 @@
|
|||
import boto
|
||||
from boto.ec2.instance import Reservation, InstanceAttribute
|
||||
from sure import expect
|
||||
import sure # flake8: noqa
|
||||
|
||||
from moto import mock_ec2
|
||||
|
||||
|
||||
################ Test Readme ###############
|
||||
def add_servers(ami_id, count):
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
for index in range(count):
|
||||
conn.run_instances(ami_id)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_add_servers():
|
||||
add_servers('ami-1234abcd', 2)
|
||||
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservations = conn.get_all_instances()
|
||||
assert len(reservations) == 2
|
||||
instance1 = reservations[0].instances[0]
|
||||
assert instance1.image_id == 'ami-1234abcd'
|
||||
|
||||
############################################
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_instance_launch_and_terminate():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('<ami-image-id>')
|
||||
reservation = conn.run_instances('ami-1234abcd')
|
||||
reservation.should.be.a(Reservation)
|
||||
reservation.instances.should.have.length_of(1)
|
||||
instance = reservation.instances[0]
|
||||
|
|
@ -31,11 +51,12 @@ def test_instance_launch_and_terminate():
|
|||
@mock_ec2
|
||||
def test_instance_start_and_stop():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('<ami-image-id>', min_count=2)
|
||||
reservation = conn.run_instances('ami-1234abcd', min_count=2)
|
||||
instances = reservation.instances
|
||||
instances.should.have.length_of(2)
|
||||
|
||||
stopped_instances = conn.stop_instances([instance.id for instance in instances])
|
||||
instance_ids = [instance.id for instance in instances]
|
||||
stopped_instances = conn.stop_instances(instance_ids)
|
||||
|
||||
for instance in stopped_instances:
|
||||
instance.state.should.equal('stopping')
|
||||
|
|
@ -47,7 +68,7 @@ def test_instance_start_and_stop():
|
|||
@mock_ec2
|
||||
def test_instance_reboot():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('<ami-image-id>')
|
||||
reservation = conn.run_instances('ami-1234abcd')
|
||||
instance = reservation.instances[0]
|
||||
instance.reboot()
|
||||
instance.state.should.equal('pending')
|
||||
|
|
@ -56,7 +77,7 @@ def test_instance_reboot():
|
|||
@mock_ec2
|
||||
def test_instance_attribute_instance_type():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('<ami-image-id>')
|
||||
reservation = conn.run_instances('ami-1234abcd')
|
||||
instance = reservation.instances[0]
|
||||
|
||||
instance.modify_attribute("instanceType", "m1.small")
|
||||
|
|
@ -69,11 +90,11 @@ def test_instance_attribute_instance_type():
|
|||
@mock_ec2
|
||||
def test_instance_attribute_user_data():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('<ami-image-id>')
|
||||
reservation = conn.run_instances('ami-1234abcd')
|
||||
instance = reservation.instances[0]
|
||||
|
||||
instance.modify_attribute("userData", "this is my user data")
|
||||
|
||||
instance_attribute = instance.get_attribute("userData")
|
||||
instance_attribute.should.be.a(InstanceAttribute)
|
||||
expect(instance_attribute.get("userData")).should.equal("this is my user data")
|
||||
instance_attribute.get("userData").should.equal("this is my user data")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue