Skip to content

Commit 5edf3b4

Browse files
Added fallback mode if streaming install fails
1 parent e88154e commit 5edf3b4

9 files changed

+92
-3
lines changed

Diff for: src/FSM/States/Installing.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,18 @@ namespace sua {
6363

6464
const auto lastError = ctx.installerAgent->getLastError();
6565
Logger::error("Installation failed: {}", lastError);
66-
send(ctx, IMqttProcessor::TOPIC_FEEDBACK, "installFailed", lastError);
67-
return FotaEvent::InstallFailed;
66+
67+
// for download mode transit to fail state
68+
if (true == ctx.downloadMode) {
69+
send(ctx, IMqttProcessor::TOPIC_FEEDBACK, "installFailed", lastError);
70+
return FotaEvent::InstallFailed;
71+
}
72+
73+
// for stream mode start again in download mode
74+
Logger::info("Trying normal download mode as fallback");
75+
send(ctx, IMqttProcessor::TOPIC_FEEDBACK, "installFailedFallback", lastError);
76+
ctx.downloadMode = true;
77+
return FotaEvent::InstallFailedFallback;
6878
}
6979

7080
} // namespace sua

Diff for: src/FotaEvent.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace sua {
3636
{ DownloadFailed , "DownloadFailed" },
3737
{ InstallStart , "InstallStart" },
3838
{ InstallCompleted , "InstallCompleted" },
39-
{ InstallFailed , "InstallFailed" }
39+
{ InstallFailed , "InstallFailed" },
40+
{ InstallFailedFallback , "InstallFailedFallback" }
4041
};
4142
// clang-format on
4243

Diff for: src/FotaEvent.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace sua {
3535
InstallStart,
3636
InstallCompleted,
3737
InstallFailed,
38+
InstallFailedFallback,
3839
NotUsed,
3940
};
4041

Diff for: src/Mqtt/MqttMessagingProtocolJSON.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ namespace sua {
209209
message, ctx.desiredState.installProgressPercentage);
210210
}
211211

212+
if(name == "installFailedFallback") {
213+
return writeFeedbackWithPayload(ctx.desiredState,
214+
"RUNNING", "Self-update agent is performing an OS image update.",
215+
"UPDATING", "Install in streaming mode failed, trying in download mode.",
216+
message, 0);
217+
}
218+
212219
if(name == "currentState") {
213220
return "";
214221
}

Diff for: src/Mqtt/MqttMessagingProtocolYAML.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ namespace sua {
178178
return serialized(base(ctx.desiredState, state));
179179
}
180180

181+
if(name == "installFailedFallback") {
182+
std::map<std::string, std::string> state;
183+
state["state/name" ] = "failed";
184+
state["state/message" ] = "Stream install failed, trying download mode";
185+
state["state/techCode"] = "3001";
186+
return serialized(base(ctx.desiredState, state));
187+
}
188+
181189
if(name == "rejected") {
182190
std::map<std::string, std::string> state;
183191
state["state/name" ] = "failed";

Diff for: src/SelfUpdateAgent.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace sua {
6868
{ FotaEvent::ConnectivityLost , "Installing" , "Uninitialized" },
6969
{ FotaEvent::InstallStart , "Installing" , "Installed" , FotaEvent::InstallCompleted },
7070
{ FotaEvent::InstallStart , "Installing" , "Failed" , FotaEvent::InstallFailed },
71+
{ FotaEvent::InstallStart , "Installing" , "Downloading" , FotaEvent::InstallFailedFallback },
7172
// from "Installed"
7273
{ FotaEvent::ConnectivityLost , "Installed" , "Uninitialized" },
7374
{ FotaEvent::Waiting , "Installed" , "Idle" },

Diff for: src/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ int main(int argc, char* argv[])
196196
downloadMode = false;
197197
} else {
198198
installerAgent = std::make_shared<sua::DummyRaucInstaller>();
199+
downloadMode = true;
199200
}
200201

201202
// Depending on testing scenario, localhost or ip address of mosquitto container shall be used.

Diff for: utest/TestMqttMessagingProtocolJSON.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,41 @@ namespace {
721721
EXPECT_EQ_MULTILINE(result, expected);
722722
}
723723

724+
TEST_F(TestMessagingProtocolJSON, createMessage_installFailedFallback)
725+
{
726+
d.installProgressPercentage = 66;
727+
728+
const std::string result = ProtocolJSON().createMessage(ctx, "installFailedFallback");
729+
730+
// clang-format off
731+
const std::string expected = R"(
732+
{
733+
"activityId": "id",
734+
"timestamp": 42,
735+
"payload": {
736+
"status": "RUNNING",
737+
"message": "Self-update agent is performing an OS image update.",
738+
"actions": [
739+
{
740+
"component": {
741+
"id": "self-update:os-image",
742+
"version": "1.0"
743+
},
744+
"status": "UPDATING",
745+
"progress": 0,
746+
"message": "Install in streaming mode failed, trying in download mode."
747+
}
748+
]
749+
}
750+
}
751+
)";
752+
// clang-format on
753+
754+
EXPECT_NO_THROW(validateJsonSyntax(expected));
755+
EXPECT_NO_THROW(validateJsonSyntax(result));
756+
EXPECT_EQ_MULTILINE(result, expected);
757+
}
758+
724759
TEST_F(TestMessagingProtocolJSON, createMessage_currentState)
725760
{
726761
const std::string result = ProtocolJSON().createMessage(ctx, "currentState");

Diff for: utest/TestMqttMessagingProtocolYAML.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,31 @@ namespace {
301301
EXPECT_EQ_MULTILINE(result, expected);
302302
}
303303

304+
TEST_F(TestMessagingProtocolYAML, createMessage_installFailedFallback)
305+
{
306+
const std::string result = sua::MqttMessagingProtocolYAML().createMessage(ctx, "installFailedFallback");
307+
308+
// clang-format off
309+
const std::string expected = R"(
310+
apiVersion: sdv.eclipse.org/v1
311+
kind: SelfUpdateBundle
312+
metadata:
313+
name: "self-update-bundle-example"
314+
spec:
315+
bundleDownloadUrl: "http://url"
316+
bundleName: "arm64-bundle"
317+
bundleTarget: base
318+
bundleVersion: 1.0
319+
state:
320+
message: "Stream install failed, trying download mode"
321+
name: failed
322+
techCode: 3001
323+
)";
324+
// clang-format on
325+
326+
EXPECT_EQ_MULTILINE(result, expected);
327+
}
328+
304329
TEST_F(TestMessagingProtocolYAML, createMessage_updateRejected)
305330
{
306331
const std::string result = sua::MqttMessagingProtocolYAML().createMessage(ctx, "rejected");

0 commit comments

Comments
 (0)