Add multi-region support to EC2 Instances
This commit is contained in:
parent
348d1803ed
commit
82eef28937
8 changed files with 92 additions and 24 deletions
44
tests/test_ec2/test_regions.py
Normal file
44
tests/test_ec2/test_regions.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import boto.ec2
|
||||
import sure
|
||||
from moto import mock_ec2
|
||||
|
||||
|
||||
def add_servers_to_region(ami_id, count, region):
|
||||
conn = boto.ec2.connect_to_region(region)
|
||||
for index in range(count):
|
||||
conn.run_instances(ami_id)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_add_servers_to_a_single_region():
|
||||
region = 'ap-northeast-1'
|
||||
add_servers_to_region('ami-1234abcd', 1, region)
|
||||
add_servers_to_region('ami-5678efgh', 1, region)
|
||||
|
||||
conn = boto.ec2.connect_to_region(region)
|
||||
instances = conn.get_only_instances()
|
||||
len(instances).should.equal(2)
|
||||
instances.sort(key=lambda x: x.image_id)
|
||||
|
||||
instances[0].image_id.should.equal('ami-1234abcd')
|
||||
instances[1].image_id.should.equal('ami-5678efgh')
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_add_servers_to_multiple_regions():
|
||||
region1 = 'us-east-1'
|
||||
region2 = 'ap-northeast-1'
|
||||
add_servers_to_region('ami-1234abcd', 1, region1)
|
||||
add_servers_to_region('ami-5678efgh', 1, region2)
|
||||
|
||||
us_conn = boto.ec2.connect_to_region(region1)
|
||||
ap_conn = boto.ec2.connect_to_region(region2)
|
||||
us_instances = us_conn.get_only_instances()
|
||||
ap_instances = ap_conn.get_only_instances()
|
||||
|
||||
len(us_instances).should.equal(1)
|
||||
len(ap_instances).should.equal(1)
|
||||
|
||||
us_instances[0].image_id.should.equal('ami-1234abcd')
|
||||
ap_instances[0].image_id.should.equal('ami-5678efgh')
|
||||
|
||||
|
|
@ -12,7 +12,10 @@ def test_ec2_server_get():
|
|||
backend = server.create_backend_app("ec2")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=RunInstances&ImageId=ami-60a54009')
|
||||
res = test_client.get(
|
||||
'/?Action=RunInstances&ImageId=ami-60a54009',
|
||||
headers={"Host": "ec2.us-east-1.amazonaws.com"}
|
||||
)
|
||||
|
||||
groups = re.search("<instanceId>(.*)</instanceId>", res.data)
|
||||
instance_id = groups.groups()[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue