Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ The module reports the status of any attached modems. For this purpose the modul

The network status is refreshed in an interval which can be configured by `REFRESH_NETWORK_STATUS_INTERVAL_SECS` environment variable. The default is 60s.

When reloading network configuration via the [reload network daemon](#reload-network-daemon) endpoint, the service waits for networkd to apply the new configuration before reporting status. The delay can be configured via `RELOAD_NETWORK_DELAY_MS` environment variable (default: 500ms).

**NOTE**: Currently reporting status of modems is no supported!

#### Feature availability
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod bootloader_env;
pub mod common;
pub mod reboot_reason;
pub mod systemd;
pub mod twin;
pub mod web_service;
9 changes: 1 addition & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
pub mod bootloader_env;
pub mod common;
pub mod reboot_reason;
pub mod systemd;
pub mod twin;
pub mod web_service;

use env_logger::{Builder, Env, Target};
use log::{error, info};
use omnect_device_service::twin::Twin;
use std::{io::Write, process};
use twin::Twin;

#[tokio::main]
async fn main() -> process::ExitCode {
Expand Down
12 changes: 5 additions & 7 deletions src/twin/firmware_update/update_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,11 @@ impl UpdateValidation {
}

async fn report_impl(status: UpdateValidationStatus) {
if cfg!(not(feature = "mock")) {
web_service::publish(
web_service::PublishChannel::UpdateValidationStatusV1,
json!({"status": status}),
)
.await;
}
web_service::publish(
web_service::PublishChannel::UpdateValidationStatusV1,
json!({"status": status}),
)
.await;
}

fn start_timeout(&mut self) -> Result<()> {
Expand Down
11 changes: 10 additions & 1 deletion src/twin/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ impl Feature for Network {
unit::UnitAction::Reload,
systemd_zbus::Mode::Fail,
)
.await?
.await?;

// Wait for networkd to apply configuration after reload.
// The reload job completion only means networkd received the signal,
// not that it finished applying the new configuration internally.
let delay_ms = env::var("RELOAD_NETWORK_DELAY_MS")
.unwrap_or("500".to_string())
.parse::<u64>()
.unwrap_or(500);
tokio::time::sleep(Duration::from_millis(delay_ms)).await;
}
_ => bail!("unexpected command"),
}
Expand Down
5 changes: 5 additions & 0 deletions src/web_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub enum PublishChannel {
UpdateValidationStatusV1,
}

#[cfg(not(feature = "mock"))]
impl PublishChannel {
fn to_status_string(&self) -> String {
match self {
Expand Down Expand Up @@ -412,6 +413,7 @@ impl WebService {
}
}

#[cfg(not(feature = "mock"))]
pub async fn publish(channel: PublishChannel, value: serde_json::Value) {
if *IS_WEBSERVICE_DISABLED.wait() {
debug!("publish: skip since feature not enabled");
Expand Down Expand Up @@ -443,6 +445,9 @@ pub async fn publish(channel: PublishChannel, value: serde_json::Value) {
}
}

#[cfg(feature = "mock")]
pub async fn publish(_channel: PublishChannel, _value: serde_json::Value) {}

async fn republish_to_endpoint(endpoint: &PublishEndpoint) -> HttpResponse {
for (channel, value) in PUBLISH_CHANNEL_MAP.lock().await.iter() {
let msg = json!({"channel": channel, "data": value}).to_string();
Expand Down
1 change: 1 addition & 0 deletions testfiles/positive/omnect-os-initramfs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading