From 1b484e2d87111d0c44bdeb8e985d6f45937618bd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 13:50:37 +0200 Subject: [PATCH 01/15] setup __cdist_base_dir Signed-off-by: Nico Schottelius --- lib/cdist/context.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/cdist/context.py b/lib/cdist/context.py index 3ecd84e0..a503372f 100644 --- a/lib/cdist/context.py +++ b/lib/cdist/context.py @@ -45,6 +45,7 @@ class Context: self.base_dir = os.environ['__cdist_base_dir'] else: self.base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + # Input directories self.cache_dir = os.path.join(self.base_dir, "cache", target_host) @@ -86,6 +87,8 @@ class Context: # Create directories self.__init_out_dirs() + self.__init_env() + def cleanup(self): # Do not use in __del__: # http://docs.python.org/reference/datamodel.html#customization @@ -100,7 +103,8 @@ class Context: def __init_env(self): """Setup environment""" - os.environ['__cdist_out_dir'] = self.out_dir + os.environ['__cdist_out_dir'] = self.out_dir + os.environ['__cdist_base_dir'] = self.base_dir def __init_out_dirs(self): """Initialise output directory structure""" From fa1a4263e062507003bc569e15086d4b184c0232 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 13:51:00 +0200 Subject: [PATCH 02/15] setup __cdist_base_dir Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index 8d926447..71d352da 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -201,8 +201,9 @@ class ConfigInstall: """Link emulator to types""" src = os.path.abspath(self.exec_path) for type in cdist.core.Type.list_types(): - log.debug("Linking emulator: %s to %s", source, destination) dst = os.path.join(self.context.bin_dir, type.name) + log.debug("Linking emulator: %s to %s", src, dst) + # FIXME: handle exception / make it more beautiful os.symlink(src, dst) From 13ec2a82b6689b075f6c65ea8dc1fb51105cd037 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 14:25:39 +0200 Subject: [PATCH 03/15] ++todo Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index 262255d7..0760f368 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -14,3 +14,7 @@ GlobalExplorer: remote_path: remote path to explorer See config_install: run_global_explorers() + +Object/Type: + - rutern relative only + - Have accept absulet path on listing From e1f0d60e8bf3aff20d028ea7920105fa274e0aec Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:03:26 +0200 Subject: [PATCH 04/15] restructure to _path and do not make context dependent on env Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 9 +++-- lib/cdist/context.py | 75 ++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index 71d352da..d122348d 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -54,11 +54,14 @@ class ConfigInstall: def cleanup(self): self.path.cleanup() + def __init_env(self): + """Setup environment""" + def run_initial_manifest(self): """Run the initial manifest""" - log.info("Running initial manifest %s", self.path.initial_manifest) - env = { "__manifest" : self.path.manifest_dir } - self.run_manifest(self.path.initial_manifest, extra_env=env) + log.info("Running initial manifest %s", self.context.initial_manifest) + env = { "__manifest" : self.context.manifest_dir } + self.run_manifest(self.context.initial_manifest, extra_env=env) def run_type_manifest(self, cdist_object): """Run manifest for a specific object""" diff --git a/lib/cdist/context.py b/lib/cdist/context.py index a503372f..edc29d60 100644 --- a/lib/cdist/context.py +++ b/lib/cdist/context.py @@ -31,58 +31,63 @@ log = logging.getLogger(__name__) import cdist.exec class Context: - """Storing context dependent information""" + """Storing context information""" - def __init__(self, target_host, initial_manifest=False, base_dir=False, + def __init__(self, + target_host, + initial_manifest=False, + base_path=False, + out_path=False, debug=False): self.target_host = target_host # Base and Temp Base - if base_dir: - self.base_dir = base_dir - elif "__cdist_base_dir" in os.environ: - self.base_dir = os.environ['__cdist_base_dir'] + if base_path: + self.base_path = base_path else: - self.base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + self.base_path = + os.path.abspath( + os.path.join(os.path.dirname(__file__), + os.pardir, + os.pardir)) # Input directories - self.cache_dir = os.path.join(self.base_dir, "cache", target_host) - self.conf_dir = os.path.join(self.base_dir, "conf") - self.manifest_dir = os.path.join(self.conf_dir, "manifest") + self.cache_path = os.path.join(self.base_path, "cache", target_host) + self.conf_path = os.path.join(self.base_path, "conf") - # Probably unused paths - # self.global_explorer_dir = os.path.join(self.conf_dir, "explorer") - # self.lib_dir = os.path.join(self.base_dir, "lib") - # self.type_base_dir = os.path.join(self.conf_dir, "type") + self.global_explorer_path = os.path.join(self.conf_path, "explorer") + self.manifest_path = os.path.join(self.conf_path, "manifest") + self.type_base_path = os.path.join(self.conf_path, "type") + self.lib_path = os.path.join(self.base_path, "lib") # Mostly static, but can be overwritten on user demand if initial_manifest: self.initial_manifest = initial_manifest else: - self.initial_manifest = os.path.join(self.manifest_dir, "init") + self.initial_manifest = os.path.join(self.manifest_path, "init") # Output directories - if "__cdist_out_dir" in os.environ: - self.out_dir = os.environ['__cdist_out_dir'] + if out_path: + self.out_path = out_path: else: - self.out_dir = os.path.join(tempfile.mkdtemp(), "out") + self.out_path = os.path.join(tempfile.mkdtemp(), "out") - self.global_explorer_out_dir = os.path.join(self.out_dir, "explorer") - self.object_base_dir = os.path.join(self.out_dir, "object") - self.bin_dir = os.path.join(self.out_dir, "bin") + self.global_explorer_out_path = os.path.join(self.out_path, "explorer") + self.object_base_path = os.path.join(self.out_path, "object") + self.bin_path = os.path.join(self.out_path, "bin") # Remote directories - if "__cdist_remote_base_dir" in os.environ: - self.remote_base_dir = os.environ['__cdist_remote_base_dir'] + if "__cdist_remote_base_path" in os.environ: + self.remote_base_path = os.environ['__cdist_remote_base_path'] else: - self.remote_base_dir = "/var/lib/cdist" + self.remote_base_path = "/var/lib/cdist" - self.remote_conf_dir = os.path.join(self.remote_base_dir, "conf") - self.remote_object_dir = os.path.join(self.remote_base_dir, "object") - self.remote_type_dir = os.path.join(self.remote_conf_dir, "type") - self.remote_global_explorer_dir = os.path.join(self.remote_conf_dir, "explorer") + self.remote_conf_path = os.path.join(self.remote_base_path, "conf") + self.remote_object_dir = os.path.join(self.remote_base_path, "object") + self.remote_type_dir = os.path.join(self.remote_conf_path, "type") + self.remote_global_explorer_dir = os.path.join(self.remote_conf_path, "explorer") # Create directories self.__init_out_dirs() @@ -95,23 +100,23 @@ class Context: # "other globals referenced by the __del__() method may already have been deleted # or in the process of being torn down (e.g. the import machinery shutting down)" # - log.debug("Saving" + self.base_dir + "to " + self.cache_dir) + log.debug("Saving" + self.base_path + "to " + self.cache_path) # Remove previous cache - if os.path.exists(self.cache_dir): - shutil.rmtree(self.cache_dir) - shutil.move(self.base_dir, self.cache_dir) + if os.path.exists(self.cache_path): + shutil.rmtree(self.cache_path) + shutil.move(self.base_path, self.cache_path) def __init_env(self): """Setup environment""" os.environ['__cdist_out_dir'] = self.out_dir - os.environ['__cdist_base_dir'] = self.base_dir + os.environ['__cdist_base_path'] = self.base_path def __init_out_dirs(self): """Initialise output directory structure""" # Create base dir, if user supplied and not existing - if not os.path.isdir(self.base_dir): - os.mkdir(self.base_dir) + if not os.path.isdir(self.base_path): + os.mkdir(self.base_path) os.mkdir(self.out_dir) os.mkdir(self.global_explorer_out_dir) From 7169d6ac42385093f721a534504b96389a18227d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:05:52 +0200 Subject: [PATCH 05/15] more s/_dir/_path/g Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 57 +++++++++++++++++++------------------ lib/cdist/context.py | 34 +++++++++++----------- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index d122348d..e8d8b0c9 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -37,7 +37,7 @@ class ConfigInstall: """Cdist main class to hold arbitrary data""" def __init__(self, target_host, initial_manifest=False, - base_dir=False, + base_path=False, exec_path=sys.argv[0], debug=False): @@ -48,7 +48,7 @@ class ConfigInstall: self.exec_path = exec_path self.context = cdist.context.Context(self.target_host, - initial_manifest=initial_manifest, base_dir=base_dir, + initial_manifest=initial_manifest, base_path=base_path, debug=debug) def cleanup(self): @@ -60,17 +60,18 @@ class ConfigInstall: def run_initial_manifest(self): """Run the initial manifest""" log.info("Running initial manifest %s", self.context.initial_manifest) - env = { "__manifest" : self.context.manifest_dir } + env = { "__manifest" : self.context.manifest_path } self.run_manifest(self.context.initial_manifest, extra_env=env) def run_type_manifest(self, cdist_object): """Run manifest for a specific object""" type = cdist_object.type - manifest = type.manifest_path + manifest_path = os.path.join(self.context.type_base_path, + type.manifest_path) log.debug("%s: Running %s", cdist_object.name, manifest) if os.path.exists(manifest): - env = { "__object" : cdist_object.path, + env = { "__object" : os.path.join(self.context.cdist_object.path, "__object_id": cdist_object.object_id, "__object_fq": cdist_object.name, "__type": type.path, @@ -81,13 +82,13 @@ class ConfigInstall: """Run a manifest""" log.debug("Running manifest %s, env=%s", manifest, extra_env) env = os.environ.copy() - env['PATH'] = self.context.bin_dir + ":" + env['PATH'] + env['PATH'] = self.context.bin_path + ":" + env['PATH'] # Information required in every manifest env['__target_host'] = self.target_host - # FIXME: __global == __cdist_out_dir - duplication - env['__global'] = self.context.out_dir + # FIXME: __global == __cdist_out_path - duplication + env['__global'] = self.context.out_path # Submit debug flag to manifest, can be used by emulator and types if self.debug: @@ -97,7 +98,7 @@ class ConfigInstall: env['__cdist_manifest'] = manifest # Required to find types - env['__cdist_type_base_dir'] = type.path + env['__cdist_type_base_path'] = type.path # Other environment stuff if extra_env: @@ -124,7 +125,7 @@ class ConfigInstall: # env = os.environ.copy() env['__target_host'] = self.target_host - env['__global'] = self.context.out_dir + env['__global'] = self.context.out_path env["__object"] = cdist_object.path env["__object_id"] = cdist_object.object_id env["__object_fq"] = cdist_object.name @@ -179,8 +180,8 @@ class ConfigInstall: self.path.transfer_type_explorers(type) cmd = [] - cmd.append("__explorer=" + self.context.remote_global_explorer_dir) - cmd.append("__type_explorer=" + type.explorer_remote_dir) + cmd.append("__explorer=" + self.context.remote_global_explorer_path) + cmd.append("__type_explorer=" + type.explorer_remote_path) cmd.append("__object=" + object.path_remote) cmd.append("__object_id=" + object.object_id) cmd.append("__object_fq=" + cdist_object) @@ -190,8 +191,8 @@ class ConfigInstall: explorers = self.path.list_type_explorers(type) for explorer in explorers: - remote_cmd = cmd + [os.path.join(type.explorer_remote_dir, explorer)] - output = os.path.join(cdist_object.explorer_output_dir(), explorer) + remote_cmd = cmd + [os.path.join(type.explorer_remote_path, explorer)] + output = os.path.join(cdist_object.explorer_output_path(), explorer) output_fd = open(output, mode='w') log.debug("%s exploring %s using %s storing to %s", cdist_object, explorer, remote_cmd, output) @@ -204,7 +205,7 @@ class ConfigInstall: """Link emulator to types""" src = os.path.abspath(self.exec_path) for type in cdist.core.Type.list_types(): - dst = os.path.join(self.context.bin_dir, type.name) + dst = os.path.join(self.context.bin_path, type.name) log.debug("Linking emulator: %s to %s", src, dst) # FIXME: handle exception / make it more beautiful @@ -214,15 +215,15 @@ class ConfigInstall: """Run global explorers""" log.info("Running global explorers") - src = cdist.core.GlobalExplorer.base_dir - dst = cdist.core.GlobalExplorer.remote_base_dir + src = cdist.core.GlobalExplorer.base_path + dst = cdist.core.GlobalExplorer.remote_base_path - self.context.transfer_dir(src, dst) + self.context.transfer_path(src, dst) for explorer in cdist.core.GlobalExplorer.list_explorers(): output_fd = open(explorer.out_path, mode='w') cmd = [] - cmd.append("__explorer=" + cdist.core.GlobalExplorer.remote_base_dir) + cmd.append("__explorer=" + cdist.core.GlobalExplorer.remote_base_path) cmd.append(explorer.remote_path) cdist.exec.run_or_fail(cmd, stdout=output_fd, remote_prefix=True) @@ -251,8 +252,8 @@ class ConfigInstall: """Ensure the base directories are cleaned up""" log.debug("Creating clean directory structure") - self.context.remove_remote_dir(self.context.remote_base_dir) - self.context.remote_mkdir(self.context.remote_base_dir) + self.context.remove_remote_path(self.context.remote_base_path) + self.context.remote_mkdir(self.context.remote_base_path) self.link_emulator() def stage_prepare(self): @@ -263,7 +264,7 @@ class ConfigInstall: log.info("Running object manifests and type explorers") - log.debug("Searching for objects in " + cdist.core.Object.base_dir()) + log.debug("Searching for objects in " + cdist.core.Object.base_path()) # Continue process until no new objects are created anymore new_objects_created = True @@ -284,17 +285,17 @@ class ConfigInstall: def transfer_object_parameter(self, cdist_object): """Transfer the object parameter to the remote destination""" # Create base path before using mkdir -p - self.remote_mkdir(self.remote_object_parameter_dir(cdist_object)) + self.remote_mkdir(self.remote_object_parameter_path(cdist_object)) # Synchronise parameter dir afterwards - self.transfer_dir(self.object_parameter_dir(cdist_object), - self.remote_object_parameter_dir(cdist_object)) + self.transfer_path(self.object_parameter_path(cdist_object), + self.remote_object_parameter_path(cdist_object)) # FIXME Move into configinstall def transfer_global_explorers(self): """Transfer the global explorers""" self.remote_mkdir(REMOTE_GLOBAL_EXPLORER_DIR) - self.transfer_dir(self.global_explorer_dir, REMOTE_GLOBAL_EXPLORER_DIR) + self.transfer_path(self.global_explorer_path, REMOTE_GLOBAL_EXPLORER_DIR) # FIXME Move into configinstall def transfer_type_explorers(self, type): @@ -306,7 +307,7 @@ class ConfigInstall: # Do not retransfer type.transferred_explorers = True - # FIXME: Can be explorer_path or explorer_dir, I don't care. + # FIXME: Can be explorer_path or explorer_path, I don't care. src = type.explorer_path() dst = type.remote_explorer_path() @@ -314,4 +315,4 @@ class ConfigInstall: if len(type.explorers) > 0: # Ensure that the path exists self.remote_mkdir(dst) - self.transfer_dir(src, dst) + self.transfer_path(src, dst) diff --git a/lib/cdist/context.py b/lib/cdist/context.py index edc29d60..1de57f94 100644 --- a/lib/cdist/context.py +++ b/lib/cdist/context.py @@ -38,6 +38,7 @@ class Context: initial_manifest=False, base_path=False, out_path=False, + remote_base_path=False, debug=False): self.target_host = target_host @@ -53,7 +54,7 @@ class Context: os.pardir)) - # Input directories + # Local input directories self.cache_path = os.path.join(self.base_path, "cache", target_host) self.conf_path = os.path.join(self.base_path, "conf") @@ -62,35 +63,34 @@ class Context: self.type_base_path = os.path.join(self.conf_path, "type") self.lib_path = os.path.join(self.base_path, "lib") - # Mostly static, but can be overwritten on user demand if initial_manifest: self.initial_manifest = initial_manifest else: self.initial_manifest = os.path.join(self.manifest_path, "init") - # Output directories + # Local output directories if out_path: self.out_path = out_path: else: self.out_path = os.path.join(tempfile.mkdtemp(), "out") + self.bin_path = os.path.join(self.out_path, "bin") self.global_explorer_out_path = os.path.join(self.out_path, "explorer") - self.object_base_path = os.path.join(self.out_path, "object") - self.bin_path = os.path.join(self.out_path, "bin") + self.object_base_path = os.path.join(self.out_path, "object") # Remote directories - if "__cdist_remote_base_path" in os.environ: - self.remote_base_path = os.environ['__cdist_remote_base_path'] + if remote_base_path: + self.remote_base_path = remote_base_path else: self.remote_base_path = "/var/lib/cdist" self.remote_conf_path = os.path.join(self.remote_base_path, "conf") - self.remote_object_dir = os.path.join(self.remote_base_path, "object") - self.remote_type_dir = os.path.join(self.remote_conf_path, "type") - self.remote_global_explorer_dir = os.path.join(self.remote_conf_path, "explorer") + self.remote_object_path = os.path.join(self.remote_base_path, "object") + self.remote_type_path = os.path.join(self.remote_conf_path, "type") + self.remote_global_explorer_path = os.path.join(self.remote_conf_path, "explorer") # Create directories - self.__init_out_dirs() + self.__init_out_paths() self.__init_env() @@ -108,24 +108,24 @@ class Context: def __init_env(self): """Setup environment""" - os.environ['__cdist_out_dir'] = self.out_dir + os.environ['__cdist_out_path'] = self.out_path os.environ['__cdist_base_path'] = self.base_path - def __init_out_dirs(self): + def __init_out_paths(self): """Initialise output directory structure""" # Create base dir, if user supplied and not existing if not os.path.isdir(self.base_path): os.mkdir(self.base_path) - os.mkdir(self.out_dir) - os.mkdir(self.global_explorer_out_dir) - os.mkdir(self.bin_dir) + os.mkdir(self.out_path) + os.mkdir(self.global_explorer_out_path) + os.mkdir(self.bin_path) def remote_mkdir(self, directory): """Create directory on remote side""" cdist.exec.run_or_fail(["mkdir", "-p", directory], remote_prefix=True) - def remove_remote_dir(self, destination): + def remove_remote_path(self, destination): cdist.exec.run_or_fail(["rm", "-rf", destination], remote_prefix=True) From 8aa91726870955967f9686d01db786e450818062 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:07:38 +0200 Subject: [PATCH 06/15] ++tests Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index 0760f368..a66255a9 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -18,3 +18,8 @@ GlobalExplorer: Object/Type: - rutern relative only - Have accept absulet path on listing + +Tests needed: + + - Fail if cache_dir from previous run cannot be deleted + - Fail if cache_dir cannot be created from current out_dir From 8af7c075ec584981e9eb8654ab35823d3f97e53b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:19:01 +0200 Subject: [PATCH 07/15] ++todo(steven) Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index a66255a9..2a953e0d 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -1,4 +1,7 @@ Object: + cdist_object.code_local_path + cdist_object.code_remote_path + cdist_object.remote_code_remote_path Type: From 4f76cfc84e8ea7d0c3dfaa428d77d68a22dff1dd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:20:38 +0200 Subject: [PATCH 08/15] changes for relative Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 43 +++++++++++++++++++------------------ lib/cdist/context.py | 8 +++---- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index e8d8b0c9..c630487f 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -70,45 +70,45 @@ class ConfigInstall: type.manifest_path) log.debug("%s: Running %s", cdist_object.name, manifest) - if os.path.exists(manifest): - env = { "__object" : os.path.join(self.context.cdist_object.path, + if os.path.exists(manifest_path): + env = { "__object" : os.path.join(self.context.object_base_path, + cdist_object.path) "__object_id": cdist_object.object_id, "__object_fq": cdist_object.name, - "__type": type.path, + "__type": os.path.join(self.context.type_base_path, + type.path) } - self.run_manifest(manifest, extra_env=env) + self.run_manifest(manifest_path, extra_env=env) - def run_manifest(self, manifest, extra_env=None): + def run_manifest(self, manifest_path, extra_env=None): """Run a manifest""" - log.debug("Running manifest %s, env=%s", manifest, extra_env) + log.debug("Running manifest %s, env=%s", manifest_path, extra_env) env = os.environ.copy() env['PATH'] = self.context.bin_path + ":" + env['PATH'] # Information required in every manifest env['__target_host'] = self.target_host - - # FIXME: __global == __cdist_out_path - duplication env['__global'] = self.context.out_path # Submit debug flag to manifest, can be used by emulator and types if self.debug: env['__debug'] = "yes" - # Required for recording source - env['__cdist_manifest'] = manifest + # Required for recording source in emulator + env['__cdist_manifest'] = manifest_path - # Required to find types + # Required to find types in emulator env['__cdist_type_base_path'] = type.path # Other environment stuff if extra_env: env.update(extra_env) - cdist.exec.shell_run_or_debug_fail(manifest, [manifest], env=env) + cdist.exec.shell_run_or_debug_fail(manifest_path, [manifest_path], env=env) def object_run(self, cdist_object): """Run gencode or code for an object""" - log.debug("Running %s from %s", mode, cdist_object) + log.debug("Running object %s", cdist_object) # Catch requirements, which re-call us if cdist_object.ran: @@ -118,7 +118,7 @@ class ConfigInstall: for requirement in cdist_object.requirements: log.debug("Object %s requires %s", cdist_object, requirement) - self.object_run(requirement, mode=mode) + self.object_run(requirement) # # Setup env Variable: @@ -126,17 +126,19 @@ class ConfigInstall: env = os.environ.copy() env['__target_host'] = self.target_host env['__global'] = self.context.out_path - env["__object"] = cdist_object.path + env["__object"] = os.path.join(self.context.object_base_path, cdist_object.path) env["__object_id"] = cdist_object.object_id env["__object_fq"] = cdist_object.name env["__type"] = type.name # gencode for cmd in ["local", "remote"]: - bin = getattr(type, "gencode_" + cmd) + bin = os.path.join(self.context.type_base_path, + getattr(type, "gencode_" + cmd)) if os.path.isfile(bin): - outfile = getattr(cdist_object, "code_" + cmd) + outfile = os.path.join(self.context.object_base_path, + getattr(cdist_object, "code_" + cmd)) outfile_fd = open(outfile, "w") @@ -158,20 +160,19 @@ class ConfigInstall: cdist_object.changed=True # code local - code_local = cdist_object.code_local + code_local = cdist_object.code_local_path if os.path.isfile(code_local): cdist.exec.run_or_fail([code_local]) # code remote - local_remote_code = cdist_object.code_remote - remote_remote_code = cdist_object.remote_code_remote + local_remote_code = cdist_object.code_remote_path + remote_remote_code = cdist_object.remote_code_remote_path if os.path.isfile(local_remote_code): self.context.transfer_file(local_remote_code, remote_remote_code) cdist.exec.run_or_fail([remote_remote_code], remote_prefix=True) cdist_object.ran = True - ### Cleaned / check functions: Round 1 :-) ################################# def run_type_explorer(self, cdist_object): """Run type specific explorers for objects""" diff --git a/lib/cdist/context.py b/lib/cdist/context.py index 1de57f94..af37199e 100644 --- a/lib/cdist/context.py +++ b/lib/cdist/context.py @@ -106,10 +106,10 @@ class Context: shutil.rmtree(self.cache_path) shutil.move(self.base_path, self.cache_path) - def __init_env(self): - """Setup environment""" - os.environ['__cdist_out_path'] = self.out_path - os.environ['__cdist_base_path'] = self.base_path + #def __init_env(self): + # """Setup environment""" + # os.environ['__cdist_out_path'] = self.out_path + # os.environ['__cdist_base_path'] = self.base_path def __init_out_paths(self): """Initialise output directory structure""" From e6e1c07531258ca225bac975db3d9dcfed9871c8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:22:01 +0200 Subject: [PATCH 09/15] ++todo(steven) Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index 2a953e0d..b79b719b 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -5,6 +5,7 @@ Object: Type: + type.transferred_explorers GlobalExplorer: From c1db2bd51ae60e7f65347fca17998ed361b17b0e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:23:48 +0200 Subject: [PATCH 10/15] ++todo(steven) Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index b79b719b..35648910 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -7,6 +7,8 @@ Object: Type: type.transferred_explorers + type.type_explorer_paths() -> relative list of paths of explorer + GlobalExplorer: out_path: local path into which the output is written From 73ba8e2366d25333314d4bf960ce558ce31d596e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:26:38 +0200 Subject: [PATCH 11/15] --todo(steven) Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index 35648910..b79b719b 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -7,8 +7,6 @@ Object: Type: type.transferred_explorers - type.type_explorer_paths() -> relative list of paths of explorer - GlobalExplorer: out_path: local path into which the output is written From 187510bbd34ccdd3a7d74d49847bfb274a254ce5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:33:27 +0200 Subject: [PATCH 12/15] ++todo(steven) Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index b79b719b..dc9f965b 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -27,3 +27,5 @@ Tests needed: - Fail if cache_dir from previous run cannot be deleted - Fail if cache_dir cannot be created from current out_dir + - transfer_type_explorers: Explorers are not transferred twice + - transfer_type_explorers: No transfer tried if there are no type_explorers From 183bbf61d4e1b96125c5e1421ef73f4a45bfde2a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:34:47 +0200 Subject: [PATCH 13/15] fix imports from path in config_install Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index c630487f..0b05f8a9 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -177,8 +177,7 @@ class ConfigInstall: """Run type specific explorers for objects""" type = cdist_object.type - # FIXME - self.path.transfer_type_explorers(type) + self.transfer_type_explorers(type) cmd = [] cmd.append("__explorer=" + self.context.remote_global_explorer_path) @@ -292,13 +291,15 @@ class ConfigInstall: self.transfer_path(self.object_parameter_path(cdist_object), self.remote_object_parameter_path(cdist_object)) - # FIXME Move into configinstall + +####FIXED ###################################################################### + def transfer_global_explorers(self): """Transfer the global explorers""" - self.remote_mkdir(REMOTE_GLOBAL_EXPLORER_DIR) - self.transfer_path(self.global_explorer_path, REMOTE_GLOBAL_EXPLORER_DIR) + self.remote_mkdir(self.context.remote_global_explorer_path) + self.transfer_path(self.context.global_explorer_path, + self.remote_global_explorer_path) - # FIXME Move into configinstall def transfer_type_explorers(self, type): """Transfer explorers of a type, but only once""" if type.transferred_explorers: @@ -308,12 +309,13 @@ class ConfigInstall: # Do not retransfer type.transferred_explorers = True - # FIXME: Can be explorer_path or explorer_path, I don't care. - src = type.explorer_path() - dst = type.remote_explorer_path() + explorers = type.explorers() + + if len(explorers) > 0: + rel_path = os.path.join(type.explorer_path(), explorer) + src = os.path.join(self.context.type_base_path, rel_path) + dst = os.path.join(self.context.remote_type_path, rel_path) - # Transfer if there is at least one explorer - if len(type.explorers) > 0: # Ensure that the path exists self.remote_mkdir(dst) self.transfer_path(src, dst) From c268e5f7c25778b2cf0fbdf58818546b08d56942 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:36:59 +0200 Subject: [PATCH 14/15] ++todo(steven) Signed-off-by: Nico Schottelius --- doc/dev/todo/steven | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/dev/todo/steven b/doc/dev/todo/steven index dc9f965b..54b43210 100644 --- a/doc/dev/todo/steven +++ b/doc/dev/todo/steven @@ -3,6 +3,10 @@ Object: cdist_object.code_remote_path cdist_object.remote_code_remote_path + cdist_object.parameter_path + + + Type: type.transferred_explorers From 79234148aa7eaf249ad6b24eb06f255acb8f3bfa Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 7 Oct 2011 15:39:29 +0200 Subject: [PATCH 15/15] transfer_object_parameter: new src/dst Signed-off-by: Nico Schottelius --- lib/cdist/config_install.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/cdist/config_install.py b/lib/cdist/config_install.py index 0b05f8a9..9c1f3b9d 100644 --- a/lib/cdist/config_install.py +++ b/lib/cdist/config_install.py @@ -284,12 +284,19 @@ class ConfigInstall: # FIXME Move into configinstall def transfer_object_parameter(self, cdist_object): """Transfer the object parameter to the remote destination""" + local_path = + os.path.join(self.context.object_base_path, + cdist_object.parameter_path) + remote_path = + os.path.join(self.context.remote_object_path, + cdist_object.parameter_path) + # Create base path before using mkdir -p - self.remote_mkdir(self.remote_object_parameter_path(cdist_object)) + # FIXME: needed? + self.remote_mkdir(remote_path) # Synchronise parameter dir afterwards - self.transfer_path(self.object_parameter_path(cdist_object), - self.remote_object_parameter_path(cdist_object)) + self.transfer_path(local_path, remote_path) ####FIXED ######################################################################