From 824381e6cac28acbf3c5cd84d9d9000b3b37249e Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 17 Jan 2014 23:35:02 +0100 Subject: [PATCH 1/3] new special value require="CDIST_HONOR_MANIFEST_ORDER" which tells cdist to execute types in the manifest order --- cdist/emulator.py | 16 ++++++++++++++++ docs/man/man7/cdist-manifest.text | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cdist/emulator.py b/cdist/emulator.py index b70ef956..fe2af4c1 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -71,6 +71,7 @@ class Emulator(object): raise MissingRequiredEnvironmentVariableError(e.args[0]) self.object_base_path = os.path.join(self.global_path, "object") + self.typeorder_path = os.path.join(self.global_path, "typeorder") self.type_name = os.path.basename(argv[0]) self.cdist_type = core.CdistType(self.type_base_path, self.type_name) @@ -152,6 +153,9 @@ class Emulator(object): else: self.cdist_object.create() self.cdist_object.parameters = self.parameters + # record the created object in typeorder file + with open(self.typeorder_path, 'a') as tofd: + tofd.write(self.cdist_object.name + os.linesep) # Record / Append source self.cdist_object.source.append(self.object_source) @@ -188,6 +192,18 @@ class Emulator(object): # Ignore empty fields - probably the only field anyway 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 try: cdist_object = self.cdist_object.object_from_name(requirement) diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index 92d0b897..d2738c2b 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -128,6 +128,22 @@ All objects that are created in a type manifest are automatically required from the type that is calling them. This is called "autorequirement" in cdist jargon. +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 +"CDIST_HONOR_MANIFEST_ORDER". + +-------------------------------------------------------------------------------- + +# Tells cdist to execute all types in the order in which they are created ... +export require="CDIST_HONOR_MANIFEST_ORDER" +__sample_type 1 +__sample_type 2 +__example_type 23 +# Now this types are executed in the creation order +-------------------------------------------------------------------------------- + + + EXAMPLES -------- From 61aec12ba1b0b0f55ec418895b61d46701c56b30 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Sat, 18 Jan 2014 19:23:21 +0100 Subject: [PATCH 2/3] Try2 to make cdist honor the manifest order, this implementation has some more lines of code, but no collision with the require variable. --- cdist/emulator.py | 36 ++++++++++++++++++------------- docs/man/man7/cdist-manifest.text | 22 ++++++++++++++----- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index fe2af4c1..eeb441aa 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -154,8 +154,8 @@ class Emulator(object): self.cdist_object.create() self.cdist_object.parameters = self.parameters # record the created object in typeorder file - with open(self.typeorder_path, 'a') as tofd: - tofd.write(self.cdist_object.name + os.linesep) + with open(self.typeorder_path, 'a') as typeorderfile: + print(self.cdist_object.name, file=typeorderfile) # Record / Append source self.cdist_object.source.append(self.object_source) @@ -184,6 +184,24 @@ class Emulator(object): def record_requirements(self): """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: requirements = self.env['require'] @@ -192,18 +210,6 @@ class Emulator(object): # Ignore empty fields - probably the only field anyway 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 try: cdist_object = self.cdist_object.object_from_name(requirement) @@ -212,7 +218,7 @@ class Emulator(object): raise - self.log.debug("Recording requirement: " + requirement) + self.log.debug("Recording requirement: %s", requirement) # Save the sanitised version, not the user supplied one # (__file//bar => __file/bar) diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index d2738c2b..d2f5ba05 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -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 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 -in the manifest by setting require to the special value of -"CDIST_HONOR_MANIFEST_ORDER". +in the manifest by exporting EXECUTE_TYPES_IN_CREATION_ORDER with the value true. -------------------------------------------------------------------------------- # 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 2 +require="__some_type_somewhere/id" __sample_type 2 __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 + -------------------------------------------------------------------------------- From 51afca5336464dc65ed183bf83c21e718d167db0 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 6 Feb 2014 15:26:17 +0100 Subject: [PATCH 3/3] Implement lastest suggestions from nico, rename ENV Variable to CDIST_ORDER_DEPENDENCY --- cdist/emulator.py | 5 ++--- docs/man/man7/cdist-manifest.text | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cdist/emulator.py b/cdist/emulator.py index 2c3c12a4..203c97e5 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -189,9 +189,8 @@ class Emulator(object): def record_requirements(self): """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': + if "CDIST_ORDER_DEPENDENCY" in self.env: # load object name created bevor this one from typeorder file ... with open(self.typeorder_path, 'r') as typecreationfile: typecreationorder = typecreationfile.readlines() @@ -202,7 +201,7 @@ class Emulator(object): 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) + self.log.debug("Injecting require for CDIST_ORDER_DEPENDENCY: %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 diff --git a/docs/man/man7/cdist-manifest.text b/docs/man/man7/cdist-manifest.text index 8ae8f966..66a4cd2a 100644 --- a/docs/man/man7/cdist-manifest.text +++ b/docs/man/man7/cdist-manifest.text @@ -142,19 +142,19 @@ into an undefined situation. THIS IS A BETA FEATURE AND MAY BE REMOVED AT ANY TIME. -EXECUTE_TYPES_IN_CREATION_ORDER is a EXPERIMENTAL FEATURE ! +CDIST_ORDER_DEPENDENCY is a EXPERIMENTAL FEATURE ! You can tell cdist to execute all types in the order in which they are created -in the manifest by exporting EXECUTE_TYPES_IN_CREATION_ORDER with the value true. +in the manifest by exporting CDIST_ORDER_DEPENDENCY. -------------------------------------------------------------------------------- # Tells cdist to execute all types in the order in which they are created ... -export EXECUTE_TYPES_IN_CREATION_ORDER=true +export CDIST_ORDER_DEPENDENCY=on __sample_type 1 require="__some_type_somewhere/id" __sample_type 2 __example_type 23 # Now this types are executed in the creation order until the variable is unset -unset EXECUTE_TYPES_IN_CREATION_ORDER +unset CDIST_ORDER_DEPENDENCY # all now following types cdist makes the order .. __not_in_order_type 42