Skip to content

Commit a87a003

Browse files
authored
Merge pull request #3959 from reubenmiller/feat-disable-software-update-op
feat: support disabling cloud handling of c8y_SoftwareUpdate operation
2 parents 4d7501b + 0df2f5a commit a87a003

File tree

8 files changed

+49
-2
lines changed

8 files changed

+49
-2
lines changed

crates/common/tedge_config/src/tedge_toml/tedge_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ define_tedge_config! {
703703
/// Enable device restart feature
704704
#[tedge_config(example = "true", default(value = true))]
705705
device_restart: bool,
706+
707+
/// Enable software update feature
708+
#[tedge_config(example = "true", default(value = true))]
709+
software_update: bool,
706710
},
707711

708712
mapper: {

crates/common/tedge_config/src/tedge_toml/tedge_config/mapper_config/compat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl FromCloudConfig for C8yMapperSpecificConfig {
129129
firmware_update: c8y.enable.firmware_update,
130130
device_profile: c8y.enable.device_profile,
131131
device_restart: c8y.enable.device_restart,
132+
software_update: c8y.enable.software_update,
132133
},
133134
mqtt_service: MqttServiceConfig {
134135
enabled: c8y.mqtt_service.enabled,

crates/common/tedge_config/src/tedge_toml/tedge_config/mapper_config/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ pub struct EnableConfig {
387387

388388
/// Enable device restart feature
389389
pub device_restart: bool,
390+
391+
/// Enable software_update feature
392+
pub software_update: bool,
390393
}
391394

392395
/// Bridge include configuration

crates/extensions/c8y_mapper_ext/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ impl C8yMapperConfig {
202202
firmware_update: c8y_config.cloud_specific.enable.firmware_update,
203203
device_profile: c8y_config.cloud_specific.enable.device_profile,
204204
device_restart: c8y_config.cloud_specific.enable.device_restart,
205+
software_update: c8y_config.cloud_specific.enable.software_update,
205206
};
206207
let bridge_config = BridgeConfig {
207208
c8y_prefix: c8y_config.bridge.topic_prefix.clone(),

crates/extensions/c8y_mapper_ext/src/converter.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,13 @@ impl CumulocityConverter {
665665
}
666666
}
667667
C8yDeviceControlOperation::SoftwareUpdate(request) => {
668-
self.forward_software_request(device_xid, cmd_id, request)
669-
.await?
668+
if self.config.capabilities.software_update {
669+
self.forward_software_request(device_xid, cmd_id, request)
670+
.await?
671+
} else {
672+
warn!("Received a c8y_SoftwareUpdate operation, however, software_update feature is disabled");
673+
vec![]
674+
}
670675
}
671676
C8yDeviceControlOperation::LogfileRequest(request) => {
672677
if self.config.capabilities.log_upload {
@@ -1603,6 +1608,12 @@ impl CumulocityConverter {
16031608
&mut self,
16041609
target: &EntityTopicId,
16051610
) -> Result<Vec<MqttMessage>, ConversionError> {
1611+
if !self.config.capabilities.software_update {
1612+
warn!(
1613+
"Received software update metadata, however, software update feature is disabled"
1614+
);
1615+
return Ok(vec![]);
1616+
}
16061617
let mut registration = match self.register_operation(target, "c8y_SoftwareUpdate").await {
16071618
Err(_) => {
16081619
error!("Fail to register `software-list` operation for unknown device: {target}");

crates/extensions/c8y_mapper_ext/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct Capabilities {
2727
pub firmware_update: bool,
2828
pub device_profile: bool,
2929
pub device_restart: bool,
30+
pub software_update: bool,
3031
}
3132

3233
#[cfg(test)]
@@ -39,6 +40,7 @@ impl Default for Capabilities {
3940
firmware_update: true,
4041
device_profile: true,
4142
device_restart: true,
43+
software_update: true,
4244
}
4345
}
4446
}

crates/extensions/c8y_mapper_ext/src/operations/handler.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ impl OperationHandler {
258258
]);
259259
}
260260

261+
if capabilities.software_update {
262+
topics.extend([
263+
(AnyEntity, Command(OperationType::SoftwareUpdate)),
264+
(AnyEntity, CommandMetadata(OperationType::SoftwareUpdate)),
265+
]);
266+
}
267+
261268
topics
262269
}
263270
}

tests/RobotFramework/tests/cumulocity/software_management/software.robot

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,24 @@ Agent should ignore unknown software-update fields
185185
... message_pattern=.*"status":"successful".*
186186
... timeout=60
187187

188+
Supports disabling the Cumulocity c8y_SoftwareUpdate Command
189+
Execute Command tedge config set c8y.enable.software_update false
190+
Execute Command rm -f /etc/tedge/operations/c8y/c8y_SoftwareUpdate
191+
192+
Restart Service tedge-mapper-c8y
193+
Service Health Status Should Be Up tedge-mapper-c8y
194+
File Should Not Exist /etc/tedge/operations/c8y/c8y_SoftwareUpdate
195+
Should Not Contain Supported Operations c8y_SoftwareUpdate
196+
${operation}= Cumulocity.Install Software dummy
197+
Sleep 5s reason=Allow time for the message to be delivered
198+
Operation Should Be PENDING ${operation} timeout=30
199+
200+
# Cleanup operation for cleaner logs (as pending operations pollute the test report output)
201+
# Note: It does not need to be run under a TearDown hook as this code will only run
202+
# if the operation is not processed, otherwise it would of been processed and thus not need cleaning up
203+
Execute Command tedge mqtt pub c8y/s/us '505,${operation.to_json()["id"]},Cancelled operation'
204+
Operation Should Be FAILED ${operation}
205+
188206

189207
*** Keywords ***
190208
Custom Setup

0 commit comments

Comments
 (0)