Refactor init manifest error handling.
This commit is contained in:
parent
0f1fa4c041
commit
7ebd69dcac
3 changed files with 15 additions and 12 deletions
|
@ -141,8 +141,8 @@ class InitialManifestError(Error):
|
||||||
@property
|
@property
|
||||||
def stderr(self):
|
def stderr(self):
|
||||||
output = []
|
output = []
|
||||||
label = "init" + ':stderr '
|
|
||||||
if os.path.getsize(self.stderr_path) > 0:
|
if os.path.getsize(self.stderr_path) > 0:
|
||||||
|
label = "init" + ':stderr '
|
||||||
output.append('{0:-<{1}}'.format(label, self.line_length))
|
output.append('{0:-<{1}}'.format(label, self.line_length))
|
||||||
with open(self.stderr_path, 'r') as fd:
|
with open(self.stderr_path, 'r') as fd:
|
||||||
output.append(fd.read())
|
output.append(fd.read())
|
||||||
|
@ -152,7 +152,7 @@ class InitialManifestError(Error):
|
||||||
output = []
|
output = []
|
||||||
output.append(self.message)
|
output.append(self.message)
|
||||||
output.append('''{label:-<{length}}
|
output.append('''{label:-<{length}}
|
||||||
initial manifest: {im}'''.format(
|
path: {im}'''.format(
|
||||||
label='---- initial manifest ',
|
label='---- initial manifest ',
|
||||||
length=self.line_length,
|
length=self.line_length,
|
||||||
im=self.initial_manifest)
|
im=self.initial_manifest)
|
||||||
|
|
|
@ -403,7 +403,14 @@ class Config(object):
|
||||||
self._init_files_dirs()
|
self._init_files_dirs()
|
||||||
|
|
||||||
self.explorer.run_global_explorers(self.local.global_explorer_out_path)
|
self.explorer.run_global_explorers(self.local.global_explorer_out_path)
|
||||||
self.manifest.run_initial_manifest(self.local.initial_manifest)
|
try:
|
||||||
|
self.manifest.run_initial_manifest(self.local.initial_manifest)
|
||||||
|
except cdist.Error as e:
|
||||||
|
which = "init"
|
||||||
|
stdout_path = os.path.join(self.local.stdout_base_path, which)
|
||||||
|
stderr_path = os.path.join(self.local.stderr_base_path, which)
|
||||||
|
raise cdist.InitialManifestError(self.local.initial_manifest,
|
||||||
|
stdout_path, stderr_path, e)
|
||||||
self.iterate_until_finished()
|
self.iterate_until_finished()
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
self._remove_files_dirs()
|
self._remove_files_dirs()
|
||||||
|
|
|
@ -158,15 +158,11 @@ class Manifest(object):
|
||||||
stdout_path = os.path.join(self.local.stdout_base_path, which)
|
stdout_path = os.path.join(self.local.stdout_base_path, which)
|
||||||
with open(stderr_path, 'ba+') as stderr, \
|
with open(stderr_path, 'ba+') as stderr, \
|
||||||
open(stdout_path, 'ba+') as stdout:
|
open(stdout_path, 'ba+') as stdout:
|
||||||
try:
|
self.local.run_script(
|
||||||
self.local.run_script(
|
initial_manifest,
|
||||||
initial_manifest,
|
env=self.env_initial_manifest(initial_manifest),
|
||||||
env=self.env_initial_manifest(initial_manifest),
|
message_prefix=message_prefix,
|
||||||
message_prefix=message_prefix,
|
stdout=stdout, stderr=stderr)
|
||||||
stdout=stdout, stderr=stderr)
|
|
||||||
except cdist.Error as e:
|
|
||||||
raise cdist.InitialManifestError(initial_manifest, stdout_path,
|
|
||||||
stderr_path, e)
|
|
||||||
|
|
||||||
def env_type_manifest(self, cdist_object):
|
def env_type_manifest(self, cdist_object):
|
||||||
type_manifest = os.path.join(self.local.type_path,
|
type_manifest = os.path.join(self.local.type_path,
|
||||||
|
|
Loading…
Reference in a new issue