Merge "Save files while updating a template."
This commit is contained in:
commit
047a92428a
@ -51,8 +51,8 @@ def raw_template_create(context, values):
|
||||
return IMPL.raw_template_create(context, values)
|
||||
|
||||
|
||||
def raw_template_update_template(context, template_id, template):
|
||||
return IMPL.raw_template_update_template(context, template_id, template)
|
||||
def raw_template_update(context, template_id, values):
|
||||
return IMPL.raw_template_update(context, template_id, values)
|
||||
|
||||
|
||||
def resource_data_get_all(resource, data=None):
|
||||
|
@ -92,10 +92,15 @@ def raw_template_create(context, values):
|
||||
return raw_template_ref
|
||||
|
||||
|
||||
def raw_template_update_template(context, template_id, template):
|
||||
def raw_template_update(context, template_id, values):
|
||||
raw_template_ref = raw_template_get(context, template_id)
|
||||
if raw_template_ref.template != template:
|
||||
raw_template_ref.update_and_save({'template': template})
|
||||
# get only the changed values
|
||||
values = dict((k, v) for k, v in values.items()
|
||||
if getattr(raw_template_ref, k) != v)
|
||||
|
||||
if values:
|
||||
raw_template_ref.update_and_save(values)
|
||||
|
||||
return raw_template_ref
|
||||
|
||||
|
||||
|
@ -118,15 +118,15 @@ class Template(collections.Mapping):
|
||||
|
||||
def store(self, context=None):
|
||||
'''Store the Template in the database and return its ID.'''
|
||||
rt = {
|
||||
'template': self.t,
|
||||
'files': self.files
|
||||
}
|
||||
if self.id is None:
|
||||
rt = {
|
||||
'template': self.t,
|
||||
'files': self.files
|
||||
}
|
||||
new_rt = db_api.raw_template_create(context, rt)
|
||||
self.id = new_rt.id
|
||||
else:
|
||||
db_api.raw_template_update_template(context, self.id, self.t)
|
||||
db_api.raw_template_update(context, self.id, rt)
|
||||
return self.id
|
||||
|
||||
def __iter__(self):
|
||||
|
@ -1191,6 +1191,48 @@ class DBAPIRawTemplateTest(HeatTestCase):
|
||||
self.assertEqual(tp.id, template.id)
|
||||
self.assertEqual(tp.template, template.template)
|
||||
|
||||
def test_raw_template_update(self):
|
||||
another_wp_template = '''
|
||||
{
|
||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||
"Description" : "WordPress",
|
||||
"Parameters" : {
|
||||
"KeyName" : {
|
||||
"Description" : "KeyName",
|
||||
"Type" : "String",
|
||||
"Default" : "test"
|
||||
}
|
||||
},
|
||||
"Resources" : {
|
||||
"WebServer": {
|
||||
"Type": "AWS::EC2::Instance",
|
||||
"Properties": {
|
||||
"ImageId" : "fedora-20.x86_64.qcow2",
|
||||
"InstanceType" : "m1.xlarge",
|
||||
"KeyName" : "test",
|
||||
"UserData" : "wordpress"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
new_t = template_format.parse(another_wp_template)
|
||||
new_files = {
|
||||
'foo': 'bar',
|
||||
'myfile': 'file:///home/somefile'
|
||||
}
|
||||
new_values = {
|
||||
'template': new_t,
|
||||
'files': new_files
|
||||
}
|
||||
orig_tp = create_raw_template(self.ctx)
|
||||
updated_tp = db_api.raw_template_update(self.ctx,
|
||||
orig_tp.id, new_values)
|
||||
|
||||
self.assertEqual(updated_tp.id, orig_tp.id)
|
||||
self.assertEqual(updated_tp.template, new_t)
|
||||
self.assertEqual(updated_tp.files, new_files)
|
||||
|
||||
|
||||
class DBAPIUserCredsTest(HeatTestCase):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user