Skip to content

Commit a95a86e

Browse files
authored
Merge pull request #45 from CiscoTestAutomation/bastell-manifest_error_handling
Add exception handling for processing manifests
2 parents 46dcf21 + 365ac1e commit a95a86e

File tree

1 file changed

+58
-52
lines changed

1 file changed

+58
-52
lines changed

src/pyatsimagebuilder/utils.py

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -415,59 +415,65 @@ def discover_manifests(search_path, ignore_folders=None, relative_path=None,
415415
logger.warning(f'No manifest data from file {manifest}')
416416
continue
417417

418-
if relative_path:
419-
manifest_data['file'] = to_image_path(str(manifest),
420-
search_path,
421-
relative_path)
422-
else:
423-
manifest_data['file'] = str(manifest)
424-
425-
# Find any repo containing this manifest file
426-
for repo in repo_data:
427-
if manifest_data['file'].startswith(repo):
428-
manifest_data['repo_path'] = repo
429-
break
430-
431-
manifest_data['run_type'] = 'manifest'
432-
manifest_data['job_type'] = manifest_data.pop('type', None)
433-
if not manifest_data['job_type']:
434-
logger.warning(f'No job type specified in {manifest}')
435-
continue
418+
try:
419+
if relative_path:
420+
manifest_data['file'] = to_image_path(str(manifest),
421+
search_path,
422+
relative_path)
423+
else:
424+
manifest_data['file'] = str(manifest)
425+
426+
# Find any repo containing this manifest file
427+
for repo in repo_data:
428+
if manifest_data['file'].startswith(repo):
429+
manifest_data['repo_path'] = repo
430+
break
431+
432+
manifest_data['run_type'] = 'manifest'
433+
manifest_data['job_type'] = manifest_data.pop('type', None)
434+
if not manifest_data['job_type']:
435+
logger.warning(f'No job type specified in {manifest}')
436+
continue
436437

437-
# Pop runtimes and profiles to add them back later as lists
438-
runtimes = manifest_data.pop('runtimes', {})
439-
profiles = manifest_data.pop('profiles', {})
440-
441-
# Create default profile from top level arguments and system environment
442-
default_arguments = manifest_data.pop('arguments', {})
443-
default_runtime = runtimes.get('system', {})
444-
default_environment = default_runtime.get('environment', {})
445-
profiles['DEFAULT'] = {}
446-
profiles['DEFAULT']['runtime'] = 'system'
447-
profiles['DEFAULT']['arguments'] = default_arguments
448-
profiles['DEFAULT']['environment'] = default_environment
449-
450-
# Update profiles with environment from runtimes
451-
for profile_name in profiles:
452-
runtime = profiles[profile_name].get('runtime', 'system')
453-
if runtime in runtimes:
454-
environment = runtimes[runtime].get('environment', {})
455-
if environment:
456-
profiles[profile_name]['environment'] = environment
457-
458-
# Convert profiles from hierarchical dict to list of dict
459-
manifest_data['profiles'] = []
460-
for profile_name in profiles:
461-
manifest_data['profiles'].append(profiles[profile_name])
462-
manifest_data['profiles'][-1]['name'] = profile_name
463-
464-
# Convert runtimes from hierarchical dict to list of dict
465-
manifest_data['runtimes'] = []
466-
for profile_name in runtimes:
467-
manifest_data['runtimes'].append(runtimes[profile_name])
468-
manifest_data['runtimes'][-1]['name'] = profile_name
469-
470-
jobs.append(manifest_data)
438+
# Pop runtimes and profiles to add them back later as lists
439+
runtimes = manifest_data.pop('runtimes', {})
440+
profiles = manifest_data.pop('profiles', {})
441+
442+
# Create default profile from top level arguments and system environment
443+
default_arguments = manifest_data.pop('arguments', {})
444+
default_runtime = runtimes.get('system', {})
445+
default_environment = default_runtime.get('environment', {})
446+
profiles['DEFAULT'] = {}
447+
profiles['DEFAULT']['runtime'] = 'system'
448+
profiles['DEFAULT']['arguments'] = default_arguments
449+
profiles['DEFAULT']['environment'] = default_environment
450+
451+
# Update profiles with environment from runtimes
452+
for profile_name in profiles:
453+
runtime = profiles[profile_name].get('runtime', 'system')
454+
if runtime in runtimes:
455+
environment = runtimes[runtime].get('environment', {})
456+
if environment:
457+
profiles[profile_name]['environment'] = environment
458+
459+
# Convert profiles from hierarchical dict to list of dict
460+
manifest_data['profiles'] = []
461+
for profile_name in profiles:
462+
manifest_data['profiles'].append(profiles[profile_name])
463+
manifest_data['profiles'][-1]['name'] = profile_name
464+
465+
# Convert runtimes from hierarchical dict to list of dict
466+
manifest_data['runtimes'] = []
467+
for profile_name in runtimes:
468+
manifest_data['runtimes'].append(runtimes[profile_name])
469+
manifest_data['runtimes'][-1]['name'] = profile_name
470+
471+
jobs.append(manifest_data)
472+
473+
except Exception:
474+
logger.error('Error processing manifest file {}\n{}'.format(
475+
manifest, str(e)))
476+
continue
471477

472478
logger.info('Number of discovered manifest files: %s' % \
473479
len(discovered_manifests))

0 commit comments

Comments
 (0)