summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKanagaraj Manickam <kanagaraj.manickam@hp.com>2015-06-12 18:58:10 +0530
committerKanagaraj Manickam <kanagaraj.manickam@hp.com>2015-07-07 14:25:44 +0530
commit6c50858954830919f983d3303addc7f5d59b23bf (patch)
treee3ebb733f4533ca674abe1f9d4d22dbf7bc05fdb
parent490c36f7d0715ba72f04e1898ccb41b5fac81e83 (diff)
downloadheat-6c50858954830919f983d3303addc7f5d59b23bf.tar.gz
List resource_type based on availability
Updates engine resource_type listing to consider the availability of resource based on service deployed and configured in keystone implements blueprint keystone-based-resource-availability Change-Id: Ide88e503a1c5501a6f7685c5f85d3c340c73824f
-rw-r--r--heat/engine/environment.py16
-rw-r--r--heat/engine/service.py2
-rw-r--r--heat/tests/test_engine_service.py23
3 files changed, 33 insertions, 8 deletions
diff --git a/heat/engine/environment.py b/heat/engine/environment.py
index abd115837..8e618bef0 100644
--- a/heat/engine/environment.py
+++ b/heat/engine/environment.py
@@ -439,7 +439,7 @@ class ResourceRegistry(object):
return _as_dict(self._registry)
- def get_types(self, support_status):
+ def get_types(self, cnxt=None, support_status=None):
'''Return a list of valid resource types.'''
def is_resource(key):
@@ -451,8 +451,16 @@ class ResourceRegistry(object):
cls.get_class().support_status.status ==
support_status.encode())
+ def is_available(cls):
+ if cnxt is None:
+ return True
+
+ return cls.get_class().is_service_available(cnxt)
+
return [name for name, cls in six.iteritems(self._registry)
- if is_resource(name) and status_matches(cls)]
+ if (is_resource(name) and
+ status_matches(cls) and
+ is_available(cls))]
class Environment(object):
@@ -532,8 +540,8 @@ class Environment(object):
def get_class(self, resource_type, resource_name=None):
return self.registry.get_class(resource_type, resource_name)
- def get_types(self, support_status=None):
- return self.registry.get_types(support_status)
+ def get_types(self, cnxt=None, support_status=None):
+ return self.registry.get_types(cnxt, support_status)
def get_resource_info(self, resource_type, resource_name=None,
registry_type=None):
diff --git a/heat/engine/service.py b/heat/engine/service.py
index cbb97a112..22295e662 100644
--- a/heat/engine/service.py
+++ b/heat/engine/service.py
@@ -1023,7 +1023,7 @@ class EngineService(service.Service):
:param cnxt: RPC context.
"""
- return resources.global_env().get_types(support_status)
+ return resources.global_env().get_types(cnxt, support_status)
def list_template_versions(self, cnxt):
mgr = templatem._get_template_extension_manager()
diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py
index 7f68ef73d..4c50682c7 100644
--- a/heat/tests/test_engine_service.py
+++ b/heat/tests/test_engine_service.py
@@ -2171,13 +2171,18 @@ class StackServiceTest(common.HeatTestCase):
self.assertIn('WordPress', s['description'])
self.assertIn('parameters', s)
- def test_list_resource_types(self):
+ @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
resources = self.eng.list_resource_types(self.ctx)
self.assertIsInstance(resources, list)
self.assertIn('AWS::EC2::Instance', resources)
self.assertIn('AWS::RDS::DBInstance', resources)
- def test_list_resource_types_deprecated(self):
+ @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
resources = self.eng.list_resource_types(self.ctx, "DEPRECATED")
self.assertEqual(set(['OS::Neutron::RouterGateway',
'OS::Heat::HARestarter',
@@ -2185,7 +2190,10 @@ class StackServiceTest(common.HeatTestCase):
'OS::Heat::StructuredDeployments']),
set(resources))
- def test_list_resource_types_supported(self):
+ @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
resources = self.eng.list_resource_types(self.ctx, "SUPPORTED")
self.assertNotIn(['OS::Neutron::RouterGateway'], resources)
self.assertIn('AWS::EC2::Instance', resources)
@@ -2212,6 +2220,15 @@ class StackServiceTest(common.HeatTestCase):
{'version': 'c.d', 'type': 'hot'}]
self.assertEqual(expected, templates)
+ @mock.patch.object(res.Resource, 'is_service_available')
+ def test_list_resource_types_unavailable(
+ self,
+ mock_is_service_available):
+ mock_is_service_available.return_value = False
+ resources = self.eng.list_resource_types(self.ctx)
+ # Check for an known resource, not listed
+ self.assertNotIn('OS::Nova::Server', resources)
+
def test_resource_schema(self):
type_name = 'ResourceWithPropsType'
expected = {