forked from ungleich-public/cdist
add dry_run option to object_run
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
parent
eb93d1bebd
commit
c270538072
1 changed files with 56 additions and 34 deletions
|
@ -104,11 +104,10 @@ class ConfigInstall(object):
|
||||||
self.manifest.run_type_manifest(cdist_object)
|
self.manifest.run_type_manifest(cdist_object)
|
||||||
cdist_object.state = core.CdistObject.STATE_PREPARED
|
cdist_object.state = core.CdistObject.STATE_PREPARED
|
||||||
|
|
||||||
def object_run(self, cdist_object):
|
def object_run(self, cdist_object, dry_run=False):
|
||||||
"""Run gencode and code for an object"""
|
"""Run gencode and code for an object"""
|
||||||
self.log.debug("Trying to run object " + cdist_object.name)
|
self.log.debug("Trying to run object " + cdist_object.name)
|
||||||
if cdist_object.state == core.CdistObject.STATE_DONE:
|
if cdist_object.state == core.CdistObject.STATE_DONE:
|
||||||
# TODO: remove once we are sure that this really never happens.
|
|
||||||
raise cdist.Error("Attempting to run an already finished object: %s", cdist_object)
|
raise cdist.Error("Attempting to run an already finished object: %s", cdist_object)
|
||||||
|
|
||||||
cdist_type = cdist_object.cdist_type
|
cdist_type = cdist_object.cdist_type
|
||||||
|
@ -121,51 +120,74 @@ class ConfigInstall(object):
|
||||||
cdist_object.changed = True
|
cdist_object.changed = True
|
||||||
|
|
||||||
# Execute
|
# Execute
|
||||||
if cdist_object.code_local:
|
if not dry_run:
|
||||||
self.code.run_code_local(cdist_object)
|
if cdist_object.code_local:
|
||||||
if cdist_object.code_remote:
|
self.code.run_code_local(cdist_object)
|
||||||
self.code.transfer_code_remote(cdist_object)
|
if cdist_object.code_remote:
|
||||||
self.code.run_code_remote(cdist_object)
|
self.code.transfer_code_remote(cdist_object)
|
||||||
|
self.code.run_code_remote(cdist_object)
|
||||||
|
|
||||||
# Mark this object as done
|
# Mark this object as done
|
||||||
self.log.debug("Finishing run of " + cdist_object.name)
|
self.log.debug("Finishing run of " + cdist_object.name)
|
||||||
cdist_object.state = core.CdistObject.STATE_DONE
|
cdist_object.state = core.CdistObject.STATE_DONE
|
||||||
|
|
||||||
|
def stage_run_prepare(self):
|
||||||
|
"""Prepare the run stage"""
|
||||||
|
|
||||||
|
self.objects = core.CdistObject.list_objects(
|
||||||
|
self.local.object_path,
|
||||||
|
self.local.type_path)
|
||||||
|
|
||||||
|
self.all_resolved = False
|
||||||
|
self.objects_changed = False
|
||||||
|
|
||||||
|
print("srp: %s - %s objects: %s" % (self.local.object_path, self.local.type_path, list(self.objects)))
|
||||||
|
|
||||||
def stage_run(self):
|
def stage_run(self):
|
||||||
"""The final (and real) step of deployment"""
|
"""The final (and real) step of deployment"""
|
||||||
self.log.info("Generating and executing code")
|
self.log.info("Generating and executing code")
|
||||||
|
self.stage_run_prepare()
|
||||||
objects = core.CdistObject.list_objects(
|
|
||||||
self.local.object_path,
|
|
||||||
self.local.type_path)
|
|
||||||
|
|
||||||
# FIXME:
|
# FIXME:
|
||||||
# - think about parallel execution (same for stage_prepare)
|
# - think about parallel execution (same for stage_prepare)
|
||||||
# - catch unresolvable trees
|
# - catch unresolvable trees
|
||||||
all_resolved = False
|
while not self.all_resolved:
|
||||||
objects_changed = False
|
self.stage_run_iterate()
|
||||||
while not all_resolved:
|
|
||||||
|
|
||||||
object_state_list=' '.join('%s:%s:%s' % (o, o.state, o.all_requirements()) for o in objects)
|
def stage_run_iterate(self):
|
||||||
self.log.debug("Object state (name:state:requirements): %s" % object_state_list)
|
logging.root.setLevel(logging.DEBUG)
|
||||||
|
"""
|
||||||
|
Run one iteration of the run
|
||||||
|
|
||||||
all_resolved = True
|
To be repeated until all objects are done
|
||||||
for cdist_object in objects:
|
"""
|
||||||
|
|
||||||
|
object_state_list=' '.join('%s:%s:%s' % (o, o.state, o.all_requirements()) for o in self.objects)
|
||||||
|
self.log.debug("Object state (name:state:requirements): %s" % object_state_list)
|
||||||
|
print("Object state (name:state:requirements): %s" % object_state_list)
|
||||||
|
|
||||||
|
self.all_resolved = True
|
||||||
|
for cdist_object in self.objects:
|
||||||
|
if not cdist_object.state == cdist_object.STATE_DONE:
|
||||||
|
self.all_resolved = False
|
||||||
|
if cdist_object.satisfied_requirements:
|
||||||
|
self.object_run(cdist_object)
|
||||||
|
self.objects_changed = True
|
||||||
|
|
||||||
|
# Not all are resolved, but nothing has been changed => bad dependencies!
|
||||||
|
if not self.objects_changed and not self.all_resolved:
|
||||||
|
# Create list of unfinished objects + their requirements for print
|
||||||
|
|
||||||
|
evil_objects = []
|
||||||
|
good_objects = []
|
||||||
|
for cdist_object in self.objects:
|
||||||
if not cdist_object.state == cdist_object.STATE_DONE:
|
if not cdist_object.state == cdist_object.STATE_DONE:
|
||||||
all_resolved = False
|
evil_objects.append("%s: required: %s, autorequired: %s" %
|
||||||
if cdist_object.satisfied_requirements:
|
(cdist_object.name, cdist_object.requirements, cdist_object.autorequire))
|
||||||
self.object_run(cdist_object)
|
else:
|
||||||
objects_changed = True
|
evil_objects.append("%s (%s): required: %s, autorequired: %s" %
|
||||||
|
(cdist_object.state, cdist_object.name,
|
||||||
|
cdist_object.requirements, cdist_object.autorequire))
|
||||||
|
|
||||||
# Reran, but no object was solved
|
errormessage = "Cannot solve requirements for the following objects: %s - solved: %s" % (",".join(evil_objects), ",".join(good_objects))
|
||||||
if not objects_changed:
|
raise cdist.Error(errormessage)
|
||||||
# Create list of unfinished objects + their requirements for print
|
|
||||||
|
|
||||||
evil_objects = []
|
|
||||||
for cdist_object in objects:
|
|
||||||
if not cdist_object.state == cdist_object.STATE_DONE:
|
|
||||||
evil_objects.append("%s (required: %s, autorequired: %s" %
|
|
||||||
(cdist_object.name, cdist_object.requirements, cdist_object.autorequire))
|
|
||||||
|
|
||||||
raise cdist.Error("Cannot solve requirements for the following objects: %s" %
|
|
||||||
(",".join(evil_objects)))
|
|
||||||
|
|
Loading…
Reference in a new issue