summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDidier Wenzek <didier.wenzek@acidalie.com>2022-04-14 15:21:57 +0100
committerGitHub <noreply@github.com>2022-04-14 15:21:57 +0100
commitc65512084af039ce17ef2869f9534878975c8a8f (patch)
treef480c0336da822d76f3ac3d8fceb0c96a1d55d94
parentc3dde3e670bd80450978c8a907e2a16082eebc74 (diff)
parentea4faf4bdd7ec872146b72ce9ad06d2749603bba (diff)
Merge pull request #1063 from makr11st/feature/759_logged_command_to_crate
#759 Move 'logged_command' to a crate as it going to be used by other components
-rw-r--r--Cargo.lock58
-rw-r--r--crates/common/logged_command/Cargo.toml20
-rw-r--r--crates/common/logged_command/src/lib.rs3
-rw-r--r--crates/common/logged_command/src/logged_command.rs (renamed from crates/core/plugin_sm/src/logged_command.rs)19
-rw-r--r--crates/core/plugin_sm/Cargo.toml1
-rw-r--r--crates/core/plugin_sm/src/lib.rs1
-rw-r--r--crates/core/plugin_sm/src/plugin.rs2
7 files changed, 89 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5356983e..7ff7885c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1401,6 +1401,21 @@ dependencies = [
]
[[package]]
+name = "logged_command"
+version = "0.6.1"
+dependencies = [
+ "anyhow",
+ "assert_matches",
+ "async-trait",
+ "log",
+ "serial_test 0.6.0",
+ "tempfile",
+ "test-case",
+ "thiserror",
+ "tokio",
+]
+
+[[package]]
name = "matches"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1568,7 +1583,7 @@ dependencies = [
"futures",
"mqtt_tests",
"rumqttc",
- "serial_test",
+ "serial_test 0.5.1",
"thiserror",
"tokio",
]
@@ -1955,9 +1970,10 @@ dependencies = [
"async-trait",
"csv",
"download",
+ "logged_command",
"serde",
"serde_json",
- "serial_test",
+ "serial_test 0.5.1",
"tedge_utils",
"tempfile",
"test-case",
@@ -2454,6 +2470,12 @@ dependencies = [
]
[[package]]
+name = "rustversion"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f"
+
+[[package]]
name = "rusty-fork"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2610,7 +2632,18 @@ checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d"
dependencies = [
"lazy_static",
"parking_lot 0.11.2",
- "serial_test_derive",
+ "serial_test_derive 0.5.1",
+]
+
+[[package]]
+name = "serial_test"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5bcc41d18f7a1d50525d080fd3e953be87c4f9f1a974f3c21798ca00d54ec15"
+dependencies = [
+ "lazy_static",
+ "parking_lot 0.11.2",
+ "serial_test_derive 0.6.0",
]
[[package]]
@@ -2625,6 +2658,19 @@ dependencies = [
]
[[package]]
+name = "serial_test_derive"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2881bccd7d60fb32dfa3d7b3136385312f8ad75e2674aab2852867a09790cae8"
+dependencies = [
+ "proc-macro-error",
+ "proc-macro2 1.0.36",
+ "quote 1.0.15",
+ "rustversion",
+ "syn 1.0.88",
+]
+
+[[package]]
name = "sha-1"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2799,7 +2845,7 @@ dependencies = [
"predicates 2.1.1",
"serde",
"serde_json",
- "serial_test",
+ "serial_test 0.5.1",
"tedge_config",
"tedge_users",
"tedge_utils",
@@ -2833,7 +2879,7 @@ dependencies = [
"hamcrest2",
"reqwest",
"serde",
- "serial_test",
+ "serial_test 0.5.1",
"tedge_utils",
"test-case",
"thiserror",
@@ -2910,7 +2956,7 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
- "serial_test",
+ "serial_test 0.5.1",
"tedge_config",
"tedge_users",
"tedge_utils",
diff --git a/crates/common/logged_command/Cargo.toml b/crates/common/logged_command/Cargo.toml
new file mode 100644
index 00000000..5a5df9c0
--- /dev/null
+++ b/crates/common/logged_command/Cargo.toml
@@ -0,0 +1,20 @@
+[package]
+name = "logged_command"
+version = "0.6.1"
+authors = ["thin-edge.io team <info@thin-edge.io>"]
+edition = "2021"
+rust-version = "1.58.1"
+
+[dependencies]
+async-trait = "0.1"
+log = "0.4"
+thiserror = "1.0"
+tokio = { version = "1.8", features = [ "fs", "io-util", "macros", "process", "rt" ] }
+
+
+[dev-dependencies]
+anyhow = "1.0"
+assert_matches = "1.5"
+serial_test = "0.6"
+tempfile = "3.2"
+test-case = "2.0"
diff --git a/crates/common/logged_command/src/lib.rs b/crates/common/logged_command/src/lib.rs
new file mode 100644
index 00000000..1bd2fdf9
--- /dev/null
+++ b/crates/common/logged_command/src/lib.rs
@@ -0,0 +1,3 @@
+mod logged_command;
+
+pub use crate::logged_command::{LoggedCommand, LoggingChild};
diff --git a/crates/core/plugin_sm/src/logged_command.rs b/crates/common/logged_command/src/logged_command.rs
index 11739ce0..08ce5990 100644
--- a/crates/core/plugin_sm/src/logged_command.rs
+++ b/crates/common/logged_command/src/logged_command.rs
@@ -1,8 +1,13 @@
-use std::ffi::OsStr;
-use std::process::{Output, Stdio};
-use tokio::fs::File;
-use tokio::io::{AsyncWriteExt, BufWriter};
-use tokio::process::{Child, Command};
+use log::error;
+use std::{
+ ffi::OsStr,
+ process::{Output, Stdio},
+};
+use tokio::{
+ fs::File,
+ io::{AsyncWriteExt, BufWriter},
+ process::{Child, Command},
+};
pub struct LoggingChild {
command_line: String,
@@ -16,7 +21,7 @@ impl LoggingChild {
) -> Result<Output, std::io::Error> {
let outcome = self.inner_child.wait_with_output().await;
if let Err(err) = LoggedCommand::log_outcome(&self.command_line, &outcome, logger).await {
- tracing::log::error!("Fail to log the command execution: {}", err);
+ error!("Fail to log the command execution: {}", err);
}
outcome
@@ -80,7 +85,7 @@ impl LoggedCommand {
let outcome = self.command.output().await;
if let Err(err) = LoggedCommand::log_outcome(&self.command_line, &outcome, logger).await {
- tracing::log::error!("Fail to log the command execution: {}", err);
+ error!("Fail to log the command execution: {}", err);
}
outcome
diff --git a/crates/core/plugin_sm/Cargo.toml b/crates/core/plugin_sm/Cargo.toml
index 21a8d003..e54837a1 100644
--- a/crates/core/plugin_sm/Cargo.toml
+++ b/crates/core/plugin_sm/Cargo.toml
@@ -10,6 +10,7 @@ agent_interface = { path = "../agent_interface" }
async-trait = "0.1"
csv = "1.1"
download = { path = "../../common/download" }
+logged_command = { path = "../../common/logged_command" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tedge_utils = { path = "../../common/tedge_utils" }
diff --git a/crates/core/plugin_sm/src/lib.rs b/crates/core/plugin_sm/src/lib.rs
index 79800999..c124bbbc 100644
--- a/crates/core/plugin_sm/src/lib.rs
+++ b/crates/core/plugin_sm/src/lib.rs
@@ -1,4 +1,3 @@
pub mod log_file;
-pub mod logged_command;
pub mod plugin;
pub mod plugin_manager;
diff --git a/crates/core/plugin_sm/src/plugin.rs b/crates/core/plugin_sm/src/plugin.rs
index f7df5449..95ab2988 100644
--- a/crates/core/plugin_sm/src/plugin.rs
+++ b/crates/core/plugin_sm/src/plugin.rs
@@ -1,8 +1,8 @@
-use crate::logged_command::LoggedCommand;
use agent_interface::*;
use async_trait::async_trait;
use csv::ReaderBuilder;
use download::Downloader;
+use logged_command::LoggedCommand;
use serde::Deserialize;
use std::path::Path;
use std::{path::PathBuf, process::Output};