Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Update lamigo/lpurge for lipe compatibililty (#2292)
Browse files Browse the repository at this point in the history
* Update lamigo/lpurge for lipe compatibililty

Remove ltuer as it's unused.

Signed-off-by: Nathaniel Clark <nclark@whamcloud.com>

* Disable Hotpools v3 by default

Setting heatfn=none will result in V2 behavior.

Signed-off-by: Nathaniel Clark <nclark@whamcloud.com>

* Fix format and cargo-test

Signed-off-by: Nathaniel Clark <nclark@whamcloud.com>

* Alter action plugin naming

Signed-off-by: Nathaniel Clark <nclark@whamcloud.com>
  • Loading branch information
utopiabound authored Oct 21, 2020
1 parent 8e67911 commit eaa8533
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 176 deletions.
8 changes: 4 additions & 4 deletions iml-agent/src/action_plugins/action_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::{
action_plugins::{
check_kernel, check_stonith, firewall_cmd, high_availability, kernel_module, lamigo, ldev,
lpurge, ltuer, lustre,
lpurge, lustre,
ntp::{action_configure, is_ntp_configured},
ostpool, package, postoffice,
stratagem::{
Expand Down Expand Up @@ -67,15 +67,15 @@ pub fn create_registry() -> action_plugins::Actions {
.add_plugin("snapshot_unmount", lustre::snapshot::unmount)
.add_plugin("postoffice_add", postoffice::route_add)
.add_plugin("postoffice_remove", postoffice::route_remove)
.add_plugin("create_lpurge_conf", lpurge::create_lpurge_conf)
.add_plugin("create_lamigo_service", lamigo::create_lamigo_service_unit)
.add_plugin(
"configure_ntp",
action_configure::update_and_write_new_config,
)
.add_plugin("is_ntp_configured", is_ntp_configured::is_ntp_configured)
.add_plugin("create_ltuer_conf", ltuer::create_ltuer_conf)
.add_plugin("create_ldev_conf", ldev::create)
// HotPools
.add_plugin("create_lpurge_conf", lpurge::create_lpurge_conf)
.add_plugin("create_lamigo_conf", lamigo::create_lamigo_conf)
// Task Actions
.add_plugin("action.mirror.extend", action_mirror::process_extend_fids)
.add_plugin("action.mirror.resync", action_mirror::process_resync_fids)
Expand Down
92 changes: 33 additions & 59 deletions iml-agent/src/action_plugins/lamigo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,33 @@ pub struct Config {
min_age: u32,

#[structopt(long)]
/// Lustre device to be mounted, e.g. `192.168.0.100@tcp0:/spfs`
/// Local mountpoint of lustre client
mountpoint: String,

#[structopt(long)]
/// IML mailbox name, e.g. `mailbox1`, where `lamigo` will write FIDs
mailbox: String,
/// IML mailbox name, e.g. `mailbox1`, where `lamigo` will write FIDs for mirror extend
mailbox_extend: String,

#[structopt(long)]
/// IML mailbox name, e.g. `mailbox2`, where `lamigo` will write FIDs for mirror resync
mailbox_resync: String,

#[structopt(long)]
heatfn: Option<u32>,
}

impl Config {
fn generate_unit(&self, mailbox: String) -> String {
fn generate_unit(&self, mailbox_extend: String, mailbox_resync: String) -> String {
format!(
"mdt={fs}-MDT{mdt:04x}\n\
mountpoint={mountpoint}\n\
mount={mountpoint}\n\
user={user}\n\
min-age={age}\n\
src={fast}\n\
tgt={slow}\n\
iml-socket={mailbox}\n\
iml-ex-socket={extend}\n\
iml-re-socket={resync}\n\
heatfn={heatfn}\n\
",
fs = self.fs,
mdt = self.mdt,
Expand All @@ -60,7 +69,13 @@ impl Config {
age = self.min_age,
fast = self.hot_pool,
slow = self.cold_pool,
mailbox = mailbox,
extend = mailbox_extend,
resync = mailbox_resync,
heatfn = if let Some(val) = self.heatfn {
format!("{}", val)
} else {
"none".into()
},
)
}
}
Expand All @@ -75,60 +90,34 @@ fn expand_path_fmt(path_fmt: &str, c: &Config) -> strfmt::Result<String> {
vars.insert("hot_pool".to_string(), &c.hot_pool);
vars.insert("cold_pool".to_string(), &c.cold_pool);
vars.insert("min_age".to_string(), &min_age_str);
vars.insert("mailbox".to_string(), &c.mailbox);
strfmt::strfmt(&path_fmt, &vars)
}

fn format_lamigo_conf_file(c: &Config, path_fmt: &str) -> Result<PathBuf, ImlAgentError> {
Ok(PathBuf::from(expand_path_fmt(path_fmt, &c)?))
}

fn format_lamigo_unit_file(c: &Config) -> PathBuf {
PathBuf::from(format!(
"/etc/systemd/system/lamigo-{}-MDT{:04x}.service",
c.fs, c.mdt
))
}

fn format_lamigo_unit_contents(c: &Config, path_fmt: &str) -> Result<String, ImlAgentError> {
Ok(format!(
"[Unit]\n\
Description=Run lamigo service for {fs}-MDT{mdt:04x}\n\
\n\
[Service]\n\
ExecStartPre=/usr/bin/lfs df {mountpoint}\n\
ExecStart=/usr/bin/lamigo -f {conf}\n",
mountpoint = c.mountpoint,
conf = format_lamigo_conf_file(c, path_fmt)?.to_string_lossy(),
fs = c.fs,
mdt = c.mdt,
))
}

async fn write(file: PathBuf, cnt: String) -> Result<(), ImlAgentError> {
if let Some(parent) = file.parent() {
fs::create_dir_all(&parent).await?;
}
fs::write(file, cnt.as_bytes()).err_into().await
}

pub async fn create_lamigo_service_unit(c: Config) -> Result<(), ImlAgentError> {
pub async fn create_lamigo_conf(c: Config) -> Result<(), ImlAgentError> {
let path_fmt = env::get_var("LAMIGO_CONF_PATH");

let path = format_lamigo_conf_file(&c, &path_fmt)?;
let cnt = c.generate_unit(env::mailbox_sock(&c.mailbox));
write(path, cnt).await?;

let path = format_lamigo_unit_file(&c);
let cnt = format_lamigo_unit_contents(&c, &path_fmt)?;
let cnt = c.generate_unit(
env::mailbox_sock(&c.mailbox_extend),
env::mailbox_sock(&c.mailbox_resync),
);
write(path, cnt).await
}

#[cfg(test)]
mod lamigo_tests {
use super::*;
use insta::assert_display_snapshot;
use std::env;

#[test]
fn test_expand_path_fmt() {
Expand All @@ -140,7 +129,9 @@ mod lamigo_tests {
cold_pool: "SLOW_POOL".into(),
min_age: 35353,
mountpoint: "/mnt/spfs".into(),
mailbox: "mailbox".into(),
mailbox_extend: "mailbox-extend".into(),
mailbox_resync: "mailbox-resync".into(),
heatfn: None,
};
let fmt1 = "/etc/systemd/system/lamigo-{fs}-{mdt}.service";
assert_eq!(
Expand Down Expand Up @@ -168,31 +159,14 @@ mod lamigo_tests {
cold_pool: "SLOW_POOL".into(),
min_age: 35353,
mountpoint: "/mnt/spfs".into(),
mailbox: "mailbox".into(),
mailbox_extend: "mailbox-extend".into(),
mailbox_resync: "mailbox-resync".into(),
heatfn: None,
};

assert_eq!(
format_lamigo_conf_file(&config, "/etc/lamigo/{fs}-{mdt}.conf").unwrap(),
PathBuf::from("/etc/lamigo/LU_TEST1-MDT0010.conf")
)
}

#[tokio::test]
async fn test_works() {
let config = Config {
fs: "LU_TEST2".into(),
mdt: 17,
user: "nick".into(),
min_age: 35353,
mailbox: "mailbox2".into(),
mountpoint: "/mnt/spfs".into(),
hot_pool: "FAST_POOL".into(),
cold_pool: "SLOW_POOL".into(),
};

let content = format_lamigo_unit_contents(&config, "/etc/lamigo/{fs}-{mdt}.conf")
.expect("cannot generate unit");

assert_display_snapshot!(content);
}
}
3 changes: 1 addition & 2 deletions iml-agent/src/action_plugins/lpurge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ impl Config {
format!(
"\
device={fs}-OST{ost:04x}\n\
dryrun=true\n\
freehi={freehi}\n\
freelo={freelo}\n\
listen_socket={socket}\n\
iml_socket={socket}\n\
max_jobs=0\n\
pool={fs}.{pool}\n\
",
Expand Down
73 changes: 0 additions & 73 deletions iml-agent/src/action_plugins/ltuer.rs

This file was deleted.

1 change: 0 additions & 1 deletion iml-agent/src/action_plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod kernel_module;
pub mod lamigo;
pub mod ldev;
pub mod lpurge;
pub mod ltuer;
pub mod lustre;
pub mod ntp;
pub mod ostpool;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ source: iml-agent/src/action_plugins/lpurge.rs
expression: cnt
---
device=lima-OST0010
dryrun=true
freehi=123
freelo=60
listen_socket=foobar
iml_socket=foobar
max_jobs=0
pool=lima.santiago

26 changes: 2 additions & 24 deletions iml-agent/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use console::{style, Term};
use iml_agent::action_plugins::{
check_kernel, check_stonith, high_availability, kernel_module, lamigo, lpurge, ltuer, lustre,
check_kernel, check_stonith, high_availability, kernel_module, lamigo, lpurge, lustre,
ntp::{action_configure, is_ntp_configured},
ostpool, package, postoffice,
stratagem::{
Expand Down Expand Up @@ -372,18 +372,6 @@ pub enum App {
command: MountCommand,
},

#[structopt(name = "create_ltuer_conf")]
CreateLtuerConf {
#[structopt(name = "MAILBOX_PATH")]
mailbox_path: String,

#[structopt(name = "FS_NAME")]
fs_name: String,

#[structopt(name = "COLD_POOL")]
cold_pool: String,
},

#[structopt(name = "kernel_module")]
/// Get kernel module state and version
KernelModule {
Expand Down Expand Up @@ -870,16 +858,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
exit(exitcode::SOFTWARE);
}
}
App::CreateLtuerConf {
mailbox_path,
fs_name,
cold_pool,
} => {
if let Err(e) = ltuer::create_ltuer_conf((mailbox_path, fs_name, cold_pool)).await {
eprintln!("{:?}", e);
exit(exitcode::SOFTWARE);
}
}
App::KernelModule { command } => {
if let Err(e) = match command {
KernelModuleCommand::Loaded { module } => kernel_module::loaded(module)
Expand All @@ -900,7 +878,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
App::LAmigo { c } => {
if let Err(e) = lamigo::create_lamigo_service_unit(c).await {
if let Err(e) = lamigo::create_lamigo_conf(c).await {
eprintln!("{}", e);
exit(exitcode::SOFTWARE);
}
Expand Down

0 comments on commit eaa8533

Please sign in to comment.