]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Allowing to pass network name to router gateway
authorBartosz Górski <bartosz.gorski@ntti3.com>
Wed, 14 Aug 2013 10:52:37 +0000 (03:52 -0700)
committerBartosz Górski <bartosz.gorski@ntti3.com>
Mon, 2 Sep 2013 15:07:52 +0000 (08:07 -0700)
This patch allows to pass newtork name instead of network id to create router
gateway. It is really useful feature because often router has gateway as public
network. It is easy to pass the name because id will change after deleting the
network and creating it again.

Change-Id: I5768408b86b509ecfd117f17b10db06af82369d8

heat/engine/resources/neutron/router.py
heat/tests/test_neutron.py

index 793b212ed272c660cc7a990bf59542579babe350..243c1718ef5b2cf1508ef553975a13c113942193 100644 (file)
@@ -19,6 +19,7 @@ from heat.engine import scheduler
 
 if clients.neutronclient is not None:
     from neutronclient.common.exceptions import NeutronClientException
+    from neutronclient.neutron import v2_0 as neutronV20
 
 from heat.openstack.common import log as logging
 
@@ -117,7 +118,10 @@ class RouterGateway(neutron.NeutronResource):
 
     def handle_create(self):
         router_id = self.properties.get('router_id')
-        network_id = self.properties.get('network_id')
+        network_id = neutronV20.find_resourceid_by_name_or_id(
+            self.neutron(),
+            'network',
+            self.properties.get('network_id'))
         self.neutron().add_gateway_router(
             router_id,
             {'network_id': network_id})
index 59500d751d3ed90693dbcf82c7ed83ebe16d0164..dff9d5baf80cf01664c4e9ad321d78f2bcb2bd55 100644 (file)
@@ -12,6 +12,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import mox
 
 from testtools import skipIf
 
@@ -524,6 +525,7 @@ class NeutronSubnetTest(HeatTestCase):
 
 @skipIf(neutronclient is None, 'neutronclient unavailable')
 class NeutronRouterTest(HeatTestCase):
+    @skipIf(router.neutronV20 is None, "Missing Neutron v2_0")
     def setUp(self):
         super(NeutronRouterTest, self).setUp()
         self.m.StubOutWithMock(neutronclient.Client, 'create_router')
@@ -533,6 +535,8 @@ class NeutronRouterTest(HeatTestCase):
         self.m.StubOutWithMock(neutronclient.Client, 'remove_interface_router')
         self.m.StubOutWithMock(neutronclient.Client, 'add_gateway_router')
         self.m.StubOutWithMock(neutronclient.Client, 'remove_gateway_router')
+        self.m.StubOutWithMock(router.neutronV20,
+                               'find_resourceid_by_name_or_id')
         self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
         utils.setup_dummy_db()
 
@@ -702,6 +706,11 @@ class NeutronRouterTest(HeatTestCase):
     def test_gateway_router(self):
         clients.OpenStackClients.keystone().AndReturn(
             fakes.FakeKeystoneClient())
+        router.neutronV20.find_resourceid_by_name_or_id(
+            mox.IsA(neutronclient.Client),
+            'network',
+            'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
+        ).AndReturn('fc68ea2c-b60b-4b4f-bd82-94ec81110766')
         neutronclient.Client.add_gateway_router(
             '3e46229d-8fce-4733-819a-b5fe630550f8',
             {'network_id': 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'}