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

mendersoftware / mender / 950534094

pending completion
950534094

push

gitlab-ci

kacf
chore: Add `StartsWith` and `EndsWith` generic utility functions.

Also use the latter in `states.cpp`.

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>

1 of 1 new or added line in 1 file covered. (100.0%)

4931 of 6276 relevant lines covered (78.57%)

196.18 hits per line

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

91.75
/mender-update/cli/actions.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/cli/actions.hpp>
16

17
#include <common/events.hpp>
18
#include <common/log.hpp>
19

20
#include <mender-update/daemon.hpp>
21
#include <mender-update/standalone.hpp>
22

23
namespace mender {
24
namespace update {
25
namespace cli {
26

27
namespace conf = mender::common::conf;
28
namespace database = mender::common::key_value_database;
29
namespace events = mender::common::events;
30
namespace log = mender::common::log;
31

32
namespace daemon = mender::update::daemon;
33
namespace standalone = mender::update::standalone;
34

35
error::Error ShowArtifactAction::Execute(context::MenderContext &main_context) {
2✔
36
        auto exp_provides = main_context.LoadProvides();
4✔
37
        if (!exp_provides) {
2✔
38
                return exp_provides.error();
×
39
        }
40

41
        auto &provides = exp_provides.value();
2✔
42
        if (provides.count("artifact_name") == 0 || provides["artifact_name"] == "") {
5✔
43
                cout << "Unknown" << endl;
1✔
44
        } else {
45
                cout << provides["artifact_name"] << endl;
1✔
46
        }
47
        return error::NoError;
2✔
48
}
49

50
error::Error ShowProvidesAction::Execute(context::MenderContext &main_context) {
28✔
51
        auto exp_provides = main_context.LoadProvides();
56✔
52
        if (!exp_provides) {
28✔
53
                return exp_provides.error();
×
54
        }
55

56
        auto &provides = exp_provides.value();
28✔
57
        for (const auto &elem : provides) {
94✔
58
                cout << elem.first << "=" << elem.second << endl;
66✔
59
        }
60

61
        return error::NoError;
28✔
62
}
63

64
static error::Error ResultHandler(standalone::ResultAndError result) {
40✔
65
        switch (result.result) {
40✔
66
        case standalone::Result::InstalledAndCommitted:
27✔
67
        case standalone::Result::Committed:
68
        case standalone::Result::Installed:
69
        case standalone::Result::RolledBack:
70
                // There should not be any error for these.
71
                assert(result.err == error::NoError);
27✔
72
                break;
27✔
73
        case standalone::Result::InstalledAndCommittedRebootRequired:
2✔
74
        case standalone::Result::InstalledRebootRequired:
75
                if (result.err == error::NoError) {
2✔
76
                        result.err = context::MakeError(context::RebootRequiredError, "Reboot required");
2✔
77
                }
78
                break;
2✔
79
        default:
11✔
80
                // All other states, make sure they have an error.
81
                if (result.err != error::NoError) {
11✔
82
                        log::Error(result.err.String());
8✔
83
                } else {
84
                        result.err = context::MakeError(context::ExitStatusOnlyError, "");
3✔
85
                }
86
                break;
11✔
87
        }
88

89
        switch (result.result) {
40✔
90
        case standalone::Result::InstalledAndCommitted:
16✔
91
        case standalone::Result::InstalledAndCommittedRebootRequired:
92
                cout << "Installed and committed." << endl;
16✔
93
                break;
16✔
94
        case standalone::Result::Committed:
3✔
95
                cout << "Committed." << endl;
3✔
96
                break;
3✔
97
        case standalone::Result::Installed:
8✔
98
        case standalone::Result::InstalledRebootRequired:
99
                cout << "Installed, but not committed." << endl;
8✔
100
                cout << "Use 'commit' to update, or 'rollback' to roll back the update." << endl;
8✔
101
                break;
8✔
102
        case standalone::Result::InstalledButFailedInPostCommit:
1✔
103
                cout << "Installed, but one or more post-commit steps failed." << endl;
1✔
104
                break;
1✔
105
        case standalone::Result::NoUpdateInProgress:
2✔
106
                cout << "No update in progress." << endl;
2✔
107
                break;
2✔
108
        case standalone::Result::FailedNothingDone:
2✔
109
                cout << "Installation failed. System not modified." << endl;
2✔
110
                break;
2✔
111
        case standalone::Result::RolledBack:
2✔
112
                cout << "Rolled back." << endl;
2✔
113
                break;
2✔
114
        case standalone::Result::NoRollback:
1✔
115
                cout << "Update Module does not support rollback." << endl;
1✔
116
                break;
1✔
117
        case standalone::Result::RollbackFailed:
1✔
118
                cout << "Rollback failed. System may be in an inconsistent state." << endl;
1✔
119
                break;
1✔
120
        case standalone::Result::FailedAndRolledBack:
1✔
121
                cout << "Installation failed. Rolled back modifications." << endl;
1✔
122
                break;
1✔
123
        case standalone::Result::FailedAndNoRollback:
1✔
124
                cout
125
                        << "Installation failed, and Update Module does not support rollback. System may be in an inconsistent state."
1✔
126
                        << endl;
1✔
127
                break;
1✔
128
        case standalone::Result::FailedAndRollbackFailed:
2✔
129
                cout
130
                        << "Installation failed, and rollback also failed. System may be in an inconsistent state."
2✔
131
                        << endl;
2✔
132
                break;
2✔
133
        }
134

135
        switch (result.result) {
40✔
136
        case standalone::Result::InstalledRebootRequired:
2✔
137
        case standalone::Result::InstalledAndCommittedRebootRequired:
138
                cout << "At least one payload requested a reboot of the device it updated." << endl;
2✔
139
                break;
2✔
140
        default:
38✔
141
                break;
38✔
142
        }
143

144
        return result.err;
40✔
145
}
146

147
error::Error InstallAction::Execute(context::MenderContext &main_context) {
31✔
148
        auto result = standalone::Install(main_context, src_);
62✔
149
        auto err = ResultHandler(result);
31✔
150
        if (!reboot_exit_code_
31✔
151
                && err.code == context::MakeError(context::RebootRequiredError, "").code) {
31✔
152
                // If reboot exit code isn't requested, then this type of error should be treated as
153
                // plain success.
154
                err = error::NoError;
1✔
155
        }
156
        return err;
62✔
157
}
158

159
error::Error CommitAction::Execute(context::MenderContext &main_context) {
4✔
160
        auto result = standalone::Commit(main_context);
4✔
161
        return ResultHandler(result);
8✔
162
}
163

164
error::Error RollbackAction::Execute(context::MenderContext &main_context) {
5✔
165
        auto result = standalone::Rollback(main_context);
5✔
166
        return ResultHandler(result);
10✔
167
}
168

169
error::Error DaemonAction::Execute(context::MenderContext &main_context) {
×
170
        events::EventLoop event_loop;
×
171
        daemon::Context ctx(main_context, event_loop);
×
172
        daemon::StateMachine state_machine(ctx, event_loop);
×
173
        state_machine.LoadStateFromDb();
×
174
        return state_machine.Run();
×
175
}
176

177
} // namespace cli
178
} // namespace update
179
} // 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