Execute update action in case resource was already created
In case if resource was already created (commit operation was triggered) we will implicitly stage 'update' action. It was default solar behaviour which was change in one of the patches related to mentioned blueprint. related to blueprint refactor-process-of-staging-changes Change-Id: I861dfca4f6a68cb8b1d9914d6f6a082ed9e865cf
This commit is contained in:
parent
8f1ca9708a
commit
5ef0be35ca
@ -38,9 +38,14 @@ from solar.dblayer.solar_models import Resource as DBResource
|
||||
from solar.events import api
|
||||
from solar import utils
|
||||
|
||||
|
||||
"""
|
||||
created - resource is created by user
|
||||
operational - set in commit part of system_log
|
||||
removed - removed by user, will be deleted from database during commit
|
||||
error - set in commit, if there was errors in task execution
|
||||
"""
|
||||
RESOURCE_STATE = Enum(
|
||||
'ResourceState', 'created operational removed error updated')
|
||||
'ResourceState', 'created operational removed error')
|
||||
|
||||
|
||||
class Resource(object):
|
||||
@ -208,18 +213,17 @@ class Resource(object):
|
||||
return
|
||||
|
||||
def update(self, args):
|
||||
# TODO: disconnect input when it is updated and end_node
|
||||
# for some input_to_input relation
|
||||
self.db_obj.state = RESOURCE_STATE.updated.name
|
||||
|
||||
for k, v in args.items():
|
||||
self.db_obj.inputs[k] = v
|
||||
self.db_obj.save_lazy()
|
||||
# run and update are same things from solar pov
|
||||
# so lets remove this redundancy
|
||||
# created state will be changed during commit
|
||||
if self.db_obj.state != RESOURCE_STATE.created.name:
|
||||
action = 'update'
|
||||
else:
|
||||
action = 'run'
|
||||
LogItem.new(
|
||||
{'resource': self.name,
|
||||
'action': 'run',
|
||||
'action': action,
|
||||
'tags': self.tags}).save_lazy()
|
||||
|
||||
def delete(self):
|
||||
|
@ -25,16 +25,16 @@ from solar.system_log import operations
|
||||
|
||||
|
||||
def create_resource(name, tags=None):
|
||||
resource = DBResource.from_dict(
|
||||
res = DBResource.from_dict(
|
||||
name,
|
||||
{'name': name,
|
||||
'base_path': 'x',
|
||||
'state': '',
|
||||
'state': resource.RESOURCE_STATE.created.name,
|
||||
'tags': tags or [],
|
||||
'meta_inputs': {'a': {'value': None,
|
||||
'schema': 'str'}}})
|
||||
resource.save_lazy()
|
||||
return resource
|
||||
res.save_lazy()
|
||||
return res
|
||||
|
||||
|
||||
def test_revert_update():
|
||||
@ -280,3 +280,12 @@ def test_childs_added_on_stage():
|
||||
child_log_item = next(li for li in staged_log
|
||||
if li.resource == res_1.name)
|
||||
assert child_log_item.action == 'run'
|
||||
|
||||
|
||||
def test_update_action_after_commit():
|
||||
res = resource.load(create_resource('1').name)
|
||||
res.set_operational()
|
||||
res.update({'a': 10})
|
||||
ModelMeta.save_all_lazy()
|
||||
staged_log = change.staged_log()
|
||||
assert staged_log[0].action == 'update'
|
||||
|
Loading…
x
Reference in New Issue
Block a user