Fix get_endpoint() call in is_using_neutron

Neutron v2 client wraps SessionClient and it's
available as an attribute `httpclient'.

Change-Id: I664be1b00975b048e2289f5be3270b4a00520e80
Closes-Bug: #1607222
This commit is contained in:
OTSUKA, Yuanying 2016-07-28 15:59:05 +09:00 committed by Rabi Mishra
parent e7a9e03132
commit f4a2d8dbc7
2 changed files with 11 additions and 11 deletions

View File

@ -2154,7 +2154,8 @@ class Resource(object):
def is_using_neutron(self):
try:
if not self.client('neutron').get_endpoint():
sess_client = self.client('neutron').httpclient
if not sess_client.get_endpoint():
return False
except Exception:
return False

View File

@ -1480,15 +1480,7 @@ class ResourceTest(common.HeatTestCase):
'Test::Resource::resource',
template_type='hot'))
def test_is_using_neutron(self):
snippet = rsrc_defn.ResourceDefinition('aresource',
'GenericResourceType')
res = resource.Resource('aresource', snippet, self.stack)
self.patch(
'heat.engine.clients.os.neutron.NeutronClientPlugin._create')
self.assertTrue(res.is_using_neutron())
def test_is_not_using_neutron(self):
def test_is_not_using_neutron_exception(self):
snippet = rsrc_defn.ResourceDefinition('aresource',
'GenericResourceType')
res = resource.Resource('aresource', snippet, self.stack)
@ -1497,13 +1489,20 @@ class ResourceTest(common.HeatTestCase):
mock_create.side_effect = Exception()
self.assertFalse(res.is_using_neutron())
def test_is_using_neutron_endpoint_lookup(self):
snippet = rsrc_defn.ResourceDefinition('aresource',
'GenericResourceType')
res = resource.Resource('aresource', snippet, self.stack)
client = mock.Mock()
self.patchobject(client, 'get_endpoint',
self.patchobject(client.httpclient, 'get_endpoint',
return_value=None)
self.patch(
'heat.engine.clients.os.neutron.NeutronClientPlugin._create',
return_value=client)
self.assertFalse(res.is_using_neutron())
self.patchobject(client.httpclient, 'get_endpoint',
return_value=mock.Mock())
self.assertTrue(res.is_using_neutron())
def _test_skip_validation_if_custom_constraint(self, tmpl):
stack = parser.Stack(utils.dummy_context(), 'test', tmpl)