• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender / 951615729

pending completion
951615729

push

gitlab-ci

larsewi
fix: Add 'build/' to '.gitignore'

Ticket: None
Changelog: None
Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>

4199 of 5286 relevant lines covered (79.44%)

166.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.61
/mender-update/update_module/v3/update_module.cpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#include <mender-update/update_module/v3/update_module.hpp>
16

17
#include <common/events.hpp>
18
#include <common/error.hpp>
19
#include <common/expected.hpp>
20
#include <common/path.hpp>
21

22
namespace mender {
23
namespace update {
24
namespace update_module {
25
namespace v3 {
26

27
namespace error = mender::common::error;
28
namespace expected = mender::common::expected;
29
namespace path = mender::common::path;
30

31
static std::string StateString[] = {
32
        "Download",
33
        "ArtifactInstall",
34
        "NeedsArtifactReboot",
35
        "ArtifactReboot",
36
        "ArtifactCommit",
37
        "SupportsRollback",
38
        "ArtifactRollback",
39
        "ArtifactVerifyReboot",
40
        "ArtifactRollbackReboot",
41
        "ArtifactVerifyRollbackReboot",
42
        "ArtifactFailure",
43
        "Cleanup"};
44

45
std::string StateToString(State state) {
162✔
46
        static_assert(
47
                sizeof(StateString) / sizeof(*StateString) == static_cast<int>(State::LastState),
48
                "Make sure to keep State and StateString in sync!");
49
        return StateString[static_cast<int>(state)];
162✔
50
}
51

52
UpdateModule::UpdateModule(MenderContext &ctx, const string &payload_type) :
61✔
53
        ctx_(ctx) {
61✔
54
        update_module_path_ = path::Join(ctx.modules_path, payload_type);
61✔
55
        update_module_workdir_ =
56
                path::Join(ctx.modules_work_path, "modules", "v3", "payloads", "0000", "tree");
61✔
57
}
61✔
58

59
UpdateModule::DownloadData::DownloadData(artifact::Payload &payload) :
40✔
60
        payload_(payload) {
40✔
61
        buffer_.resize(MENDER_BUFSIZE);
40✔
62
}
40✔
63

64
error::Error UpdateModule::CallStateNoCapture(State state) {
97✔
65
        return CallState(state, nullptr);
97✔
66
}
67

68
error::Error UpdateModule::Download(artifact::Payload &payload) {
40✔
69
        download_ = make_unique<DownloadData>(payload);
40✔
70

71
        download_->event_loop_.Post([this]() { StartDownloadProcess(); });
80✔
72

73
        download_->event_loop_.Run();
40✔
74

75
        auto result = std::move(download_->result_);
40✔
76
        download_.reset();
40✔
77
        return result;
40✔
78
}
79

80
error::Error UpdateModule::ArtifactInstall() {
29✔
81
        return CallStateNoCapture(State::ArtifactInstall);
29✔
82
}
83

84
ExpectedRebootAction UpdateModule::NeedsReboot() {
29✔
85
        std::string processStdOut;
58✔
86
        auto err = CallState(State::NeedsReboot, &processStdOut);
58✔
87
        if (err != error::NoError) {
29✔
88
                return expected::unexpected(err);
2✔
89
        }
90
        if (processStdOut == "Yes") {
28✔
91
                return RebootAction::Yes;
1✔
92
        } else if (processStdOut == "No" || processStdOut == "") {
27✔
93
                return RebootAction::No;
23✔
94
        } else if (processStdOut == "Automatic") {
4✔
95
                return RebootAction::Automatic;
3✔
96
        }
97
        return expected::unexpected(error::Error(
1✔
98
                make_error_condition(errc::protocol_error),
1✔
99
                "Unexpected output from the process for NeedsReboot state"));
3✔
100
}
101

102
error::Error UpdateModule::ArtifactReboot() {
1✔
103
        return CallStateNoCapture(State::ArtifactReboot);
1✔
104
}
105

106
error::Error UpdateModule::ArtifactCommit() {
24✔
107
        return CallStateNoCapture(State::ArtifactCommit);
24✔
108
}
109

110
expected::ExpectedBool UpdateModule::SupportsRollback() {
36✔
111
        std::string processStdOut;
72✔
112
        auto err = CallState(State::SupportsRollback, &processStdOut);
72✔
113
        if (err != error::NoError) {
36✔
114
                return expected::unexpected(err);
2✔
115
        }
116
        if (processStdOut == "Yes") {
35✔
117
                return true;
15✔
118
        } else if (processStdOut == "No" || processStdOut == "") {
20✔
119
                return false;
19✔
120
        }
121
        return expected::unexpected(error::Error(
1✔
122
                make_error_condition(errc::protocol_error),
1✔
123
                "Unexpected output from the process for SupportsRollback state"));
3✔
124
}
125

126
error::Error UpdateModule::ArtifactRollback() {
7✔
127
        return CallStateNoCapture(State::ArtifactRollback);
7✔
128
}
129

130
error::Error UpdateModule::ArtifactVerifyReboot() {
1✔
131
        return CallStateNoCapture(State::ArtifactVerifyReboot);
1✔
132
}
133

134
error::Error UpdateModule::ArtifactRollbackReboot() {
1✔
135
        return CallStateNoCapture(State::ArtifactRollbackReboot);
1✔
136
}
137

138
error::Error UpdateModule::ArtifactVerifyRollbackReboot() {
1✔
139
        return CallStateNoCapture(State::ArtifactVerifyRollbackReboot);
1✔
140
}
141

142
error::Error UpdateModule::ArtifactFailure() {
5✔
143
        return CallStateNoCapture(State::ArtifactFailure);
5✔
144
}
145

146
error::Error UpdateModule::Cleanup() {
28✔
147
        return CallStateNoCapture(State::Cleanup);
28✔
148
}
149

150
string UpdateModule::GetModulePath() const {
161✔
151
        return update_module_path_;
161✔
152
}
153

154
string UpdateModule::GetModulesWorkPath() const {
484✔
155
        return update_module_workdir_;
484✔
156
}
157

158
error::Error UpdateModule::GetProcessError(const error::Error &err) {
3✔
159
        if (err.code == make_error_condition(errc::no_such_file_or_directory)) {
3✔
160
                return context::MakeError(context::NoSuchUpdateModuleError, err.message);
×
161
        }
162
        return err;
3✔
163
}
164

165
} // namespace v3
166
} // namespace update_module
167
} // namespace update
168
} // namespace mender
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc