blob: 9d0f8382f3a3df9fc7c96fdf3678bd12bce49d37 [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)
Thomas Herve525f03e2017-02-01 14:24:31 +010068 self.assertIn('ResourceTypeUnavailable', ex.message.decode('utf-8'))
69 self.assertIn('OS::Sahara::NodeGroupTemplate',
70 ex.message.decode('utf-8'))
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +000071
72
73class RoleBasedExposureTest(functional_base.FunctionalTestsBase):
huangtianhua23f18f32016-05-17 16:55:45 +080074
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +000075 fl_tmpl = """
76heat_template_version: 2015-10-15
77
78resources:
79 not4everyone:
80 type: OS::Nova::Flavor
81 properties:
82 ram: 20000
83 vcpus: 10
84"""
85
huangtianhua23f18f32016-05-17 16:55:45 +080086 cvt_tmpl = """
87heat_template_version: 2015-10-15
88
89resources:
90 cvt:
91 type: OS::Cinder::VolumeType
92 properties:
93 name: cvt_test
94"""
95
96 host_aggr_tmpl = """
97heat_template_version: 2015-10-15
98parameters:
99 az:
100 type: string
101 default: nova
102resources:
103 cvt:
104 type: OS::Nova::HostAggregate
105 properties:
106 name: aggregate_test
107 availability_zone: {get_param: az}
108"""
109
110 scenarios = [
111 ('r_nova_flavor', dict(
112 stack_name='s_nova_flavor',
113 template=fl_tmpl,
114 forbidden_r_type="OS::Nova::Flavor",
115 test_creation=True)),
116 ('r_nova_host_aggregate', dict(
117 stack_name='s_nova_ost_aggregate',
118 template=host_aggr_tmpl,
119 forbidden_r_type="OS::Nova::HostAggregate",
120 test_creation=True)),
121 ('r_cinder_vtype', dict(
122 stack_name='s_cinder_vtype',
123 template=cvt_tmpl,
124 forbidden_r_type="OS::Cinder::VolumeType",
125 test_creation=True)),
126 ('r_cinder_vtype_encrypt', dict(
127 forbidden_r_type="OS::Cinder::EncryptedVolumeType",
128 test_creation=False)),
129 ('r_neutron_qos', dict(
130 forbidden_r_type="OS::Neutron::QoSPolicy",
131 test_creation=False)),
132 ('r_neutron_qos_bandwidth_limit', dict(
133 forbidden_r_type="OS::Neutron::QoSBandwidthLimitRule",
134 test_creation=False)),
135 ('r_manila_share_type', dict(
136 forbidden_r_type="OS::Manila::ShareType",
137 test_creation=False))
138 ]
139
140 def test_non_admin_forbidden_create_resources(self):
141 """Fail to create resource w/o admin role.
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000142
143 Integration tests job runs as normal OpenStack user,
huangtianhua23f18f32016-05-17 16:55:45 +0800144 and the resources above are configured to require
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000145 admin role in default policy file of Heat.
146 """
huangtianhua23f18f32016-05-17 16:55:45 +0800147 if self.test_creation:
148 ex = self.assertRaises(exc.Forbidden,
149 self.client.stacks.create,
150 stack_name=self.stack_name,
151 template=self.template)
Thomas Herve525f03e2017-02-01 14:24:31 +0100152 self.assertIn(self.forbidden_r_type, ex.message.decode('utf-8'))
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000153
154 def test_forbidden_resource_not_listed(self):
155 resources = self.client.resource_types.list()
huangtianhua23f18f32016-05-17 16:55:45 +0800156 self.assertNotIn(self.forbidden_r_type,
Pavlo Shchelokovskyy67a64d92015-08-20 14:39:14 +0000157 (r.resource_type for r in resources))