Revision 35007011 lib/backend.py

b/lib/backend.py
2051 2051
    return False, ("API version mismatch for path '%s': found %s, want %s." %
2052 2052
                   (os_dir, api_versions, constants.OS_API_VERSIONS))
2053 2053

  
2054
  # OS Files dictionary, we will populate it with the absolute path names
2055
  os_files = dict.fromkeys(constants.OS_SCRIPTS)
2054
  # OS Files dictionary, we will populate it with the absolute path
2055
  # names; if the value is True, then it is a required file, otherwise
2056
  # an optional one
2057
  os_files = dict.fromkeys(constants.OS_SCRIPTS, True)
2056 2058

  
2057 2059
  if max(api_versions) >= constants.OS_API_V15:
2058
    os_files[constants.OS_VARIANTS_FILE] = ""
2060
    os_files[constants.OS_VARIANTS_FILE] = False
2059 2061

  
2060 2062
  if max(api_versions) >= constants.OS_API_V20:
2061
    os_files[constants.OS_PARAMETERS_FILE] = ""
2063
    os_files[constants.OS_PARAMETERS_FILE] = True
2062 2064
  else:
2063 2065
    del os_files[constants.OS_SCRIPT_VERIFY]
2064 2066

  
2065
  for filename in os_files:
2067
  for (filename, required) in os_files.items():
2066 2068
    os_files[filename] = utils.PathJoin(os_dir, filename)
2067 2069

  
2068 2070
    try:
2069 2071
      st = os.stat(os_files[filename])
2070 2072
    except EnvironmentError, err:
2073
      if err.errno == errno.ENOENT and not required:
2074
        del os_files[filename]
2075
        continue
2071 2076
      return False, ("File '%s' under path '%s' is missing (%s)" %
2072 2077
                     (filename, os_dir, _ErrnoOrStr(err)))
2073 2078

  
......
2086 2091
    try:
2087 2092
      variants = utils.ReadFile(variants_file).splitlines()
2088 2093
    except EnvironmentError, err:
2089
      return False, ("Error while reading the OS variants file at %s: %s" %
2090
                     (variants_file, _ErrnoOrStr(err)))
2091
    if not variants:
2092
      return False, ("No supported os variant found")
2094
      # we accept missing files, but not other errors
2095
      if err.errno != errno.ENOENT:
2096
        return False, ("Error while reading the OS variants file at %s: %s" %
2097
                       (variants_file, _ErrnoOrStr(err)))
2093 2098

  
2094 2099
  parameters = []
2095 2100
  if constants.OS_PARAMETERS_FILE in os_files:
......
2166 2171
  result["DEBUG_LEVEL"] = "%d" % debug
2167 2172

  
2168 2173
  # OS variants
2169
  if api_version >= constants.OS_API_V15:
2174
  if api_version >= constants.OS_API_V15 and inst_os.supported_variants:
2170 2175
    variant = objects.OS.GetVariant(os_name)
2171 2176
    if not variant:
2172 2177
      variant = inst_os.supported_variants[0]
2173
    result["OS_VARIANT"] = variant
2178
  else:
2179
    variant = ""
2180
  result["OS_VARIANT"] = variant
2174 2181

  
2175 2182
  # OS params
2176 2183
  for pname, pvalue in os_params.items():

Also available in: Unified diff