blob: d03771235f2464b3ed078521d4949f424a57ed93 [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
Rabi Mishra477efc92015-07-31 13:01:45 +053016from heat_integrationtests.functional import functional_base
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000017
18
Steve Bakerdbea6ab2015-08-19 13:37:08 +120019class ServiceBasedExposureTest(functional_base.FunctionalTestsBase):
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000020 # NOTE(pas-ha) if we ever decide to install Sahara on Heat
21 # functional gate, this must be changed to other not-installed
22 # but in principle supported service
23 unavailable_service = 'Sahara'
24 unavailable_template = """
25heat_template_version: 2015-10-15
26resources:
27 not_available:
28 type: OS::Sahara::NodeGroupTemplate
29 properties:
30 plugin_name: fake
31 hadoop_version: 0.1
32 flavor: m1.large
33 node_processes: []
34"""
35
36 def setUp(self):
37 super(ServiceBasedExposureTest, self).setUp()
38 # check that Sahara endpoint is available
39 if self._is_sahara_deployed():
40 self.skipTest("Sahara is actually deployed, "
41 "can not run negative tests on "
42 "Sahara resources availability.")
43
44 def _is_sahara_deployed(self):
45 keystone = self.identity_client
46 try:
47 keystone.service_catalog.url_for(
48 attr='region',
49 filter_value=self.conf.region,
50 service_type='data-processing',
51 endpoint_type='publicURL')
52 except keystoneclient.exceptions.EndpointNotFound:
53 return False
54 return True
55
56 def test_unavailable_resources_not_listed(self):
57 resources = self.client.resource_types.list()
58 self.assertFalse(any(self.unavailable_service in r.resource_type
59 for r in resources))
60
61 def test_unavailable_resources_not_created(self):
62 stack_name = self._stack_rand_name()
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000063 ex = self.assertRaises(exc.HTTPBadRequest,
64 self.client.stacks.create,
65 stack_name=stack_name,
66 template=self.unavailable_template)
67 self.assertIn('ResourceTypeUnavailable', ex.message)
68 self.assertIn('OS::Sahara::NodeGroupTemplate', ex.message)
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +000069
70
71class RoleBasedExposureTest(functional_base.FunctionalTestsBase):
72 forbidden_resource_type = "OS::Nova::Flavor"
73 fl_tmpl = """
74heat_template_version: 2015-10-15
75
76resources:
77 not4everyone:
78 type: OS::Nova::Flavor
79 properties:
80 ram: 20000
81 vcpus: 10
82"""
83
84 def test_non_admin_forbidden_create_flavors(self):
85 """Fail to create Flavor resource w/o admin role
86
87 Integration tests job runs as normal OpenStack user,
88 and OS::Nova:Flavor is configured to require
89 admin role in default policy file of Heat.
90 """
91 stack_name = self._stack_rand_name()
92 ex = self.assertRaises(exc.Forbidden,
93 self.client.stacks.create,
94 stack_name=stack_name,
95 template=self.fl_tmpl)
96 self.assertIn(self.forbidden_resource_type, ex.message)
97
98 def test_forbidden_resource_not_listed(self):
99 resources = self.client.resource_types.list()
100 self.assertNotIn(self.forbidden_resource_type,
101 (r.resource_type for r in resources))