summaryrefslogtreecommitdiff
path: root/heat
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-09-27 16:38:48 +0000
committerGerrit Code Review <review@openstack.org>2014-09-27 16:38:48 +0000
commit5fe448ef1853a1e5f3868c6e39746374db969019 (patch)
treec927d7f4011ac995262c37b4a3a789c4957d055b /heat
parent3061bf3dc4a69b4abc575b93a4eabf60a02d3e3b (diff)
parent5c158edac6950899c41d3090cde8c636e63c4a2f (diff)
downloadheat-5fe448ef1853a1e5f3868c6e39746374db969019.tar.gz
Merge "Associate floating IP with router interface"
Diffstat (limited to 'heat')
-rw-r--r--heat/engine/resources/neutron/floatingip.py31
-rw-r--r--heat/tests/test_neutron.py17
2 files changed, 46 insertions, 2 deletions
diff --git a/heat/engine/resources/neutron/floatingip.py b/heat/engine/resources/neutron/floatingip.py
index cfea9d34c..57e816110 100644
--- a/heat/engine/resources/neutron/floatingip.py
+++ b/heat/engine/resources/neutron/floatingip.py
@@ -14,6 +14,7 @@
from heat.engine import attributes
from heat.engine import properties
from heat.engine.resources.neutron import neutron
+from heat.engine.resources.neutron import port
from heat.engine.resources.neutron import router
from heat.engine import support
@@ -95,9 +96,10 @@ class FloatingIP(neutron.NeutronResource):
def add_dependencies(self, deps):
super(FloatingIP, self).add_dependencies(deps)
- # depend on any RouterGateway in this template with the same
- # network_id as this floating_network_id
+
for resource in self.stack.itervalues():
+ # depend on any RouterGateway in this template with the same
+ # network_id as this floating_network_id
if resource.has_interface('OS::Neutron::RouterGateway'):
gateway_network = resource.properties.get(
router.RouterGateway.NETWORK) or resource.properties.get(
@@ -108,6 +110,31 @@ class FloatingIP(neutron.NeutronResource):
if gateway_network == floating_network:
deps += (self, resource)
+ # depend on any RouterInterface in this template which interfaces
+ # with the same subnet that this floating IP's port is assigned
+ # to
+ elif resource.has_interface('OS::Neutron::RouterInterface'):
+
+ def port_on_subnet(resource, subnet):
+ if not resource.has_interface('OS::Neutron::Port'):
+ return False
+ for fixed_ip in resource.properties.get(
+ port.Port.FIXED_IPS):
+
+ port_subnet = (
+ fixed_ip.properties.get(port.Port.FIXED_IP_SUBNET)
+ or fixed_ip.get(port.Port.FIXED_IP_SUBNET_ID))
+ return subnet == port_subnet
+ return False
+
+ interface_subnet = (
+ resource.properties.get(router.RouterInterface.SUBNET) or
+ resource.properties.get(router.RouterInterface.SUBNET_ID))
+ for d in deps.required_by(self):
+ if port_on_subnet(d, interface_subnet):
+ deps += (self, resource)
+ break
+
def validate(self):
super(FloatingIP, self).validate()
self._validate_depr_property_required(
diff --git a/heat/tests/test_neutron.py b/heat/tests/test_neutron.py
index b8d25ca2f..a8d6362a4 100644
--- a/heat/tests/test_neutron.py
+++ b/heat/tests/test_neutron.py
@@ -269,6 +269,13 @@ neutron_floating_template_deprecated = '''
"router": {
"Type": "OS::Neutron::Router"
},
+ "router_interface": {
+ "Type": "OS::Neutron::RouterInterface",
+ "Properties": {
+ "router_id": { "Ref" : "router" },
+ "subnet": "sub1234"
+ }
+ },
"gateway": {
"Type": "OS::Neutron::RouterGateway",
"Properties": {
@@ -312,6 +319,13 @@ neutron_floating_template = '''
"router": {
"Type": "OS::Neutron::Router"
},
+ "router_interface": {
+ "Type": "OS::Neutron::RouterInterface",
+ "Properties": {
+ "router_id": { "Ref" : "router" },
+ "subnet": "sub1234"
+ }
+ },
"gateway": {
"Type": "OS::Neutron::RouterGateway",
"Properties": {
@@ -1964,6 +1978,9 @@ class NeutronFloatingIPTest(HeatTestCase):
self.assertIn(stack['floating_ip'], deps)
+ deps = stack.dependencies[stack['router_interface']]
+ self.assertIn(stack['floating_ip'], deps)
+
fip = stack['floating_ip']
scheduler.TaskRunner(fip.create)()
self.assertEqual((fip.CREATE, fip.COMPLETE), fip.state)