forked from ungleich-public/cdist
		
	Change path removal suitable for integration and normal run.
This commit is contained in:
		
					parent
					
						
							
								47d72fb83a
							
						
					
				
			
			
				commit
				
					
						ac04edc233
					
				
			
		
					 2 changed files with 20 additions and 1 deletions
				
			
		| 
						 | 
					@ -44,6 +44,22 @@ from cdist.util.remoteutil import inspect_ssh_mux_opts
 | 
				
			||||||
class Config(object):
 | 
					class Config(object):
 | 
				
			||||||
    """Cdist main class to hold arbitrary data"""
 | 
					    """Cdist main class to hold arbitrary data"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # list of paths (files and/or directories) that will be removed on finish
 | 
				
			||||||
 | 
					    _paths_for_removal = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @classmethod
 | 
				
			||||||
 | 
					    def _register_path_for_removal(cls, path):
 | 
				
			||||||
 | 
					        cls._paths_for_removal.append(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @classmethod
 | 
				
			||||||
 | 
					    def _remove_paths(cls):
 | 
				
			||||||
 | 
					        while cls._paths_for_removal:
 | 
				
			||||||
 | 
					            path = cls._paths_for_removal.pop()
 | 
				
			||||||
 | 
					            if os.path.isfile(path):
 | 
				
			||||||
 | 
					                os.remove(path)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                shutil.rmtree(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, local, remote, dry_run=False, jobs=None,
 | 
					    def __init__(self, local, remote, dry_run=False, jobs=None,
 | 
				
			||||||
                 cleanup_cmds=None, remove_remote_files_dirs=False):
 | 
					                 cleanup_cmds=None, remove_remote_files_dirs=False):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -266,8 +282,8 @@ class Config(object):
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def _resolve_ssh_control_path(cls):
 | 
					    def _resolve_ssh_control_path(cls):
 | 
				
			||||||
        base_path = tempfile.mkdtemp()
 | 
					        base_path = tempfile.mkdtemp()
 | 
				
			||||||
 | 
					        cls._register_path_for_removal(base_path)
 | 
				
			||||||
        control_path = os.path.join(base_path, "s")
 | 
					        control_path = os.path.join(base_path, "s")
 | 
				
			||||||
        atexit.register(lambda: shutil.rmtree(base_path))
 | 
					 | 
				
			||||||
        return control_path
 | 
					        return control_path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
| 
						 | 
					@ -345,6 +361,7 @@ class Config(object):
 | 
				
			||||||
                    cleanup_cmds=cleanup_cmds,
 | 
					                    cleanup_cmds=cleanup_cmds,
 | 
				
			||||||
                    remove_remote_files_dirs=remove_remote_files_dirs)
 | 
					                    remove_remote_files_dirs=remove_remote_files_dirs)
 | 
				
			||||||
            c.run()
 | 
					            c.run()
 | 
				
			||||||
 | 
					            cls._remove_paths()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except cdist.Error as e:
 | 
					        except cdist.Error as e:
 | 
				
			||||||
            log.error(e)
 | 
					            log.error(e)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,6 +36,7 @@ import os
 | 
				
			||||||
import os.path
 | 
					import os.path
 | 
				
			||||||
import collections
 | 
					import collections
 | 
				
			||||||
import uuid
 | 
					import uuid
 | 
				
			||||||
 | 
					import shutil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def find_cdist_exec_in_path():
 | 
					def find_cdist_exec_in_path():
 | 
				
			||||||
| 
						 | 
					@ -123,6 +124,7 @@ def _process_hosts_simple(action, host, manifest, verbose,
 | 
				
			||||||
        theclass.onehost(target_host, None, host_base_path, hostdir, args,
 | 
					        theclass.onehost(target_host, None, host_base_path, hostdir, args,
 | 
				
			||||||
                         parallel=False, configuration=configuration,
 | 
					                         parallel=False, configuration=configuration,
 | 
				
			||||||
                         remove_remote_files_dirs=True)
 | 
					                         remove_remote_files_dirs=True)
 | 
				
			||||||
 | 
					    shutil.rmtree(base_root_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def configure_hosts_simple(host, manifest,
 | 
					def configure_hosts_simple(host, manifest,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue