Filter out deployments with None config

It's possible to get a None config from the db[1].
Filter the deployments with  None config when pushing deployment
metadata.

[1] https://github.com/openstack/heat/blob/master/heat/objects/software_config.py#L43

Change-Id: I682f82d22efc888272de8e441d8819cde8519993
Closes-Bug: #1536890
This commit is contained in:
Rabi Mishra 2016-01-22 12:24:32 +05:30
parent bfe4ce7d92
commit e4b9bd712f
2 changed files with 28 additions and 2 deletions

View File

@ -81,10 +81,14 @@ class SoftwareConfigService(service.Service):
raise ValueError(_('server_id must be specified'))
all_sd = software_deployment_object.SoftwareDeployment.get_all(
cnxt, server_id)
# filter out the sds with None config
flt_sd = six.moves.filterfalse(lambda sd: sd.config is None,
all_sd)
# sort the configs by config name, to give the list of metadata a
# deterministic and controllable order.
all_sd_s = sorted(all_sd, key=lambda sd: sd.config.name)
result = [api.format_software_config(sd.config) for sd in all_sd_s]
flt_sd_s = sorted(flt_sd, key=lambda sd: sd.config.name)
result = [api.format_software_config(sd.config) for sd in flt_sd_s]
return result
@oslo_db_api.wrap_db_retry(max_retries=10, retry_on_request=True)

View File

@ -29,6 +29,7 @@ from heat.engine.clients.os import zaqar
from heat.engine import service
from heat.engine import service_software_config
from heat.objects import resource as resource_objects
from heat.objects import software_config as software_config_object
from heat.objects import software_deployment as software_deployment_object
from heat.tests import common
from heat.tests.engine import tools
@ -86,6 +87,18 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
return self.engine.create_software_config(
self.ctx, group, name, config, inputs, outputs, options)
def _create_dummy_config_object(self):
obj_config = software_config_object.SoftwareConfig()
obj_config['id'] = str(uuid.uuid4())
obj_config['name'] = 'myconfig'
obj_config['group'] = 'mygroup'
obj_config['config'] = {'config': 'hello world',
'inputs': [],
'outputs': [],
'options': {}}
obj_config['created_at'] = timeutils.utcnow()
return obj_config
def assert_status_reason(self, expected, actual):
expected_dict = dict((i.split(' : ') for i in expected.split(', ')))
actual_dict = dict((i.split(' : ') for i in actual.split(', ')))
@ -275,6 +288,15 @@ class SoftwareConfigServiceTest(common.HeatTestCase):
ctx, server_id=server_id)
self.assertEqual(0, len(metadata))
# assert None config is filtered out
obj_conf = self._create_dummy_config_object()
side_effect = [obj_conf, obj_conf, None]
self.patchobject(software_config_object.SoftwareConfig,
'_from_db_object', side_effect=side_effect)
metadata = self.engine.metadata_software_deployments(
self.ctx, server_id=server_id)
self.assertEqual(2, len(metadata))
def test_show_software_deployment(self):
deployment_id = str(uuid.uuid4())
ex = self.assertRaises(dispatcher.ExpectedException,