Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart operation on child-devices #2245

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use camino::Utf8Path;
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
use std::time::Duration;

pub const SERVICE_CONFIG_FILE: &str = "system.toml";
const REBOOT_COMMAND: &[&str] = &["init", "6"];
Expand Down Expand Up @@ -32,6 +33,23 @@ pub struct InitConfig {
#[serde(deny_unknown_fields)]
pub struct SystemSpecificCommands {
pub reboot: Vec<String>,
#[serde(default = "SystemSpecificCommands::default_reboot_timeout_seconds")]
pub reboot_timeout_seconds: u64,
}

impl SystemSpecificCommands {
pub fn default_reboot_timeout_seconds() -> u64 {
// The linux shutdown command only supports triggering the shutdown immediately
// or in minutes, a delay in seconds is not supported. Using a shell script to delay
// the call to shutdown is generally not very reliable.
// Choose a sensible default that won't timeout if 'shutdown -r' is used
// (with some buffer), e.g. 2 x default interval (60 seconds)
120
}

pub fn reboot_timeout(&self) -> Duration {
Duration::from_secs(self.reboot_timeout_seconds)
}
}

impl Default for SystemSpecificCommands {
Expand All @@ -41,6 +59,7 @@ impl Default for SystemSpecificCommands {
.iter()
.map(|value| String::from(*value))
.collect::<Vec<String>>(),
reboot_timeout_seconds: SystemSpecificCommands::default_reboot_timeout_seconds(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core/c8y_api/src/json_c8y.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ mod tests {
let expected_json = r#"{"c8y_SoftwareList":[{"name":"a","version":"::debian","url":""},{"name":"b","version":"1.0::debian","url":""},{"name":"c","version":"::debian","url":"https://foobar.io/c.deb"},{"name":"d","version":"beta::debian","url":"https://foobar.io/d.deb"},{"name":"m","version":"::apama","url":"https://foobar.io/m.epl"}]}"#;

assert_eq!(c8y_software_list, expected_struct);
assert_eq!(c8y_software_list.to_json().unwrap(), expected_json);
assert_eq!(c8y_software_list.to_json(), expected_json);
}

#[test]
Expand All @@ -518,7 +518,7 @@ mod tests {
let expected_json = r#"{"c8y_SoftwareList":[]}"#;

assert_eq!(c8y_software_list, expected_struct);
assert_eq!(c8y_software_list.to_json().unwrap(), expected_json);
assert_eq!(c8y_software_list.to_json(), expected_json);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ mod tests {
.from_smartrest(&smartrest)
.unwrap()
.to_thin_edge_json_with_id("123");
let output_json = software_update_request.unwrap().to_json().unwrap();
let output_json = software_update_request.unwrap().to_json();

let expected_json = json!({
"id": "123",
Expand Down
12 changes: 12 additions & 0 deletions crates/core/c8y_api/src/smartrest/topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ pub enum C8yTopic {
}

impl C8yTopic {
/// Return the c8y SmartRest response topic for the given entity
pub fn smartrest_response_topic(entity: &EntityMetadata) -> Option<Topic> {
match entity.r#type {
EntityType::MainDevice => Some(C8yTopic::upstream_topic()),
EntityType::ChildDevice | EntityType::Service => {
Self::ChildSmartRestResponse(entity.entity_id.clone())
.to_topic()
.ok()
}
}
}

pub fn to_topic(&self) -> Result<Topic, MqttError> {
Topic::new(self.to_string().as_str())
}
Expand Down
5 changes: 4 additions & 1 deletion crates/core/tedge_agent/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ impl AgentConfig {
.with_ip_address(http_bind_address);

// Restart config
let restart_config = RestartManagerConfig::from_tedge_config(tedge_config_location)?;
let restart_config =
RestartManagerConfig::from_tedge_config(&mqtt_device_topic_id, tedge_config_location)?;

// Software update config
let sw_update_config = SoftwareManagerConfig::from_tedge_config(tedge_config_location)?;
Expand Down Expand Up @@ -170,6 +171,8 @@ impl Agent {

// Converter actor
let converter_actor_builder = TedgeOperationConverterBuilder::new(
self.config.mqtt_topic_root.as_ref(),
self.config.mqtt_device_topic_id.clone(),
&mut software_update_builder,
&mut restart_actor_builder,
&mut mqtt_actor_builder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ mod test {
assert_eq!(actual_file_name, expected_file_name);
}

const VALID_TEST_URI: &str = "http://127.0.0.1:3000/tedge/file-transfer/another/dir/test-file";
const INVALID_TEST_URI: &str = "http://127.0.0.1:3000/wrong/place/test-file";
const VALID_TEST_URI: &str = "http://127.0.0.1:3333/tedge/file-transfer/another/dir/test-file";
const INVALID_TEST_URI: &str = "http://127.0.0.1:3333/wrong/place/test-file";

#[test_case(hyper::Method::GET, VALID_TEST_URI, hyper::StatusCode::OK)]
#[test_case(hyper::Method::GET, INVALID_TEST_URI, hyper::StatusCode::NOT_FOUND)]
Expand Down Expand Up @@ -348,7 +348,7 @@ mod test {
let tempdir_path = ttd.utf8_path_buf();
let http_config = HttpConfig::default()
.with_data_dir(tempdir_path)
.with_port(3000);
.with_port(3333);
didier-wenzek marked this conversation as resolved.
Show resolved Hide resolved
let server = http_file_transfer_server(&http_config).unwrap();
(ttd, server)
}
Expand Down
Loading