chromeos-config: disallow passing a SKU ID to CrosConfig::Init
Since configuration probing is moving to ChromeOS ConfigFS, we want to
disallow using a different SKU id with the default config.json, as the
default config.json will go away.
Only accept a SKU id in InitForTest.
BUG=chromium:1041544
TEST=sudo FEATURES=test emerge chromeos-config-tools
Change-Id: Ia0607e1f26b82f7b8325e9091d417257d31c3cd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2065477
Tested-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Yuval Peress <peress@chromium.org>
diff --git a/chromeos-config/cros_config_main.cc b/chromeos-config/cros_config_main.cc
index 11f3877..3e9cea5 100644
--- a/chromeos-config/cros_config_main.cc
+++ b/chromeos-config/cros_config_main.cc
@@ -31,6 +31,11 @@
"debug logging messages.\n";
brillo::FlagHelper::Init(argc, argv, usage);
+ if (FLAGS_test_sku_id != brillo::kDefaultSkuId && FLAGS_test_file.empty()) {
+ std::cerr << "Passing --test_sku_id requires you pass --test_file.\n";
+ return 1;
+ }
+
CHECK_EQ(FLAGS_test_file.empty(), FLAGS_test_name.empty())
<< "You must pass both --test_file and --test_name or neither.";
@@ -44,7 +49,7 @@
brillo::CrosConfig cros_config;
if (FLAGS_test_file.empty()) {
- if (!cros_config.Init(FLAGS_test_sku_id)) {
+ if (!cros_config.Init()) {
return 1;
}
} else {
diff --git a/chromeos-config/libcros_config/cros_config.cc b/chromeos-config/libcros_config/cros_config.cc
index 7c9cfb7..eb7dbf9 100644
--- a/chromeos-config/libcros_config/cros_config.cc
+++ b/chromeos-config/libcros_config/cros_config.cc
@@ -65,7 +65,7 @@
return true;
}
-bool CrosConfig::Init(const int sku_id) {
+bool CrosConfig::Init() {
base::FilePath vpd_file;
base::FilePath product_name_file;
base::FilePath product_sku_file;
@@ -75,7 +75,7 @@
return false;
}
base::FilePath json_path(kConfigJsonPath);
- return InitInternal(sku_id, json_path, arch, product_name_file,
+ return InitInternal(kDefaultSkuId, json_path, arch, product_name_file,
product_sku_file, vpd_file);
}
diff --git a/chromeos-config/libcros_config/cros_config.h b/chromeos-config/libcros_config/cros_config.h
index 470cb46..a179f2f 100644
--- a/chromeos-config/libcros_config/cros_config.h
+++ b/chromeos-config/libcros_config/cros_config.h
@@ -31,11 +31,8 @@
// Prepare the configuration system for access to the configuration for
// the model this is running on. This reads the configuration file into
// memory.
- // @sku_id: If sku_id is kDefaultSkuId, then the SKU of the device
- // will be probed. Otherwise (if sku_id is not kDefaultSkuId),
- // the value here is used to match the configuration.
// @return true if OK, false on error.
- bool Init(const int sku_id = kDefaultSkuId);
+ bool Init();
// Prepare the configuration system for testing.
// This reads in the given configuration file and selects the config