• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# This file contains utility functions to get and set stable versions for given
6# boards.
7
8import common
9import logging
10import django.core.exceptions
11from autotest_lib.client.common_lib import global_config
12from autotest_lib.frontend import setup_django_environment
13from autotest_lib.frontend.afe import models
14
15
16# Name of the default board. For boards that don't have stable version
17# explicitly set, version for the default board will be used.
18DEFAULT = 'DEFAULT'
19
20# Type of metadata to store stable_version changes.
21_STABLE_VERSION_TYPE = 'stable_version'
22
23def get_all():
24    """Get stable versions of all boards.
25
26    @return: A dictionary of boards and stable versions.
27    """
28    versions = dict([(v.board, v.version)
29                     for v in models.StableVersion.objects.all()])
30    # Set default to the global config value of CROS.stable_cros_version if
31    # there is no entry in afe_stable_versions table.
32    if not versions:
33        versions = {DEFAULT: global_config.global_config.get_config_value(
34                            'CROS', 'stable_cros_version')}
35    return versions
36
37
38def get(board=DEFAULT):
39    """Get stable version for the given board.
40
41    @param board: Name of the board, default to value `DEFAULT`.
42
43    @return: Stable version of the given board. If the given board is not listed
44             in afe_stable_versions table, DEFAULT will be used.
45             Return global_config value of CROS.stable_cros_version if
46             afe_stable_versions table does not have entry of board DEFAULT.
47    """
48    try:
49        return models.StableVersion.objects.get(board=board).version
50    except django.core.exceptions.ObjectDoesNotExist:
51        if board == DEFAULT:
52            return global_config.global_config.get_config_value(
53                    'CROS', 'stable_cros_version')
54        else:
55            return get(board=DEFAULT)
56
57
58def set(version, board=DEFAULT):
59    """Set stable version for the given board.
60
61    @param version: The new value of stable version for given board.
62    @param board: Name of the board, default to value `DEFAULT`.
63    """
64
65    logging.warning("stable_version_utils::set: attmpted to set stable version. setting the stable version is not permitted")
66    return None
67
68
69def delete(board):
70    """Delete stable version record for the given board.
71
72    @param board: Name of the board.
73    """
74    logging.warning("stable_version_utils::set: attmpted to delete stable version. deleting the stable version is not permitted")
75    return None
76