Skip to content

Commit

Permalink
Merge pull request #3033 from reubenmiller/fix-tedge-agent-as-child-d…
Browse files Browse the repository at this point in the history
…evice

fix: tedge-agent use the root topic when provided by the cli flag
  • Loading branch information
reubenmiller committed Aug 1, 2024
2 parents 3bc7785 + a3a5356 commit 139a5ae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
7 changes: 5 additions & 2 deletions crates/core/tedge_agent/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ impl AgentConfig {
let sw_update_config = SoftwareManagerConfig::from_tedge_config(tedge_config_location)?;

// Operation Workflow config
let operation_config =
OperationConfig::from_tedge_config(&mqtt_device_topic_id, tedge_config_location)?;
let operation_config = OperationConfig::from_tedge_config(
mqtt_topic_root.to_string(),
&mqtt_device_topic_id,
tedge_config_location,
)?;

// For flockfile
let run_dir = tedge_config.run.path.clone();
Expand Down
3 changes: 2 additions & 1 deletion crates/core/tedge_agent/src/operation_workflows/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ pub struct OperationConfig {

impl OperationConfig {
pub fn from_tedge_config(
topic_root: String,
device_topic_id: &EntityTopicId,
tedge_config_location: &tedge_config::TEdgeConfigLocation,
) -> Result<OperationConfig, tedge_config::TEdgeConfigError> {
let tedge_config = tedge_config::TEdgeConfig::try_new(tedge_config_location.clone())?;

Ok(OperationConfig {
mqtt_schema: MqttSchema::with_root(tedge_config.mqtt.topic_root.clone()),
mqtt_schema: MqttSchema::with_root(topic_root),
device_topic_id: device_topic_id.clone(),
log_dir: tedge_config.logs.path.join("agent"),
config_dir: tedge_config_location.tedge_config_root_path.clone(),
Expand Down
23 changes: 23 additions & 0 deletions tests/RobotFramework/tests/tedge_agent/tedge_agent_as_child.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
*** Settings ***
Resource ../../resources/common.resource
Library ThinEdgeIO

Test Tags theme:tedge_agent
Test Setup Custom Setup
Test Teardown Get Logs

*** Test Cases ***

Run agent with a custom topic prefix #3031
# Only run tedge-agent for a few seconds
${output}= Execute Command timeout 5 tedge-agent --mqtt-topic-root "custom_root" --mqtt-device-topic-id "device/customname//" 2>&1 ignore_exit_code=${True}
Should Not Contain ${output} te/
Should Contain ${output} custom_root/device/customname//


*** Keywords ***

Custom Setup
${DEVICE_SN}= Setup skip_bootstrap=${True}
Execute Command test -f ./bootstrap.sh && ./bootstrap.sh --no-connect
Set Suite Variable $DEVICE_SN

0 comments on commit 139a5ae

Please sign in to comment.