Merge "Cleanup neutron finder functions"
This commit is contained in:
commit
2f3be6eb07
|
@ -68,10 +68,6 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||
def is_no_unique(self, ex):
|
||||
return isinstance(ex, exceptions.NeutronClientNoUniqueMatch)
|
||||
|
||||
def find_neutron_resource(self, props, key, key_type):
|
||||
return self.find_resourceid_by_name_or_id(
|
||||
key_type, props.get(key))
|
||||
|
||||
def find_resourceid_by_name_or_id(self, resource, name_or_id,
|
||||
cmd_resource=None):
|
||||
return self._find_resource_id(self.context.tenant_id,
|
||||
|
@ -97,9 +93,8 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
|
|||
|
||||
def _resolve(self, props, key, id_key, key_type):
|
||||
if props.get(key):
|
||||
props[id_key] = self.find_neutron_resource(
|
||||
props, key, key_type)
|
||||
props.pop(key)
|
||||
props[id_key] = self.find_resourceid_by_name_or_id(key_type,
|
||||
props.pop(key))
|
||||
return props[id_key]
|
||||
|
||||
def resolve_network(self, props, net_key, net_id_key):
|
||||
|
|
|
@ -472,10 +472,12 @@ class Port(neutron.NeutronResource):
|
|||
# Switching between name and ID is OK, provided the value resolves
|
||||
# to the same network. If the network changes, port is replaced.
|
||||
if self.NETWORK in changed_properties_set:
|
||||
after_id = self.client_plugin().find_neutron_resource(
|
||||
after_props, self.NETWORK, 'network')
|
||||
before_id = self.client_plugin().find_neutron_resource(
|
||||
before_props, self.NETWORK, 'network')
|
||||
before_id = self.client_plugin().find_resourceid_by_name_or_id(
|
||||
'network',
|
||||
before_props[self.NETWORK])
|
||||
after_id = self.client_plugin().find_resourceid_by_name_or_id(
|
||||
'network',
|
||||
after_props[self.NETWORK])
|
||||
changed_properties_set.remove(self.NETWORK)
|
||||
return before_id != after_id
|
||||
|
||||
|
|
|
@ -216,8 +216,9 @@ class SaharaCluster(resource.Resource):
|
|||
net_id = self.properties[self.MANAGEMENT_NETWORK]
|
||||
if net_id:
|
||||
if self.is_using_neutron():
|
||||
net_id = self.client_plugin('neutron').find_neutron_resource(
|
||||
self.properties, self.MANAGEMENT_NETWORK, 'network')
|
||||
net_id = self.client_plugin(
|
||||
'neutron').find_resourceid_by_name_or_id('network',
|
||||
net_id)
|
||||
else:
|
||||
net_id = self.client_plugin('nova').get_nova_network_id(
|
||||
net_id)
|
||||
|
|
|
@ -282,10 +282,12 @@ class SaharaNodeGroupTemplate(resource.Resource):
|
|||
'use_autoconfig': self.properties[self.USE_AUTOCONFIG],
|
||||
'shares': self.properties[self.SHARES]
|
||||
}
|
||||
if props['floating_ip_pool'] and self.is_using_neutron():
|
||||
floating_ip_pool = props['floating_ip_pool']
|
||||
if floating_ip_pool and self.is_using_neutron():
|
||||
props['floating_ip_pool'] = self.client_plugin(
|
||||
'neutron').find_neutron_resource(
|
||||
self.properties, self.FLOATING_IP_POOL, 'network')
|
||||
'neutron').find_resourceid_by_name_or_id(
|
||||
'network',
|
||||
floating_ip_pool)
|
||||
return props
|
||||
|
||||
def handle_create(self):
|
||||
|
@ -312,14 +314,16 @@ class SaharaNodeGroupTemplate(resource.Resource):
|
|||
if pool:
|
||||
if self.is_using_neutron():
|
||||
try:
|
||||
self.client_plugin('neutron').find_neutron_resource(
|
||||
self.properties, self.FLOATING_IP_POOL, 'network')
|
||||
self.client_plugin(
|
||||
'neutron').find_resourceid_by_name_or_id('network',
|
||||
pool)
|
||||
except Exception as ex:
|
||||
if (self.client_plugin('neutron').is_not_found(ex)
|
||||
or self.client_plugin('neutron').is_no_unique(ex)):
|
||||
err_msg = encodeutils.exception_to_unicode(ex)
|
||||
raise exception.StackValidationFailed(message=err_msg)
|
||||
raise
|
||||
|
||||
else:
|
||||
try:
|
||||
self.client('nova').floating_ip_pools.find(name=pool)
|
||||
|
@ -551,14 +555,15 @@ class SaharaClusterTemplate(resource.Resource):
|
|||
'use_autoconfig': self.properties[self.USE_AUTOCONFIG],
|
||||
'shares': self.properties[self.SHARES]
|
||||
}
|
||||
if props['net_id']:
|
||||
net_id = props['net_id']
|
||||
if net_id:
|
||||
if self.is_using_neutron():
|
||||
props['net_id'] = self.client_plugin(
|
||||
'neutron').find_neutron_resource(
|
||||
self.properties, self.MANAGEMENT_NETWORK, 'network')
|
||||
'neutron').find_resourceid_by_name_or_id('network',
|
||||
net_id)
|
||||
else:
|
||||
props['net_id'] = self.client_plugin(
|
||||
'nova').get_nova_network_id(props['net_id'])
|
||||
'nova').get_nova_network_id(net_id)
|
||||
return props
|
||||
|
||||
def handle_create(self):
|
||||
|
|
|
@ -341,9 +341,9 @@ class OSDBInstance(resource.Resource):
|
|||
net = nic.get(self.NET)
|
||||
if net:
|
||||
if self.is_using_neutron():
|
||||
net_id = (self.client_plugin(
|
||||
'neutron').find_neutron_resource(
|
||||
nic, self.NET, 'network'))
|
||||
net_id = self.client_plugin(
|
||||
'neutron').find_resourceid_by_name_or_id('network',
|
||||
net)
|
||||
else:
|
||||
net_id = (self.client_plugin(
|
||||
'nova').get_nova_network_id(net))
|
||||
|
@ -351,8 +351,8 @@ class OSDBInstance(resource.Resource):
|
|||
port = nic.get(self.PORT)
|
||||
if port:
|
||||
neutron = self.client_plugin('neutron')
|
||||
nic_dict['port-id'] = neutron.find_neutron_resource(
|
||||
nic, self.PORT, 'port')
|
||||
nic_dict['port-id'] = neutron.find_resourceid_by_name_or_id(
|
||||
'port', port)
|
||||
ip = nic.get(self.V4_FIXED_IP)
|
||||
if ip:
|
||||
nic_dict['v4-fixed-ip'] = ip
|
||||
|
|
|
@ -42,16 +42,6 @@ class NeutronClientPluginTests(NeutronClientPluginTestCase):
|
|||
'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',
|
||||
cmd_resource=None)
|
||||
|
||||
def test_resolve_network(self):
|
||||
props = {'net': 'test_network'}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class RBACPolicyTest(common.HeatTestCase):
|
|||
self.rbac.client = mock.MagicMock()
|
||||
self.rbac.client.return_value = self.neutron_client
|
||||
|
||||
self.rbac.client_plugin().find_neutron_resource = (
|
||||
self.rbac.client_plugin().find_resourceid_by_name_or_id = (
|
||||
mock.MagicMock(return_value='123'))
|
||||
props = {
|
||||
"action": "access_as_shared",
|
||||
|
|
|
@ -67,8 +67,9 @@ class SaharaClusterTest(common.HeatTestCase):
|
|||
'find_image_by_name_or_id'
|
||||
).return_value = 'some_image_id'
|
||||
self.patchobject(neutron.NeutronClientPlugin, '_create')
|
||||
self.patchobject(neutron.NeutronClientPlugin, 'find_neutron_resource'
|
||||
).return_value = 'some_network_id'
|
||||
self.patchobject(neutron.NeutronClientPlugin,
|
||||
'find_resourceid_by_name_or_id',
|
||||
return_value='some_network_id')
|
||||
self.sahara_mock = mock.MagicMock()
|
||||
self.patchobject(sahara.SaharaClientPlugin, '_create'
|
||||
).return_value = self.sahara_mock
|
||||
|
|
|
@ -114,8 +114,9 @@ class SaharaNodeGroupTemplateTest(common.HeatTestCase):
|
|||
self.patchobject(nova.NovaClientPlugin, 'find_flavor_by_name_or_id'
|
||||
).return_value = 'someflavorid'
|
||||
self.patchobject(neutron.NeutronClientPlugin, '_create')
|
||||
self.patchobject(neutron.NeutronClientPlugin, 'find_neutron_resource'
|
||||
).return_value = 'some_pool_id'
|
||||
self.patchobject(neutron.NeutronClientPlugin,
|
||||
'find_resourceid_by_name_or_id',
|
||||
return_value='some_pool_id')
|
||||
sahara_mock = mock.MagicMock()
|
||||
self.ngt_mgr = sahara_mock.node_group_templates
|
||||
self.plugin_mgr = sahara_mock.plugins
|
||||
|
@ -180,7 +181,8 @@ class SaharaNodeGroupTemplateTest(common.HeatTestCase):
|
|||
self.patchobject(ngt, 'is_using_neutron').return_value = True
|
||||
|
||||
self.patchobject(
|
||||
neutron.NeutronClientPlugin, 'find_neutron_resource'
|
||||
neutron.NeutronClientPlugin,
|
||||
'find_resourceid_by_name_or_id'
|
||||
).side_effect = [
|
||||
neutron.exceptions.NeutronClientNoUniqueMatch(message='Too many'),
|
||||
neutron.exceptions.NeutronClientException(message='Not found',
|
||||
|
@ -293,8 +295,9 @@ class SaharaClusterTemplateTest(common.HeatTestCase):
|
|||
self.patchobject(st.constraints.CustomConstraint, '_is_valid'
|
||||
).return_value = True
|
||||
self.patchobject(neutron.NeutronClientPlugin, '_create')
|
||||
self.patchobject(neutron.NeutronClientPlugin, 'find_neutron_resource'
|
||||
).return_value = 'some_network_id'
|
||||
self.patchobject(neutron.NeutronClientPlugin,
|
||||
'find_resourceid_by_name_or_id',
|
||||
return_value='some_network_id')
|
||||
sahara_mock = mock.MagicMock()
|
||||
self.ct_mgr = sahara_mock.cluster_templates
|
||||
self.patchobject(sahara.SaharaClientPlugin,
|
||||
|
|
|
@ -607,10 +607,11 @@ class OSDBInstanceTest(common.HeatTestCase):
|
|||
instance = self._setup_test_clouddbinstance('dbinstance_test', t)
|
||||
self._stubout_common_create()
|
||||
self.m.StubOutWithMock(neutron.NeutronClientPlugin,
|
||||
'find_neutron_resource')
|
||||
neutron.NeutronClientPlugin.find_neutron_resource(
|
||||
instance.properties.get('networks')[0],
|
||||
'port', 'port').AndReturn('someportid')
|
||||
'find_resourceid_by_name_or_id')
|
||||
neutron.NeutronClientPlugin.find_resourceid_by_name_or_id(
|
||||
'port',
|
||||
instance.properties.get(
|
||||
'networks')[0]['port']).AndReturn('someportid')
|
||||
|
||||
self.fc.instances.create('test', 1, volume={'size': 30},
|
||||
databases=[],
|
||||
|
@ -642,10 +643,11 @@ class OSDBInstanceTest(common.HeatTestCase):
|
|||
self.stub_NetworkConstraint_validate()
|
||||
self._stubout_common_create()
|
||||
self.m.StubOutWithMock(neutron.NeutronClientPlugin,
|
||||
'find_neutron_resource')
|
||||
neutron.NeutronClientPlugin.find_neutron_resource(
|
||||
instance.properties.get('networks')[0],
|
||||
'network', 'network').AndReturn(net_id)
|
||||
'find_resourceid_by_name_or_id')
|
||||
neutron.NeutronClientPlugin.find_resourceid_by_name_or_id(
|
||||
'network',
|
||||
instance.properties.get(
|
||||
'networks')[0]['network']).AndReturn(net_id)
|
||||
self.fc.instances.create('test', 1, volume={'size': 30},
|
||||
databases=[],
|
||||
users=[],
|
||||
|
|
Loading…
Reference in New Issue