blob: 69cff79d78daa7edfefdd5d53a48104e5f883ff3 [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
rabi8bba7332016-12-06 12:11:48 +053026parameters:
27 instance_type:
28 type: string
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000029resources:
30 not_available:
31 type: OS::Sahara::NodeGroupTemplate
32 properties:
33 plugin_name: fake
34 hadoop_version: 0.1
rabi8bba7332016-12-06 12:11:48 +053035 flavor: {get_param: instance_type}
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000036 node_processes: []
37"""
38
39 def setUp(self):
40 super(ServiceBasedExposureTest, self).setUp()
41 # check that Sahara endpoint is available
42 if self._is_sahara_deployed():
43 self.skipTest("Sahara is actually deployed, "
44 "can not run negative tests on "
45 "Sahara resources availability.")
46
47 def _is_sahara_deployed(self):
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000048 try:
Rabi Mishra65493fb2016-01-29 22:23:21 +053049 self.identity_client.get_endpoint_url('data-processing',
50 self.conf.region)
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000051 except keystoneclient.exceptions.EndpointNotFound:
52 return False
53 return True
54
55 def test_unavailable_resources_not_listed(self):
56 resources = self.client.resource_types.list()
57 self.assertFalse(any(self.unavailable_service in r.resource_type
58 for r in resources))
59
60 def test_unavailable_resources_not_created(self):
61 stack_name = self._stack_rand_name()
rabi8bba7332016-12-06 12:11:48 +053062 parameters = {'instance_type': self.conf.minimal_instance_type}
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000063 ex = self.assertRaises(exc.HTTPBadRequest,
64 self.client.stacks.create,
65 stack_name=stack_name,
rabi8bba7332016-12-06 12:11:48 +053066 parameters=parameters,
Pavlo Shchelokovskyy245ccc42015-07-16 09:47:20 +000067 template=self.unavailable_template)
68 self.assertIn('ResourceTypeUnavailable', ex.message)
69 self.assertIn('OS::Sahara::NodeGroupTemplate', ex.message)
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +000070
71
72class RoleBasedExposureTest(functional_base.FunctionalTestsBase):
huangtianhua23f18f32016-05-17 16:55:45 +080073
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +000074 fl_tmpl = """
75heat_template_version: 2015-10-15
76
77resources:
78 not4everyone:
79 type: OS::Nova::Flavor
80 properties:
81 ram: 20000
82 vcpus: 10
83"""
84
huangtianhua23f18f32016-05-17 16:55:45 +080085 cvt_tmpl = """
86heat_template_version: 2015-10-15
87
88resources:
89 cvt:
90 type: OS::Cinder::VolumeType
91 properties:
92 name: cvt_test
93"""
94
95 host_aggr_tmpl = """
96heat_template_version: 2015-10-15
97parameters:
98 az:
99 type: string
100 default: nova
101resources:
102 cvt:
103 type: OS::Nova::HostAggregate
104 properties:
105 name: aggregate_test
106 availability_zone: {get_param: az}
107"""
108
109 scenarios = [
110 ('r_nova_flavor', dict(
111 stack_name='s_nova_flavor',
112 template=fl_tmpl,
113 forbidden_r_type="OS::Nova::Flavor",
114 test_creation=True)),
115 ('r_nova_host_aggregate', dict(
116 stack_name='s_nova_ost_aggregate',
117 template=host_aggr_tmpl,
118 forbidden_r_type="OS::Nova::HostAggregate",
119 test_creation=True)),
120 ('r_cinder_vtype', dict(
121 stack_name='s_cinder_vtype',
122 template=cvt_tmpl,
123 forbidden_r_type="OS::Cinder::VolumeType",
124 test_creation=True)),
125 ('r_cinder_vtype_encrypt', dict(
126 forbidden_r_type="OS::Cinder::EncryptedVolumeType",
127 test_creation=False)),
128 ('r_neutron_qos', dict(
129 forbidden_r_type="OS::Neutron::QoSPolicy",
130 test_creation=False)),
131 ('r_neutron_qos_bandwidth_limit', dict(
132 forbidden_r_type="OS::Neutron::QoSBandwidthLimitRule",
133 test_creation=False)),
134 ('r_manila_share_type', dict(
135 forbidden_r_type="OS::Manila::ShareType",
136 test_creation=False))
137 ]
138
139 def test_non_admin_forbidden_create_resources(self):
140 """Fail to create resource w/o admin role.
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000141
142 Integration tests job runs as normal OpenStack user,
huangtianhua23f18f32016-05-17 16:55:45 +0800143 and the resources above are configured to require
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000144 admin role in default policy file of Heat.
145 """
huangtianhua23f18f32016-05-17 16:55:45 +0800146 if self.test_creation:
147 ex = self.assertRaises(exc.Forbidden,
148 self.client.stacks.create,
149 stack_name=self.stack_name,
150 template=self.template)
151 self.assertIn(self.forbidden_r_type, ex.message)
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000152
153 def test_forbidden_resource_not_listed(self):
154 resources = self.client.resource_types.list()
huangtianhua23f18f32016-05-17 16:55:45 +0800155 self.assertNotIn(self.forbidden_r_type,
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000156 (r.resource_type for r in resources))