Merge pull request #767 from darko-poljak/feature/better-explorer-error-report
Report explorer error better
This commit is contained in:
		
				commit
				
					
						84c4bf5577
					
				
			
		
					 3 changed files with 66 additions and 14 deletions
				
			
		| 
						 | 
					@ -181,17 +181,40 @@ class CdistObjectError(CdistEntityError):
 | 
				
			||||||
                         params, stdout_paths, stderr_paths, subject)
 | 
					                         params, stdout_paths, stderr_paths, subject)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CdistObjectExplorerError(CdistEntityError):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Something went wrong while working on a specific
 | 
				
			||||||
 | 
					    cdist object explorer
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    def __init__(self, cdist_object, explorer_name, explorer_path,
 | 
				
			||||||
 | 
					                 stderr_path, subject=''):
 | 
				
			||||||
 | 
					        params = [
 | 
				
			||||||
 | 
					            ('object name', cdist_object.name, ),
 | 
				
			||||||
 | 
					            ('object path', cdist_object.absolute_path, ),
 | 
				
			||||||
 | 
					            ('object source', " ".join(cdist_object.source), ),
 | 
				
			||||||
 | 
					            ('object type', os.path.realpath(
 | 
				
			||||||
 | 
					                cdist_object.cdist_type.absolute_path), ),
 | 
				
			||||||
 | 
					            ('explorer name', explorer_name, ),
 | 
				
			||||||
 | 
					            ('explorer path', explorer_path, ),
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        stdout_paths = []
 | 
				
			||||||
 | 
					        stderr_paths = [
 | 
				
			||||||
 | 
					            ('remote', stderr_path, ),
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        super().__init__("explorer '{}' of object '{}'".format(
 | 
				
			||||||
 | 
					            explorer_name, cdist_object.name), params, stdout_paths,
 | 
				
			||||||
 | 
					            stderr_paths, subject)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class InitialManifestError(CdistEntityError):
 | 
					class InitialManifestError(CdistEntityError):
 | 
				
			||||||
    """Something went wrong while executing initial manifest"""
 | 
					    """Something went wrong while executing initial manifest"""
 | 
				
			||||||
    def __init__(self, initial_manifest, stdout_path, stderr_path, subject=''):
 | 
					    def __init__(self, initial_manifest, stdout_path, stderr_path, subject=''):
 | 
				
			||||||
        params = [
 | 
					        params = [
 | 
				
			||||||
            ('path', initial_manifest, ),
 | 
					            ('path', initial_manifest, ),
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
        stdout_paths = []
 | 
					 | 
				
			||||||
        stdout_paths = [
 | 
					        stdout_paths = [
 | 
				
			||||||
            ('init', stdout_path, ),
 | 
					            ('init', stdout_path, ),
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
        stderr_paths = []
 | 
					 | 
				
			||||||
        stderr_paths = [
 | 
					        stderr_paths = [
 | 
				
			||||||
            ('init', stderr_path, ),
 | 
					            ('init', stderr_path, ),
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
| 
						 | 
					@ -199,6 +222,20 @@ class InitialManifestError(CdistEntityError):
 | 
				
			||||||
                         stderr_paths, subject)
 | 
					                         stderr_paths, subject)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class GlobalExplorerError(CdistEntityError):
 | 
				
			||||||
 | 
					    """Something went wrong while executing global explorer"""
 | 
				
			||||||
 | 
					    def __init__(self, name, path, stderr_path, subject=''):
 | 
				
			||||||
 | 
					        params = [
 | 
				
			||||||
 | 
					            ('name', name, ),
 | 
				
			||||||
 | 
					            ('path', path, ),
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        stderr_paths = [
 | 
				
			||||||
 | 
					            ('remote', stderr_path, ),
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        super().__init__("global explorer '{}'".format(name),
 | 
				
			||||||
 | 
					                         params, [], stderr_paths, subject)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def file_to_list(filename):
 | 
					def file_to_list(filename):
 | 
				
			||||||
    """Return list from \n seperated file"""
 | 
					    """Return list from \n seperated file"""
 | 
				
			||||||
    if os.path.isfile(filename):
 | 
					    if os.path.isfile(filename):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -702,12 +702,11 @@ class Config(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def object_prepare(self, cdist_object, transfer_type_explorers=True):
 | 
					    def object_prepare(self, cdist_object, transfer_type_explorers=True):
 | 
				
			||||||
        """Prepare object: Run type explorer + manifest"""
 | 
					        """Prepare object: Run type explorer + manifest"""
 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
        self.log.verbose("Preparing object {}".format(cdist_object.name))
 | 
					        self.log.verbose("Preparing object {}".format(cdist_object.name))
 | 
				
			||||||
        self.log.verbose(
 | 
					        self.log.verbose(
 | 
				
			||||||
            "Running manifest and explorers for " + cdist_object.name)
 | 
					            "Running manifest and explorers for " + cdist_object.name)
 | 
				
			||||||
            self.explorer.run_type_explorers(cdist_object,
 | 
					        self.explorer.run_type_explorers(cdist_object, transfer_type_explorers)
 | 
				
			||||||
                                             transfer_type_explorers)
 | 
					        try:
 | 
				
			||||||
            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
 | 
				
			||||||
        except cdist.Error as e:
 | 
					        except cdist.Error as e:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -109,10 +109,17 @@ class Explorer(object):
 | 
				
			||||||
            self._run_global_explorers_parallel(out_path)
 | 
					            self._run_global_explorers_parallel(out_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _run_global_explorer(self, explorer, out_path):
 | 
					    def _run_global_explorer(self, explorer, out_path):
 | 
				
			||||||
        output = self.run_global_explorer(explorer)
 | 
					        try:
 | 
				
			||||||
            path = os.path.join(out_path, explorer)
 | 
					            path = os.path.join(out_path, explorer)
 | 
				
			||||||
 | 
					            output = self.run_global_explorer(explorer)
 | 
				
			||||||
            with open(path, 'w') as fd:
 | 
					            with open(path, 'w') as fd:
 | 
				
			||||||
                fd.write(output)
 | 
					                fd.write(output)
 | 
				
			||||||
 | 
					        except cdist.Error as e:
 | 
				
			||||||
 | 
					            local_path = os.path.join(self.local.global_explorer_path,
 | 
				
			||||||
 | 
					                                      explorer)
 | 
				
			||||||
 | 
					            stderr_path = os.path.join(self.local.stderr_base_path, "remote")
 | 
				
			||||||
 | 
					            raise cdist.GlobalExplorerError(explorer, local_path, stderr_path,
 | 
				
			||||||
 | 
					                                            e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _run_global_explorers_seq(self, out_path):
 | 
					    def _run_global_explorers_seq(self, out_path):
 | 
				
			||||||
        self.log.debug("Running global explorers sequentially")
 | 
					        self.log.debug("Running global explorers sequentially")
 | 
				
			||||||
| 
						 | 
					@ -186,11 +193,20 @@ class Explorer(object):
 | 
				
			||||||
        self.log.trace("Transferring object parameters for object: %s",
 | 
					        self.log.trace("Transferring object parameters for object: %s",
 | 
				
			||||||
                       cdist_object.name)
 | 
					                       cdist_object.name)
 | 
				
			||||||
        self.transfer_object_parameters(cdist_object)
 | 
					        self.transfer_object_parameters(cdist_object)
 | 
				
			||||||
        for explorer in self.list_type_explorer_names(cdist_object.cdist_type):
 | 
					        cdist_type = cdist_object.cdist_type
 | 
				
			||||||
            output = self.run_type_explorer(explorer, cdist_object)
 | 
					        for explorer in self.list_type_explorer_names(cdist_type):
 | 
				
			||||||
            self.log.trace("Running type explorer '%s' for object '%s'",
 | 
					            self.log.trace("Running type explorer '%s' for object '%s'",
 | 
				
			||||||
                           explorer, cdist_object.name)
 | 
					                           explorer, cdist_object.name)
 | 
				
			||||||
 | 
					            try:
 | 
				
			||||||
 | 
					                output = self.run_type_explorer(explorer, cdist_object)
 | 
				
			||||||
                cdist_object.explorers[explorer] = output
 | 
					                cdist_object.explorers[explorer] = output
 | 
				
			||||||
 | 
					            except cdist.Error as e:
 | 
				
			||||||
 | 
					                path = os.path.join(self.local.type_path,
 | 
				
			||||||
 | 
					                                    cdist_type.explorer_path,
 | 
				
			||||||
 | 
					                                    explorer)
 | 
				
			||||||
 | 
					                stderr_path = os.path.join(self.local.stderr_base_path, "remote")
 | 
				
			||||||
 | 
					                raise cdist.CdistObjectExplorerError(
 | 
				
			||||||
 | 
					                    cdist_object, explorer, path, stderr_path, e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def run_type_explorer(self, explorer, cdist_object):
 | 
					    def run_type_explorer(self, explorer, cdist_object):
 | 
				
			||||||
        """Run the given type explorer for the given object and return
 | 
					        """Run the given type explorer for the given object and return
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue