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:
parent
a37e5e86a5
commit
d825e2be11
@ -348,10 +348,6 @@ class ActionInProgress(HeatException):
|
|||||||
"in progress.")
|
"in progress.")
|
||||||
|
|
||||||
|
|
||||||
class SoftwareConfigMissing(HeatException):
|
|
||||||
msg_fmt = _("The config (%(software_config_id)s) could not be found.")
|
|
||||||
|
|
||||||
|
|
||||||
class StopActionFailed(HeatException):
|
class StopActionFailed(HeatException):
|
||||||
msg_fmt = _("Failed to stop stack (%(stack_name)s) on other engine "
|
msg_fmt = _("Failed to stop stack (%(stack_name)s) on other engine "
|
||||||
"(%(engine_id)s)")
|
"(%(engine_id)s)")
|
||||||
|
@ -23,7 +23,6 @@ from heat.engine import properties
|
|||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources.neutron import subnet
|
from heat.engine.resources.neutron import subnet
|
||||||
from heat.engine.resources import nova_utils
|
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 scheduler
|
||||||
from heat.engine import stack_user
|
from heat.engine import stack_user
|
||||||
from heat.engine import support
|
from heat.engine import support
|
||||||
@ -456,11 +455,10 @@ class Server(stack_user.StackUser):
|
|||||||
if uuidutils.is_uuid_like(ud_content):
|
if uuidutils.is_uuid_like(ud_content):
|
||||||
# attempt to load the userdata from software config
|
# attempt to load the userdata from software config
|
||||||
try:
|
try:
|
||||||
ud_content = sc.SoftwareConfig.get_software_config(
|
ud_content = self.heat().software_configs.get(
|
||||||
self.heat(), ud_content)
|
ud_content).config
|
||||||
except exception.SoftwareConfigMissing:
|
except Exception as ex:
|
||||||
# no config was found, so do not modify the user_data
|
self.client_plugin('heat').ignore_not_found(ex)
|
||||||
pass
|
|
||||||
|
|
||||||
if self.user_data_software_config():
|
if self.user_data_software_config():
|
||||||
self._create_transport_credentials()
|
self._create_transport_credentials()
|
||||||
|
@ -16,7 +16,6 @@ from email.mime.multipart import MIMEMultipart
|
|||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from heat.common import exception
|
|
||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine.resources.software_config import software_config
|
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_type = item.get(self.TYPE, self.TEXT)
|
||||||
part = config
|
part = config
|
||||||
try:
|
try:
|
||||||
part = self.get_software_config(self.heat(), config)
|
part = self.heat().software_configs.get(config).config
|
||||||
except exception.SoftwareConfigMissing:
|
except Exception as ex:
|
||||||
pass
|
self.client_plugin().ignore_not_found(ex)
|
||||||
|
|
||||||
if part_type == self.MULTIPART:
|
if part_type == self.MULTIPART:
|
||||||
self._append_multiparts(subparts, part)
|
self._append_multiparts(subparts, part)
|
||||||
|
@ -11,9 +11,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import heatclient.exc as heat_exp
|
|
||||||
|
|
||||||
from heat.common import exception
|
|
||||||
from heat.engine import attributes
|
from heat.engine import attributes
|
||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
@ -152,6 +149,8 @@ class SoftwareConfig(resource.Resource):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default_client_name = 'heat'
|
||||||
|
|
||||||
def handle_create(self):
|
def handle_create(self):
|
||||||
props = dict(self.properties)
|
props = dict(self.properties)
|
||||||
props[self.NAME] = self.physical_resource_name()
|
props[self.NAME] = self.physical_resource_name()
|
||||||
@ -166,9 +165,8 @@ class SoftwareConfig(resource.Resource):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.heat().software_configs.delete(self.resource_id)
|
self.heat().software_configs.delete(self.resource_id)
|
||||||
except heat_exp.HTTPNotFound:
|
except Exception as ex:
|
||||||
LOG.debug(
|
self.client_plugin().ignore_not_found(ex)
|
||||||
'Software config %s is not found.' % self.resource_id)
|
|
||||||
|
|
||||||
def _resolve_attribute(self, name):
|
def _resolve_attribute(self, name):
|
||||||
'''
|
'''
|
||||||
@ -177,25 +175,11 @@ class SoftwareConfig(resource.Resource):
|
|||||||
'''
|
'''
|
||||||
if name == self.CONFIG_ATTR and self.resource_id:
|
if name == self.CONFIG_ATTR and self.resource_id:
|
||||||
try:
|
try:
|
||||||
return self.get_software_config(self.heat(), self.resource_id)
|
return self.heat().software_configs.get(
|
||||||
except exception.SoftwareConfigMissing:
|
self.resource_id).config
|
||||||
return ''
|
except Exception as ex:
|
||||||
|
if self.client_plugin().is_not_found(ex):
|
||||||
@staticmethod
|
return None
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def resource_mapping():
|
def resource_mapping():
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
import copy
|
import copy
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import heatclient.exc as heat_exp
|
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.engine import attributes
|
from heat.engine import attributes
|
||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
@ -160,6 +158,8 @@ class SoftwareDeployment(signal_responder.SignalResponder):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default_client_name = 'heat'
|
||||||
|
|
||||||
def _signal_transport_cfn(self):
|
def _signal_transport_cfn(self):
|
||||||
return self.properties.get(
|
return self.properties.get(
|
||||||
self.SIGNAL_TRANSPORT) == self.CFN_SIGNAL
|
self.SIGNAL_TRANSPORT) == self.CFN_SIGNAL
|
||||||
@ -191,8 +191,8 @@ class SoftwareDeployment(signal_responder.SignalResponder):
|
|||||||
def _delete_derived_config(self, derived_config_id):
|
def _delete_derived_config(self, derived_config_id):
|
||||||
try:
|
try:
|
||||||
self.heat().software_configs.delete(derived_config_id)
|
self.heat().software_configs.delete(derived_config_id)
|
||||||
except heat_exp.HTTPNotFound:
|
except Exception as ex:
|
||||||
pass
|
self.client_plugin().ignore_not_found(ex)
|
||||||
|
|
||||||
def _get_derived_config(self, action):
|
def _get_derived_config(self, action):
|
||||||
|
|
||||||
@ -404,8 +404,8 @@ class SoftwareDeployment(signal_responder.SignalResponder):
|
|||||||
sd = self.heat().software_deployments.get(self.resource_id)
|
sd = self.heat().software_deployments.get(self.resource_id)
|
||||||
derived_config_id = sd.config_id
|
derived_config_id = sd.config_id
|
||||||
sd.delete()
|
sd.delete()
|
||||||
except heat_exp.HTTPNotFound:
|
except Exception as ex:
|
||||||
pass
|
self.client_plugin().ignore_not_found(ex)
|
||||||
|
|
||||||
if derived_config_id:
|
if derived_config_id:
|
||||||
self._delete_derived_config(derived_config_id)
|
self._delete_derived_config(derived_config_id)
|
||||||
|
@ -23,13 +23,13 @@ from novaclient import exceptions as nova_exceptions
|
|||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
from heat.engine.clients.os import glance
|
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.clients.os import nova
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources import nova_utils
|
from heat.engine.resources import nova_utils
|
||||||
from heat.engine.resources import server as servers
|
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.engine import scheduler
|
||||||
from heat.openstack.common.gettextutils import _
|
from heat.openstack.common.gettextutils import _
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests.common import HeatTestCase
|
||||||
@ -481,14 +481,14 @@ class ServersTest(HeatTestCase):
|
|||||||
server = servers.Server('WebServer',
|
server = servers.Server('WebServer',
|
||||||
resource_defns['WebServer'], stack)
|
resource_defns['WebServer'], stack)
|
||||||
|
|
||||||
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, '_create')
|
||||||
self.m.StubOutWithMock(server, 'heat')
|
heat_client = mock.Mock()
|
||||||
self.m.StubOutWithMock(sc.SoftwareConfig, 'get_software_config')
|
heat_plugin.HeatClientPlugin._create().AndReturn(heat_client)
|
||||||
server.heat().AndReturn(None)
|
sc = mock.Mock()
|
||||||
sc.SoftwareConfig.get_software_config(
|
sc.config = 'wordpress from config'
|
||||||
None, '8c813873-f6ee-4809-8eec-959ef39acb55').AndReturn(
|
heat_client.software_configs.get.return_value = sc
|
||||||
'wordpress from config')
|
|
||||||
|
|
||||||
|
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
||||||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
||||||
self._mock_get_image_id_success('F17-x86_64-gold', 744)
|
self._mock_get_image_id_success('F17-x86_64-gold', 744)
|
||||||
|
|
||||||
@ -522,14 +522,13 @@ class ServersTest(HeatTestCase):
|
|||||||
server = servers.Server('WebServer',
|
server = servers.Server('WebServer',
|
||||||
resource_defns['WebServer'], stack)
|
resource_defns['WebServer'], stack)
|
||||||
|
|
||||||
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
self.m.StubOutWithMock(heat_plugin.HeatClientPlugin, '_create')
|
||||||
self.m.StubOutWithMock(server, 'heat')
|
heat_client = mock.Mock()
|
||||||
self.m.StubOutWithMock(sc.SoftwareConfig, 'get_software_config')
|
heat_plugin.HeatClientPlugin._create().AndReturn(heat_client)
|
||||||
server.heat().AndReturn(None)
|
heat_client.software_configs.get.side_effect = \
|
||||||
sc.SoftwareConfig.get_software_config(
|
heat_plugin.exc.HTTPNotFound()
|
||||||
None, sc_id).AndRaise(exception.SoftwareConfigMissing(
|
|
||||||
software_config_id=sc_id))
|
|
||||||
|
|
||||||
|
self.m.StubOutWithMock(nova.NovaClientPlugin, '_create')
|
||||||
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
nova.NovaClientPlugin._create().AndReturn(self.fc)
|
||||||
self._mock_get_image_id_success('F17-x86_64-gold', 744)
|
self._mock_get_image_id_success('F17-x86_64-gold', 744)
|
||||||
|
|
||||||
|
@ -13,9 +13,7 @@
|
|||||||
|
|
||||||
from heatclient.exc import HTTPNotFound
|
from heatclient.exc import HTTPNotFound
|
||||||
import mock
|
import mock
|
||||||
import six
|
|
||||||
|
|
||||||
from heat.common import exception
|
|
||||||
from heat.engine import parser
|
from heat.engine import parser
|
||||||
from heat.engine.resources.software_config import software_config as sc
|
from heat.engine.resources.software_config import software_config as sc
|
||||||
from heat.engine import template
|
from heat.engine import template
|
||||||
@ -76,24 +74,6 @@ class SoftwareConfigTest(HeatTestCase):
|
|||||||
self.software_configs.delete.side_effect = HTTPNotFound()
|
self.software_configs.delete.side_effect = HTTPNotFound()
|
||||||
self.assertIsNone(self.config.handle_delete())
|
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):
|
def test_resolve_attribute(self):
|
||||||
self.assertIsNone(self.config._resolve_attribute('others'))
|
self.assertIsNone(self.config._resolve_attribute('others'))
|
||||||
self.config.resource_id = None
|
self.config.resource_id = None
|
||||||
@ -105,4 +85,4 @@ class SoftwareConfigTest(HeatTestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'#!/bin/bash', self.config._resolve_attribute('config'))
|
'#!/bin/bash', self.config._resolve_attribute('config'))
|
||||||
self.software_configs.get.side_effect = HTTPNotFound()
|
self.software_configs.get.side_effect = HTTPNotFound()
|
||||||
self.assertEqual('', self.config._resolve_attribute('config'))
|
self.assertEqual(None, self.config._resolve_attribute('config'))
|
||||||
|
Loading…
Reference in New Issue
Block a user