Merge "Correct message when extension is not available"

This commit is contained in:
Jenkins 2016-06-28 04:45:13 +00:00 committed by Gerrit Code Review
commit a758dff5aa
10 changed files with 42 additions and 28 deletions

View File

@ -30,7 +30,7 @@ from .test_cloud_loadbalancer import FakeNode # noqa
class LBNode(lb_node.LBNode):
@classmethod
def is_service_available(cls, context):
return True
return (True, None)
class LBNodeTest(common.HeatTestCase):

View File

@ -599,7 +599,7 @@ class ResourceRegistry(object):
return True
try:
return cls.get_class().is_service_available(cnxt)
return cls.get_class().is_service_available(cnxt)[0]
except Exception:
return False

View File

@ -166,7 +166,7 @@ class Resource(object):
@classmethod
def _validate_service_availability(cls, context, resource_type):
try:
svc_available = cls.is_service_available(context)
(svc_available, reason) = cls.is_service_available(context)
except Exception as exc:
LOG.exception(_LE("Resource type %s unavailable"),
resource_type)
@ -180,7 +180,7 @@ class Resource(object):
ex = exception.ResourceTypeUnavailable(
resource_type=resource_type,
service_name=cls.default_client_name,
reason='Service endpoint not in service catalog.')
reason=reason)
LOG.info(six.text_type(ex))
raise ex
@ -646,7 +646,7 @@ class Resource(object):
# resource does not have endpoint, such as RandomString, OS::Heat
# resources as they are implemented within the engine.
if cls.default_client_name is None:
return True
return (True, None)
client_plugin = clients.Clients(context).client_plugin(
cls.default_client_name)
@ -656,7 +656,7 @@ class Resource(object):
service_types = client_plugin.service_types
if not service_types:
return True
return (True, None)
# NOTE(kanagaraj-manickam): if one of the service_type does
# exist in the keystone, then considered it as available.
@ -670,8 +670,16 @@ class Resource(object):
not req_extension or client_plugin.has_extension(
req_extension))
if is_ext_available:
return True
return False
return (True, None)
else:
reason = _('Required extension {0} in {1} service '
'is not available.')
reason = reason.format(req_extension,
cls.default_client_name)
else:
reason = _('{0} {1} endpoint is not in service catalog.')
reason = reason.format(cls.default_client_name, service_type)
return (False, reason)
def keystone(self):
return self.client('keystone')

View File

@ -1514,7 +1514,7 @@ class EngineService(service.Service):
raise exception.NotSupported(type_name)
try:
svc_available = resource_class.is_service_available(cnxt)
svc_available = resource_class.is_service_available(cnxt)[0]
except Exception as exc:
raise exception.ResourceTypeUnavailable(
service_name=resource_class.default_client_name,

View File

@ -32,7 +32,7 @@ class ResourceTypeTest(common.HeatTestCase):
@mock.patch.object(res.Resource, 'is_service_available')
def test_list_resource_types(self, mock_is_service_available):
mock_is_service_available.return_value = True
mock_is_service_available.return_value = (True, None)
resources = self.eng.list_resource_types(self.ctx)
self.assertIsInstance(resources, list)
self.assertIn('AWS::EC2::Instance', resources)
@ -41,7 +41,7 @@ class ResourceTypeTest(common.HeatTestCase):
@mock.patch.object(res.Resource, 'is_service_available')
def test_list_resource_types_deprecated(self,
mock_is_service_available):
mock_is_service_available.return_value = True
mock_is_service_available.return_value = (True, None)
resources = self.eng.list_resource_types(self.ctx, "DEPRECATED")
self.assertEqual(set(['OS::Heat::HARestarter',
'OS::Heat::SoftwareDeployments',
@ -55,7 +55,7 @@ class ResourceTypeTest(common.HeatTestCase):
@mock.patch.object(res.Resource, 'is_service_available')
def test_list_resource_types_supported(self,
mock_is_service_available):
mock_is_service_available.return_value = True
mock_is_service_available.return_value = (True, None)
resources = self.eng.list_resource_types(self.ctx, "SUPPORTED")
self.assertNotIn(['OS::Neutron::RouterGateway'], resources)
self.assertIn('AWS::EC2::Instance', resources)
@ -64,14 +64,15 @@ class ResourceTypeTest(common.HeatTestCase):
def test_list_resource_types_unavailable(
self,
mock_is_service_available):
mock_is_service_available.return_value = False
mock_is_service_available.return_value = (
False, 'Service endpoint not in service catalog.')
resources = self.eng.list_resource_types(self.ctx)
# Check for a known resource, not listed
self.assertNotIn('OS::Nova::Server', resources)
@mock.patch.object(res.Resource, 'is_service_available')
def test_list_resource_types_with_descr(self, mock_is_service_available):
mock_is_service_available.return_value = True
mock_is_service_available.return_value = (True, None)
resources = self.eng.list_resource_types(self.ctx,
with_description=True)
self.assertIsInstance(resources, list)
@ -186,7 +187,8 @@ class ResourceTypeTest(common.HeatTestCase):
with mock.patch.object(
generic_rsrc.ResourceWithDefaultClientName,
'is_service_available') as mock_is_service_available:
mock_is_service_available.return_value = False
mock_is_service_available.return_value = (
False, 'Service endpoint not in service catalog.')
ex = self.assertRaises(exception.ResourceTypeUnavailable,
self.eng.resource_schema,
self.ctx,

View File

@ -36,7 +36,7 @@ class GenericResource(resource.Resource):
@classmethod
def is_service_available(cls, context):
return True
return (True, None)
def handle_create(self):
LOG.warning(_LW('Creating generic resource (Type "%s")'),

View File

@ -79,7 +79,7 @@ class NeutronTest(common.HeatTestCase):
@classmethod
def is_service_available(cls, context):
return True
return (True, None)
tmpl = rsrc_defn.ResourceDefinition('test_res', 'Foo')
stack = mock.MagicMock()

View File

@ -221,6 +221,7 @@ class WaitConditionMetadataUpdateTest(common.HeatTestCase):
mock_check, mock_handle, *args):
"""Tests a wait condition metadata update after a signal call."""
mock_available.return_value = (True, None)
# Setup Stack
temp = template_format.parse(TEST_TEMPLATE_WAIT_CONDITION)
template = tmpl.Template(temp)

View File

@ -3158,7 +3158,7 @@ class ResourceAvailabilityTest(common.HeatTestCase):
new_callable=mock.PropertyMock) as mock_client_name:
mock_client_name.return_value = None
self.assertTrue((generic_rsrc.ResourceWithDefaultClientName.
is_service_available(context=mock.Mock())))
is_service_available(context=mock.Mock())[0]))
@mock.patch.object(clients.OpenStackClients, 'client_plugin')
def test_default_true_empty_service_types(
@ -3174,7 +3174,7 @@ class ResourceAvailabilityTest(common.HeatTestCase):
self.assertTrue(
generic_rsrc.ResourceWithDefaultClientName.is_service_available(
context=mock.Mock()))
context=mock.Mock())[0])
mock_client_plugin_method.assert_called_once_with(
generic_rsrc.ResourceWithDefaultClientName.default_client_name)
mock_service_types.assert_called_once_with()
@ -3195,7 +3195,7 @@ class ResourceAvailabilityTest(common.HeatTestCase):
self.assertTrue(
generic_rsrc.ResourceWithDefaultClientName.is_service_available(
context=mock.Mock()))
context=mock.Mock())[0])
mock_client_plugin_method.assert_called_once_with(
generic_rsrc.ResourceWithDefaultClientName.default_client_name)
mock_service_types.assert_called_once_with()
@ -3223,7 +3223,7 @@ class ResourceAvailabilityTest(common.HeatTestCase):
self.assertFalse(
generic_rsrc.ResourceWithDefaultClientName.is_service_available(
context=mock.Mock()))
context=mock.Mock())[0])
mock_client_plugin_method.assert_called_once_with(
generic_rsrc.ResourceWithDefaultClientName.default_client_name)
mock_service_types.assert_called_once_with()
@ -3248,7 +3248,7 @@ class ResourceAvailabilityTest(common.HeatTestCase):
self.assertTrue(
generic_rsrc.ResourceWithDefaultClientNameExt.is_service_available(
context=mock.Mock()))
context=mock.Mock())[0])
mock_client_plugin_method.assert_called_once_with(
generic_rsrc.ResourceWithDefaultClientName.default_client_name)
mock_service_types.assert_called_once_with()
@ -3273,7 +3273,7 @@ class ResourceAvailabilityTest(common.HeatTestCase):
self.assertFalse(
generic_rsrc.ResourceWithDefaultClientNameExt.is_service_available(
context=mock.Mock()))
context=mock.Mock())[0])
mock_client_plugin_method.assert_called_once_with(
generic_rsrc.ResourceWithDefaultClientName.default_client_name)
mock_service_types.assert_called_once_with()
@ -3327,7 +3327,7 @@ class ResourceAvailabilityTest(common.HeatTestCase):
self.assertFalse(
generic_rsrc.ResourceWithDefaultClientNameExt.is_service_available(
context=mock.Mock()))
context=mock.Mock())[0])
mock_client_plugin_method.assert_called_once_with(
generic_rsrc.ResourceWithDefaultClientName.default_client_name)
mock_service_types.assert_called_once_with()
@ -3363,7 +3363,8 @@ class ResourceAvailabilityTest(common.HeatTestCase):
with mock.patch.object(
generic_rsrc.ResourceWithDefaultClientName,
'is_service_available') as mock_method:
mock_method.return_value = False
mock_method.return_value = (
False, 'Service endpoint not in service catalog.')
definition = rsrc_defn.ResourceDefinition(
name='Test Resource',

View File

@ -909,7 +909,7 @@ class ValidateTest(common.HeatTestCase):
self.ctx = utils.dummy_context()
self.mock_isa = mock.patch(
'heat.engine.resource.Resource.is_service_available',
return_value=True)
return_value=(True, None))
self.mock_is_service_available = self.mock_isa.start()
self.addCleanup(self.mock_isa.stop)
self.engine = service.EngineService('a', 't')
@ -1662,7 +1662,8 @@ class ValidateTest(common.HeatTestCase):
type: AWS::EC2::Instance
""")
self.mock_is_service_available.return_value = False
self.mock_is_service_available.return_value = (
False, 'Service endpoint not in service catalog.')
ex = self.assertRaises(dispatcher.ExpectedException,
self.engine.validate_template,
self.ctx,
@ -1679,7 +1680,8 @@ class ValidateTest(common.HeatTestCase):
type: AWS::EC2::Instance
""")
engine = service.EngineService('a', 't')
self.mock_is_service_available.return_value = False
self.mock_is_service_available.return_value = (
False, 'Service endpoint not in service catalog.')
res = dict(engine.validate_template(
self.ctx,