deb-heat/heat/tests/clients/test_senlin_client.py
Ethan Lynn 9115a114b6 Catch correct not found error in senlin plugin
Senlin client changed recently and directly raise openstacksdk
ResourceNotFound error if can't find resource. This patch will catch
the correct exception.

Change-Id: I8ad6d495f75acb6b2e7b13cf65778bf4a40b891c
2016-01-26 06:48:27 +00:00

50 lines
1.7 KiB
Python

#
# 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.clients.os import senlin as senlin_plugin
from heat.tests import common
from heat.tests import utils
from senlinclient.common import exc
class SenlinClientPluginTests(common.HeatTestCase):
def test_cluster_get(self):
context = utils.dummy_context()
plugin = context.clients.client_plugin('senlin')
client = plugin.client()
self.assertIsNotNone(client.clusters)
class ProfileConstraintTest(common.HeatTestCase):
def setUp(self):
super(ProfileConstraintTest, self).setUp()
self.senlin_client = mock.MagicMock()
self.ctx = utils.dummy_context()
self.mock_get_profile = mock.Mock()
self.ctx.clients.client(
'senlin').get_profile = self.mock_get_profile
self.constraint = senlin_plugin.ProfileConstraint()
def test_validate_true(self):
self.mock_get_profile.return_value = None
self.assertTrue(self.constraint.validate("PROFILE_ID", self.ctx))
def test_validate_false(self):
self.mock_get_profile.side_effect = exc.sdkexc.ResourceNotFound(
'PROFILE_ID')
self.assertFalse(self.constraint.validate("PROFILE_ID", self.ctx))