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 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 19 | class ConditionalExposureTestBase(functional_base.FunctionalTestsBase): |
Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 20 | def setUp(self): |
| 21 | super(ConditionalExposureTestBase, self).setUp() |
Pavlo Shchelokovskyy | 245ccc4 | 2015-07-16 09:47:20 +0000 | [diff] [blame] | 22 | |
| 23 | def _delete(self, stack_name): |
| 24 | stacks = self.client.stacks.list() |
| 25 | for s in stacks: |
| 26 | if s.stack_name == stack_name: |
| 27 | self._stack_delete(s.identifier) |
| 28 | break |
| 29 | |
| 30 | |
| 31 | class ServiceBasedExposureTest(ConditionalExposureTestBase): |
| 32 | # NOTE(pas-ha) if we ever decide to install Sahara on Heat |
| 33 | # functional gate, this must be changed to other not-installed |
| 34 | # but in principle supported service |
| 35 | unavailable_service = 'Sahara' |
| 36 | unavailable_template = """ |
| 37 | heat_template_version: 2015-10-15 |
| 38 | resources: |
| 39 | not_available: |
| 40 | type: OS::Sahara::NodeGroupTemplate |
| 41 | properties: |
| 42 | plugin_name: fake |
| 43 | hadoop_version: 0.1 |
| 44 | flavor: m1.large |
| 45 | node_processes: [] |
| 46 | """ |
| 47 | |
| 48 | def setUp(self): |
| 49 | super(ServiceBasedExposureTest, self).setUp() |
| 50 | # check that Sahara endpoint is available |
| 51 | if self._is_sahara_deployed(): |
| 52 | self.skipTest("Sahara is actually deployed, " |
| 53 | "can not run negative tests on " |
| 54 | "Sahara resources availability.") |
| 55 | |
| 56 | def _is_sahara_deployed(self): |
| 57 | keystone = self.identity_client |
| 58 | try: |
| 59 | keystone.service_catalog.url_for( |
| 60 | attr='region', |
| 61 | filter_value=self.conf.region, |
| 62 | service_type='data-processing', |
| 63 | endpoint_type='publicURL') |
| 64 | except keystoneclient.exceptions.EndpointNotFound: |
| 65 | return False |
| 66 | return True |
| 67 | |
| 68 | def test_unavailable_resources_not_listed(self): |
| 69 | resources = self.client.resource_types.list() |
| 70 | self.assertFalse(any(self.unavailable_service in r.resource_type |
| 71 | for r in resources)) |
| 72 | |
| 73 | def test_unavailable_resources_not_created(self): |
| 74 | stack_name = self._stack_rand_name() |
| 75 | self.addCleanup(self._delete, stack_name) |
| 76 | ex = self.assertRaises(exc.HTTPBadRequest, |
| 77 | self.client.stacks.create, |
| 78 | stack_name=stack_name, |
| 79 | template=self.unavailable_template) |
| 80 | self.assertIn('ResourceTypeUnavailable', ex.message) |
| 81 | self.assertIn('OS::Sahara::NodeGroupTemplate', ex.message) |