Skip to content

Commit

Permalink
Merge pull request #2399 from albinsuresh/bug/2396/tedge-plugin-migra…
Browse files Browse the repository at this point in the history
…te-c8y-plugin-config

Tedge operation plugins to migrate legacy config file contents
  • Loading branch information
reubenmiller authored Nov 2, 2023
2 parents 45d241f + 10f15d7 commit b8e00c1
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
14 changes: 14 additions & 0 deletions crates/extensions/tedge_config_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod tests;

use actor::*;
pub use config::*;
use std::fs::rename;
use std::path::PathBuf;
use tedge_actors::futures::channel::mpsc;
use tedge_actors::Builder;
Expand Down Expand Up @@ -88,9 +89,22 @@ impl ConfigManagerBuilder {
}

pub fn init(config: &ConfigManagerConfig) -> Result<(), FileError> {
if config.plugin_config_path.exists() {
return Ok(());
}

// creating plugin config parent dir
create_directory_with_defaults(&config.plugin_config_dir)?;

let legacy_plugin_config = config
.config_dir
.join("c8y")
.join("c8y-configuration-plugin.toml");
if legacy_plugin_config.exists() {
rename(legacy_plugin_config, &config.plugin_config_path)?;
return Ok(());
}

// create tedge-configuration-plugin.toml
let example_config = r#"# Add the configurations to be managed by tedge-configuration-plugin
files = [
Expand Down
11 changes: 11 additions & 0 deletions crates/extensions/tedge_log_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod tests;
pub use actor::*;
pub use config::*;
use log_manager::LogPluginConfig;
use std::fs::rename;
use std::path::PathBuf;
use tedge_actors::adapt;
use tedge_actors::Builder;
Expand Down Expand Up @@ -70,9 +71,19 @@ impl LogManagerBuilder {
}

pub fn init(config: &LogManagerConfig) -> Result<(), FileError> {
if config.plugin_config_path.exists() {
return Ok(());
}

// creating plugin config parent dir
create_directory_with_defaults(&config.plugin_config_dir)?;

let legacy_plugin_config = config.config_dir.join("c8y").join("c8y-log-plugin.toml");
if legacy_plugin_config.exists() {
rename(legacy_plugin_config, &config.plugin_config_path)?;
return Ok(());
}

// creating tedge-log-plugin.toml
let example_config = r#"# Add the list of log files that should be managed by tedge-log-plugin
files = [
Expand Down
2 changes: 1 addition & 1 deletion tests/RobotFramework/requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dateparser~=1.1.7
paho-mqtt~=1.6.1
python-dotenv~=0.20.0
robotframework~=6.0.0
robotframework-c8y @ git+/~https://github.com/reubenmiller/robotframework-c8y.git@0.23.2
robotframework-c8y @ git+/~https://github.com/reubenmiller/robotframework-c8y.git@0.26.0
robotframework-debuglibrary~=2.3.0
robotframework-jsonlibrary~=0.5
robotframework-pabot~=2.13.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*** Settings ***
Resource ../../../resources/common.resource
Library ThinEdgeIO
Library Cumulocity

Test Teardown Get Logs name=${DEVICE_SN}

Test Tags theme:configuration theme:installation

*** Test Cases ***

Migrate Legacy Configuration Files
${DEVICE_SN}= Setup skip_bootstrap=${True}
Set Suite Variable $DEVICE_SN

# Copy old c8y-configuration-plugin's config file before bootstrapping
ThinEdgeIO.Execute Command rm -f /etc/tedge/plugins/*
ThinEdgeIO.Transfer To Device ${CURDIR}/c8y-configuration-plugin.toml /etc/tedge/c8y/
ThinEdgeIO.Transfer To Device ${CURDIR}/config1.json /etc/

# Bootstrap the tedge-config-plugin so that it picks up the old c8y-configuration-plugin.toml
Execute Command ./bootstrap.sh
Cumulocity.Device Should Exist ${DEVICE_SN}
${operation}= Cumulocity.Get Configuration TEST_CONFIG
${operation}= Operation Should Be SUCCESSFUL ${operation}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files = [
{ path = '/etc/config1.json', type = 'TEST_CONFIG', user = 'tedge', group = 'tedge', mode = 0o640 },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
*** Settings ***
Resource ../../../resources/common.resource
Library ThinEdgeIO
Library Cumulocity

Test Teardown Get Logs name=${DEVICE_SN}

Test Tags theme:troubleshooting theme:installation

*** Test Cases ***

Migrate Legacy Configuration Files
${DEVICE_SN}= Setup skip_bootstrap=${True}
Set Suite Variable $DEVICE_SN

# Copy old c8y-log-plugin's config file before bootstrapping
ThinEdgeIO.Execute Command rm -f /etc/tedge/plugins/*
ThinEdgeIO.Transfer To Device ${CURDIR}/tedge-log-plugin.toml /etc/tedge/c8y/c8y-log-plugin.toml
ThinEdgeIO.Transfer To Device ${CURDIR}/example.log /var/log/example/
# touch file again to change last modified timestamp, otherwise the logfile retrieval could be outside of the requested range
Execute Command
... chown root:root /etc/tedge/c8y/c8y-log-plugin.toml /var/log/example/example.log && touch /var/log/example/example.log

# Bootstrap the tedge-log-plugin so that it picks up the old c8y-log-plugin.toml
Execute Command ./bootstrap.sh
Cumulocity.Device Should Exist ${DEVICE_SN}

${operation}= Cumulocity.Get Log File example
${operation}= Operation Should Be SUCCESSFUL ${operation}

0 comments on commit b8e00c1

Please sign in to comment.