List dependencies for services - add integration test to verify
This commit is contained in:
parent
9f0f230d13
commit
db1d7123f6
41 changed files with 1405 additions and 1245 deletions
|
|
@ -12,7 +12,7 @@ import sure # noqa
|
|||
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
from moto.ec2.models import AMIS, OWNER_ID
|
||||
from moto.iam.models import ACCOUNT_ID
|
||||
from moto.core import ACCOUNT_ID
|
||||
from tests.helpers import requires_boto_gte
|
||||
|
||||
|
||||
|
|
|
|||
100
tests/test_ec2/test_ec2_cloudformation.py
Normal file
100
tests/test_ec2/test_ec2_cloudformation.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
from moto import mock_cloudformation_deprecated, mock_ec2_deprecated
|
||||
from moto import mock_cloudformation, mock_ec2
|
||||
from tests.test_cloudformation.fixtures import vpc_eni
|
||||
import boto
|
||||
import boto3
|
||||
import json
|
||||
import sure # noqa
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
@mock_cloudformation_deprecated
|
||||
def test_elastic_network_interfaces_cloudformation():
|
||||
template = vpc_eni.template
|
||||
template_json = json.dumps(template)
|
||||
conn = boto.cloudformation.connect_to_region("us-west-1")
|
||||
conn.create_stack("test_stack", template_body=template_json)
|
||||
ec2_conn = boto.ec2.connect_to_region("us-west-1")
|
||||
eni = ec2_conn.get_all_network_interfaces()[0]
|
||||
eni.private_ip_addresses.should.have.length_of(1)
|
||||
|
||||
stack = conn.describe_stacks()[0]
|
||||
resources = stack.describe_resources()
|
||||
cfn_eni = [
|
||||
resource
|
||||
for resource in resources
|
||||
if resource.resource_type == "AWS::EC2::NetworkInterface"
|
||||
][0]
|
||||
cfn_eni.physical_resource_id.should.equal(eni.id)
|
||||
|
||||
outputs = {output.key: output.value for output in stack.outputs}
|
||||
outputs["ENIIpAddress"].should.equal(eni.private_ip_addresses[0].private_ip_address)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_cloudformation
|
||||
def test_volume_size_through_cloudformation():
|
||||
ec2 = boto3.client("ec2", region_name="us-east-1")
|
||||
cf = boto3.client("cloudformation", region_name="us-east-1")
|
||||
|
||||
volume_template = {
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
"Resources": {
|
||||
"testInstance": {
|
||||
"Type": "AWS::EC2::Instance",
|
||||
"Properties": {
|
||||
"ImageId": "ami-d3adb33f",
|
||||
"KeyName": "dummy",
|
||||
"InstanceType": "t2.micro",
|
||||
"BlockDeviceMappings": [
|
||||
{"DeviceName": "/dev/sda2", "Ebs": {"VolumeSize": "50"}}
|
||||
],
|
||||
"Tags": [
|
||||
{"Key": "foo", "Value": "bar"},
|
||||
{"Key": "blah", "Value": "baz"},
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
template_json = json.dumps(volume_template)
|
||||
cf.create_stack(StackName="test_stack", TemplateBody=template_json)
|
||||
instances = ec2.describe_instances()
|
||||
volume = instances["Reservations"][0]["Instances"][0]["BlockDeviceMappings"][0][
|
||||
"Ebs"
|
||||
]
|
||||
|
||||
volumes = ec2.describe_volumes(VolumeIds=[volume["VolumeId"]])
|
||||
volumes["Volumes"][0]["Size"].should.equal(50)
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
@mock_cloudformation_deprecated
|
||||
def test_subnet_tags_through_cloudformation():
|
||||
vpc_conn = boto.vpc.connect_to_region("us-west-1")
|
||||
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||
|
||||
subnet_template = {
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
"Resources": {
|
||||
"testSubnet": {
|
||||
"Type": "AWS::EC2::Subnet",
|
||||
"Properties": {
|
||||
"VpcId": vpc.id,
|
||||
"CidrBlock": "10.0.0.0/24",
|
||||
"AvailabilityZone": "us-west-1b",
|
||||
"Tags": [
|
||||
{"Key": "foo", "Value": "bar"},
|
||||
{"Key": "blah", "Value": "baz"},
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
cf_conn = boto.cloudformation.connect_to_region("us-west-1")
|
||||
template_json = json.dumps(subnet_template)
|
||||
cf_conn.create_stack("test_stack", template_body=template_json)
|
||||
|
||||
subnet = vpc_conn.get_all_subnets(filters={"cidrBlock": "10.0.0.0/24"})[0]
|
||||
subnet.tags["foo"].should.equal("bar")
|
||||
subnet.tags["blah"].should.equal("baz")
|
||||
|
|
@ -7,15 +7,12 @@ from nose.tools import assert_raises
|
|||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import boto
|
||||
import boto.cloudformation
|
||||
import boto.ec2
|
||||
from boto.exception import EC2ResponseError
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ec2, mock_cloudformation_deprecated, mock_ec2_deprecated
|
||||
from moto import mock_ec2, mock_ec2_deprecated
|
||||
from tests.helpers import requires_boto_gte
|
||||
from tests.test_cloudformation.fixtures import vpc_eni
|
||||
import json
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
|
|
@ -501,27 +498,3 @@ def test_elastic_network_interfaces_describe_network_interfaces_with_filter():
|
|||
eni1.private_ip_address
|
||||
)
|
||||
response["NetworkInterfaces"][0]["Description"].should.equal(eni1.description)
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
@mock_cloudformation_deprecated
|
||||
def test_elastic_network_interfaces_cloudformation():
|
||||
template = vpc_eni.template
|
||||
template_json = json.dumps(template)
|
||||
conn = boto.cloudformation.connect_to_region("us-west-1")
|
||||
conn.create_stack("test_stack", template_body=template_json)
|
||||
ec2_conn = boto.ec2.connect_to_region("us-west-1")
|
||||
eni = ec2_conn.get_all_network_interfaces()[0]
|
||||
eni.private_ip_addresses.should.have.length_of(1)
|
||||
|
||||
stack = conn.describe_stacks()[0]
|
||||
resources = stack.describe_resources()
|
||||
cfn_eni = [
|
||||
resource
|
||||
for resource in resources
|
||||
if resource.resource_type == "AWS::EC2::NetworkInterface"
|
||||
][0]
|
||||
cfn_eni.physical_resource_id.should.equal(eni.id)
|
||||
|
||||
outputs = {output.key: output.value for output in stack.outputs}
|
||||
outputs["ENIIpAddress"].should.equal(eni.private_ip_addresses[0].private_ip_address)
|
||||
|
|
|
|||
|
|
@ -7,19 +7,17 @@ import tests.backport_assert_raises
|
|||
from nose.tools import assert_raises
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import ipaddress
|
||||
import json
|
||||
|
||||
import six
|
||||
import boto
|
||||
import boto3
|
||||
from boto.ec2.instance import Reservation, InstanceAttribute
|
||||
from boto.exception import EC2ResponseError, EC2ResponseError
|
||||
from boto.exception import EC2ResponseError
|
||||
from freezegun import freeze_time
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ec2_deprecated, mock_ec2, mock_cloudformation
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
from tests.helpers import requires_boto_gte
|
||||
|
||||
|
||||
|
|
@ -1673,40 +1671,3 @@ def test_describe_instance_attribute():
|
|||
invalid_instance_attribute=invalid_instance_attribute
|
||||
)
|
||||
ex.exception.response["Error"]["Message"].should.equal(message)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_cloudformation
|
||||
def test_volume_size_through_cloudformation():
|
||||
ec2 = boto3.client("ec2", region_name="us-east-1")
|
||||
cf = boto3.client("cloudformation", region_name="us-east-1")
|
||||
|
||||
volume_template = {
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
"Resources": {
|
||||
"testInstance": {
|
||||
"Type": "AWS::EC2::Instance",
|
||||
"Properties": {
|
||||
"ImageId": "ami-d3adb33f",
|
||||
"KeyName": "dummy",
|
||||
"InstanceType": "t2.micro",
|
||||
"BlockDeviceMappings": [
|
||||
{"DeviceName": "/dev/sda2", "Ebs": {"VolumeSize": "50"}}
|
||||
],
|
||||
"Tags": [
|
||||
{"Key": "foo", "Value": "bar"},
|
||||
{"Key": "blah", "Value": "baz"},
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
template_json = json.dumps(volume_template)
|
||||
cf.create_stack(StackName="test_stack", TemplateBody=template_json)
|
||||
instances = ec2.describe_instances()
|
||||
volume = instances["Reservations"][0]["Instances"][0]["BlockDeviceMappings"][0][
|
||||
"Ebs"
|
||||
]
|
||||
|
||||
volumes = ec2.describe_volumes(VolumeIds=[volume["VolumeId"]])
|
||||
volumes["Volumes"][0]["Size"].should.equal(50)
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ from botocore.exceptions import ClientError
|
|||
import pytz
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ec2, mock_ec2_deprecated
|
||||
from moto.backends import get_model
|
||||
from moto import mock_ec2, mock_ec2_deprecated, settings
|
||||
from moto.ec2.models import ec2_backends
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||
|
||||
|
||||
|
|
@ -184,13 +184,14 @@ def test_request_spot_instances_fulfilled():
|
|||
|
||||
request.state.should.equal("open")
|
||||
|
||||
get_model("SpotInstanceRequest", "us-east-1")[0].state = "active"
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
ec2_backends["us-east-1"].spot_instance_requests[request.id].state = "active"
|
||||
|
||||
requests = conn.get_all_spot_instance_requests()
|
||||
requests.should.have.length_of(1)
|
||||
request = requests[0]
|
||||
requests = conn.get_all_spot_instance_requests()
|
||||
requests.should.have.length_of(1)
|
||||
request = requests[0]
|
||||
|
||||
request.state.should.equal("active")
|
||||
request.state.should.equal("active")
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
|
|
@ -247,10 +248,11 @@ def test_request_spot_instances_setting_instance_id():
|
|||
conn = boto.ec2.connect_to_region("us-east-1")
|
||||
request = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234")
|
||||
|
||||
req = get_model("SpotInstanceRequest", "us-east-1")[0]
|
||||
req.state = "active"
|
||||
req.instance_id = "i-12345678"
|
||||
if not settings.TEST_SERVER_MODE:
|
||||
req = ec2_backends["us-east-1"].spot_instance_requests[request[0].id]
|
||||
req.state = "active"
|
||||
req.instance_id = "i-12345678"
|
||||
|
||||
request = conn.get_all_spot_instance_requests()[0]
|
||||
assert request.state == "active"
|
||||
assert request.instance_id == "i-12345678"
|
||||
request = conn.get_all_spot_instance_requests()[0]
|
||||
assert request.state == "active"
|
||||
assert request.instance_id == "i-12345678"
|
||||
|
|
|
|||
|
|
@ -9,11 +9,10 @@ import boto
|
|||
import boto.vpc
|
||||
from boto.exception import EC2ResponseError
|
||||
from botocore.exceptions import ParamValidationError, ClientError
|
||||
import json
|
||||
import sure # noqa
|
||||
import random
|
||||
|
||||
from moto import mock_cloudformation_deprecated, mock_ec2, mock_ec2_deprecated
|
||||
from moto import mock_ec2, mock_ec2_deprecated
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
|
|
@ -311,38 +310,6 @@ def test_get_subnets_filtering():
|
|||
).should.throw(NotImplementedError)
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
@mock_cloudformation_deprecated
|
||||
def test_subnet_tags_through_cloudformation():
|
||||
vpc_conn = boto.vpc.connect_to_region("us-west-1")
|
||||
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||
|
||||
subnet_template = {
|
||||
"AWSTemplateFormatVersion": "2010-09-09",
|
||||
"Resources": {
|
||||
"testSubnet": {
|
||||
"Type": "AWS::EC2::Subnet",
|
||||
"Properties": {
|
||||
"VpcId": vpc.id,
|
||||
"CidrBlock": "10.0.0.0/24",
|
||||
"AvailabilityZone": "us-west-1b",
|
||||
"Tags": [
|
||||
{"Key": "foo", "Value": "bar"},
|
||||
{"Key": "blah", "Value": "baz"},
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
cf_conn = boto.cloudformation.connect_to_region("us-west-1")
|
||||
template_json = json.dumps(subnet_template)
|
||||
cf_conn.create_stack("test_stack", template_body=template_json)
|
||||
|
||||
subnet = vpc_conn.get_all_subnets(filters={"cidrBlock": "10.0.0.0/24"})[0]
|
||||
subnet.tags["foo"].should.equal("bar")
|
||||
subnet.tags["blah"].should.equal("baz")
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_create_subnet_response_fields():
|
||||
ec2 = boto3.resource("ec2", region_name="us-west-1")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue