Remove SystemState from post-install step.
The post-install action only requires to mark the new slot as ready,
for which it was including a reference to the whole SystemState. This
patch removes said dependency replacing it for just the
BootControlInterface.
Bug: 25773375
TEST=FEATURES=test emerge-link update_engine; mma
Change-Id: I814d47c138c7565e9a80f316f25e124adb0d9c4e
diff --git a/payload_consumer/postinstall_runner_action.cc b/payload_consumer/postinstall_runner_action.cc
index 33bbf5b..84ca398 100644
--- a/payload_consumer/postinstall_runner_action.cc
+++ b/payload_consumer/postinstall_runner_action.cc
@@ -25,6 +25,7 @@
#include <base/files/file_util.h>
#include "update_engine/common/action_processor.h"
+#include "update_engine/common/boot_control_interface.h"
#include "update_engine/common/subprocess.h"
#include "update_engine/common/utils.h"
@@ -159,8 +160,7 @@
// We only attempt to mark the new slot as active if all the postinstall
// steps succeeded.
if (error_code == ErrorCode::kSuccess &&
- !system_state_->boot_control()->SetActiveBootSlot(
- install_plan_.target_slot)) {
+ !boot_control_->SetActiveBootSlot(install_plan_.target_slot)) {
error_code = ErrorCode::kPostinstallRunnerError;
}
diff --git a/payload_consumer/postinstall_runner_action.h b/payload_consumer/postinstall_runner_action.h
index de19c0c..ab267b8 100644
--- a/payload_consumer/postinstall_runner_action.h
+++ b/payload_consumer/postinstall_runner_action.h
@@ -21,17 +21,18 @@
#include "update_engine/common/action.h"
#include "update_engine/payload_consumer/install_plan.h"
-#include "update_engine/system_state.h"
// The Postinstall Runner Action is responsible for running the postinstall
// script of a successfully downloaded update.
namespace chromeos_update_engine {
+class BootControlInterface;
+
class PostinstallRunnerAction : public InstallPlanAction {
public:
- explicit PostinstallRunnerAction(SystemState* system_state)
- : PostinstallRunnerAction(system_state, nullptr) {}
+ explicit PostinstallRunnerAction(BootControlInterface* boot_control)
+ : PostinstallRunnerAction(boot_control, nullptr) {}
void PerformAction();
@@ -46,9 +47,9 @@
friend class PostinstallRunnerActionTest;
// Special constructor used for testing purposes.
- PostinstallRunnerAction(SystemState* system_state,
+ PostinstallRunnerAction(BootControlInterface* boot_control,
const char* powerwash_marker_file)
- : system_state_(system_state),
+ : boot_control_(boot_control),
powerwash_marker_file_(powerwash_marker_file) {}
void PerformPartitionPostinstall();
@@ -57,7 +58,8 @@
void CompletePartitionPostinstall(int return_code,
const std::string& output);
- //
+ // Complete the Action with the passed |error_code| and mark the new slot as
+ // ready. Called when the post-install script was run for all the partitions.
void CompletePostinstall(ErrorCode error_code);
InstallPlan install_plan_;
@@ -67,8 +69,8 @@
// InstallPlan.
size_t current_partition_{0};
- // The main SystemState singleton.
- SystemState* system_state_;
+ // The BootControlInerface used to mark the new slot as ready.
+ BootControlInterface* boot_control_;
// True if Powerwash Marker was created before invoking post-install script.
// False otherwise. Used for cleaning up if post-install fails.
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc
index c54ace8..beed4f1 100644
--- a/payload_consumer/postinstall_runner_action_unittest.cc
+++ b/payload_consumer/postinstall_runner_action_unittest.cc
@@ -34,9 +34,9 @@
#include <gtest/gtest.h>
#include "update_engine/common/constants.h"
+#include "update_engine/common/fake_boot_control.h"
#include "update_engine/common/test_utils.h"
#include "update_engine/common/utils.h"
-#include "update_engine/fake_system_state.h"
using brillo::MessageLoop;
using chromeos_update_engine::test_utils::System;
@@ -66,7 +66,7 @@
brillo::BaseMessageLoop loop_{&base_loop_};
brillo::AsynchronousSignalHandler async_signal_handler_;
Subprocess subprocess_;
- FakeSystemState fake_system_state_;
+ FakeBootControl fake_boot_control_;
};
class PostinstActionProcessorDelegate : public ActionProcessorDelegate {
@@ -196,7 +196,7 @@
install_plan.download_url = "http://devserver:8080/update";
install_plan.powerwash_required = powerwash_required;
feeder_action.set_obj(install_plan);
- PostinstallRunnerAction runner_action(&fake_system_state_,
+ PostinstallRunnerAction runner_action(&fake_boot_control_,
powerwash_marker_file.c_str());
BondActions(&feeder_action, &runner_action);
ObjectCollectorAction<InstallPlan> collector_action;
@@ -252,7 +252,7 @@
// Death tests don't seem to be working on Hardy
TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) {
ASSERT_EQ(0, getuid());
- PostinstallRunnerAction runner_action(&fake_system_state_);
+ PostinstallRunnerAction runner_action(&fake_boot_control_);
ASSERT_DEATH({ runner_action.TerminateProcessing(); },
"postinstall_runner_action.h:.*] Check failed");
}