Remove broken heat.resource_type custom constraint
This reverts the commits f5c32ad8fd
and
14fdf72b000c82a80abb2587189dd7c6c7dfa0a0e.
The constraint never worked and the stuff to pass the template to
constraints (which was broken because we actually passed a
ResourceDefinition instead) is a pain. Just get rid of it rather than
fix it.
Change-Id: I4e1e787ad94ac1951f472ea066a9b1c9d3e03611
Closes-Bug: #1661403
changes/82/489682/1
parent
8c7b66a8a3
commit
c26f367b03
@ -1,45 +0,0 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
|
||||
import six
|
||||
|
||||
from heat.common.i18n import _
|
||||
from heat.engine import constraints
|
||||
|
||||
|
||||
class ResourceTypeConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
def validate(self, value, context, template=None):
|
||||
|
||||
if not isinstance(value, collections.Sequence):
|
||||
return False
|
||||
|
||||
if isinstance(value, six.string_types):
|
||||
value = [value]
|
||||
|
||||
invalid_types = []
|
||||
for t in value:
|
||||
try:
|
||||
template.env.get_class(t)
|
||||
except Exception:
|
||||
invalid_types.append(t)
|
||||
|
||||
if invalid_types:
|
||||
msg = _('The following resource types could not be found: %s')
|
||||
types = ','.join(invalid_types)
|
||||
self._error_message = msg % types
|
||||
return False
|
||||
|
||||
return True
|
@ -1,82 +0,0 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from heat.engine.constraint import heat_constraints as hc
|
||||
from heat.tests import common
|
||||
|
||||
|
||||
class ResourceTypeConstraintTest(common.HeatTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ResourceTypeConstraintTest, self).setUp()
|
||||
self.constraint = hc.ResourceTypeConstraint()
|
||||
|
||||
self.mock_template = mock.MagicMock()
|
||||
self.mock_env = mock.MagicMock()
|
||||
self.mock_template.env = self.mock_env
|
||||
|
||||
def test_validate(self):
|
||||
# Setup
|
||||
value = ['OS::Heat::None']
|
||||
|
||||
# Test
|
||||
result = self.constraint.validate(value, None, self.mock_template)
|
||||
|
||||
# Verify
|
||||
self.assertTrue(result)
|
||||
self.mock_env.get_class.assert_called_once_with(value[0])
|
||||
|
||||
def test_validate_failure(self):
|
||||
# Setup
|
||||
value = ['OS::Heat::None']
|
||||
self.mock_env.get_class.side_effect = Exception()
|
||||
|
||||
# Test
|
||||
result = self.constraint.validate(value, None, self.mock_template)
|
||||
|
||||
# Verify
|
||||
self.assertFalse(result)
|
||||
self.assertIn('OS::Heat::None', self.constraint._error_message)
|
||||
self.mock_env.get_class.assert_called_once_with(value[0])
|
||||
|
||||
def test_validate_multiple_failures(self):
|
||||
# Setup
|
||||
value = ['OS::Heat::None', 'OS::Heat::RandomString']
|
||||
self.mock_env.get_class.side_effect = [Exception(), Exception()]
|
||||
|
||||
# Test
|
||||
result = self.constraint.validate(value, None, self.mock_template)
|
||||
|
||||
# Verify
|
||||
self.assertFalse(result)
|
||||
self.assertIn('OS::Heat::None,OS::Heat::RandomString',
|
||||
self.constraint._error_message)
|
||||
self.mock_env.get_class.assert_has_calls([mock.call(value[0]),
|
||||
mock.call(value[1])])
|
||||
|
||||
def test_validate_single_item(self):
|
||||
# Setup
|
||||
value = 'OS::Heat::None'
|
||||
|
||||
# Test
|
||||
result = self.constraint.validate(value, None, self.mock_template)
|
||||
|
||||
# Verify
|
||||
self.assertTrue(result)
|
||||
self.mock_env.get_class.assert_called_once_with(value)
|
||||
|
||||
def test_validate_non_string(self):
|
||||
result = self.constraint.validate(dict(), None, self.mock_template)
|
||||
self.assertFalse(result)
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
deprecations:
|
||||
- The heat.resource_type custom constraint has been removed. This constraint
|
||||
never actually worked.
|
Loading…
Reference in New Issue