Move neutron_utils functions to neutron client
All uses of neutron_utils functions have been migrated to using the neutron client plugin version. Functions in neutron_utils are deprecated and will be deleted in the next patch. Change-Id: I1b00485bddffcb6b9dba2ac770668dde9d6a0d70
This commit is contained in:
parent
848bc37e2a
commit
8f0035ed99
@ -59,6 +59,24 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
||||
return False
|
||||
return ex.status_code == 413
|
||||
|
||||
def find_neutron_resource(self, props, key, key_type):
|
||||
return neutronV20.find_resourceid_by_name_or_id(
|
||||
self.client(), key_type, props.get(key))
|
||||
|
||||
def resolve_network(self, props, net_key, net_id_key):
|
||||
if props.get(net_key):
|
||||
props[net_id_key] = self.find_neutron_resource(
|
||||
props, net_key, 'network')
|
||||
props.pop(net_key)
|
||||
return props[net_id_key]
|
||||
|
||||
def resolve_subnet(self, props, subnet_key, subnet_id_key):
|
||||
if props.get(subnet_key):
|
||||
props[subnet_id_key] = self.find_neutron_resource(
|
||||
props, subnet_key, 'subnet')
|
||||
props.pop(subnet_key)
|
||||
return props[subnet_id_key]
|
||||
|
||||
|
||||
class NetworkConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
|
@ -12,14 +12,19 @@
|
||||
# under the License.
|
||||
|
||||
from neutronclient.neutron import v2_0 as neutronV20
|
||||
import warnings
|
||||
|
||||
|
||||
def find_neutron_resource(neutron_client, props, key, key_type):
|
||||
warnings.warn('neutron_utils.find_neutron_resource is deprecated. '
|
||||
'Use self.client_plugin("neutron").find_neutron_resource')
|
||||
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):
|
||||
warnings.warn('neutron_utils.resolve_network is deprecated. '
|
||||
'Use self.client_plugin("neutron").resolve_network')
|
||||
if props.get(net_key):
|
||||
props[net_id_key] = find_neutron_resource(
|
||||
neutron_client, props, net_key, 'network')
|
||||
@ -28,6 +33,8 @@ def resolve_network(neutron_client, props, net_key, net_id_key):
|
||||
|
||||
|
||||
def resolve_subnet(neutron_client, props, subnet_key, subnet_id_key):
|
||||
warnings.warn('neutron_utils.resolve_subnet is deprecated. '
|
||||
'Use self.client_plugin("neutron").resolve_subnet')
|
||||
if props.get(subnet_key):
|
||||
props[subnet_id_key] = find_neutron_resource(
|
||||
neutron_client, props, subnet_key, 'subnet')
|
||||
|
79
heat/tests/test_neutron_client.py
Normal file
79
heat/tests/test_neutron_client.py
Normal file
@ -0,0 +1,79 @@
|
||||
#
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
|
||||
|
||||
from heat.engine.clients.os import neutron
|
||||
from heat.tests.common import HeatTestCase
|
||||
from heat.tests import utils
|
||||
|
||||
|
||||
class NeutronClientPluginTestCase(HeatTestCase):
|
||||
def setUp(self):
|
||||
super(NeutronClientPluginTestCase, self).setUp()
|
||||
self.neutron_client = mock.MagicMock()
|
||||
|
||||
con = utils.dummy_context()
|
||||
c = con.clients
|
||||
self.neutron_plugin = c.client_plugin('neutron')
|
||||
self.neutron_plugin._client = self.neutron_client
|
||||
|
||||
|
||||
class NeutronClientPluginTests(NeutronClientPluginTestCase):
|
||||
def setUp(self):
|
||||
super(NeutronClientPluginTests, self).setUp()
|
||||
self.mock_find = self.patchobject(neutron.neutronV20,
|
||||
'find_resourceid_by_name_or_id')
|
||||
self.mock_find.return_value = 42
|
||||
|
||||
def test_find_neutron_resource(self):
|
||||
props = {'net': 'test_network'}
|
||||
|
||||
res = self.neutron_plugin.find_neutron_resource(props, 'net',
|
||||
'network')
|
||||
self.assertEqual(42, res)
|
||||
self.mock_find.assert_called_once_with(self.neutron_client, 'network',
|
||||
'test_network')
|
||||
|
||||
def test_resolve_network(self):
|
||||
props = {'net': 'test_network'}
|
||||
|
||||
res = self.neutron_plugin.resolve_network(props, 'net', 'net_id')
|
||||
self.assertEqual(42, res)
|
||||
self.mock_find.assert_called_once_with(self.neutron_client, 'network',
|
||||
'test_network')
|
||||
|
||||
# check resolve if was send id instead of name
|
||||
props = {'net_id': 77}
|
||||
res = self.neutron_plugin.resolve_network(props, 'net', 'net_id')
|
||||
self.assertEqual(77, res)
|
||||
# in this case find_resourceid_by_name_or_id is not called
|
||||
self.mock_find.assert_called_once_with(self.neutron_client, 'network',
|
||||
'test_network')
|
||||
|
||||
def test_resolve_subnet(self):
|
||||
props = {'snet': 'test_subnet'}
|
||||
|
||||
res = self.neutron_plugin.resolve_subnet(props, 'snet', 'snet_id')
|
||||
self.assertEqual(42, res)
|
||||
self.mock_find.assert_called_once_with(self.neutron_client, 'subnet',
|
||||
'test_subnet')
|
||||
|
||||
# check resolve if was send id instead of name
|
||||
props = {'snet_id': 77}
|
||||
res = self.neutron_plugin.resolve_subnet(props, 'snet', 'snet_id')
|
||||
self.assertEqual(77, res)
|
||||
# in this case find_resourceid_by_name_or_id is not called
|
||||
self.mock_find.assert_called_once_with(self.neutron_client, 'subnet',
|
||||
'test_subnet')
|
Loading…
Reference in New Issue
Block a user