def check_metadata()

in scripts/dashboard/validate_dashboards_format.py [0:0]


def check_metadata(directory, path_map):
  '''Make following assertions about metadata.yam files:
      * At least 1 sample dashboard exists
      * Each dashboard entry has all required fields
      * Each dashboard entry has a corresponding json template with same name & id
      
    note: this function mutates the path_map dictionary'''
  path = os.path.join('.', 'dashboards', directory, 'metadata.yaml')

  with open(path) as f:
    data = yaml.safe_load(f)
  sample_dashboards = data.get("sample_dashboards")
  if not sample_dashboards:
    raise MetadataFormattingError("sample_dashboards not defined in {}".format(path))
  for sample_dashboard in sample_dashboards:
    # Call function to check metadata file fields
    check_metadata_entries(path, sample_dashboard)

    dashboard_id = sample_dashboard.get('id')
    dashboard_name = sample_dashboard.get('display_name')

    path_map[directory]['metadata'][dashboard_id] = dashboard_name

    if not dashboard_id in path_map[directory]['json_data']:
      raise MetadataInJsonMisMatchError("{} does not have a matching json file".format(dashboard_id))
    
    if not dashboard_name == path_map[directory]['json_data'][dashboard_id]:
      raise MetadataInJsonMisMatchError("{} does not have a matching json file".format(dashboard_name))