diff options
author | initard <solo@softwareag.com> | 2022-02-11 13:52:03 +0000 |
---|---|---|
committer | initard <solo@softwareag.com> | 2022-02-15 11:43:49 +0000 |
commit | ff40d4e958fefb289cb76e8f1cc168cb61fb0f81 (patch) | |
tree | 7c1464485af1343c33a264acfba3b8bfda9b4c67 | |
parent | d07c04771f017760667c0cae2ec76113c8ee23c4 (diff) |
adding tedge_log_request_plugin to workflow (#790)
- cargo-deb config in cargo.toml
- cargo build in workflow
- stripping binary
- updated get-thin-edge.io script
Signed-off-by: initard <solo@softwareag.com>
-rw-r--r-- | .github/workflows/build-workflow.yml | 17 | ||||
-rw-r--r-- | configuration/contrib/operations/c8y/C8y_LogfileRequest | 4 | ||||
-rwxr-xr-x | get-thin-edge_io.sh | 4 | ||||
-rw-r--r-- | plugins/log_request_plugin/Cargo.toml | 8 | ||||
-rw-r--r-- | plugins/log_request_plugin/src/main.rs | 69 | ||||
-rw-r--r-- | plugins/log_request_plugin/src/smartrest.rs | 2 |
6 files changed, 33 insertions, 71 deletions
diff --git a/.github/workflows/build-workflow.yml b/.github/workflows/build-workflow.yml index 6d930ac1..a20eb9c7 100644 --- a/.github/workflows/build-workflow.yml +++ b/.github/workflows/build-workflow.yml @@ -75,6 +75,13 @@ jobs: command: deb args: -p tedge_agent + - name: Build tedge_logfile_request_plugin debian package + uses: actions-rs/cargo@v1 + # https://github.com/marketplace/actions/rust-cargo + with: + command: deb + args: -p tedge_logfile_request_plugin + - name: build sawtooth-publisher for amd64 uses: actions-rs/cargo@v1 # https://github.com/marketplace/actions/rust-cargo @@ -187,6 +194,9 @@ jobs: - name: Strip tedge_apama_plugin run: arm-linux-gnueabihf-strip target/${{ matrix.target }}/release/tedge_apama_plugin || aarch64-linux-gnu-strip target/${{ matrix.target }}/release/tedge_apama_plugin + - name: Strip tedge_logfile_request_plugin + run: arm-linux-gnueabihf-strip target/${{ matrix.target }}/release/tedge_logfile_request_plugin || aarch64-linux-gnu-strip target/${{ matrix.target }}/release/tedge_logfile_request_plugin + - name: build tedge debian package for target uses: actions-rs/cargo@v1 # https://github.com/marketplace/actions/rust-cargo @@ -222,6 +232,13 @@ jobs: command: deb args: -p tedge_apama_plugin --no-strip --no-build --target=${{ matrix.target }} + - name: build tedge_logfile_request_plugin debian package for target + uses: actions-rs/cargo@v1 + # https://github.com/marketplace/actions/rust-cargo + with: + command: deb + args: -p tedge_logfile_request_plugin --no-strip --no-build --target=${{ matrix.target }} + - name: build sawtooth publisher uses: actions-rs/cargo@v1 # https://github.com/marketplace/actions/rust-cargo diff --git a/configuration/contrib/operations/c8y/C8y_LogfileRequest b/configuration/contrib/operations/c8y/C8y_LogfileRequest new file mode 100644 index 00000000..d93a71c2 --- /dev/null +++ b/configuration/contrib/operations/c8y/C8y_LogfileRequest @@ -0,0 +1,4 @@ +[exec] +topic = "c8y/s/ds" +on_message = "522" +command = "/usr/bin/log_request_plugin" diff --git a/get-thin-edge_io.sh b/get-thin-edge_io.sh index 6742a913..0d03e320 100755 --- a/get-thin-edge_io.sh +++ b/get-thin-edge_io.sh @@ -40,6 +40,10 @@ install_tedge_plugins() { # Download and install apama plugin wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_apama_plugin_${VERSION}_${ARCH}.deb -P /tmp/tedge dpkg -i /tmp/tedge/tedge_apama_plugin_${VERSION}_${ARCH}.deb + + # Download and install logfile plugin + wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_logfile_request_plugin_${VERSION}_${ARCH}.deb -P /tmp/tedge + dpkg -i /tmp/tedge/tedge_logfile_request_plugin_${VERSION}_${ARCH}.deb } if [ $# -lt 3 ]; then diff --git a/plugins/log_request_plugin/Cargo.toml b/plugins/log_request_plugin/Cargo.toml index 456d3dce..ce2699f4 100644 --- a/plugins/log_request_plugin/Cargo.toml +++ b/plugins/log_request_plugin/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "log_request_plugin" +name = "tedge_logfile_request_plugin" version = "0.5.2" authors = ["thin-edge.io team <info@thin-edge.io>"] edition = "2021" @@ -9,6 +9,12 @@ description = "Thin.edge.io operation plugin for Cumulocity log request" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[package.metadata.deb] +depends = "tedge_mapper" +assets = [ + ["../../configuration/contrib/operations/c8y/C8y_LogfileRequest", "/etc/tedge/operations/c8y/", "644"] +] + [dependencies] anyhow = "1.0" async-trait = "0.1" diff --git a/plugins/log_request_plugin/src/main.rs b/plugins/log_request_plugin/src/main.rs index 274090ce..b1ebb569 100644 --- a/plugins/log_request_plugin/src/main.rs +++ b/plugins/log_request_plugin/src/main.rs @@ -82,72 +82,3 @@ async fn main() -> Result<(), anyhow::Error> { async fn do_one_second_pause() { sleep(Duration::from_secs(1)).await; } - -#[cfg(test)] -mod tests { - use crate::smartrest::read_tedge_logs; - use c8y_smartrest::smartrest_deserializer::SmartRestLogRequest; - use std::fs::File; - use std::io::Write; - - fn parse_file_names_from_log_content(log_content: &str) -> [&str; 5] { - let mut files: Vec<&str> = vec![]; - for line in log_content.lines() { - if line.contains("filename: ") { - let filename: &str = line.split("filename: ").last().unwrap(); - files.push(filename); - } - } - match files.try_into() { - Ok(arr) => arr, - Err(_) => panic!("Could not convert to Array &str, size 5"), - } - } - - #[test] - /// testing read_tedge_logs - /// - /// this test creates 5 fake log files in a temporary directory. - /// files are dated 2021-01-0XT01:00Z, where X = a different day. - /// - /// this tests will assert that files are read alphanumerically from oldest to newest - fn test_read_logs() { - // order in which files are created - const LOG_FILE_NAMES: [&str; 5] = [ - "software-list-2021-01-03T01:00:00Z.log", - "software-list-2021-01-02T01:00:00Z.log", - "software-list-2021-01-01T01:00:00Z.log", - "software-update-2021-01-03T01:00:00Z.log", - "software-update-2021-01-02T01:00:00Z.log", - ]; - - // expected (sorted) output - const EXPECTED_OUTPUT: [&str; 5] = [ - "software-list-2021-01-01T01:00:00Z", - "software-list-2021-01-02T01:00:00Z", - "software-list-2021-01-03T01:00:00Z", - "software-update-2021-01-02T01:00:00Z", - "software-update-2021-01-03T01:00:00Z", - ]; - - let smartrest_obj = SmartRestLogRequest::from_smartrest( - "522,DeviceSerial,syslog,2021-01-01T00:00:00+0200,2021-01-10T00:00:00+0200,,1000", - ) - .unwrap(); - - let temp_dir = tempfile::tempdir().unwrap(); - // creating the files - for (idx, file) in LOG_FILE_NAMES.iter().enumerate() { - let file_path = &temp_dir.path().join(file); - let mut file = File::create(file_path).unwrap(); - writeln!(file, "file num {}", idx).unwrap(); - } - - // reading the logs and extracting the file names from the log output. - let output = read_tedge_logs(&smartrest_obj, temp_dir.path().to_str().unwrap()).unwrap(); - let parsed_values = parse_file_names_from_log_content(&output); - - // asserting the order = `EXPECTED_OUTPUT` - assert!(parsed_values.eq(&EXPECTED_OUTPUT)); - } -} diff --git a/plugins/log_request_plugin/src/smartrest.rs b/plugins/log_request_plugin/src/smartrest.rs index 187daa44..c1047d92 100644 --- a/plugins/log_request_plugin/src/smartrest.rs +++ b/plugins/log_request_plugin/src/smartrest.rs @@ -119,7 +119,7 @@ pub fn read_tedge_logs( #[cfg(test)] mod tests { - use crate::smartrest::read_tedge_logs; + use super::read_tedge_logs; use c8y_smartrest::smartrest_deserializer::SmartRestLogRequest; use std::fs::File; use std::io::Write; |