Try2 to make cdist honor the manifest order,

this implementation has some more lines of code,
but no collision with the require variable.
This commit is contained in:
Daniel Heule 2014-01-18 19:23:21 +01:00
parent 824381e6ca
commit 61aec12ba1
2 changed files with 38 additions and 20 deletions

View file

@ -154,8 +154,8 @@ class Emulator(object):
self.cdist_object.create() self.cdist_object.create()
self.cdist_object.parameters = self.parameters self.cdist_object.parameters = self.parameters
# record the created object in typeorder file # record the created object in typeorder file
with open(self.typeorder_path, 'a') as tofd: with open(self.typeorder_path, 'a') as typeorderfile:
tofd.write(self.cdist_object.name + os.linesep) print(self.cdist_object.name, file=typeorderfile)
# Record / Append source # Record / Append source
self.cdist_object.source.append(self.object_source) self.cdist_object.source.append(self.object_source)
@ -184,6 +184,24 @@ class Emulator(object):
def record_requirements(self): def record_requirements(self):
"""record requirements""" """record requirements"""
#from pudb import set_trace; set_trace();
if "EXECUTE_TYPES_IN_CREATION_ORDER" in self.env and self.env['EXECUTE_TYPES_IN_CREATION_ORDER'] == 'true':
# load object name created bevor this one from typeorder file ...
with open(self.typeorder_path, 'r') as typecreationfile:
typecreationorder = typecreationfile.readlines()
# get the type created bevore this one ...
try:
lastcreatedtype = typecreationorder[-2].strip()
if 'require' in self.env:
self.env['require'] += " " + lastcreatedtype
else:
self.env['require'] = lastcreatedtype
self.log.debug("Injecting require for EXECUTE_TYPES_IN_CREATION_ORDER: %s for %s", lastcreatedtype, self.cdist_object.name)
except IndexError:
# if no second last line, we are on the first type, so do not set a requirement
pass
if "require" in self.env: if "require" in self.env:
requirements = self.env['require'] requirements = self.env['require']
@ -192,18 +210,6 @@ class Emulator(object):
# Ignore empty fields - probably the only field anyway # Ignore empty fields - probably the only field anyway
if len(requirement) == 0: continue if len(requirement) == 0: continue
if requirement == "CDIST_HONOR_MANIFEST_ORDER":
# load object name created bevor this one from typeorder file ...
with open(self.typeorder_path, 'r') as tofd:
lines = tofd.readlines()
# replace the placeholder with the last created object
try:
requirement = lines[-2].strip()
except IndexError:
# if no second last line, we are on the first object, so do not set a requirement
continue
# Raises an error, if object cannot be created # Raises an error, if object cannot be created
try: try:
cdist_object = self.cdist_object.object_from_name(requirement) cdist_object = self.cdist_object.object_from_name(requirement)
@ -212,7 +218,7 @@ class Emulator(object):
raise raise
self.log.debug("Recording requirement: " + requirement) self.log.debug("Recording requirement: %s", requirement)
# Save the sanitised version, not the user supplied one # Save the sanitised version, not the user supplied one
# (__file//bar => __file/bar) # (__file//bar => __file/bar)

View file

@ -128,18 +128,30 @@ All objects that are created in a type manifest are automatically required
from the type that is calling them. This is called "autorequirement" in from the type that is calling them. This is called "autorequirement" in
cdist jargon. cdist jargon.
EXECUTE_TYPES_IN_CREATION_ORDER is a EXPERIMENTAL FEATURE !
You can tell cdist to execute all types in the order in which they are created You can tell cdist to execute all types in the order in which they are created
in the manifest by setting require to the special value of in the manifest by exporting EXECUTE_TYPES_IN_CREATION_ORDER with the value true.
"CDIST_HONOR_MANIFEST_ORDER".
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# Tells cdist to execute all types in the order in which they are created ... # Tells cdist to execute all types in the order in which they are created ...
export require="CDIST_HONOR_MANIFEST_ORDER" export EXECUTE_TYPES_IN_CREATION_ORDER=true
__sample_type 1 __sample_type 1
__sample_type 2 require="__some_type_somewhere/id" __sample_type 2
__example_type 23 __example_type 23
# Now this types are executed in the creation order # Now this types are executed in the creation order until the variable is unset
unset EXECUTE_TYPES_IN_CREATION_ORDER
# all now following types cdist makes the order ..
__not_in_order_type 42
# how it works :
# this lines above are translated to:
__sample_type 1
require="__some_type_somewhere/id __sample_type/1" __sample_type 2
require="__sample_type/2" __example_type 23
__not_in_order_type 42
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------