diff options
author | Ari Hausman-Cohen <arihc@google.com> | 2016-05-10 11:37:38 -0700 |
---|---|---|
committer | Ari Hausman-Cohen <arihc@google.com> | 2016-05-10 11:37:38 -0700 |
commit | f104ad1f86fb348dea97541382d5fa16fdb7033f (patch) | |
tree | bfc27e585260ed75eeb6a809db5029027333fd58 | |
parent | 567e5d85d6ca03464b4b0804a4fe86a470d9f488 (diff) | |
download | bdk-f104ad1f86fb348dea97541382d5fa16fdb7033f.tar.gz |
Adds os_root user config setting.
BUG: 28666685
TEST: unit tests pass, os_root shows up for 'bdk config' commands,
confirmed other BDK commands still work.
Change-Id: If33efed3006fd32ac0837e1be33fe1e3230b3799
-rw-r--r-- | cli/lib/bsp/operating_system.py | 5 | ||||
-rw-r--r-- | cli/lib/bsp/operating_system_unittest.py | 37 | ||||
-rw-r--r-- | cli/lib/core/user_config.py | 8 | ||||
-rw-r--r-- | cli/lib/core/user_config_stub.py | 4 | ||||
-rw-r--r-- | cli/lib/core/user_config_unittest.py | 10 |
5 files changed, 43 insertions, 21 deletions
diff --git a/cli/lib/bsp/operating_system.py b/cli/lib/bsp/operating_system.py index 7c39692..1549620 100644 --- a/cli/lib/bsp/operating_system.py +++ b/cli/lib/bsp/operating_system.py @@ -21,6 +21,7 @@ import os import re +from core import user_config from core import util import error @@ -98,6 +99,4 @@ class OperatingSystem(object): def init_default_operating_system(): """Gets a new object representing the default OS.""" - # For now, the BDK is actually under the OS at <os>/tools/bdk, - # so we can figure out where the OS is based on that. - return OperatingSystem('brillo', util.GetBDKPath('..', '..')) + return OperatingSystem('brillo', user_config.USER_CONFIG.os_root) diff --git a/cli/lib/bsp/operating_system_unittest.py b/cli/lib/bsp/operating_system_unittest.py index 041ce25..c8c1a77 100644 --- a/cli/lib/bsp/operating_system_unittest.py +++ b/cli/lib/bsp/operating_system_unittest.py @@ -21,6 +21,7 @@ import unittest from bsp import operating_system +from core import user_config_stub from core import util_stub from test import stubs @@ -29,59 +30,67 @@ class OperatingSystemTest(unittest.TestCase): _OS = 'os_name' _OS_VERSION = '99.11.00' - _OS_PATH = '/stuff/path' + _OS_ROOT = '/stuff/path' # Should not match any other version used above. _BAD_VERSION = '0.0' - # For now, needs to be 2 dirs within _OS_PATH. - _BDK_PATH = '/stuff/path/tools/bdk' - def setUp(self): self.stub_os = stubs.StubOs() self.stub_open = stubs.StubOpen(self.stub_os) - self.stub_util = util_stub.StubUtil(bdk_path=self._BDK_PATH) + self.stub_user_config = user_config_stub.StubUserConfig( + os_root=self._OS_ROOT) + self.stub_util = util_stub.StubUtil() operating_system.os = self.stub_os operating_system.open = self.stub_open.open + operating_system.user_config = self.stub_user_config operating_system.util = self.stub_util self.version_file_path = self.stub_os.path.join( - self._BDK_PATH, 'VERSION') + self._OS_ROOT, 'tools', 'bdk', 'VERSION') self.stub_os.path.should_exist = [self.version_file_path] self.stub_open.files[self.version_file_path] = stubs.StubFile( self._OS_VERSION) self.os = operating_system.OperatingSystem(name=self._OS, - root=self._OS_PATH) + root=self._OS_ROOT) def test_init_valid(self): # Check that values initialized correctly. self.assertEqual(self.os.name, self._OS) - self.assertEqual(self.os.root, self._OS_PATH) + self.assertEqual(self.os.root, self._OS_ROOT) self.assertEqual(self.os.version, self._OS_VERSION) def test_init_missing_version(self): self.stub_os.path.should_exist = [] with self.assertRaises(operating_system.VersionError): - operating_system.OperatingSystem(name=self._OS, root=self._OS_PATH) + operating_system.OperatingSystem(name=self._OS, root=self._OS_ROOT) def test_init_bad_version(self): self.stub_open.files[self.version_file_path].contents = 'not_a_version' with self.assertRaises(operating_system.VersionError): - operating_system.OperatingSystem(name=self._OS, root=self._OS_PATH) + operating_system.OperatingSystem(name=self._OS, root=self._OS_ROOT) def test_path(self): - self.assertEqual(self.os.path(), self._OS_PATH) + self.assertEqual(self.os.path(), self._OS_ROOT) self.assertEqual(self.os.path('sub', 'path'), - self.stub_os.path.join(self._OS_PATH, 'sub', 'path')) + self.stub_os.path.join(self._OS_ROOT, 'sub', 'path')) def test_is_available(self): self.stub_os.path.should_be_dir = [] self.assertFalse(self.os.is_available()) - self.stub_os.path.should_be_dir = [self._OS_PATH] + self.stub_os.path.should_be_dir = [self._OS_ROOT] self.assertTrue(self.os.is_available()) def test_default_os(self): os = operating_system.init_default_operating_system() self.assertEqual(os.name, 'brillo') - self.assertEqual(os.root, self._OS_PATH) + self.assertEqual(os.root, self._OS_ROOT) self.assertEqual(os.version, self._OS_VERSION) + + def test_default_from_config(self): + """Confirm the default OS is using the value from user_config.""" + self.stub_user_config.USER_CONFIG.os_root = 'root_is_elsewhere' + # Should complain about missing version file. + with self.assertRaisesRegexp(operating_system.VersionError, + 'root_is_elsewhere/tools/bdk/VERSION'): + operating_system.init_default_operating_system() diff --git a/cli/lib/core/user_config.py b/cli/lib/core/user_config.py index 768c63d..612afee 100644 --- a/cli/lib/core/user_config.py +++ b/cli/lib/core/user_config.py @@ -24,17 +24,18 @@ from core import util BSP_DIR = 'bsp_dir' UID = 'uid' +OS_ROOT = 'os_root' PLATFORM_CACHE = 'platform_cache' METRICS_OPT_IN = 'metrics_opt_in' # Don't expose uid. -EXPOSED = [BSP_DIR, PLATFORM_CACHE, METRICS_OPT_IN] -PATHS = [BSP_DIR, PLATFORM_CACHE] +EXPOSED = [BSP_DIR, OS_ROOT, PLATFORM_CACHE, METRICS_OPT_IN] +PATHS = [BSP_DIR, OS_ROOT, PLATFORM_CACHE] class UserConfig(config.Store): REQUIRED_PROPS = {METRICS_OPT_IN:['0', '1'], UID:[]} - OPTIONAL_PROPS = {BSP_DIR:[], PLATFORM_CACHE:[]} + OPTIONAL_PROPS = {BSP_DIR:[], OS_ROOT:[], PLATFORM_CACHE:[]} PREFIX = 'user_' def __init__(self, file_path='', table='user'): @@ -43,6 +44,7 @@ class UserConfig(config.Store): self._defaults = { BSP_DIR: util.GetBDKPath('BSPs'), + OS_ROOT: util.DEPRECATED_GetDefaultOSPath(), PLATFORM_CACHE: util.GetBDKPath('platform_cache') } diff --git a/cli/lib/core/user_config_stub.py b/cli/lib/core/user_config_stub.py index 905559a..7feada6 100644 --- a/cli/lib/core/user_config_stub.py +++ b/cli/lib/core/user_config_stub.py @@ -25,8 +25,9 @@ class StubUserConfig(object): EXPOSED = user_config.EXPOSED - def __init__(self, metrics_opt_in='0'): + def __init__(self, metrics_opt_in='0', os_root='/path/to/os'): self.USER_CONFIG.metrics_opt_in = metrics_opt_in + self.USER_CONFIG.os_root = os_root class UserConfig(object): def __init__(self, file_path='user_data.db', table='totally_private'): @@ -37,6 +38,7 @@ class StubUserConfig(object): self.bsp_dir = 'somewhere/bsps' self.platform_cache = 'elsewhere/pc' self.is_complete = True + self.os_root = '/where/the/tree/is' def complete(self): return self.is_complete diff --git a/cli/lib/core/user_config_unittest.py b/cli/lib/core/user_config_unittest.py index a1fee76..8d64e85 100644 --- a/cli/lib/core/user_config_unittest.py +++ b/cli/lib/core/user_config_unittest.py @@ -81,6 +81,8 @@ class UserConfigTest(unittest.TestCase): self.stub_util.GetBDKPath('BSPs')) self.assertEqual(self.user_config.platform_cache, self.stub_util.GetBDKPath('platform_cache')) + self.assertEqual(self.user_config.os_root, + self.stub_util.DEPRECATED_GetDefaultOSPath()) # Set values (except for metrics_opt_in, tested above). self.user_config.uid = 'uid!' @@ -89,6 +91,8 @@ class UserConfigTest(unittest.TestCase): self.assertEqual(self.user_config.bsp_dir, 'bsp_dir!') self.user_config.platform_cache = 'platform_cache!' self.assertEqual(self.user_config.platform_cache, 'platform_cache!') + self.user_config.os_root = 'os_root!' + self.assertEqual(self.user_config.os_root, 'os_root!') # Reset values. self.user_config.uid = None @@ -99,6 +103,9 @@ class UserConfigTest(unittest.TestCase): self.user_config.platform_cache = None self.assertEqual(self.user_config.platform_cache, self.stub_util.GetBDKPath('platform_cache')) + self.user_config.os_root = None + self.assertEqual(self.user_config.os_root, + self.stub_util.DEPRECATED_GetDefaultOSPath()) # Empty string should behave like default for those with defaults. self.user_config.uid = '' @@ -109,3 +116,6 @@ class UserConfigTest(unittest.TestCase): self.user_config.platform_cache = '' self.assertEqual(self.user_config.platform_cache, self.stub_util.GetBDKPath('platform_cache')) + self.user_config.os_root = '' + self.assertEqual(self.user_config.os_root, + self.stub_util.DEPRECATED_GetDefaultOSPath()) |