Skip to content

Commit 5478d39

Browse files
committed
feat: publish supported log types on config_update completion
1 parent e6cdbf0 commit 5478d39

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed

crates/extensions/tedge_log_manager/src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ impl LogManagerConfig {
6363
ChannelFilter::Command(OperationType::LogUpload),
6464
);
6565

66-
let log_metadata_sync_topics = mqtt_schema.topics(
66+
let mut log_metadata_sync_topics = mqtt_schema.topics(
6767
EntityFilter::Entity(&mqtt_device_topic_id),
6868
ChannelFilter::Command(OperationType::SoftwareUpdate),
6969
);
70+
log_metadata_sync_topics.add_all(mqtt_schema.topics(
71+
EntityFilter::Entity(&mqtt_device_topic_id),
72+
ChannelFilter::Command(OperationType::ConfigUpdate),
73+
));
7074

7175
Ok(Self {
7276
mqtt_schema,

crates/extensions/tedge_log_manager/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,6 @@ impl MessageSink<CmdMetaSyncSignal> for LogManagerBuilder {
262262
impl SyncOnCommand for LogManagerBuilder {
263263
/// Return the list of operations for which this actor wants to receive sync signals
264264
fn sync_on_commands(&self) -> Vec<OperationType> {
265-
vec![OperationType::SoftwareUpdate]
265+
vec![OperationType::SoftwareUpdate, OperationType::ConfigUpdate]
266266
}
267267
}

crates/extensions/tedge_log_manager/src/tests.rs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ async fn new_log_manager_builder(
9999
SimpleMessageBox<NoMessage, FsWatchEvent>,
100100
UploaderMessageBox,
101101
) {
102-
let log_metadata_sync_topics =
102+
let mut log_metadata_sync_topics =
103103
TopicFilter::new_unchecked("te/device/main///cmd/software_update/+");
104+
log_metadata_sync_topics.add_unchecked("te/device/main///cmd/config_update/+");
104105

105106
let config = LogManagerConfig {
106107
mqtt_schema: MqttSchema::default(),
@@ -672,6 +673,82 @@ async fn log_types_published_on_software_update_message() -> Result<(), anyhow::
672673
Ok(())
673674
}
674675

676+
#[tokio::test]
677+
async fn log_types_published_on_config_update_message() -> Result<(), anyhow::Error> {
678+
let tempdir = prepare()?;
679+
let (mut mqtt, _fs, _uploader) = spawn_log_manager_actor(tempdir.path()).await;
680+
681+
let log_reload_topic = Topic::new_unchecked("te/device/main///cmd/log_upload");
682+
let config_update_topic = Topic::new_unchecked("te/device/main///cmd/config_update/1234");
683+
684+
// Skip the initial log types message on startup
685+
mqtt.skip(1).await;
686+
687+
mqtt.send(MqttMessage::new(
688+
&config_update_topic,
689+
r#"
690+
{
691+
"status": "init",
692+
"updateList": []
693+
}"#,
694+
))
695+
.await?;
696+
697+
mqtt.send(MqttMessage::new(
698+
&config_update_topic,
699+
r#"
700+
{
701+
"status": "executing",
702+
"updateList": []
703+
}"#,
704+
))
705+
.await?;
706+
707+
// The log manager does not react to `config_update` in state other than "successful" or "failed"
708+
assert!(mqtt.recv().await.is_none());
709+
710+
// Send a config_update message in terminal state that trigger log types reload
711+
let config_update_message = r#"
712+
{
713+
"status": "successful",
714+
"updateList": []
715+
}"#;
716+
mqtt.send(MqttMessage::new(
717+
&config_update_topic,
718+
config_update_message,
719+
))
720+
.await?;
721+
722+
// The log manager should publish the log types again
723+
assert_eq!(
724+
mqtt.recv().await,
725+
Some(
726+
MqttMessage::new(&log_reload_topic, r#"{"types":["type_one","type_two"]}"#)
727+
.with_retain()
728+
)
729+
);
730+
731+
// Failed config update should also trigger log types reload
732+
mqtt.send(MqttMessage::new(
733+
&config_update_topic,
734+
r#"
735+
{
736+
"status": "failed",
737+
"updateList": []
738+
}"#,
739+
))
740+
.await?;
741+
assert_eq!(
742+
mqtt.recv().await,
743+
Some(
744+
MqttMessage::new(&log_reload_topic, r#"{"types":["type_one","type_two"]}"#)
745+
.with_retain()
746+
)
747+
);
748+
749+
Ok(())
750+
}
751+
675752
#[tokio::test]
676753
async fn log_types_not_published_on_random_command_update() -> Result<(), anyhow::Error> {
677754
let tempdir = prepare()?;

tests/RobotFramework/tests/cumulocity/log/log_operation_plugins.robot

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ Supported log types updated on software update
3737
... message_contains=cron::journald
3838
Should Support Log File Types cron::journald includes=${True}
3939

40+
Supported log types updated on config update
41+
[Documentation] Updating any configuration should trigger supported log types update
42+
${config_url}= Cumulocity.Create Inventory Binary
43+
... tedge-configuration-plugin
44+
... tedge-configuration-plugin
45+
... contents=files=[]
46+
${start_time}= Get Unix Timestamp
47+
${operation}= Cumulocity.Set Configuration tedge-configuration-plugin url=${config_url}
48+
Operation Should Be SUCCESSFUL ${operation} timeout=120
49+
50+
Should Have MQTT Messages
51+
... topic=te/device/main///cmd/log_upload
52+
... date_from=${start_time}
53+
... message_contains=software-management
54+
4055
Log operation journald plugin can return logs for all units
4156
Should Support Log File Types all-units::journald includes=${True}
4257
${start_timestamp}= Get Current Date UTC -1 hours result_format=%Y-%m-%dT%H:%M:%S+0000

0 commit comments

Comments
 (0)