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

mendersoftware / mender / 950545443

pending completion
950545443

push

gitlab-ci

vpodzime
feat: Introduce deployments::DeploymentLog

A simple class that can scope logging of a specific deployment.

Ticket: MEN-6578
Changelog: none
Signed-off-by: Vratislav Podzimek <v.podzimek@mykolab.com>

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

4283 of 5387 relevant lines covered (79.51%)

159.37 hits per line

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

97.8
/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/log.hpp>
18

19
#include <mender-update/standalone.hpp>
20

21
namespace mender {
22
namespace update {
23
namespace cli {
24

25
namespace conf = mender::common::conf;
26
namespace database = mender::common::key_value_database;
27
namespace log = mender::common::log;
28

29
namespace standalone = mender::update::standalone;
30

31
error::Error ShowArtifactAction::Execute(context::MenderContext &main_context) {
2✔
32
        auto exp_provides = main_context.LoadProvides();
4✔
33
        if (!exp_provides) {
2✔
34
                return exp_provides.error();
×
35
        }
36

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

46
error::Error ShowProvidesAction::Execute(context::MenderContext &main_context) {
28✔
47
        auto exp_provides = main_context.LoadProvides();
56✔
48
        if (!exp_provides) {
28✔
49
                return exp_provides.error();
×
50
        }
51

52
        auto &provides = exp_provides.value();
28✔
53
        for (const auto &elem : provides) {
94✔
54
                cout << elem.first << "=" << elem.second << endl;
66✔
55
        }
56

57
        return error::NoError;
28✔
58
}
59

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

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

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

140
        return result.err;
40✔
141
}
142

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

155
error::Error CommitAction::Execute(context::MenderContext &main_context) {
4✔
156
        auto result = standalone::Commit(main_context);
4✔
157
        return ResultHandler(result);
8✔
158
}
159

160
error::Error RollbackAction::Execute(context::MenderContext &main_context) {
5✔
161
        auto result = standalone::Rollback(main_context);
5✔
162
        return ResultHandler(result);
10✔
163
}
164

165
} // namespace cli
166
} // namespace update
167
} // 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