Skip to content

Commit

Permalink
Call into oxlog from illumos-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Jan 19, 2024
1 parent 09ad1b5 commit caf3cd5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 27 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ nexus-inventory = { path = "nexus/inventory" }
omicron-certificates = { path = "certificates" }
omicron-passwords = { path = "passwords" }
omicron-workspace-hack = "0.1.0"
oxlog = { path = "dev-tools/oxlog" }
nexus-test-interface = { path = "nexus/test-interface" }
nexus-test-utils-macros = { path = "nexus/test-utils-macros" }
nexus-test-utils = { path = "nexus/test-utils" }
Expand Down
1 change: 1 addition & 0 deletions illumos-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ libc.workspace = true
macaddr.workspace = true
omicron-common.workspace = true
oxide-vpc.workspace = true
oxlog.workspace = true
schemars.workspace = true
serde.workspace = true
slog.workspace = true
Expand Down
28 changes: 1 addition & 27 deletions illumos-utils/src/running_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use camino::{Utf8Path, Utf8PathBuf};
use camino_tempfile::Utf8TempDir;
use ipnetwork::IpNetwork;
use omicron_common::backoff;
pub use oxlog::is_oxide_smf_log_file;
use slog::{error, info, o, warn, Logger};
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::sync::Arc;
Expand Down Expand Up @@ -1411,24 +1412,8 @@ pub fn is_oxide_smf_service(fmri: impl AsRef<str>) -> bool {
SMF_SERVICE_PREFIXES.iter().any(|prefix| fmri.starts_with(prefix))
}

/// Return true if the provided file name appears to be a valid log file for an
/// Oxide-managed SMF service.
///
/// Note that this operates on the _file name_. Any leading path components will
/// cause this check to return `false`.
pub fn is_oxide_smf_log_file(filename: impl AsRef<str>) -> bool {
// Log files are named by the SMF services, with the `/` in the FMRI
// translated to a `-`.
const PREFIXES: [&str; 2] = ["oxide-", "system-illumos-"];
let filename = filename.as_ref();
PREFIXES
.iter()
.any(|prefix| filename.starts_with(prefix) && filename.contains(".log"))
}

#[cfg(test)]
mod tests {
use super::is_oxide_smf_log_file;
use super::is_oxide_smf_service;

#[test]
Expand All @@ -1438,15 +1423,4 @@ mod tests {
assert!(!is_oxide_smf_service("svc:/system/blah:default"));
assert!(!is_oxide_smf_service("svc:/not/oxide/blah:default"));
}

#[test]
fn test_is_oxide_smf_log_file() {
assert!(is_oxide_smf_log_file("oxide-blah:default.log"));
assert!(is_oxide_smf_log_file("oxide-blah:default.log.0"));
assert!(is_oxide_smf_log_file("oxide-blah:default.log.1111"));
assert!(is_oxide_smf_log_file("system-illumos-blah:default.log"));
assert!(is_oxide_smf_log_file("system-illumos-blah:default.log.0"));
assert!(!is_oxide_smf_log_file("not-oxide-blah:default.log"));
assert!(!is_oxide_smf_log_file("not-system-illumos-blah:default.log"));
}
}

0 comments on commit caf3cd5

Please sign in to comment.