Refactor neutron resources lookup

This patch moves new neutron resources resolution methods
of basic neutron resource to a separate module neutron_utils
(similar to nova_utils) for easier usage in other parts of the code.

Change-Id: Ifb2e103e6b66dd021e24eb48c816b8c46da921e1
This commit is contained in:
Pavlo Shchelokovskyy 2014-05-20 13:29:47 +03:00
parent 5d1b4ab3e9
commit a13ab4d35d
14 changed files with 113 additions and 93 deletions

View File

@ -16,7 +16,7 @@ from testtools import skipIf
from heat.common import template_format from heat.common import template_format
from heat.engine import clients from heat.engine import clients
from heat.engine import resource from heat.engine import resource
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron_utils
from heat.engine import scheduler from heat.engine import scheduler
from heat.openstack.common.importutils import try_import from heat.openstack.common.importutils import try_import
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
@ -60,7 +60,7 @@ neutron_template = '''
@skipIf(neutronclient is None, 'neutronclient unavailable') @skipIf(neutronclient is None, 'neutronclient unavailable')
class NeutronExtraRouteTest(HeatTestCase): class NeutronExtraRouteTest(HeatTestCase):
@skipIf(neutron.neutronV20 is None, "Missing Neutron v2_0") @skipIf(neutron_utils.neutronV20 is None, "Missing Neutron v2_0")
def setUp(self): def setUp(self):
super(NeutronExtraRouteTest, self).setUp() super(NeutronExtraRouteTest, self).setUp()
self.m.StubOutWithMock(neutronclient.Client, 'show_router') self.m.StubOutWithMock(neutronclient.Client, 'show_router')

View File

@ -14,6 +14,7 @@
from heat.engine import clients from heat.engine import clients
from heat.engine import properties from heat.engine import properties
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources.neutron import router from heat.engine.resources.neutron import router
from heat.engine import support from heat.engine import support
@ -98,7 +99,7 @@ class FloatingIP(neutron.NeutronResource):
props = self.prepare_properties( props = self.prepare_properties(
self.properties, self.properties,
self.physical_resource_name()) self.physical_resource_name())
self._resolve_network( neutron_utils.resolve_network(
self.neutron(), props, self.FLOATING_NETWORK, self.neutron(), props, self.FLOATING_NETWORK,
'floating_network_id') 'floating_network_id')
fip = self.neutron().create_floatingip({ fip = self.neutron().create_floatingip({

View File

@ -17,6 +17,7 @@ from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
from heat.engine import resource from heat.engine import resource
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources import nova_utils from heat.engine.resources import nova_utils
from heat.engine import scheduler from heat.engine import scheduler
from heat.engine import support from heat.engine import support
@ -321,7 +322,7 @@ class Pool(neutron.NeutronResource):
properties = self.prepare_properties( properties = self.prepare_properties(
self.properties, self.properties,
self.physical_resource_name()) self.physical_resource_name())
self._resolve_subnet( neutron_utils.resolve_subnet(
self.neutron(), properties, self.SUBNET, 'subnet_id') self.neutron(), properties, self.SUBNET, 'subnet_id')
vip_properties = properties.pop(self.VIP) vip_properties = properties.pop(self.VIP)
monitors = properties.pop(self.MONITORS) monitors = properties.pop(self.MONITORS)
@ -347,7 +348,7 @@ class Pool(neutron.NeutronResource):
if vip_arguments.get(self.VIP_SUBNET) is None: if vip_arguments.get(self.VIP_SUBNET) is None:
vip_arguments['subnet_id'] = properties[self.SUBNET_ID] vip_arguments['subnet_id'] = properties[self.SUBNET_ID]
else: else:
vip_arguments['subnet_id'] = self._resolve_subnet( vip_arguments['subnet_id'] = neutron_utils.resolve_subnet(
self.neutron(), self.neutron(),
vip_arguments, self.VIP_SUBNET, 'subnet_id') vip_arguments, self.VIP_SUBNET, 'subnet_id')

View File

@ -19,6 +19,7 @@ from heat.engine import clients
from heat.engine import constraints from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine import support from heat.engine import support
if clients.neutronclient is not None: if clients.neutronclient is not None:
@ -164,7 +165,7 @@ class NetworkGateway(neutron.NeutronResource):
{'network_gateway': props})['network_gateway'] {'network_gateway': props})['network_gateway']
for connection in connections: for connection in connections:
self._resolve_network( neutron_utils.resolve_network(
self.neutron(), connection, self.NETWORK, 'network_id') self.neutron(), connection, self.NETWORK, 'network_id')
if self.NETWORK in connection.keys(): if self.NETWORK in connection.keys():
connection.pop(self.NETWORK) connection.pop(self.NETWORK)
@ -182,7 +183,7 @@ class NetworkGateway(neutron.NeutronResource):
connections = self.properties[self.CONNECTIONS] connections = self.properties[self.CONNECTIONS]
for connection in connections: for connection in connections:
try: try:
self._resolve_network( neutron_utils.resolve_network(
self.neutron(), connection, self.NETWORK, 'network_id') self.neutron(), connection, self.NETWORK, 'network_id')
if self.NETWORK in connection.keys(): if self.NETWORK in connection.keys():
connection.pop(self.NETWORK) connection.pop(self.NETWORK)
@ -218,7 +219,7 @@ class NetworkGateway(neutron.NeutronResource):
if self.CONNECTIONS in prop_diff: if self.CONNECTIONS in prop_diff:
for connection in self.properties[self.CONNECTIONS]: for connection in self.properties[self.CONNECTIONS]:
try: try:
self._resolve_network( neutron_utils.resolve_network(
self.neutron(), connection, self.NETWORK, 'network_id') self.neutron(), connection, self.NETWORK, 'network_id')
if self.NETWORK in connection.keys(): if self.NETWORK in connection.keys():
connection.pop(self.NETWORK) connection.pop(self.NETWORK)
@ -228,7 +229,7 @@ class NetworkGateway(neutron.NeutronResource):
except NeutronClientException as ex: except NeutronClientException as ex:
self._handle_not_found_exception(ex) self._handle_not_found_exception(ex)
for connection in connections: for connection in connections:
self._resolve_network( neutron_utils.resolve_network(
self.neutron(), connection, self.NETWORK, 'network_id') self.neutron(), connection, self.NETWORK, 'network_id')
if self.NETWORK in connection.keys(): if self.NETWORK in connection.keys():
connection.pop(self.NETWORK) connection.pop(self.NETWORK)

View File

@ -12,7 +12,6 @@
# under the License. # under the License.
from neutronclient.common.exceptions import NeutronClientException from neutronclient.common.exceptions import NeutronClientException
from neutronclient.neutron import v2_0 as neutronV20
from heat.common import exception from heat.common import exception
from heat.engine import function from heat.engine import function
@ -67,27 +66,6 @@ class NeutronResource(resource.Resource):
'depr_prop_key': depr_prop_key} 'depr_prop_key': depr_prop_key}
raise exception.StackValidationFailed(message=msg) raise exception.StackValidationFailed(message=msg)
@staticmethod
def _find_neutron_resource(neutron_client, props, key, key_type):
return neutronV20.find_resourceid_by_name_or_id(
neutron_client, key_type, props.get(key))
@staticmethod
def _resolve_network(neutron_client, props, net_key, net_id_key):
if props.get(net_key):
props[net_id_key] = NeutronResource._find_neutron_resource(
neutron_client, props, net_key, 'network')
props.pop(net_key)
return props[net_id_key]
@staticmethod
def _resolve_subnet(neutron_client, props, subnet_key, subnet_id_key):
if props.get(subnet_key):
props[subnet_id_key] = NeutronResource._find_neutron_resource(
neutron_client, props, subnet_key, 'subnet')
props.pop(subnet_key)
return props[subnet_id_key]
@staticmethod @staticmethod
def prepare_properties(properties, name): def prepare_properties(properties, name):
''' '''

View File

@ -0,0 +1,35 @@
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutronclient.neutron import v2_0 as neutronV20
def find_neutron_resource(neutron_client, props, key, key_type):
return neutronV20.find_resourceid_by_name_or_id(
neutron_client, key_type, props.get(key))
def resolve_network(neutron_client, props, net_key, net_id_key):
if props.get(net_key):
props[net_id_key] = find_neutron_resource(
neutron_client, props, net_key, 'network')
props.pop(net_key)
return props[net_id_key]
def resolve_subnet(neutron_client, props, subnet_key, subnet_id_key):
if props.get(subnet_key):
props[subnet_id_key] = find_neutron_resource(
neutron_client, props, subnet_key, 'subnet')
props.pop(subnet_key)
return props[subnet_id_key]

View File

@ -14,6 +14,7 @@
from heat.engine import clients from heat.engine import clients
from heat.engine import properties from heat.engine import properties
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources.neutron import subnet from heat.engine.resources.neutron import subnet
from heat.engine import support from heat.engine import support
from heat.openstack.common import log as logging from heat.openstack.common import log as logging
@ -191,8 +192,8 @@ class Port(neutron.NeutronResource):
props = self.prepare_properties( props = self.prepare_properties(
self.properties, self.properties,
self.physical_resource_name()) self.physical_resource_name())
self._resolve_network(self.neutron(), neutron_utils.resolve_network(self.neutron(),
props, self.NETWORK, 'network_id') props, self.NETWORK, 'network_id')
self._prepare_list_properties(props) self._prepare_list_properties(props)
if not props['fixed_ips']: if not props['fixed_ips']:
@ -207,7 +208,7 @@ class Port(neutron.NeutronResource):
if value is None: if value is None:
fixed_ip.pop(key) fixed_ip.pop(key)
if fixed_ip.get(self.FIXED_IP_SUBNET): if fixed_ip.get(self.FIXED_IP_SUBNET):
self._resolve_subnet( neutron_utils.resolve_subnet(
self.neutron(), fixed_ip, self.neutron(), fixed_ip,
self.FIXED_IP_SUBNET, 'subnet_id') self.FIXED_IP_SUBNET, 'subnet_id')
# delete empty MAC addresses so that Neutron validation code # delete empty MAC addresses so that Neutron validation code

View File

@ -15,6 +15,7 @@ from heat.common import exception
from heat.engine import clients from heat.engine import clients
from heat.engine import properties from heat.engine import properties
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources.neutron import subnet from heat.engine.resources.neutron import subnet
from heat.engine import support from heat.engine import support
@ -111,7 +112,7 @@ class Router(neutron.NeutronResource):
props = super(Router, self).prepare_properties(properties, name) props = super(Router, self).prepare_properties(properties, name)
gateway = props.get(self.EXTERNAL_GATEWAY) gateway = props.get(self.EXTERNAL_GATEWAY)
if gateway: if gateway:
self._resolve_network( neutron_utils.resolve_network(
self.neutron(), gateway, self.neutron(), gateway,
self.EXTERNAL_GATEWAY_NETWORK, 'network_id') self.EXTERNAL_GATEWAY_NETWORK, 'network_id')
if gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT] is None: if gateway[self.EXTERNAL_GATEWAY_ENABLE_SNAT] is None:
@ -233,7 +234,7 @@ class RouterInterface(neutron.NeutronResource):
def handle_create(self): def handle_create(self):
router_id = self.properties.get(self.ROUTER_ID) router_id = self.properties.get(self.ROUTER_ID)
key = 'subnet_id' key = 'subnet_id'
value = self._resolve_subnet( value = neutron_utils.resolve_subnet(
self.neutron(), dict(self.properties), self.SUBNET, key) self.neutron(), dict(self.properties), self.SUBNET, key)
if not value: if not value:
key = self.PORT_ID key = self.PORT_ID
@ -325,7 +326,7 @@ class RouterGateway(neutron.NeutronResource):
def handle_create(self): def handle_create(self):
router_id = self.properties.get(self.ROUTER_ID) router_id = self.properties.get(self.ROUTER_ID)
network_id = self._resolve_network( network_id = neutron_utils.resolve_network(
self.neutron(), dict(self.properties), self.NETWORK, self.neutron(), dict(self.properties), self.NETWORK,
'network_id') 'network_id')
self.neutron().add_gateway_router( self.neutron().add_gateway_router(

View File

@ -15,6 +15,7 @@ from heat.engine import clients
from heat.engine import constraints from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine import support from heat.engine import support
if clients.neutronclient is not None: if clients.neutronclient is not None:
@ -175,7 +176,7 @@ class Subnet(neutron.NeutronResource):
props = self.prepare_properties( props = self.prepare_properties(
self.properties, self.properties,
self.physical_resource_name()) self.physical_resource_name())
self._resolve_network( neutron_utils.resolve_network(
self.neutron(), props, self.NETWORK, 'network_id') self.neutron(), props, self.NETWORK, 'network_id')
self._null_gateway_ip(props) self._null_gateway_ip(props)

View File

@ -15,6 +15,7 @@ from heat.engine import clients
from heat.engine import constraints from heat.engine import constraints
from heat.engine import properties from heat.engine import properties
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron import neutron_utils
from heat.engine import support from heat.engine import support
if clients.neutronclient is not None: if clients.neutronclient is not None:
@ -97,7 +98,7 @@ class VPNService(neutron.NeutronResource):
props = self.prepare_properties( props = self.prepare_properties(
self.properties, self.properties,
self.physical_resource_name()) self.physical_resource_name())
self._resolve_subnet( neutron_utils.resolve_subnet(
self.neutron(), props, self.neutron(), props,
self.SUBNET, 'subnet_id') self.SUBNET, 'subnet_id')
vpnservice = self.neutron().create_vpnservice({'vpnservice': props})[ vpnservice = self.neutron().create_vpnservice({'vpnservice': props})[

View File

@ -22,8 +22,8 @@ from heat.engine import clients
from heat.engine import properties from heat.engine import properties
from heat.engine import resource from heat.engine import resource
from heat.engine.resources.neutron import net from heat.engine.resources.neutron import net
from heat.engine.resources.neutron import neutron
from heat.engine.resources.neutron.neutron import NeutronResource as qr from heat.engine.resources.neutron.neutron import NeutronResource as qr
from heat.engine.resources.neutron import neutron_utils
from heat.engine.resources.neutron import provider_net from heat.engine.resources.neutron import provider_net
from heat.engine.resources.neutron import router from heat.engine.resources.neutron import router
from heat.engine.resources.neutron import subnet from heat.engine.resources.neutron import subnet
@ -857,7 +857,7 @@ class NeutronSubnetTest(HeatTestCase):
self.m.StubOutWithMock(neutronclient.Client, 'delete_subnet') self.m.StubOutWithMock(neutronclient.Client, 'delete_subnet')
self.m.StubOutWithMock(neutronclient.Client, 'show_subnet') self.m.StubOutWithMock(neutronclient.Client, 'show_subnet')
self.m.StubOutWithMock(neutronclient.Client, 'update_subnet') self.m.StubOutWithMock(neutronclient.Client, 'update_subnet')
self.m.StubOutWithMock(neutron.neutronV20, self.m.StubOutWithMock(neutron_utils.neutronV20,
'find_resourceid_by_name_or_id') 'find_resourceid_by_name_or_id')
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
@ -868,7 +868,7 @@ class NeutronSubnetTest(HeatTestCase):
def test_subnet(self): def test_subnet(self):
t = self._test_subnet() t = self._test_subnet()
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'None' 'None'
@ -1031,7 +1031,7 @@ class NeutronSubnetTest(HeatTestCase):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'None' 'None'
@ -1158,7 +1158,7 @@ class NeutronSubnetTest(HeatTestCase):
@skipIf(neutronclient is None, 'neutronclient unavailable') @skipIf(neutronclient is None, 'neutronclient unavailable')
class NeutronRouterTest(HeatTestCase): class NeutronRouterTest(HeatTestCase):
@skipIf(neutron.neutronV20 is None, "Missing Neutron v2_0") @skipIf(neutron_utils.neutronV20 is None, "Missing Neutron v2_0")
def setUp(self): def setUp(self):
super(NeutronRouterTest, self).setUp() super(NeutronRouterTest, self).setUp()
self.m.StubOutWithMock(neutronclient.Client, 'create_router') self.m.StubOutWithMock(neutronclient.Client, 'create_router')
@ -1175,7 +1175,7 @@ class NeutronRouterTest(HeatTestCase):
'remove_router_from_l3_agent') 'remove_router_from_l3_agent')
self.m.StubOutWithMock(neutronclient.Client, self.m.StubOutWithMock(neutronclient.Client,
'list_l3_agent_hosting_routers') 'list_l3_agent_hosting_routers')
self.m.StubOutWithMock(neutron.neutronV20, self.m.StubOutWithMock(neutron_utils.neutronV20,
'find_resourceid_by_name_or_id') 'find_resourceid_by_name_or_id')
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
@ -1405,7 +1405,7 @@ class NeutronRouterTest(HeatTestCase):
t = template_format.parse(neutron_template) t = template_format.parse(neutron_template)
stack = utils.parse_stack(t) stack = utils.parse_stack(t)
if resolve_neutron: if resolve_neutron:
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'91e47a57-7508-46fe-afc9-fc454e8580e1' '91e47a57-7508-46fe-afc9-fc454e8580e1'
@ -1529,7 +1529,7 @@ class NeutronRouterTest(HeatTestCase):
def test_gateway_router(self): def test_gateway_router(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'fc68ea2c-b60b-4b4f-bd82-94ec81110766' 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
@ -1563,7 +1563,7 @@ class NeutronRouterTest(HeatTestCase):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'public' 'public'
@ -1645,7 +1645,7 @@ class NeutronRouterTest(HeatTestCase):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'public' 'public'
@ -1706,7 +1706,7 @@ class NeutronRouterTest(HeatTestCase):
def test_update_router_gateway_as_property(self): def test_update_router_gateway_as_property(self):
self._create_router_with_gateway() self._create_router_with_gateway()
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'other_public' 'other_public'
@ -1791,7 +1791,7 @@ class NeutronFloatingIPTest(HeatTestCase):
self.m.StubOutWithMock(neutronclient.Client, 'delete_port') self.m.StubOutWithMock(neutronclient.Client, 'delete_port')
self.m.StubOutWithMock(neutronclient.Client, 'update_port') self.m.StubOutWithMock(neutronclient.Client, 'update_port')
self.m.StubOutWithMock(neutronclient.Client, 'show_port') self.m.StubOutWithMock(neutronclient.Client, 'show_port')
self.m.StubOutWithMock(neutron.neutronV20, self.m.StubOutWithMock(neutron_utils.neutronV20,
'find_resourceid_by_name_or_id') 'find_resourceid_by_name_or_id')
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
@ -1829,7 +1829,7 @@ class NeutronFloatingIPTest(HeatTestCase):
qe.NeutronClientException(status_code=404)) qe.NeutronClientException(status_code=404))
if resolve_neutron: if resolve_neutron:
t = template_format.parse(neutron_floating_template) t = template_format.parse(neutron_floating_template)
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'abcd1234' 'abcd1234'
@ -1874,12 +1874,12 @@ class NeutronFloatingIPTest(HeatTestCase):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'xyz1234' 'xyz1234'
).AndReturn('xyz1234') ).AndReturn('xyz1234')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub1234' 'sub1234'
@ -1974,17 +1974,17 @@ class NeutronFloatingIPTest(HeatTestCase):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'abcd1234' 'abcd1234'
).AndReturn('abcd1234') ).AndReturn('abcd1234')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'xyz1234' 'xyz1234'
).AndReturn('xyz1234') ).AndReturn('xyz1234')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub1234' 'sub1234'
@ -2104,14 +2104,14 @@ class NeutronPortTest(HeatTestCase):
super(NeutronPortTest, self).setUp() super(NeutronPortTest, self).setUp()
self.m.StubOutWithMock(neutronclient.Client, 'create_port') self.m.StubOutWithMock(neutronclient.Client, 'create_port')
self.m.StubOutWithMock(neutronclient.Client, 'show_port') self.m.StubOutWithMock(neutronclient.Client, 'show_port')
self.m.StubOutWithMock(neutron.neutronV20, self.m.StubOutWithMock(neutron_utils.neutronV20,
'find_resourceid_by_name_or_id') 'find_resourceid_by_name_or_id')
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
def test_missing_subnet_id(self): def test_missing_subnet_id(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'net1234' 'net1234'
@ -2149,12 +2149,12 @@ class NeutronPortTest(HeatTestCase):
def test_missing_ip_address(self): def test_missing_ip_address(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'net1234' 'net1234'
).AndReturn('net1234') ).AndReturn('net1234')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub1234' 'sub1234'
@ -2192,7 +2192,7 @@ class NeutronPortTest(HeatTestCase):
def test_missing_fixed_ips(self): def test_missing_fixed_ips(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'net1234' 'net1234'
@ -2230,7 +2230,7 @@ class NeutronPortTest(HeatTestCase):
def test_allowed_address_pair(self): def test_allowed_address_pair(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'abcd1234' 'abcd1234'
@ -2266,7 +2266,7 @@ class NeutronPortTest(HeatTestCase):
def test_missing_mac_address(self): def test_missing_mac_address(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'abcd1234' 'abcd1234'
@ -2304,12 +2304,12 @@ class NeutronPortTest(HeatTestCase):
def test_security_groups(self): def test_security_groups(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'net1234' 'net1234'
).AndReturn('net1234') ).AndReturn('net1234')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub1234' 'sub1234'

View File

@ -20,7 +20,7 @@ from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import clients from heat.engine import clients
from heat.engine.resources.neutron import loadbalancer from heat.engine.resources.neutron import loadbalancer
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron_utils
from heat.engine import scheduler from heat.engine import scheduler
from heat.openstack.common.importutils import try_import from heat.openstack.common.importutils import try_import
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
@ -362,7 +362,7 @@ class PoolTest(HeatTestCase):
self.m.StubOutWithMock(neutronclient.Client, self.m.StubOutWithMock(neutronclient.Client,
'disassociate_health_monitor') 'disassociate_health_monitor')
self.m.StubOutWithMock(neutronclient.Client, 'create_vip') self.m.StubOutWithMock(neutronclient.Client, 'create_vip')
self.m.StubOutWithMock(neutron.neutronV20, self.m.StubOutWithMock(neutron_utils.neutronV20,
'find_resourceid_by_name_or_id') 'find_resourceid_by_name_or_id')
self.m.StubOutWithMock(neutronclient.Client, 'delete_vip') self.m.StubOutWithMock(neutronclient.Client, 'delete_vip')
self.m.StubOutWithMock(neutronclient.Client, 'show_vip') self.m.StubOutWithMock(neutronclient.Client, 'show_vip')
@ -392,12 +392,12 @@ class PoolTest(HeatTestCase):
stvippsn['vip']['subnet_id'] = 'sub123' stvippsn['vip']['subnet_id'] = 'sub123'
if resolve_neutron and with_vip_subnet: if resolve_neutron and with_vip_subnet:
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
).AndReturn('sub123') ).AndReturn('sub123')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub9999' 'sub9999'
@ -407,7 +407,7 @@ class PoolTest(HeatTestCase):
).AndReturn({'vip': {'id': 'xyz'}}) ).AndReturn({'vip': {'id': 'xyz'}})
elif resolve_neutron and not with_vip_subnet: elif resolve_neutron and not with_vip_subnet:
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -446,7 +446,7 @@ class PoolTest(HeatTestCase):
def test_create_pending(self): def test_create_pending(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -485,7 +485,7 @@ class PoolTest(HeatTestCase):
def test_create_failed_unexpected_status(self): def test_create_failed_unexpected_status(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -523,7 +523,7 @@ class PoolTest(HeatTestCase):
def test_create_failed_unexpected_vip_status(self): def test_create_failed_unexpected_vip_status(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -563,7 +563,7 @@ class PoolTest(HeatTestCase):
def test_create_failed(self): def test_create_failed(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -592,7 +592,7 @@ class PoolTest(HeatTestCase):
def test_create_with_session_persistence(self): def test_create_with_session_persistence(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -654,7 +654,7 @@ class PoolTest(HeatTestCase):
def test_properties_are_prepared_for_session_persistence(self): def test_properties_are_prepared_for_session_persistence(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -804,7 +804,7 @@ class PoolTest(HeatTestCase):
def test_update_monitors(self): def test_update_monitors(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'

View File

@ -22,7 +22,7 @@ from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import clients from heat.engine import clients
from heat.engine.resources.neutron import network_gateway from heat.engine.resources.neutron import network_gateway
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron_utils
from heat.engine import scheduler from heat.engine import scheduler
from heat.openstack.common.importutils import try_import from heat.openstack.common.importutils import try_import
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
@ -110,7 +110,7 @@ class NeutronNetworkGatewayTest(HeatTestCase):
self.m.StubOutWithMock(neutronclient.Client, self.m.StubOutWithMock(neutronclient.Client,
'disconnect_network_gateway') 'disconnect_network_gateway')
self.m.StubOutWithMock(neutronclient.Client, 'list_networks') self.m.StubOutWithMock(neutronclient.Client, 'list_networks')
self.m.StubOutWithMock(neutron.neutronV20, self.m.StubOutWithMock(neutron_utils.neutronV20,
'find_resourceid_by_name_or_id') 'find_resourceid_by_name_or_id')
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
@ -150,7 +150,7 @@ class NeutronNetworkGatewayTest(HeatTestCase):
} }
}) })
if resolve_neutron: if resolve_neutron:
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
@ -168,12 +168,12 @@ class NeutronNetworkGatewayTest(HeatTestCase):
def _test_network_gateway_create(self, resolve_neutron=True): def _test_network_gateway_create(self, resolve_neutron=True):
rsrc = self.prepare_create_network_gateway(resolve_neutron) rsrc = self.prepare_create_network_gateway(resolve_neutron)
if resolve_neutron: if resolve_neutron:
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35') ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
@ -238,32 +238,32 @@ class NeutronNetworkGatewayTest(HeatTestCase):
def test_network_gateway_update(self): def test_network_gateway_update(self):
rsrc = self.prepare_create_network_gateway() rsrc = self.prepare_create_network_gateway()
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35') ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35') ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35') ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35') ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'
).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35') ).AndReturn('6af055d3-26f6-48dd-a597-7611d7e58d35')
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'network', 'network',
'6af055d3-26f6-48dd-a597-7611d7e58d35' '6af055d3-26f6-48dd-a597-7611d7e58d35'

View File

@ -20,7 +20,7 @@ from heat.common import exception
from heat.common import template_format from heat.common import template_format
from heat.engine import clients from heat.engine import clients
from heat.engine.resources.neutron import vpnservice from heat.engine.resources.neutron import vpnservice
from heat.engine.resources.neutron import neutron from heat.engine.resources.neutron import neutron_utils
from heat.engine import scheduler from heat.engine import scheduler
from heat.openstack.common.importutils import try_import from heat.openstack.common.importutils import try_import
from heat.tests.common import HeatTestCase from heat.tests.common import HeatTestCase
@ -174,7 +174,7 @@ class VPNServiceTest(HeatTestCase):
self.m.StubOutWithMock(neutronclient.Client, 'delete_vpnservice') self.m.StubOutWithMock(neutronclient.Client, 'delete_vpnservice')
self.m.StubOutWithMock(neutronclient.Client, 'show_vpnservice') self.m.StubOutWithMock(neutronclient.Client, 'show_vpnservice')
self.m.StubOutWithMock(neutronclient.Client, 'update_vpnservice') self.m.StubOutWithMock(neutronclient.Client, 'update_vpnservice')
self.m.StubOutWithMock(neutron.neutronV20, self.m.StubOutWithMock(neutron_utils.neutronV20,
'find_resourceid_by_name_or_id') 'find_resourceid_by_name_or_id')
self.m.StubOutWithMock(clients.OpenStackClients, 'keystone') self.m.StubOutWithMock(clients.OpenStackClients, 'keystone')
@ -182,7 +182,7 @@ class VPNServiceTest(HeatTestCase):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
if resolve_neutron: if resolve_neutron:
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'
@ -214,7 +214,7 @@ class VPNServiceTest(HeatTestCase):
def test_create_failed(self): def test_create_failed(self):
clients.OpenStackClients.keystone().AndReturn( clients.OpenStackClients.keystone().AndReturn(
fakes.FakeKeystoneClient()) fakes.FakeKeystoneClient())
neutron.neutronV20.find_resourceid_by_name_or_id( neutron_utils.neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client), mox.IsA(neutronclient.Client),
'subnet', 'subnet',
'sub123' 'sub123'