From 835259607a5552cb505c6add019a56dccbf85cde Mon Sep 17 00:00:00 2001 From: Joseph Lawson Date: Tue, 21 Oct 2014 21:55:08 -0400 Subject: [PATCH] test eip allocation via CloudFormation for VPC and EC2 classic --- .../fixtures/ec2_classic_eip.py | 9 ++++ tests/test_cloudformation/fixtures/vpc_eip.py | 12 +++++ .../test_cloudformation_stack_integration.py | 45 ++++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/test_cloudformation/fixtures/ec2_classic_eip.py create mode 100644 tests/test_cloudformation/fixtures/vpc_eip.py diff --git a/tests/test_cloudformation/fixtures/ec2_classic_eip.py b/tests/test_cloudformation/fixtures/ec2_classic_eip.py new file mode 100644 index 00000000..626e90ad --- /dev/null +++ b/tests/test_cloudformation/fixtures/ec2_classic_eip.py @@ -0,0 +1,9 @@ +from __future__ import unicode_literals + +template = { + "Resources": { + "EC2EIP": { + "Type": "AWS::EC2::EIP" + } + } +} diff --git a/tests/test_cloudformation/fixtures/vpc_eip.py b/tests/test_cloudformation/fixtures/vpc_eip.py new file mode 100644 index 00000000..c7a46c83 --- /dev/null +++ b/tests/test_cloudformation/fixtures/vpc_eip.py @@ -0,0 +1,12 @@ +from __future__ import unicode_literals + +template = { + "Resources": { + "VPCEIP": { + "Type": "AWS::EC2::EIP", + "Properties": { + "Domain": "vpc" + } + } + } +} diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index 499762d3..0161ee0a 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -12,7 +12,12 @@ from moto import ( mock_iam, ) -from .fixtures import single_instance_with_ebs_volume, vpc_single_instance_in_subnet +from .fixtures import ( + single_instance_with_ebs_volume, + vpc_single_instance_in_subnet, + ec2_classic_eip, + vpc_eip +) @mock_cloudformation() @@ -476,3 +481,41 @@ def test_single_instance_with_ebs_volume(): resources = stack.describe_resources() ebs_volume = [resource for resource in resources if resource.resource_type == 'AWS::EC2::Volume'][0] ebs_volume.physical_resource_id.should.equal(volume.id) + + +@mock_ec2() +@mock_cloudformation() +def test_classic_eip(): + + template_json = json.dumps(ec2_classic_eip.template) + conn = boto.connect_cloudformation() + conn.create_stack( + "test_stack", + template_body=template_json, + ) + ec2_conn = boto.connect_ec2() + eip = ec2_conn.get_all_addresses()[0] + + stack = conn.describe_stacks()[0] + resources = stack.describe_resources() + cfn_eip = [resource for resource in resources if resource.resource_type == 'AWS::EC2::EIP'][0] + cfn_eip.physical_resource_id.should.equal(eip.public_ip) + + +@mock_ec2() +@mock_cloudformation() +def test_vpc_eip(): + + template_json = json.dumps(vpc_eip.template) + conn = boto.connect_cloudformation() + conn.create_stack( + "test_stack", + template_body=template_json, + ) + ec2_conn = boto.connect_ec2() + eip = ec2_conn.get_all_addresses()[0] + + stack = conn.describe_stacks()[0] + resources = stack.describe_resources() + cfn_eip = [resource for resource in resources if resource.resource_type == 'AWS::EC2::EIP'][0] + cfn_eip.physical_resource_id.should.equal(eip.allocation_id)