Merge "Default implementation parse_live_resource_data"
This commit is contained in:
commit
cf6394c2ee
@ -228,6 +228,8 @@ class Resource(object):
|
||||
client_resolve=False)
|
||||
self.update_policy = self.t.update_policy(self.update_policy_schema,
|
||||
self.context)
|
||||
self._update_allowed_properties = self.calc_update_allowed(
|
||||
self.properties)
|
||||
self.attributes_schema.update(self.base_attributes_schema)
|
||||
self.attributes = self._init_attributes()
|
||||
|
||||
@ -374,6 +376,13 @@ class Resource(object):
|
||||
if translate:
|
||||
self.translate_properties(self.properties, client_resolve)
|
||||
|
||||
def calc_update_allowed(self, props):
|
||||
update_allowed_set = set(self.update_allowed_properties)
|
||||
for (psk, psv) in six.iteritems(props.props):
|
||||
if psv.update_allowed():
|
||||
update_allowed_set.add(psk)
|
||||
return update_allowed_set
|
||||
|
||||
def __eq__(self, other):
|
||||
"""Allow == comparison of two resources."""
|
||||
# For the purposes of comparison, we declare two resource objects
|
||||
@ -537,11 +546,9 @@ class Resource(object):
|
||||
If any properties have changed which are not in
|
||||
update_allowed_properties, raises UpdateReplace.
|
||||
"""
|
||||
update_allowed_set = set(self.update_allowed_properties)
|
||||
update_allowed_set = self.calc_update_allowed(after_props)
|
||||
immutable_set = set()
|
||||
for (psk, psv) in six.iteritems(after_props.props):
|
||||
if psv.update_allowed():
|
||||
update_allowed_set.add(psk)
|
||||
if psv.immutable():
|
||||
immutable_set.add(psk)
|
||||
|
||||
@ -1916,7 +1923,11 @@ class Resource(object):
|
||||
:param resource_properties: properties of stored resource plugin.
|
||||
:param resource_data: data from current live state of a resource.
|
||||
"""
|
||||
return {}
|
||||
resource_result = {}
|
||||
for key in self._update_allowed_properties:
|
||||
resource_result[key] = resource_data.get(key)
|
||||
|
||||
return resource_result
|
||||
|
||||
def get_live_state(self, resource_properties):
|
||||
"""Default implementation; should be overridden by resources.
|
||||
|
@ -185,11 +185,8 @@ class OSDBInstanceTest(common.HeatTestCase):
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_create_failed(self):
|
||||
mock_stack = mock.Mock()
|
||||
mock_stack.db_resource_get.return_value = None
|
||||
mock_stack.has_cache_data.return_value = False
|
||||
res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
|
||||
osdb_res = os_database.OSDBInstance("test", res_def, mock_stack)
|
||||
t = template_format.parse(db_template)
|
||||
osdb_res = self._setup_test_clouddbinstance('dbinstance_create', t)
|
||||
|
||||
trove_mock = mock.Mock()
|
||||
self.patchobject(osdb_res, 'client', return_value=trove_mock)
|
||||
|
@ -164,6 +164,9 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
|
||||
return mockclient()
|
||||
|
||||
mock_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
|
||||
props = mock.Mock()
|
||||
props.props = {}
|
||||
mock_def.properties.return_value = props
|
||||
mock_stack = mock.Mock()
|
||||
mock_stack.db_resource_get.return_value = None
|
||||
mock_stack.has_cache_data.return_value = False
|
||||
|
@ -3947,6 +3947,8 @@ class TestLiveStateUpdate(common.HeatTestCase):
|
||||
Need to revert changes of resource properties schema for correct work
|
||||
of other tests.
|
||||
"""
|
||||
res.update_allowed_properties = []
|
||||
res.update_allowed_set = []
|
||||
for prop in six.itervalues(res.properties.props):
|
||||
prop.schema.update_allowed = False
|
||||
|
||||
@ -3994,6 +3996,19 @@ class TestLiveStateUpdate(common.HeatTestCase):
|
||||
six.text_type(ex))
|
||||
self._clean_tests_after_resource_live_state(res)
|
||||
|
||||
def test_parse_live_resource_data(self):
|
||||
res = self._prepare_resource_live_state()
|
||||
|
||||
res.update_allowed_props = mock.Mock(return_value=['Foo'])
|
||||
resource_data = {
|
||||
'Foo': 'brave new data',
|
||||
'Something not so good': 'for all of us'
|
||||
}
|
||||
res._update_allowed_properties = ['Foo']
|
||||
result = res.parse_live_resource_data(res.properties, resource_data)
|
||||
self.assertEqual({'Foo': 'brave new data'}, result)
|
||||
self._clean_tests_after_resource_live_state(res)
|
||||
|
||||
def test_get_live_resource_data_not_found_no_default_client_name(self):
|
||||
class MyException(Exception):
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user