From 589d0cbd2b8542228af8a48ece56698e34b22082 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 18 Nov 2020 15:07:43 -0500 Subject: [PATCH] rust: Move to new systemd journal API for opening The `Journal::open` API has been deprecated in favour of the new `OpenOptions` builder pattern. We could dedupe this a bit more, though the mock journal in the history code makes it trickier and there's little value in mocking the builder pattern too. --- rust/src/history.rs | 22 ++++++++++++++++++---- rust/src/journal.rs | 6 +++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/rust/src/history.rs b/rust/src/history.rs index 1a1a38de..86a72cc2 100644 --- a/rust/src/history.rs +++ b/rust/src/history.rs @@ -187,8 +187,22 @@ where s.and_then(|s| s.parse::().ok()) } +#[cfg(not(test))] +fn journal_open() -> Result { + Ok(journal::OpenOptions::default() + .system(true) + .local_only(true) + .runtime_only(false) + .open()?) +} + +#[cfg(test)] +fn journal_open() -> Result { + mock_journal::Journal::new() +} + fn history_get_oldest_deployment_msg_timestamp() -> Result> { - let mut journal = journal::Journal::open(journal::JournalFiles::System, false, true)?; + let mut journal = journal_open()?; journal.seek(journal::JournalSeek::Head)?; journal.match_add("MESSAGE_ID", RPMOSTREE_DEPLOY_MSG)?; while let Some(rec) = journal.next_entry()? { @@ -239,7 +253,7 @@ fn history_prune() -> Result<()> { impl HistoryCtx { /// Create a new context object. Called from C through `ror_history_ctx_new()`. fn new_boxed() -> Result> { - let mut journal = journal::Journal::open(journal::JournalFiles::System, false, true)?; + let mut journal = journal_open()?; journal.seek(journal::JournalSeek::Tail)?; Ok(Box::new(HistoryCtx { @@ -446,7 +460,7 @@ impl HistoryCtx { #[cfg(test)] mod mock_journal { use super::Result; - pub use systemd::journal::{JournalFiles, JournalRecord, JournalSeek}; + pub use systemd::journal::{JournalRecord, JournalSeek}; pub struct Journal { pub entries: Vec<(u64, JournalRecord)>, @@ -455,7 +469,7 @@ mod mock_journal { } impl Journal { - pub fn open(_: JournalFiles, _: bool, _: bool) -> Result { + pub fn new() -> Result { Ok(Journal { entries: Vec::new(), current_timestamp: None, diff --git a/rust/src/journal.rs b/rust/src/journal.rs index ed26debf..11be15e3 100644 --- a/rust/src/journal.rs +++ b/rust/src/journal.rs @@ -26,7 +26,11 @@ fn print_staging_failure_msg(msg: Option<&str>) -> Result<()> { /// Look for a failure from ostree-finalized-stage.service in the journal of the previous boot. fn journal_print_staging_failure() -> Result<()> { - let mut j = journal::Journal::open(journal::JournalFiles::System, false, true)?; + let mut j = journal::OpenOptions::default() + .system(true) + .local_only(true) + .runtime_only(false) + .open()?; j.seek(journal::JournalSeek::Head)?; // first, go to the first entry of the current boot