diff options
author | initard <alex.solomes@softwareag.com> | 2022-01-12 12:18:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-12 12:18:21 +0100 |
commit | 735f39337f41362003d60a482542c0fecd603b58 (patch) | |
tree | 72c245961b70481e93d48ec6a77aaad5baddbe08 /crates/core/tedge_agent/src/agent.rs | |
parent | 141e93c03c8f9d9a9dd7076830445b3fd9cd5154 (diff) |
Feature/651/configurable temp path (#732)
* configurable download path (WIP) (#651)
Signed-off-by: initard <solo@softwareag.com>
* download path test (WIP) (#651)
Signed-off-by: initard <solo@softwareag.com>
* default download path #651
Signed-off-by: initard <solo@softwareag.com>
* install to download.path test (#651)
Signed-off-by: initard <solo@softwareag.com>
* formatting issues (#651)
Signed-off-by: initard <solo@softwareag.com>
* formatting issues (#651)
Signed-off-by: initard <solo@softwareag.com>
* rename download path to tmp path & test fix (#651)
Signed-off-by: initard <solo@softwareag.com>
* cargo fmt
Signed-off-by: initard <solo@softwareag.com>
* download path integration test (#651)
Signed-off-by: initard <solo@softwareag.com>
* adding doc detailing how to set temp path (#651)
Signed-off-by: initard <solo@softwareag.com>
* test fix (#651)
Signed-off-by: initard <solo@softwareag.com>
* adding sudo to doc (#651)
Signed-off-by: initard <solo@softwareag.com>
* removing unused test (#651)
Signed-off-by: initard <solo@softwareag.com>
* renaming, refactoring and extra documentation (#651)
Signed-off-by: initard <solo@softwareag.com>
* fixing naming of tmp.path (#651)
Signed-off-by: initard <solo@softwareag.com>
* changes to tmp dto #651
Signed-off-by: initard <solo@softwareag.com>
Co-authored-by: initard <solo@softwareag.com>
Diffstat (limited to 'crates/core/tedge_agent/src/agent.rs')
-rw-r--r-- | crates/core/tedge_agent/src/agent.rs | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/crates/core/tedge_agent/src/agent.rs b/crates/core/tedge_agent/src/agent.rs index 8b39260e..43731214 100644 --- a/crates/core/tedge_agent/src/agent.rs +++ b/crates/core/tedge_agent/src/agent.rs @@ -22,7 +22,7 @@ use std::{ }; use tedge_config::{ ConfigRepository, ConfigSettingAccessor, ConfigSettingAccessorStringExt, MqttPortSetting, - SoftwarePluginDefaultSetting, TEdgeConfigLocation, + SoftwarePluginDefaultSetting, TEdgeConfigLocation, TmpPathDefaultSetting, }; use tracing::{debug, error, info, instrument}; @@ -46,6 +46,7 @@ pub struct SmAgentConfig { pub sm_home: PathBuf, pub log_dir: PathBuf, config_location: TEdgeConfigLocation, + pub download_dir: PathBuf, } impl Default for SmAgentConfig { @@ -83,6 +84,8 @@ impl Default for SmAgentConfig { let config_location = TEdgeConfigLocation::from_default_system_location(); + let download_dir = PathBuf::from("/tmp"); + Self { errors_topic, mqtt_client_config, @@ -96,6 +99,7 @@ impl Default for SmAgentConfig { sm_home, log_dir, config_location, + download_dir, } } } @@ -114,10 +118,13 @@ impl SmAgentConfig { .tedge_config_root_path() .to_path_buf(); + let tedge_download_dir = tedge_config.query_string(TmpPathDefaultSetting)?.into(); + Ok(SmAgentConfig::default() .with_sm_home(tedge_config_path) .with_mqtt_client_config(mqtt_config) - .with_config_location(tedge_config_location)) + .with_config_location(tedge_config_location) + .with_download_directory(tedge_download_dir)) } pub fn with_sm_home(self, sm_home: PathBuf) -> Self { @@ -137,6 +144,13 @@ impl SmAgentConfig { ..self } } + + pub fn with_download_directory(self, tmp_dir: PathBuf) -> Self { + Self { + download_dir: tmp_dir, + ..self + } + } } #[derive(Debug)] @@ -378,7 +392,11 @@ impl SmAgent { .new_log_file(LogKind::SoftwareUpdate) .await?; - let response = plugins.lock().unwrap().process(&request, log_file).await; // `unwrap` should be safe here as we only access data. + let response = plugins + .lock() + .unwrap() + .process(&request, log_file, &self.config.download_dir) + .await; // `unwrap` should be safe here as we only access data. let _ = mqtt .publish(Message::new(response_topic, response.to_bytes()?)) @@ -524,8 +542,19 @@ fn get_default_plugin( #[cfg(test)] mod tests { + use super::*; + use std::fs::File; + use std::io::Write; + + use mqtt_client::{Client, Message, MqttClient, Topic, TopicFilter}; + use mqtt_tests::publish; + use std::fs; + use std::time::Duration; + + use tokio::time::sleep; const SLASH_RUN_PATH_TEDGE_AGENT_RESTART: &str = "/run/tedge_agent/tedge_agent_restart"; + const TIMEOUT: Duration = Duration::from_secs(10); #[ignore] #[tokio::test] |