Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 1 | # 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 | |
| 13 | from heatclient import exc |
| 14 | import keystoneclient |
| 15 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 16 | from heat_integrationtests.functional import functional_base |
Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 17 | |
| 18 | |
Steve Baker | dbea6ab | 2015-08-19 13:37:08 +1200 | [diff] [blame] | 19 | class ServiceBasedExposureTest(functional_base.FunctionalTestsBase): |
Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 20 | # 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 = """ |
| 25 | heat_template_version: 2015-10-15 |
| 26 | resources: |
| 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): |
Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 45 | try: |
Rabi Mishra | 65493fb | 2016-01-29 22:23:21 +0530 | [diff] [blame] | 46 | self.identity_client.get_endpoint_url('data-processing', |
| 47 | self.conf.region) |
Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 48 | except keystoneclient.exceptions.EndpointNotFound: |
| 49 | return False |
| 50 | return True |
| 51 | |
| 52 | def test_unavailable_resources_not_listed(self): |
| 53 | resources = self.client.resource_types.list() |
| 54 | self.assertFalse(any(self.unavailable_service in r.resource_type |
| 55 | for r in resources)) |
| 56 | |
| 57 | def test_unavailable_resources_not_created(self): |
| 58 | stack_name = self._stack_rand_name() |
Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 59 | ex = self.assertRaises(exc.HTTPBadRequest, |
| 60 | self.client.stacks.create, |
| 61 | stack_name=stack_name, |
| 62 | template=self.unavailable_template) |
| 63 | self.assertIn('ResourceTypeUnavailable', ex.message) |
| 64 | self.assertIn('OS::Sahara::NodeGroupTemplate', ex.message) |
Pavlo Shchelokovskyy | 67a64d9 | 2015-08-20 14:39:14 +0000 | [diff] [blame] | 65 | |
| 66 | |
| 67 | class RoleBasedExposureTest(functional_base.FunctionalTestsBase): |
huangtianhua | 23f18f3 | 2016-05-17 16:55:45 +0800 | [diff] [blame] | 68 | |
Pavlo Shchelokovskyy | 67a64d9 | 2015-08-20 14:39:14 +0000 | [diff] [blame] | 69 | fl_tmpl = """ |
| 70 | heat_template_version: 2015-10-15 |
| 71 | |
| 72 | resources: |
| 73 | not4everyone: |
| 74 | type: OS::Nova::Flavor |
| 75 | properties: |
| 76 | ram: 20000 |
| 77 | vcpus: 10 |
| 78 | """ |
| 79 | |
huangtianhua | 23f18f3 | 2016-05-17 16:55:45 +0800 | [diff] [blame] | 80 | cvt_tmpl = """ |
| 81 | heat_template_version: 2015-10-15 |
| 82 | |
| 83 | resources: |
| 84 | cvt: |
| 85 | type: OS::Cinder::VolumeType |
| 86 | properties: |
| 87 | name: cvt_test |
| 88 | """ |
| 89 | |
| 90 | host_aggr_tmpl = """ |
| 91 | heat_template_version: 2015-10-15 |
| 92 | parameters: |
| 93 | az: |
| 94 | type: string |
| 95 | default: nova |
| 96 | resources: |
| 97 | cvt: |
| 98 | type: OS::Nova::HostAggregate |
| 99 | properties: |
| 100 | name: aggregate_test |
| 101 | availability_zone: {get_param: az} |
| 102 | """ |
| 103 | |
| 104 | scenarios = [ |
| 105 | ('r_nova_flavor', dict( |
| 106 | stack_name='s_nova_flavor', |
| 107 | template=fl_tmpl, |
| 108 | forbidden_r_type="OS::Nova::Flavor", |
| 109 | test_creation=True)), |
| 110 | ('r_nova_host_aggregate', dict( |
| 111 | stack_name='s_nova_ost_aggregate', |
| 112 | template=host_aggr_tmpl, |
| 113 | forbidden_r_type="OS::Nova::HostAggregate", |
| 114 | test_creation=True)), |
| 115 | ('r_cinder_vtype', dict( |
| 116 | stack_name='s_cinder_vtype', |
| 117 | template=cvt_tmpl, |
| 118 | forbidden_r_type="OS::Cinder::VolumeType", |
| 119 | test_creation=True)), |
| 120 | ('r_cinder_vtype_encrypt', dict( |
| 121 | forbidden_r_type="OS::Cinder::EncryptedVolumeType", |
| 122 | test_creation=False)), |
| 123 | ('r_neutron_qos', dict( |
| 124 | forbidden_r_type="OS::Neutron::QoSPolicy", |
| 125 | test_creation=False)), |
| 126 | ('r_neutron_qos_bandwidth_limit', dict( |
| 127 | forbidden_r_type="OS::Neutron::QoSBandwidthLimitRule", |
| 128 | test_creation=False)), |
| 129 | ('r_manila_share_type', dict( |
| 130 | forbidden_r_type="OS::Manila::ShareType", |
| 131 | test_creation=False)) |
| 132 | ] |
| 133 | |
| 134 | def test_non_admin_forbidden_create_resources(self): |
| 135 | """Fail to create resource w/o admin role. |
Pavlo Shchelokovskyy | 67a64d9 | 2015-08-20 14:39:14 +0000 | [diff] [blame] | 136 | |
| 137 | Integration tests job runs as normal OpenStack user, |
huangtianhua | 23f18f3 | 2016-05-17 16:55:45 +0800 | [diff] [blame] | 138 | and the resources above are configured to require |
Pavlo Shchelokovskyy | 67a64d9 | 2015-08-20 14:39:14 +0000 | [diff] [blame] | 139 | admin role in default policy file of Heat. |
| 140 | """ |
huangtianhua | 23f18f3 | 2016-05-17 16:55:45 +0800 | [diff] [blame] | 141 | if self.test_creation: |
| 142 | ex = self.assertRaises(exc.Forbidden, |
| 143 | self.client.stacks.create, |
| 144 | stack_name=self.stack_name, |
| 145 | template=self.template) |
| 146 | self.assertIn(self.forbidden_r_type, ex.message) |
Pavlo Shchelokovskyy | 67a64d9 | 2015-08-20 14:39:14 +0000 | [diff] [blame] | 147 | |
| 148 | def test_forbidden_resource_not_listed(self): |
| 149 | resources = self.client.resource_types.list() |
huangtianhua | 23f18f3 | 2016-05-17 16:55:45 +0800 | [diff] [blame] | 150 | self.assertNotIn(self.forbidden_r_type, |
Pavlo Shchelokovskyy | 67a64d9 | 2015-08-20 14:39:14 +0000 | [diff] [blame] | 151 | (r.resource_type for r in resources)) |