From 579655b873c02c397f28c1d818395ee3680ac8f7 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Fri, 24 Jul 2020 19:44:13 +0200 Subject: [PATCH] Deduplicate lctl calls in iml-agent (#2099) Signed-off-by: Igor Pashev --- iml-agent/src/action_plugins/action_plugin.rs | 17 ++++++++++------- iml-agent/src/action_plugins/lctl.rs | 12 ------------ iml-agent/src/action_plugins/lustre.rs | 9 +-------- iml-agent/src/action_plugins/ostpool.rs | 2 +- iml-agent/src/daemon_plugins/ostpool.rs | 3 +-- iml-agent/src/lustre.rs | 9 ++++++++- 6 files changed, 21 insertions(+), 31 deletions(-) delete mode 100644 iml-agent/src/action_plugins/lctl.rs diff --git a/iml-agent/src/action_plugins/action_plugin.rs b/iml-agent/src/action_plugins/action_plugin.rs index 3e4ad616d1..f1fca383a5 100644 --- a/iml-agent/src/action_plugins/action_plugin.rs +++ b/iml-agent/src/action_plugins/action_plugin.rs @@ -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; @@ -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::, 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) diff --git a/iml-agent/src/action_plugins/lctl.rs b/iml-agent/src/action_plugins/lctl.rs deleted file mode 100644 index e09d2d2bd1..0000000000 --- a/iml-agent/src/action_plugins/lctl.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2020 DDN. All rights reserved. -// 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}; - -/// Runs lctl with given arguments -pub async fn lctl(args: Vec) -> Result { - lustre::lctl(args.iter().map(|s| s.as_ref()).collect()) - .await - .map(|o| String::from_utf8_lossy(&o.stdout).to_string()) -} diff --git a/iml-agent/src/action_plugins/lustre.rs b/iml-agent/src/action_plugins/lustre.rs index 2a02824440..101a8ac2d0 100644 --- a/iml-agent/src/action_plugins/lustre.rs +++ b/iml-agent/src/action_plugins/lustre.rs @@ -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) -> Result { - 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 diff --git a/iml-agent/src/action_plugins/ostpool.rs b/iml-agent/src/action_plugins/ostpool.rs index 1ba786b248..cf7d7eb6fb 100644 --- a/iml-agent/src/action_plugins/ostpool.rs +++ b/iml-agent/src/action_plugins/ostpool.rs @@ -90,7 +90,7 @@ pub async fn action_pool_destroy(cmd: CmdPool) -> Result<(), ImlAgentError> { pub async fn pool_list(filesystem: &str) -> Result, 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()) diff --git a/iml-agent/src/daemon_plugins/ostpool.rs b/iml-agent/src/daemon_plugins/ostpool.rs index 61abe8f478..9aa9f8b05a 100644 --- a/iml-agent/src/daemon_plugins/ostpool.rs +++ b/iml-agent/src/daemon_plugins/ostpool.rs @@ -44,8 +44,7 @@ async fn list_fs() -> Vec { 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) diff --git a/iml-agent/src/lustre.rs b/iml-agent/src/lustre.rs index 999e4e7fad..523e9f9aba 100644 --- a/iml-agent/src/lustre.rs +++ b/iml-agent/src/lustre.rs @@ -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 { +/// Runs lctl with given arguments +pub async fn lctl(args: I) -> Result +where + I: IntoIterator, + S: AsRef, +{ Command::new("/usr/sbin/lctl") .args(args) .checked_output() .err_into() .await + .map(|o| String::from_utf8_lossy(&o.stdout).to_string()) }