Include the major version in update_engine.conf
This patch moves all the payload definition version numbers to
payload_constants.h and exposes the supported one in the .conf file.
Bug: 23946683
Test: Added unittest to match the .conf file with the code.
Change-Id: I7d84d2aa3c85d2b4d5da8bf102aa9bf99acc0136
diff --git a/delta_performer.cc b/delta_performer.cc
index 4b1981b..0482a8f 100644
--- a/delta_performer.cc
+++ b/delta_performer.cc
@@ -59,7 +59,6 @@
const uint64_t DeltaPerformer::kDeltaManifestSizeSize = 8;
const uint64_t DeltaPerformer::kSupportedMajorPayloadVersion = 1;
const uint64_t DeltaPerformer::kSupportedMinorPayloadVersion = 2;
-const uint64_t DeltaPerformer::kFullPayloadMinorVersion = 0;
const char DeltaPerformer::kUpdatePayloadPublicKeyPath[] =
"/usr/share/update_engine/update-payload-key.pub.pem";
@@ -68,11 +67,6 @@
const unsigned DeltaPerformer::kProgressDownloadWeight = 50;
const unsigned DeltaPerformer::kProgressOperationsWeight = 50;
-const uint64_t kChromeOSMajorPayloadVersion = 1;
-const uint64_t kBrilloMajorPayloadVersion = 2;
-const uint32_t kInPlaceMinorPayloadVersion = 1;
-const uint32_t kSourceMinorPayloadVersion = 2;
-
namespace {
const int kUpdateStateOperationInvalid = -1;
const int kMaxResumedUpdateFailures = 10;
diff --git a/delta_performer.h b/delta_performer.h
index ef0bd9b..d088796 100644
--- a/delta_performer.h
+++ b/delta_performer.h
@@ -36,18 +36,6 @@
namespace chromeos_update_engine {
-// The major version used by Chrome OS.
-extern const uint64_t kChromeOSMajorPayloadVersion;
-
-// The major version used by Brillo.
-extern const uint64_t kBrilloMajorPayloadVersion;
-
-// The minor version used by the in-place delta generator algorithm.
-extern const uint32_t kInPlaceMinorPayloadVersion;
-
-// The minor version used by the A to B delta generator algorithm.
-extern const uint32_t kSourceMinorPayloadVersion;
-
class PrefsInterface;
// This class performs the actions in a delta update synchronously. The delta
@@ -65,7 +53,6 @@
static const uint64_t kDeltaManifestSizeSize;
static const uint64_t kSupportedMajorPayloadVersion;
static const uint64_t kSupportedMinorPayloadVersion;
- static const uint64_t kFullPayloadMinorVersion;
static const char kUpdatePayloadPublicKeyPath[];
// Defines the granularity of progress logging in terms of how many "completed
diff --git a/delta_performer_integration_test.cc b/delta_performer_integration_test.cc
index 4a2505c..1e3dea8 100644
--- a/delta_performer_integration_test.cc
+++ b/delta_performer_integration_test.cc
@@ -910,7 +910,7 @@
void DoOperationHashMismatchTest(OperationHashTest op_hash_test,
bool hash_checks_mandatory) {
DeltaState state;
- uint64_t minor_version = DeltaPerformer::kFullPayloadMinorVersion;
+ uint64_t minor_version = kFullPayloadMinorVersion;
GenerateDeltaFile(true, true, false, -1, kSignatureGenerated, &state,
minor_version);
ScopedPathUnlinker a_img_unlinker(state.a_img);
@@ -955,7 +955,7 @@
TEST(DeltaPerformerIntegrationTest, RunAsRootFullSmallImageTest) {
DoSmallImageTest(true, true, false, -1, kSignatureGenerator,
- true, DeltaPerformer::kFullPayloadMinorVersion);
+ true, kFullPayloadMinorVersion);
}
TEST(DeltaPerformerIntegrationTest, RunAsRootNoopSmallImageTest) {
diff --git a/delta_performer_unittest.cc b/delta_performer_unittest.cc
index eca216f..cc3d6e2 100644
--- a/delta_performer_unittest.cc
+++ b/delta_performer_unittest.cc
@@ -24,6 +24,7 @@
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/strings/stringprintf.h>
+#include <base/strings/string_number_conversions.h>
#include <base/strings/string_util.h>
#include <google/protobuf/repeated_field.h>
#include <gtest/gtest.h>
@@ -187,7 +188,7 @@
// Loads the payload and parses the manifest.
chromeos::Blob payload = GeneratePayload(chromeos::Blob(),
vector<AnnotatedOperation>(), sign_payload,
- DeltaPerformer::kFullPayloadMinorVersion);
+ kFullPayloadMinorVersion);
LOG(INFO) << "Payload size: " << payload.size();
@@ -270,7 +271,7 @@
aops.push_back(aop);
chromeos::Blob payload_data = GeneratePayload(expected_data, aops, false,
- DeltaPerformer::kFullPayloadMinorVersion);
+ kFullPayloadMinorVersion);
EXPECT_EQ(expected_data, ApplyPayload(payload_data, ""));
}
@@ -363,7 +364,7 @@
DeltaArchiveManifest manifest;
manifest.mutable_new_kernel_info();
manifest.mutable_new_rootfs_info();
- manifest.set_minor_version(DeltaPerformer::kFullPayloadMinorVersion);
+ manifest.set_minor_version(kFullPayloadMinorVersion);
RunManifestValidation(manifest, true, ErrorCode::kSuccess);
}
@@ -573,14 +574,20 @@
EXPECT_TRUE(test_utils::RecursiveUnlinkDir(temp_dir));
}
-TEST_F(DeltaPerformerTest, MinorVersionsMatch) {
- // Test that the minor version in update_engine.conf that is installed to
- // the image matches the supported delta minor version in the update engine.
+TEST_F(DeltaPerformerTest, ConfVersionsMatch) {
+ // Test that the versions in update_engine.conf that is installed to the
+ // image match the supported delta versions in the update engine.
uint32_t minor_version;
chromeos::KeyValueStore store;
EXPECT_TRUE(store.Load(base::FilePath("update_engine.conf")));
EXPECT_TRUE(utils::GetMinorVersion(store, &minor_version));
EXPECT_EQ(DeltaPerformer::kSupportedMinorPayloadVersion, minor_version);
+
+ string major_version_str;
+ uint64_t major_version;
+ EXPECT_TRUE(store.GetString("PAYLOAD_MAJOR_VERSION", &major_version_str));
+ EXPECT_TRUE(base::StringToUint64(major_version_str, &major_version));
+ EXPECT_EQ(DeltaPerformer::kSupportedMajorPayloadVersion, major_version);
}
} // namespace chromeos_update_engine
diff --git a/payload_constants.cc b/payload_constants.cc
index 9d6fb3d..aeddf11 100644
--- a/payload_constants.cc
+++ b/payload_constants.cc
@@ -18,6 +18,13 @@
namespace chromeos_update_engine {
+const uint64_t kChromeOSMajorPayloadVersion = 1;
+const uint64_t kBrilloMajorPayloadVersion = 2;
+
+const uint32_t kFullPayloadMinorVersion = 0;
+const uint32_t kInPlaceMinorPayloadVersion = 1;
+const uint32_t kSourceMinorPayloadVersion = 2;
+
const char kLegacyPartitionNameKernel[] = "boot";
const char kLegacyPartitionNameRoot[] = "system";
diff --git a/payload_constants.h b/payload_constants.h
index 188ea84..21dab00 100644
--- a/payload_constants.h
+++ b/payload_constants.h
@@ -23,6 +23,22 @@
namespace chromeos_update_engine {
+// The major version used by Chrome OS.
+extern const uint64_t kChromeOSMajorPayloadVersion;
+
+// The major version used by Brillo.
+extern const uint64_t kBrilloMajorPayloadVersion;
+
+// The minor version used for all full payloads.
+extern const uint32_t kFullPayloadMinorVersion;
+
+// The minor version used by the in-place delta generator algorithm.
+extern const uint32_t kInPlaceMinorPayloadVersion;
+
+// The minor version used by the A to B delta generator algorithm.
+extern const uint32_t kSourceMinorPayloadVersion;
+
+
// The kernel and rootfs partition names used by the BootControlInterface when
// handling update payloads with a major version 1. The names of the updated
// partitions are include in the payload itself for major version 2.
diff --git a/payload_generator/full_update_generator_unittest.cc b/payload_generator/full_update_generator_unittest.cc
index 2f39126..6c1047c 100644
--- a/payload_generator/full_update_generator_unittest.cc
+++ b/payload_generator/full_update_generator_unittest.cc
@@ -21,7 +21,7 @@
#include <gtest/gtest.h>
-#include "update_engine/delta_performer.h"
+#include "update_engine/payload_constants.h"
#include "update_engine/payload_generator/extent_utils.h"
#include "update_engine/test_utils.h"
@@ -35,7 +35,7 @@
protected:
void SetUp() override {
config_.is_delta = false;
- config_.minor_version = DeltaPerformer::kFullPayloadMinorVersion;
+ config_.minor_version = kFullPayloadMinorVersion;
config_.hard_chunk_size = 128 * 1024;
config_.block_size = 4096;
diff --git a/payload_generator/generate_delta_main.cc b/payload_generator/generate_delta_main.cc
index e122fb9..d38c5c5 100644
--- a/payload_generator/generate_delta_main.cc
+++ b/payload_generator/generate_delta_main.cc
@@ -30,6 +30,7 @@
#include <chromeos/flag_helper.h>
#include "update_engine/delta_performer.h"
+#include "update_engine/payload_constants.h"
#include "update_engine/payload_generator/delta_diff_generator.h"
#include "update_engine/payload_generator/delta_diff_utils.h"
#include "update_engine/payload_generator/payload_generation_config.h"
@@ -424,7 +425,7 @@
payload_config.minor_version = kInPlaceMinorPayloadVersion;
}
} else {
- payload_config.minor_version = DeltaPerformer::kFullPayloadMinorVersion;
+ payload_config.minor_version = kFullPayloadMinorVersion;
}
LOG(INFO) << "Auto-detected minor_version=" << payload_config.minor_version;
} else {
diff --git a/payload_generator/payload_generation_config.cc b/payload_generator/payload_generation_config.cc
index a2d9311..786c4e2 100644
--- a/payload_generator/payload_generation_config.cc
+++ b/payload_generator/payload_generation_config.cc
@@ -115,8 +115,7 @@
} else {
// All the "source" image fields must be empty for full payloads.
TEST_AND_RETURN_FALSE(source.ValidateIsEmpty());
- TEST_AND_RETURN_FALSE(minor_version ==
- DeltaPerformer::kFullPayloadMinorVersion);
+ TEST_AND_RETURN_FALSE(minor_version == kFullPayloadMinorVersion);
}
// In all cases, the target image must exists.
diff --git a/update_engine.conf b/update_engine.conf
index dc65ebe..dea31e4 100644
--- a/update_engine.conf
+++ b/update_engine.conf
@@ -1 +1,2 @@
+PAYLOAD_MAJOR_VERSION=1
PAYLOAD_MINOR_VERSION=2