Skip to content

Commit

Permalink
Deduplicate lctl calls in iml-agent (whamcloud#2099)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Pashev <pashev.igor@gmail.com>
  • Loading branch information
ip1981 authored and beevans committed Aug 6, 2020
1 parent 0569544 commit 579655b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
17 changes: 10 additions & 7 deletions iml-agent/src/action_plugins/action_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::action_plugins::{
check_kernel, check_stonith, firewall_cmd, high_availability, kernel_module, lamigo, lpurge,
ltuer, lustre,
ntp::{action_configure, is_ntp_configured},
ostpool, package, postoffice,
stratagem::{action_purge, action_warning, action_filesync, server},
use crate::{
action_plugins::{
check_kernel, check_stonith, firewall_cmd, high_availability, kernel_module, lamigo,
lpurge, ltuer, lustre,
ntp::{action_configure, is_ntp_configured},
ostpool, package, postoffice,
stratagem::{action_purge, action_warning, server},
},
lustre::lctl,
};
use iml_util::action_plugins;
use iml_wire_types::ActionName;
Expand Down Expand Up @@ -46,7 +49,7 @@ pub fn create_registry() -> action_plugins::Actions {
.add_plugin("add_firewall_port", firewall_cmd::add_port)
.add_plugin("remove_firewall_port", firewall_cmd::remove_port)
.add_plugin("pcs", high_availability::pcs)
.add_plugin("lctl", lustre::lctl)
.add_plugin("lctl", lctl::<Vec<_>, String>)
.add_plugin("ostpool_create", ostpool::action_pool_create)
.add_plugin("ostpool_wait", ostpool::action_pool_wait)
.add_plugin("ostpool_destroy", ostpool::action_pool_destroy)
Expand Down
12 changes: 0 additions & 12 deletions iml-agent/src/action_plugins/lctl.rs

This file was deleted.

9 changes: 1 addition & 8 deletions iml-agent/src/action_plugins/lustre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{agent_error::ImlAgentError, lustre};
use crate::agent_error::ImlAgentError;
use futures::TryFutureExt;
use iml_cmd::{CheckedCommandExt, Command};

/// Runs lctl with given arguments
pub async fn lctl(args: Vec<String>) -> Result<String, ImlAgentError> {
lustre::lctl(args.iter().map(|s| s.as_ref()).collect())
.await
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
}

/// According to http://wiki.lustre.org/Mounting_a_Lustre_File_System_on_Client_Nodes
/// we need to execute mount command
/// ```bash
Expand Down
2 changes: 1 addition & 1 deletion iml-agent/src/action_plugins/ostpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub async fn action_pool_destroy(cmd: CmdPool) -> Result<(), ImlAgentError> {

pub async fn pool_list(filesystem: &str) -> Result<Vec<String>, ImlAgentError> {
match lctl(vec!["pool_list", &filesystem]).await {
Ok(o) => Ok(String::from_utf8_lossy(&o.stdout)
Ok(o) => Ok(o
.lines()
.skip(1)
.map(|s| s.rsplit('.').next().unwrap().to_string())
Expand Down
3 changes: 1 addition & 2 deletions iml-agent/src/daemon_plugins/ostpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ async fn list_fs() -> Vec<String> {
lctl(vec!["get_param", "-N", "mdt.*-MDT0000"])
.await
.map(|o| {
String::from_utf8_lossy(&o.stdout)
.lines()
o.lines()
.filter_map(|line| {
line.split('.')
.nth(1)
Expand Down
9 changes: 8 additions & 1 deletion iml-agent/src/lustre.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use crate::agent_error::ImlAgentError;
use futures::TryFutureExt;
use iml_cmd::{CheckedCommandExt, Command};
use std::ffi::OsStr;

pub async fn lctl(args: Vec<&str>) -> Result<std::process::Output, ImlAgentError> {
/// Runs lctl with given arguments
pub async fn lctl<I, S>(args: I) -> Result<String, ImlAgentError>
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
Command::new("/usr/sbin/lctl")
.args(args)
.checked_output()
.err_into()
.await
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
}

0 comments on commit 579655b

Please sign in to comment.