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
This commit is contained in:
Steve Baker 2014-06-18 14:59:30 +12:00 committed by Randall Burt
parent a37e5e86a5
commit d825e2be11
7 changed files with 37 additions and 81 deletions

View File

@ -348,10 +348,6 @@ class ActionInProgress(HeatException):
"in progress.")
class SoftwareConfigMissing(HeatException):
msg_fmt = _("The config (%(software_config_id)s) could not be found.")
class StopActionFailed(HeatException):
msg_fmt = _("Failed to stop stack (%(stack_name)s) on other engine "
"(%(engine_id)s)")

View File

@ -23,7 +23,6 @@ from heat.engine import properties
from heat.engine import resource
from heat.engine.resources.neutron import subnet
from heat.engine.resources import nova_utils
from heat.engine.resources.software_config import software_config as sc
from heat.engine import scheduler
from heat.engine import stack_user
from heat.engine import support
@ -456,11 +455,10 @@ class Server(stack_user.StackUser):
if uuidutils.is_uuid_like(ud_content):
# attempt to load the userdata from software config
try:
ud_content = sc.SoftwareConfig.get_software_config(
self.heat(), ud_content)
except exception.SoftwareConfigMissing:
# no config was found, so do not modify the user_data
pass
ud_content = self.heat().software_configs.get(
ud_content).config
except Exception as ex:
self.client_plugin('heat').ignore_not_found(ex)
if self.user_data_software_config():
self._create_transport_credentials()

View File

@ -16,7 +16,6 @@ from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import os
from heat.common import exception
from heat.engine import constraints
from heat.engine import properties
from heat.engine.resources.software_config import software_config
@ -106,9 +105,9 @@ class MultipartMime(software_config.SoftwareConfig):
part_type = item.get(self.TYPE, self.TEXT)
part = config
try:
part = self.get_software_config(self.heat(), config)
except exception.SoftwareConfigMissing:
pass
part = self.heat().software_configs.get(config).config
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
if part_type == self.MULTIPART:
self._append_multiparts(subparts, part)

View File

@ -11,9 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import heatclient.exc as heat_exp
from heat.common import exception
from heat.engine import attributes
from heat.engine import constraints
from heat.engine import properties
@ -152,6 +149,8 @@ class SoftwareConfig(resource.Resource):
),
}
default_client_name = 'heat'
def handle_create(self):
props = dict(self.properties)
props[self.NAME] = self.physical_resource_name()
@ -166,9 +165,8 @@ class SoftwareConfig(resource.Resource):
try:
self.heat().software_configs.delete(self.resource_id)
except heat_exp.HTTPNotFound:
LOG.debug(
'Software config %s is not found.' % self.resource_id)
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def _resolve_attribute(self, name):
'''
@ -177,25 +175,11 @@ class SoftwareConfig(resource.Resource):
'''
if name == self.CONFIG_ATTR and self.resource_id:
try:
return self.get_software_config(self.heat(), self.resource_id)
except exception.SoftwareConfigMissing:
return ''
@staticmethod
def get_software_config(heat_client, software_config_id):
'''
Get the software config specified by :software_config_id:
:param heat_client: the heat client to use
:param software_config_id: the ID of the config to look for
:returns: the config script string for :software_config_id:
:raises: exception.NotFound
'''
try:
return heat_client.software_configs.get(software_config_id).config
except heat_exp.HTTPNotFound:
raise exception.SoftwareConfigMissing(
software_config_id=software_config_id)
return self.heat().software_configs.get(
self.resource_id).config
except Exception as ex:
if self.client_plugin().is_not_found(ex):
return None
def resource_mapping():

View File

@ -16,8 +16,6 @@
import copy
import uuid
import heatclient.exc as heat_exp
from heat.common import exception
from heat.engine import attributes
from heat.engine import constraints
@ -160,6 +158,8 @@ class SoftwareDeployment(signal_responder.SignalResponder):
),
}
default_client_name = 'heat'
def _signal_transport_cfn(self):
return self.properties.get(
self.SIGNAL_TRANSPORT) == self.CFN_SIGNAL
@ -191,8 +191,8 @@ class SoftwareDeployment(signal_responder.SignalResponder):
def _delete_derived_config(self, derived_config_id):
try:
self.heat().software_configs.delete(derived_config_id)
except heat_exp.HTTPNotFound:
pass
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def _get_derived_config(self, action):
@ -404,8 +404,8 @@ class SoftwareDeployment(signal_responder.SignalResponder):
sd = self.heat().software_deployments.get(self.resource_id)
derived_config_id = sd.config_id
sd.delete()
except heat_exp.HTTPNotFound:
pass
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
if derived_config_id:
self._delete_derived_config(derived_config_id)

View File

@ -23,13 +23,13 @@ from novaclient import exceptions as nova_exceptions
from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import glance
from heat.engine.clients.os import heat_plugin
from heat.engine.clients.os import nova
from heat.engine import environment
from heat.engine import parser
from heat.engine import resource
from heat.engine.resources import nova_utils
from heat.engine.resources import server as servers
from heat.engine.resources.software_config import software_config as sc
from heat.engine import scheduler
from heat.openstack.common.gettextutils import _
from heat.tests.common import HeatTestCase
@ -481,14 +481,14 @@ class ServersTest(HeatTestCase):
server = servers.Server('WebServer',
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
self.m.StubOutWithMock(server, 'heat')
self.m.StubOutWithMock(sc.SoftwareConfig, 'get_software_config')
server.heat().AndReturn(None)
sc.SoftwareConfig.get_software_config(
None, '8c813873-f6ee-4809-8eec-959ef39acb55').AndReturn(
'wordpress from config')
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, '_create')
heat_client = mock.Mock()
heat_plugin.HeatClientPlugin._create().AndReturn(heat_client)
sc = mock.Mock()
sc.config = 'wordpress from config'
heat_client.software_configs.get.return_value = sc
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 744)
@ -522,14 +522,13 @@ class ServersTest(HeatTestCase):
server = servers.Server('WebServer',
resource_defns['WebServer'], stack)
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
self.m.StubOutWithMock(server, 'heat')
self.m.StubOutWithMock(sc.SoftwareConfig, 'get_software_config')
server.heat().AndReturn(None)
sc.SoftwareConfig.get_software_config(
None, sc_id).AndRaise(exception.SoftwareConfigMissing(
software_config_id=sc_id))
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, '_create')
heat_client = mock.Mock()
heat_plugin.HeatClientPlugin._create().AndReturn(heat_client)
heat_client.software_configs.get.side_effect = \
heat_plugin.exc.HTTPNotFound()
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
nova.NovaClientPlugin._create().AndReturn(self.fc)
self._mock_get_image_id_success('F17-x86_64-gold', 744)

View File

@ -13,9 +13,7 @@
from heatclient.exc import HTTPNotFound
import mock
import six
from heat.common import exception
from heat.engine import parser
from heat.engine.resources.software_config import software_config as sc
from heat.engine import template
@ -76,24 +74,6 @@ class SoftwareConfigTest(HeatTestCase):
self.software_configs.delete.side_effect = HTTPNotFound()
self.assertIsNone(self.config.handle_delete())
def test_get_software_config(self):
config_id = 'c8a19429-7fde-47ea-a42f-40045488226c'
value = mock.MagicMock()
value.config = '#!/bin/bash'
self.software_configs.get.return_value = value
heatclient = self.heatclient
config = sc.SoftwareConfig.get_software_config(heatclient, config_id)
self.assertEqual('#!/bin/bash', config)
self.software_configs.get.side_effect = HTTPNotFound()
err = self.assertRaises(
exception.SoftwareConfigMissing,
self.config.get_software_config,
heatclient, config_id)
self.assertEqual(
('The config (c8a19429-7fde-47ea-a42f-40045488226c) '
'could not be found.'), six.text_type(err))
def test_resolve_attribute(self):
self.assertIsNone(self.config._resolve_attribute('others'))
self.config.resource_id = None
@ -105,4 +85,4 @@ class SoftwareConfigTest(HeatTestCase):
self.assertEqual(
'#!/bin/bash', self.config._resolve_attribute('config'))
self.software_configs.get.side_effect = HTTPNotFound()
self.assertEqual('', self.config._resolve_attribute('config'))
self.assertEqual(None, self.config._resolve_attribute('config'))