@@ -527,59 +527,61 @@ def discover_yamls(manifests, search_path, relative_path=None):
527527 manifest_dir = os .path .dirname (manifest ['file' ])
528528 for profile in manifest ['profiles' ]:
529529 profile ['yaml_files' ] = []
530- if isinstance (profile .get ('arguments' ), dict ):
531- for argument , value in profile ['arguments' ].items ():
532- if argument not in yaml_processors :
533- # Filter for only testbed and clean files. No need to
534- # load other yaml files
530+ if not isinstance (profile .get ('arguments' ), dict ):
531+ continue
532+ for argument , value in profile ['arguments' ].items ():
533+ if argument not in yaml_processors :
534+ # Filter for only testbed and clean files. No need to
535+ # load other yaml files
536+ continue
537+ if not (isinstance (value , str ) and value .lower ().endswith ('.yaml' )):
538+ continue
539+
540+ # Do not process any files that start with a variable
541+ # or some inaccessible absolute path. If the yaml file
542+ # starts with the relative path, it should be
543+ # accessible in the image, and still valid
544+ if value .startswith ('$' ):
545+ continue
546+ elif value .startswith ('/' ):
547+ if not relative_path or not value .startswith (relative_path ):
535548 continue
536549
537- if isinstance (value , str ) and value .endswith ('.yaml' ):
538- # Do not process any files that start with a variable
539- # or some inaccessible absolute path. If the yaml file
540- # starts with the relative path, it should be
541- # accessible in the image, and still valid
542- if value .startswith ('$' ):
543- continue
544- elif value .startswith ('/' ):
545- if not relative_path or not value .startswith (relative_path ):
546- continue
547-
548- # Construct an absolute path using the dir of the manifest
549- # This will be the relative path to the image root once
550- # built, not the actual path of the file in the build
551- # environment
552- yaml_file = os .path .abspath (os .path .join (manifest_dir , value ))
553- # Convert to a real path so we can find the file in our
554- # build environment
555- if relative_path :
556- yaml_file = to_image_path (yaml_file , relative_path , search_path )
557- if os .path .isfile (yaml_file ):
558- try :
559- with open (yaml_file ) as f :
560- # load yaml contents with handling for an
561- # empty file
562- yaml_contents = yaml .safe_load (f .read ()) or {}
563- except Exception as e :
564- msg = f'Error loading YAML file { value } from ' \
565- f'manifest { manifest ["file" ]} '
566- logger .exception (msg )
567- continue
568- else :
569- # YAML file relative path from manifest does not
570- # exist.
571- msg = f'Could not find YAML file { value } from ' \
572- f'manifest { manifest ["file" ]} '
573- logger .warning (msg )
574-
575- processor = yaml_processors .get (argument )
576- if processor :
577- try :
578- processor (profile , yaml_contents )
579- except Exception as e :
580- # Problem processing the specific type of YAML file
581- msg = f'Error processing { argument } { value } from ' \
582- f'manifest { manifest ["file" ]} '
583- logger .exception (msg )
550+ # Construct an absolute path using the dir of the manifest
551+ # This will be the relative path to the image root once
552+ # built, not the actual path of the file in the build
553+ # environment
554+ yaml_file = os .path .abspath (os .path .join (manifest_dir , value ))
555+ # Convert to a real path so we can find the file in our
556+ # build environment
557+ if relative_path :
558+ yaml_file = to_image_path (yaml_file , relative_path , search_path )
559+ if os .path .isfile (yaml_file ):
560+ try :
561+ with open (yaml_file ) as f :
562+ # load yaml contents with handling for an
563+ # empty file
564+ yaml_contents = yaml .safe_load (f .read ()) or {}
565+ except Exception as e :
566+ msg = f'Error loading YAML file { value } from ' \
567+ f'manifest { manifest ["file" ]} '
568+ logger .exception (msg )
569+ continue
570+ else :
571+ # YAML file relative path from manifest does not
572+ # exist.
573+ msg = f'Could not find YAML file { value } from ' \
574+ f'manifest { manifest ["file" ]} '
575+ logger .warning (msg )
576+
577+ processor = yaml_processors .get (argument )
578+ if processor :
579+ try :
580+ processor (profile , yaml_contents )
581+ except Exception as e :
582+ # Problem processing the specific type of YAML file
583+ msg = f'Error processing { argument } { value } from ' \
584+ f'manifest { manifest ["file" ]} '
585+ logger .exception (msg )
584586
585587 return manifests
0 commit comments