blob: 11386e0ca858e642997679159463a217a8bd9295 [file] [log] [blame]
Patrick Venture3ecb3502019-05-17 11:03:51 -07001/*
2 * Copyright 2019 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Patrick Venture26a17262019-05-20 11:03:35 -070017#include "verify_systemd.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -070018
19#include "status.hpp"
Patrick Venture26a17262019-05-20 11:03:35 -070020#include "verify.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -070021
22#include <fstream>
23#include <memory>
24#include <sdbusplus/bus.hpp>
25#include <string>
26#include <vector>
27
Patrick Venture1d5a31c2019-05-20 11:38:22 -070028namespace ipmi_flash
Patrick Venture3ecb3502019-05-17 11:03:51 -070029{
30
31std::unique_ptr<VerificationInterface>
Patrick Venture26a17262019-05-20 11:03:35 -070032 SystemdVerification::CreateVerification(sdbusplus::bus::bus&& bus,
Patrick Venture3ecb3502019-05-17 11:03:51 -070033 const std::string& path,
34 const std::string& service)
35{
Patrick Venture26a17262019-05-20 11:03:35 -070036 return std::make_unique<SystemdVerification>(std::move(bus), path, service);
Patrick Venture3ecb3502019-05-17 11:03:51 -070037}
38
Patrick Venture26a17262019-05-20 11:03:35 -070039bool SystemdVerification::triggerVerification()
Patrick Venture3ecb3502019-05-17 11:03:51 -070040{
41 static constexpr auto systemdService = "org.freedesktop.systemd1";
42 static constexpr auto systemdRoot = "/org/freedesktop/systemd1";
43 static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
44
45 auto method = bus.new_method_call(systemdService, systemdRoot,
46 systemdInterface, "StartUnit");
47 method.append(triggerService);
48 method.append("replace");
49
50 try
51 {
52 bus.call_noreply(method);
53 }
54 catch (const sdbusplus::exception::SdBusError& ex)
55 {
56 /* TODO: Once logging supports unit-tests, add a log message to test
57 * this failure.
58 */
59 return false;
60 }
61
62 return true;
63}
64
Patrick Venture26a17262019-05-20 11:03:35 -070065void SystemdVerification::abortVerification()
Patrick Venture3ecb3502019-05-17 11:03:51 -070066{
67 /* TODO: Implement this. */
68}
69
Patrick Venturef1f0f652019-06-03 09:10:19 -070070VerifyCheckResponses SystemdVerification::status()
Patrick Venture3ecb3502019-05-17 11:03:51 -070071{
72 VerifyCheckResponses result = VerifyCheckResponses::other;
73
74 std::ifstream ifs;
75 ifs.open(checkPath);
76 if (ifs.good())
77 {
78 /*
79 * Check for the contents of the file, accepting:
80 * running, success, or failed.
81 */
82 std::string status;
83 ifs >> status;
84 if (status == "running")
85 {
86 result = VerifyCheckResponses::running;
87 }
88 else if (status == "success")
89 {
90 result = VerifyCheckResponses::success;
91 }
92 else if (status == "failed")
93 {
94 result = VerifyCheckResponses::failed;
95 }
96 }
97
98 return result;
99}
100
Patrick Venture1d5a31c2019-05-20 11:38:22 -0700101} // namespace ipmi_flash