deb-heat/heat/tests/test_software_config.py
Steve Baker d825e2be11 Remove function get_software_config
This change removes the function get_software_config
and replaces it with direct calls to heatclient.

This allows the heat client plugin's ignore_not_found handling
to be used.

The SoftwareConfigMissing exception is also no longer required.

Change-Id: I61fbe9556d9988fffd4afddf3fad5d2fa211475a
2014-08-13 11:00:18 -05:00

89 lines
3.4 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.
from heatclient.exc import HTTPNotFound
import mock
from heat.engine import parser
from heat.engine.resources.software_config import software_config as sc
from heat.engine import template
from heat.tests.common import HeatTestCase
from heat.tests import utils
class SoftwareConfigTest(HeatTestCase):
def setUp(self):
super(SoftwareConfigTest, self).setUp()
self.ctx = utils.dummy_context()
self.properties = {
'group': 'Heat::Shell',
'inputs': [],
'outputs': [],
'options': {},
'config': '#!/bin/bash'
}
self.stack = parser.Stack(
self.ctx, 'software_config_test_stack',
template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'config_mysql': {
'Type': 'OS::Heat::SoftwareConfig',
'Properties': self.properties
}}}))
self.config = self.stack['config_mysql']
heat = mock.MagicMock()
self.heatclient = mock.MagicMock()
self.config.heat = heat
heat.return_value = self.heatclient
self.software_configs = self.heatclient.software_configs
def test_resource_mapping(self):
mapping = sc.resource_mapping()
self.assertEqual(1, len(mapping))
self.assertEqual(sc.SoftwareConfig,
mapping['OS::Heat::SoftwareConfig'])
self.assertIsInstance(self.config, sc.SoftwareConfig)
def test_handle_create(self):
value = mock.MagicMock()
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
value.id = config_id
self.software_configs.create.return_value = value
self.config.handle_create()
self.assertEqual(config_id, self.config.resource_id)
def test_handle_delete(self):
self.resource_id = None
self.assertIsNone(self.config.handle_delete())
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
self.config.resource_id = config_id
self.software_configs.delete.return_value = None
self.assertIsNone(self.config.handle_delete())
self.software_configs.delete.side_effect = HTTPNotFound()
self.assertIsNone(self.config.handle_delete())
def test_resolve_attribute(self):
self.assertIsNone(self.config._resolve_attribute('others'))
self.config.resource_id = None
self.assertIsNone(self.config._resolve_attribute('config'))
self.config.resource_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
value = mock.MagicMock()
value.config = '#!/bin/bash'
self.software_configs.get.return_value = value
self.assertEqual(
'#!/bin/bash', self.config._resolve_attribute('config'))
self.software_configs.get.side_effect = HTTPNotFound()
self.assertEqual(None, self.config._resolve_attribute('config'))