forked from ungleich-public/cdist
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)
|
||||
|
||||
|
||||
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):
|
||||
"""Something went wrong while executing initial manifest"""
|
||||
def __init__(self, initial_manifest, stdout_path, stderr_path, subject=''):
|
||||
params = [
|
||||
('path', initial_manifest, ),
|
||||
]
|
||||
stdout_paths = []
|
||||
stdout_paths = [
|
||||
('init', stdout_path, ),
|
||||
]
|
||||
stderr_paths = []
|
||||
stderr_paths = [
|
||||
('init', stderr_path, ),
|
||||
]
|
||||
|
@ -199,6 +222,20 @@ class InitialManifestError(CdistEntityError):
|
|||
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):
|
||||
"""Return list from \n seperated file"""
|
||||
if os.path.isfile(filename):
|
||||
|
|
|
@ -702,12 +702,11 @@ class Config(object):
|
|||
|
||||
def object_prepare(self, cdist_object, transfer_type_explorers=True):
|
||||
"""Prepare object: Run type explorer + manifest"""
|
||||
self.log.verbose("Preparing object {}".format(cdist_object.name))
|
||||
self.log.verbose(
|
||||
"Running manifest and explorers for " + cdist_object.name)
|
||||
self.explorer.run_type_explorers(cdist_object, transfer_type_explorers)
|
||||
try:
|
||||
self.log.verbose("Preparing object {}".format(cdist_object.name))
|
||||
self.log.verbose(
|
||||
"Running manifest and explorers for " + cdist_object.name)
|
||||
self.explorer.run_type_explorers(cdist_object,
|
||||
transfer_type_explorers)
|
||||
self.manifest.run_type_manifest(cdist_object)
|
||||
cdist_object.state = core.CdistObject.STATE_PREPARED
|
||||
except cdist.Error as e:
|
||||
|
|
|
@ -109,10 +109,17 @@ class Explorer(object):
|
|||
self._run_global_explorers_parallel(out_path)
|
||||
|
||||
def _run_global_explorer(self, explorer, out_path):
|
||||
output = self.run_global_explorer(explorer)
|
||||
path = os.path.join(out_path, explorer)
|
||||
with open(path, 'w') as fd:
|
||||
fd.write(output)
|
||||
try:
|
||||
path = os.path.join(out_path, explorer)
|
||||
output = self.run_global_explorer(explorer)
|
||||
with open(path, 'w') as fd:
|
||||
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):
|
||||
self.log.debug("Running global explorers sequentially")
|
||||
|
@ -186,11 +193,20 @@ class Explorer(object):
|
|||
self.log.trace("Transferring object parameters for object: %s",
|
||||
cdist_object.name)
|
||||
self.transfer_object_parameters(cdist_object)
|
||||
for explorer in self.list_type_explorer_names(cdist_object.cdist_type):
|
||||
output = self.run_type_explorer(explorer, cdist_object)
|
||||
cdist_type = cdist_object.cdist_type
|
||||
for explorer in self.list_type_explorer_names(cdist_type):
|
||||
self.log.trace("Running type explorer '%s' for object '%s'",
|
||||
explorer, cdist_object.name)
|
||||
cdist_object.explorers[explorer] = output
|
||||
try:
|
||||
output = self.run_type_explorer(explorer, cdist_object)
|
||||
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):
|
||||
"""Run the given type explorer for the given object and return
|
||||
|
|
Loading…
Reference in a new issue