blob: 0477c340979662fcfaaeb9f55ec8788c9382ec0c [file] [log] [blame]
# Copyright 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This file contains utility functions to get and set stable versions for given
# boards.
import common
import django.core.exceptions
from autotest_lib.client.common_lib import global_config
from autotest_lib.client.common_lib.cros.graphite import autotest_es
from autotest_lib.frontend import setup_django_environment
from autotest_lib.frontend.afe import models
# Name of the default board. For boards that don't have stable version
# explicitly set, version for the default board will be used.
# Type of metadata to store stable_version changes.
_STABLE_VERSION_TYPE = 'stable_version'
def get_all():
"""Get stable versions of all boards.
@return: A dictionary of boards and stable versions.
versions = dict([(v.board, v.version)
for v in models.StableVersion.objects.all()])
# Set default to the global config value of CROS.stable_cros_version if
# there is no entry in afe_stable_versions table.
if not versions:
versions = {DEFAULT: global_config.global_config.get_config_value(
'CROS', 'stable_cros_version')}
return versions
def get(board=DEFAULT, android=False):
"""Get stable version for the given board.
@param board: Name of the board, default to value `DEFAULT`.
@param android: If True, indicates we are looking up a Android/Brillo-based
board. There is no default version that works for all
Android/Brillo boards. If False, we are looking up a Chrome
OS based board.
@return: Stable version of the given board. If the given board is not listed
in afe_stable_versions table, DEFAULT will be used.
Return global_config value of CROS.stable_cros_version if
afe_stable_versions table does not have entry of board DEFAULT.
if board == DEFAULT and android:
return None
return models.StableVersion.objects.get(board=board).version
except django.core.exceptions.ObjectDoesNotExist:
if board == DEFAULT:
return global_config.global_config.get_config_value(
'CROS', 'stable_cros_version')
elif android:
return global_config.global_config.get_config_value(
'ANDROID', 'stable_version_%s' % board, default=None)
return get(board=DEFAULT)
def set(version, board=DEFAULT):
"""Set stable version for the given board.
@param version: The new value of stable version for given board.
@param board: Name of the board, default to value `DEFAULT`.
stable_version = models.StableVersion.objects.get(board=board)
stable_version.version = version
except django.core.exceptions.ObjectDoesNotExist:
models.StableVersion.objects.create(board=board, version=version),
metadata={'board': board, 'version': version})
def delete(board):
"""Delete stable version record for the given board.
@param board: Name of the board.
stable_version = models.StableVersion.objects.get(board=board)
metadata={'board': board, 'version': get()})