blob: c74b29741f65ecb24c6c541fc34292710a518d4d [file] [log] [blame]
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +00001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from heatclient import exc
14import keystoneclient
15
16from heat_integrationtests.common import test
17
18
19class ConditionalExposureTestBase(test.HeatIntegrationTest):
20 def setUp(self):
21 super(ConditionalExposureTestBase, self).setUp()
22 self.client = self.orchestration_client
23
24 def _delete(self, stack_name):
25 stacks = self.client.stacks.list()
26 for s in stacks:
27 if s.stack_name == stack_name:
28 self._stack_delete(s.identifier)
29 break
30
31
32class ServiceBasedExposureTest(ConditionalExposureTestBase):
33 # NOTE(pas-ha) if we ever decide to install Sahara on Heat
34 # functional gate, this must be changed to other not-installed
35 # but in principle supported service
36 unavailable_service = 'Sahara'
37 unavailable_template = """
38heat_template_version: 2015-10-15
39resources:
40 not_available:
41 type: OS::Sahara::NodeGroupTemplate
42 properties:
43 plugin_name: fake
44 hadoop_version: 0.1
45 flavor: m1.large
46 node_processes: []
47"""
48
49 def setUp(self):
50 super(ServiceBasedExposureTest, self).setUp()
51 # check that Sahara endpoint is available
52 if self._is_sahara_deployed():
53 self.skipTest("Sahara is actually deployed, "
54 "can not run negative tests on "
55 "Sahara resources availability.")
56
57 def _is_sahara_deployed(self):
58 keystone = self.identity_client
59 try:
60 keystone.service_catalog.url_for(
61 attr='region',
62 filter_value=self.conf.region,
63 service_type='data-processing',
64 endpoint_type='publicURL')
65 except keystoneclient.exceptions.EndpointNotFound:
66 return False
67 return True
68
69 def test_unavailable_resources_not_listed(self):
70 resources = self.client.resource_types.list()
71 self.assertFalse(any(self.unavailable_service in r.resource_type
72 for r in resources))
73
74 def test_unavailable_resources_not_created(self):
75 stack_name = self._stack_rand_name()
76 self.addCleanup(self._delete, stack_name)
77 ex = self.assertRaises(exc.HTTPBadRequest,
78 self.client.stacks.create,
79 stack_name=stack_name,
80 template=self.unavailable_template)
81 self.assertIn('ResourceTypeUnavailable', ex.message)
82 self.assertIn('OS::Sahara::NodeGroupTemplate', ex.message)