1#!/usr/bin/python2 2# Copyright 2017 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Unittests for the lsbrelease_utils module.""" 7 8import unittest 9 10import common 11from autotest_lib.client.common_lib import lsbrelease_utils 12 13 14# pylint: disable=line-too-long 15_GUADO_MOBLAB_LSB_RELEASE_REDACTED = """ 16DEVICETYPE=CHROMEBOX 17CHROMEOS_RELEASE_BUILDER_PATH=guado_moblab-release/R61-9641.0.0 18GOOGLE_RELEASE=9641.0.0 19CHROMEOS_DEVSERVER= 20CHROMEOS_RELEASE_BOARD=guado_moblab 21CHROMEOS_RELEASE_BUILD_NUMBER=9641 22CHROMEOS_RELEASE_BRANCH_NUMBER=0 23CHROMEOS_RELEASE_CHROME_MILESTONE=61 24CHROMEOS_RELEASE_PATCH_NUMBER=0 25CHROMEOS_RELEASE_TRACK=testimage-channel 26CHROMEOS_RELEASE_DESCRIPTION=9641.0.0 (Official Build) dev-channel guado_moblab test 27CHROMEOS_RELEASE_BUILD_TYPE=Official Build 28CHROMEOS_RELEASE_NAME=Chrome OS 29CHROMEOS_RELEASE_VERSION=9641.0.0 30CHROMEOS_AUSERVER=https://tools.google.com/service/update2 31""" 32 33_LINK_LSB_RELEASE_REDACTED = """ 34DEVICETYPE=CHROMEBOOK 35CHROMEOS_RELEASE_BUILDER_PATH=link-release/R61-9641.0.0 36GOOGLE_RELEASE=9641.0.0 37CHROMEOS_DEVSERVER= 38CHROMEOS_RELEASE_BOARD=link 39CHROMEOS_RELEASE_BUILD_NUMBER=9641 40CHROMEOS_RELEASE_BRANCH_NUMBER=0 41CHROMEOS_RELEASE_CHROME_MILESTONE=61 42CHROMEOS_RELEASE_PATCH_NUMBER=0 43CHROMEOS_RELEASE_TRACK=testimage-channel 44CHROMEOS_RELEASE_DESCRIPTION=9641.0.0 (Official Build) dev-channel link test 45CHROMEOS_RELEASE_BUILD_TYPE=Official Build 46CHROMEOS_RELEASE_NAME=Chrome OS 47CHROMEOS_RELEASE_VERSION=9641.0.0 48CHROMEOS_AUSERVER=https://tools.google.com/service/update2 49""" 50 51_GALE_LSB_RELEASE_REDACTED = """ 52DEVICETYPE=OTHER 53HWID_OVERRIDE=GALE DOGFOOD 54CHROMEOS_RELEASE_BUILDER_PATH=gale-release/R61-9641.0.0 55GOOGLE_RELEASE=9641.0.0 56CHROMEOS_DEVSERVER= 57CHROMEOS_RELEASE_BOARD=gale 58CHROMEOS_RELEASE_BUILD_NUMBER=9641 59CHROMEOS_RELEASE_BRANCH_NUMBER=0 60CHROMEOS_RELEASE_CHROME_MILESTONE=61 61CHROMEOS_RELEASE_PATCH_NUMBER=0 62CHROMEOS_RELEASE_TRACK=testimage-channel 63CHROMEOS_RELEASE_DESCRIPTION=9641.0.0 (Official Build) dev-channel gale test 64CHROMEOS_RELEASE_BUILD_TYPE=Official Build 65CHROMEOS_RELEASE_NAME=Chrome OS 66CHROMEOS_RELEASE_VERSION=9641.0.0 67CHROMEOS_AUSERVER=https://tools.google.com/service/update2 68""" 69 70# pylint: disable=line-too-long 71_WHIRLWIND_LSB_RELEASE_REDACTED = """ 72DEVICETYPE=OTHER 73HWID_OVERRIDE=WHIRLWIND DOGFOOD 74CHROMEOS_RELEASE_BUILDER_PATH=whirlwind-release/R61-9641.0.0 75GOOGLE_RELEASE=9641.0.0 76CHROMEOS_DEVSERVER= 77CHROMEOS_RELEASE_BOARD=whirlwind 78CHROMEOS_RELEASE_BUILD_NUMBER=9641 79CHROMEOS_RELEASE_BRANCH_NUMBER=0 80CHROMEOS_RELEASE_CHROME_MILESTONE=61 81CHROMEOS_RELEASE_PATCH_NUMBER=0 82CHROMEOS_RELEASE_TRACK=testimage-channel 83CHROMEOS_RELEASE_DESCRIPTION=9641.0.0 (Official Build) dev-channel whirlwind test 84CHROMEOS_RELEASE_BUILD_TYPE=Official Build 85CHROMEOS_RELEASE_NAME=Chrome OS 86CHROMEOS_RELEASE_VERSION=9641.0.0 87CHROMEOS_AUSERVER=https://tools.google.com/service/update2 88""" 89 90 91class LsbreleaseUtilsTestCase(unittest.TestCase): 92 """Validates the helper free functions in lsbrelease_utils.""" 93 94 def test_is_jetstream_with_link_lsbrelease(self): 95 """Test helper function.""" 96 self.assertFalse(lsbrelease_utils.is_jetstream( 97 _LINK_LSB_RELEASE_REDACTED)) 98 99 def test_is_jetstream_with_moblab_lsbrelease(self): 100 """Test helper function.""" 101 self.assertFalse(lsbrelease_utils.is_jetstream( 102 _GUADO_MOBLAB_LSB_RELEASE_REDACTED)) 103 104 def test_is_jestream_with_gale_lsbrelease(self): 105 """Test helper function.""" 106 self.assertTrue(lsbrelease_utils.is_jetstream( 107 _GALE_LSB_RELEASE_REDACTED)) 108 109 def test_is_jestream_with_whirlwind_lsbrelease(self): 110 """Test helper function.""" 111 self.assertTrue(lsbrelease_utils.is_jetstream( 112 _WHIRLWIND_LSB_RELEASE_REDACTED)) 113 114 def test_is_moblab_with_empty_lsbrelease(self): 115 """is_moblab correctly validates trivial lsb-release information.""" 116 self.assertFalse(lsbrelease_utils.is_moblab('')) 117 118 def test_is_moblab_with_link_lsbrelease(self): 119 """is_moblab correctly validates the contents from some other board.""" 120 self.assertFalse(lsbrelease_utils.is_moblab( 121 _LINK_LSB_RELEASE_REDACTED)) 122 123 def test_is_moblab_with_moblab_lsbrelease(self): 124 """is_moblab correctly validates the contents from a moblab device.""" 125 self.assertTrue(lsbrelease_utils.is_moblab( 126 _GUADO_MOBLAB_LSB_RELEASE_REDACTED)) 127 128 def test_get_chromeos_release_version(self): 129 """Test helper function.""" 130 result = lsbrelease_utils.get_chromeos_release_builder_path( 131 _GUADO_MOBLAB_LSB_RELEASE_REDACTED) 132 133 self.assertEqual(result, 'guado_moblab-release/R61-9641.0.0') 134 135 136if __name__ == '__main__': 137 unittest.main() 138