Skip to content

Commit fa2d962

Browse files
log-manager: enable non-standard path for local tests
Enable the log-manager to be launched with a path other than `/var/phosphor-logging` to allow it to be ran on a development system for test purposes. This required some refactoring throughout as to how paths were handled. Tested: After running tests, `/tmp/phosphor-logging` is populated with entries. Launching `./builddir/phosphor-log-manager /tmp/phosphor-logging`, the log-manager will have the entries on dbus: ``` $ busctl --user tree xyz.openbmc_project.Logging └─ /xyz └─ /xyz/openbmc_project └─ /xyz/openbmc_project/logging ├─ /xyz/openbmc_project/logging/entry │ ├─ /xyz/openbmc_project/logging/entry/100 │ ├─ /xyz/openbmc_project/logging/entry/101 │ ├─ /xyz/openbmc_project/logging/entry/102 │ ├─ /xyz/openbmc_project/logging/entry/103 ``` Signed-off-by: Patrick Williams <[email protected]> Change-Id: I84968edeed0dcf73aaf8bb653060b6d3400b9b7b
1 parent 253bfb7 commit fa2d962

19 files changed

+67
-25
lines changed

config/config.h.meson

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
#define RSYSLOG_SERVER_CONFIG_FILE "@rsyslog_server_conf@"
2727

28-
extern const char *ERRLOG_PERSIST_PATH;
29-
extern const char *EXTENSION_PERSIST_DIR;
3028
extern const bool IS_UNIT_TEST;
3129

3230
static constexpr size_t ERROR_CAP = @error_cap@;

config_main.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
22

3-
const char* ERRLOG_PERSIST_PATH = "/var/lib/phosphor-logging/errors";
4-
const char* EXTENSION_PERSIST_DIR = "/var/lib/phosphor-logging/extensions";
3+
const char* PERSIST_PATH_ROOT = "/var/lib/phosphor-logging";
54
const bool IS_UNIT_TEST = false;

elog_entry.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "elog_serialize.hpp"
44
#include "extensions.hpp"
55
#include "log_manager.hpp"
6+
#include "paths.hpp"
67

78
#include <fcntl.h>
89
#include <unistd.h>

elog_serialize.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "config.h"
44

55
#include "elog_entry.hpp"
6+
#include "paths.hpp"
67

78
#include <filesystem>
89
#include <string>
@@ -22,7 +23,7 @@ namespace fs = std::filesystem;
2223
* @return fs::path - pathname of persisted error file
2324
*/
2425
fs::path serialize(const Entry& e,
25-
const fs::path& dir = fs::path(ERRLOG_PERSIST_PATH));
26+
const fs::path& dir = fs::path(paths::error()));
2627

2728
/** @brief Deserialze a persisted error into a d-bus object
2829
* @param[in] path - pathname of persisted error file
@@ -38,8 +39,8 @@ bool deserialize(const fs::path& path, Entry& e);
3839
* be placed.
3940
* @return fs::path - pathname of persisted error file
4041
*/
41-
fs::path getEntrySerializePath(
42-
uint32_t id, const fs::path& dir = fs::path(ERRLOG_PERSIST_PATH));
42+
fs::path getEntrySerializePath(uint32_t id,
43+
const fs::path& dir = fs::path(paths::error()));
4344

4445
} // namespace logging
4546
} // namespace phosphor

extensions/openpower-pels/meson.build

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ libpel_sources = files(
6868
'severity.cpp',
6969
'user_header.cpp',
7070
'temporary_file.cpp',
71+
'../../paths.cpp',
7172
'../../util.cpp',
7273
extra_sources,
7374
)
@@ -86,7 +87,7 @@ libpel_deps = [
8687
libpel_lib = static_library(
8788
'pel',
8889
libpel_sources,
89-
'paths.cpp', # paths is separate because it is overridden during test.
90+
'pel_paths.cpp', # paths is separate because it is overridden during test.
9091
include_directories: include_directories('../..', '../../gen'),
9192
cpp_args: extra_args,
9293
dependencies: [

extensions/openpower-pels/paths.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
2+
#include "../../paths.hpp"
3+
24
#include <filesystem>
35

46
namespace openpower

extensions/openpower-pels/paths.cpp renamed to extensions/openpower-pels/pel_paths.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ static constexpr size_t defaultMaxNumPELs = 3000;
3030

3131
fs::path getPELIDFile()
3232
{
33-
fs::path logIDPath{EXTENSION_PERSIST_DIR};
33+
fs::path logIDPath{phosphor::logging::paths::extension()};
3434
logIDPath /= fs::path{"pels"} / fs::path{"pelID"};
3535
return logIDPath;
3636
}
3737

3838
fs::path getPELRepoPath()
3939
{
40-
std::filesystem::path repoPath{EXTENSION_PERSIST_DIR};
40+
std::filesystem::path repoPath{phosphor::logging::paths::extension()};
4141
repoPath /= "pels";
4242
return repoPath;
4343
}

extensions/openpower-pels/tools/peltool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ constexpr auto logging = "/xyz/openbmc_project/logging";
6565

6666
std::string pelLogDir()
6767
{
68-
return std::string(EXTENSION_PERSIST_DIR) + "/pels/logs";
68+
return std::string(phosphor::logging::paths::extension()) + "/pels/logs";
6969
}
7070

7171
/**

log_manager.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "elog_meta.hpp"
77
#include "elog_serialize.hpp"
88
#include "extensions.hpp"
9+
#include "paths.hpp"
910
#include "util.hpp"
1011

1112
#include <systemd/sd-bus.h>
@@ -584,7 +585,7 @@ void Manager::erase(uint32_t entryId)
584585
}
585586

586587
// Delete the persistent representation of this error.
587-
fs::path errorPath(ERRLOG_PERSIST_PATH);
588+
fs::path errorPath(paths::error());
588589
errorPath /= std::to_string(entryId);
589590
fs::remove(errorPath);
590591

@@ -633,7 +634,7 @@ void Manager::restore()
633634
return id == restoredId;
634635
};
635636

636-
fs::path dir(ERRLOG_PERSIST_PATH);
637+
fs::path dir(paths::error());
637638
if (!fs::exists(dir) || fs::is_empty(dir))
638639
{
639640
return;

log_manager_main.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "extensions.hpp"
66
#include "log_manager.hpp"
7+
#include "paths.hpp"
78

89
#include <phosphor-logging/lg2.hpp>
910
#include <sdbusplus/bus.hpp>
@@ -12,10 +13,16 @@
1213

1314
#include <filesystem>
1415

15-
int main(int /*argc*/, char* /*argv*/[])
16+
int main(int argc, char* argv[])
1617
{
1718
PHOSPHOR_LOG2_USING_WITH_FLAGS;
1819

20+
if (argc >= 1)
21+
{
22+
PERSIST_PATH_ROOT = strdup(argv[1]);
23+
info("Using temporary {PATH} for logs", "PATH", PERSIST_PATH_ROOT);
24+
}
25+
1926
auto bus = sdbusplus::bus::new_default();
2027
auto event = sdeventplus::Event::get_default();
2128
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
@@ -28,7 +35,7 @@ int main(int /*argc*/, char* /*argv*/[])
2835
phosphor::logging::Manager mgr(bus, OBJ_LOGGING, iMgr);
2936

3037
// Create a directory to persist errors.
31-
std::filesystem::create_directories(ERRLOG_PERSIST_PATH);
38+
std::filesystem::create_directories(phosphor::logging::paths::error());
3239

3340
// Recreate error d-bus objects from persisted errors.
3441
iMgr.restore();

meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ log_manager_sources = [
128128
'elog_serialize.cpp',
129129
'extensions.cpp',
130130
'log_manager.cpp',
131+
'paths.cpp',
131132
'util.cpp',
132133
)
133134
]

paths.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "config.h"
2+
3+
#include "paths.hpp"
4+
5+
namespace phosphor::logging::paths
6+
{
7+
auto error() -> std::filesystem::path
8+
{
9+
return std::filesystem::path(PERSIST_PATH_ROOT) / "errors";
10+
}
11+
auto extension() -> std::filesystem::path
12+
{
13+
return std::filesystem::path(PERSIST_PATH_ROOT) / "extensions";
14+
}
15+
} // namespace phosphor::logging::paths

paths.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <filesystem>
4+
#include <string>
5+
6+
extern const char* PERSIST_PATH_ROOT;
7+
8+
namespace phosphor::logging::paths
9+
{
10+
11+
auto error() -> std::filesystem::path;
12+
auto extension() -> std::filesystem::path;
13+
14+
} // namespace phosphor::logging::paths

test/common.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "config.h"
22

3-
const char* ERRLOG_PERSIST_PATH = "/tmp/errors";
4-
const char* EXTENSION_PERSIST_DIR = "/tmp/extensions";
3+
const char* PERSIST_PATH_ROOT = "/tmp/phosphor-logging";
54
const bool IS_UNIT_TEST = true;

test/elog_errorwrap_test.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "elog_serialize.hpp"
44
#include "log_manager.hpp"
5+
#include "paths.hpp"
56
#include "xyz/openbmc_project/Common/error.hpp"
67

78
#include <phosphor-logging/elog-errors.hpp>
@@ -87,7 +88,7 @@ class TestLogManager : public testing::Test
8788
bus(sdbusplus::bus::new_default()),
8889
manager(bus, "/xyz/openbmc_test/abc")
8990
{
90-
fs::create_directories(ERRLOG_PERSIST_PATH);
91+
fs::create_directories(paths::error());
9192
}
9293

9394
~TestLogManager()

test/elog_quiesce_test.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "elog_entry.hpp"
44
#include "log_manager.hpp"
5+
#include "paths.hpp"
56

67
#include <sdbusplus/bus.hpp>
78
#include <sdbusplus/test/sdbus_mock.hpp>
@@ -28,7 +29,7 @@ class TestQuiesceOnError : public testing::Test
2829
TestQuiesceOnError() : manager(mockedBus, OBJ_INTERNAL)
2930
{
3031
// Ensure any errors serializing to filesystem have directory created
31-
std::filesystem::create_directory(ERRLOG_PERSIST_PATH);
32+
std::filesystem::create_directories(paths::error());
3233
}
3334
};
3435

test/elog_update_ts_test.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "elog_serialize.hpp"
55
#include "extensions.hpp"
66
#include "log_manager.hpp"
7+
#include "paths.hpp"
78

89
#include <filesystem>
910
#include <thread>
@@ -34,11 +35,11 @@ void deleteIsNotProhibitedMock(uint32_t /*id*/, bool& prohibited)
3435
TEST(TestUpdateTS, testChangeResolved)
3536
{
3637
// Setting resolved will serialize, so need this directory.
37-
fs::create_directory(ERRLOG_PERSIST_PATH);
38+
fs::create_directories(paths::error());
3839

39-
if (!fs::exists(ERRLOG_PERSIST_PATH))
40+
if (!fs::exists(paths::error()))
4041
{
41-
ADD_FAILURE() << "Could not create " << ERRLOG_PERSIST_PATH << "\n";
42+
ADD_FAILURE() << "Could not create " << paths::error() << "\n";
4243
exit(1);
4344
}
4445

@@ -50,7 +51,7 @@ TEST(TestUpdateTS, testChangeResolved)
5051
std::srand(std::time(nullptr));
5152
uint32_t id = std::rand();
5253

53-
if (fs::exists(fs::path{ERRLOG_PERSIST_PATH} / std::to_string(id)))
54+
if (fs::exists(fs::path{paths::error()} / std::to_string(id)))
5455
{
5556
std::cerr << "Another testcase is using ID " << id << "\n";
5657
id = std::rand();
@@ -96,7 +97,7 @@ TEST(TestUpdateTS, testChangeResolved)
9697
EXPECT_EQ(updateTS, elog.updateTimestamp());
9798

9899
// Leave the directory in case other CI instances are running
99-
fs::remove(fs::path{ERRLOG_PERSIST_PATH} / std::to_string(id));
100+
fs::remove(fs::path{paths::error()} / std::to_string(id));
100101
}
101102

102103
TEST(TestResolveProhibited, testResolveFlagChange)

test/openpower-pels/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ openpower_pels = {
6767
openpower_test_lib = static_library(
6868
'openpower_test_lib',
6969
'pel_utils.cpp',
70-
'paths.cpp',
70+
'pel_paths.cpp',
7171
libpel_sources,
7272
peltool_sources,
7373
'../common.cpp',
File renamed without changes.

0 commit comments

Comments
 (0)