From 9b49e1896294040be41539e800f7cae107054469 Mon Sep 17 00:00:00 2001 From: Rina Fujino <18257209+rina23q@users.noreply.github.com> Date: Wed, 14 Jun 2023 17:19:38 +0200 Subject: [PATCH 1/7] Make tedge external topics configurable to subscribe for c8y-mapper Some users want c8y-mapper to subscribe selected topics. Introduce `c8y.topics` tedge config key to support such use-case. Change those topics to be configurable, and they are the default value of `c8y.topics`. - tedge/measurements - tedge/measurements/+ - tedge/alarms/+/+ - tedge/alarms/+/+/+ - tedge/events/+ - tedge/events/+/+ - tedge/health/+ - tedge/health/+/+ Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com> --- .../tedge_config/src/tedge_config_cli/new.rs | 5 +++ crates/extensions/c8y_mapper_ext/src/actor.rs | 6 +-- .../extensions/c8y_mapper_ext/src/config.rs | 42 +++++++++++++++---- .../c8y_mapper_ext/src/converter.rs | 9 ++-- crates/extensions/c8y_mapper_ext/src/tests.rs | 13 +++--- 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/crates/common/tedge_config/src/tedge_config_cli/new.rs b/crates/common/tedge_config/src/tedge_config_cli/new.rs index 6e6f420c3e5..ae2bcf3dc4a 100644 --- a/crates/common/tedge_config/src/tedge_config_cli/new.rs +++ b/crates/common/tedge_config/src/tedge_config_cli/new.rs @@ -352,6 +352,11 @@ define_tedge_config! { #[tedge_config(default(from_optional_key = "c8y.url"))] mqtt: HostPort, + /// Set of MQTT topics the Cumulocity mapper should subscribe to + #[tedge_config(example = "tedge/alarms/#,tedge/measurements/+")] + #[tedge_config(default(value = "tedge/measurements,tedge/measurements/+,tedge/alarms/+/+,tedge/alarms/+/+/+,tedge/events/+,tedge/events/+/+,tedge/health/+,tedge/health/+/+"))] + topics: TemplatesSet, + }, #[tedge_config(deprecated_name = "azure")] // for 0.1.0 compatibility diff --git a/crates/extensions/c8y_mapper_ext/src/actor.rs b/crates/extensions/c8y_mapper_ext/src/actor.rs index 7f2ec5854e3..094f596db1a 100644 --- a/crates/extensions/c8y_mapper_ext/src/actor.rs +++ b/crates/extensions/c8y_mapper_ext/src/actor.rs @@ -180,10 +180,8 @@ impl C8yMapperBuilder { let box_builder = SimpleMessageBoxBuilder::new("CumulocityMapper", 16); - let mqtt_publisher = mqtt.connect_consumer( - C8yMapperConfig::subscriptions(&config.config_dir).unwrap(), - adapt(&box_builder.get_sender()), - ); + let mqtt_publisher = + mqtt.connect_consumer(config.topics.clone(), adapt(&box_builder.get_sender())); let http_proxy = C8YHttpProxy::new("C8yMapper => C8YHttpProxy", http); let timer_sender = timer.connect_consumer(NoConfig, adapt(&box_builder.get_sender())); fs_watcher.register_peer(config.ops_dir.clone(), adapt(&box_builder.get_sender())); diff --git a/crates/extensions/c8y_mapper_ext/src/config.rs b/crates/extensions/c8y_mapper_ext/src/config.rs index af30095bfd0..dd515a83bc5 100644 --- a/crates/extensions/c8y_mapper_ext/src/config.rs +++ b/crates/extensions/c8y_mapper_ext/src/config.rs @@ -9,6 +9,7 @@ use tedge_config::new::ConfigNotSet; use tedge_config::new::ReadError; use tedge_config::new::TEdgeConfig; use tedge_mqtt_ext::TopicFilter; +use tracing::log::warn; pub const MQTT_MESSAGE_SIZE_THRESHOLD: usize = 16184; @@ -20,6 +21,7 @@ pub struct C8yMapperConfig { pub service_type: String, pub ops_dir: PathBuf, pub c8y_host: String, + pub topics: TopicFilter, } impl C8yMapperConfig { @@ -30,6 +32,7 @@ impl C8yMapperConfig { device_type: String, service_type: String, c8y_host: String, + topics: TopicFilter, ) -> Self { let ops_dir = config_dir.join("operations").join("c8y"); @@ -41,6 +44,7 @@ impl C8yMapperConfig { service_type, ops_dir, c8y_host, + topics, } } @@ -56,6 +60,14 @@ impl C8yMapperConfig { let service_type = tedge_config.service.ty.clone(); let c8y_host = tedge_config.c8y_url().or_config_not_set()?.to_string(); + // The topics to subscribe = default internal topics + user configurable external topics + let mut topics = Self::internal_topic_filter(&config_dir)?; + for topic in tedge_config.c8y.topics.0.clone() { + if let Err(_) = topics.add(&topic) { + warn!("The configured topic '{topic}' is invalid and ignored."); + } + } + Ok(C8yMapperConfig::new( config_dir, logs_path, @@ -63,22 +75,15 @@ impl C8yMapperConfig { device_type, service_type, c8y_host, + topics, )) } - pub fn subscriptions(config_dir: &Path) -> Result { + pub fn internal_topic_filter(config_dir: &Path) -> Result { let operations = Operations::try_new(config_dir.join("operations/c8y"))?; let mut topic_filter: TopicFilter = vec![ - "tedge/measurements", - "tedge/measurements/+", - "tedge/alarms/+/+", - "tedge/alarms/+/+/+", "c8y-internal/alarms/+/+", "c8y-internal/alarms/+/+/+", - "tedge/events/+", - "tedge/events/+/+", - "tedge/health/+", - "tedge/health/+/+", C8yTopic::SmartRestRequest.to_string().as_str(), ResponseTopic::SoftwareListResponse.as_str(), ResponseTopic::SoftwareUpdateResponse.as_str(), @@ -93,6 +98,22 @@ impl C8yMapperConfig { Ok(topic_filter) } + + /// List of all possible external topics that Cumulocity mapper addresses. For testing purpose. + pub fn default_external_topic_filter() -> TopicFilter { + vec![ + "tedge/measurements", + "tedge/measurements/+", + "tedge/alarms/+/+", + "tedge/alarms/+/+/+", + "tedge/events/+", + "tedge/events/+/+", + "tedge/health/+", + "tedge/health/+/+", + ] + .try_into() + .unwrap() + } } #[derive(Debug, thiserror::Error)] @@ -102,6 +123,9 @@ pub enum C8yMapperConfigBuildError { #[error(transparent)] FromConfigNotSet(#[from] ConfigNotSet), + + #[error(transparent)] + FromC8yMapperConfigError(#[from] C8yMapperConfigError), } #[derive(thiserror::Error, Debug)] diff --git a/crates/extensions/c8y_mapper_ext/src/converter.rs b/crates/extensions/c8y_mapper_ext/src/converter.rs index df338bafa49..081ddda2408 100644 --- a/crates/extensions/c8y_mapper_ext/src/converter.rs +++ b/crates/extensions/c8y_mapper_ext/src/converter.rs @@ -1707,13 +1707,15 @@ mod tests { CumulocityConverter, SimpleMessageBox, ) { + tmp_dir.dir("operations").dir("c8y"); + tmp_dir.dir("tedge").dir("agent"); + let device_id = "test-device".into(); let device_type = "test-device-type".into(); let service_type = "service".into(); let c8y_host = "test.c8y.io".into(); - - tmp_dir.dir("operations").dir("c8y"); - tmp_dir.dir("tedge").dir("agent"); + let mut topics = C8yMapperConfig::internal_topic_filter(&tmp_dir.to_path_buf()).unwrap(); + topics.add_all(C8yMapperConfig::default_external_topic_filter()); let config = C8yMapperConfig::new( tmp_dir.to_path_buf(), @@ -1722,6 +1724,7 @@ mod tests { device_type, service_type, c8y_host, + topics, ); let mqtt_builder: SimpleMessageBoxBuilder = diff --git a/crates/extensions/c8y_mapper_ext/src/tests.rs b/crates/extensions/c8y_mapper_ext/src/tests.rs index 90463fc46b7..411239592f6 100644 --- a/crates/extensions/c8y_mapper_ext/src/tests.rs +++ b/crates/extensions/c8y_mapper_ext/src/tests.rs @@ -1013,7 +1013,6 @@ EOF } #[tokio::test] - async fn custom_operation_timeout_sigterm() { // The test assures SM Mapper correctly receives custom operation on `c8y/s/ds` // and executes the custom operation, it will timeout because it will not complete before given timeout @@ -1086,7 +1085,6 @@ operation failed due to timeout: duration=1sEOF"; } #[tokio::test] - async fn custom_operation_timeout_sigkill() { // The test assures SM Mapper correctly receives custom operation on `c8y/s/ds` // and executes the custom operation, it will timeout because it will not complete before given timeout @@ -1243,14 +1241,16 @@ async fn spawn_c8y_mapper_actor( SimpleMessageBox, SimpleMessageBox, ) { + if init { + config_dir.dir("operations").dir("c8y"); + } + let device_name = "test-device".into(); let device_type = "test-device-type".into(); let service_type = "service".into(); let c8y_host = "test.c8y.io".into(); - - if init { - config_dir.dir("operations").dir("c8y"); - } + let mut topics = C8yMapperConfig::internal_topic_filter(config_dir.path()).unwrap(); + topics.add_all(C8yMapperConfig::default_external_topic_filter()); let config = C8yMapperConfig::new( config_dir.to_path_buf(), @@ -1259,6 +1259,7 @@ async fn spawn_c8y_mapper_actor( device_type, service_type, c8y_host, + topics, ); let mut mqtt_builder: SimpleMessageBoxBuilder = From 54f772c4fa6e9f346f96a6423a7d30d37c495c54 Mon Sep 17 00:00:00 2001 From: Rina Fujino <18257209+rina23q@users.noreply.github.com> Date: Wed, 14 Jun 2023 18:17:16 +0200 Subject: [PATCH 2/7] Make tedge external topics configurable to subscribe for az-mapper Some users want az-mapper to subscribe selected topics. Introduce `az.topics` tedge config key to support such use-case. Change those topics to be configurable, and they are the default value of `az.topics`. - tedge/measurements - tedge/measurements/+ Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com> --- .../tedge_config/src/tedge_config_cli/new.rs | 7 ++++++- crates/core/tedge_mapper/src/az/mapper.rs | 19 ++++++++++++++----- .../extensions/az_mapper_ext/src/converter.rs | 9 --------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/crates/common/tedge_config/src/tedge_config_cli/new.rs b/crates/common/tedge_config/src/tedge_config_cli/new.rs index ae2bcf3dc4a..53586dfcf9c 100644 --- a/crates/common/tedge_config/src/tedge_config_cli/new.rs +++ b/crates/common/tedge_config/src/tedge_config_cli/new.rs @@ -376,7 +376,12 @@ define_tedge_config! { #[tedge_config(example = "true")] #[tedge_config(default(value = true))] timestamp: bool, - } + }, + + /// Set of MQTT topics the Azure IoT mapper should subscribe to + #[tedge_config(example = "tedge/measurements,tedge/measurements/+")] + #[tedge_config(default(value = "tedge/measurements,tedge/measurements/+"))] + topics: TemplatesSet, }, aws: { diff --git a/crates/core/tedge_mapper/src/az/mapper.rs b/crates/core/tedge_mapper/src/az/mapper.rs index 13a4959a474..c0016eba0a2 100644 --- a/crates/core/tedge_mapper/src/az/mapper.rs +++ b/crates/core/tedge_mapper/src/az/mapper.rs @@ -3,12 +3,14 @@ use crate::core::mapper::start_basic_actors; use async_trait::async_trait; use az_mapper_ext::converter::AzureConverter; use clock::WallClock; +use mqtt_channel::TopicFilter; use std::path::Path; use tedge_actors::ConvertingActor; use tedge_actors::MessageSink; use tedge_actors::MessageSource; use tedge_actors::NoConfig; use tedge_config::new::TEdgeConfig; +use tracing::warn; const AZURE_MAPPER_NAME: &str = "tedge-mapper-az"; @@ -36,11 +38,8 @@ impl TEdgeComponent for AzureMapper { let az_converter = AzureConverter::new(tedge_config.az.mapper.timestamp, Box::new(WallClock)); - let mut az_converting_actor = ConvertingActor::builder( - "AzConverter", - az_converter, - AzureConverter::in_topic_filter(), - ); + let mut az_converting_actor = + ConvertingActor::builder("AzConverter", az_converter, get_topic_filter(&tedge_config)); az_converting_actor.add_input(&mut mqtt_actor); az_converting_actor.register_peer(NoConfig, mqtt_actor.get_sender()); @@ -51,3 +50,13 @@ impl TEdgeComponent for AzureMapper { Ok(()) } } + +fn get_topic_filter(tedge_config: &TEdgeConfig) -> TopicFilter { + let mut topics = TopicFilter::empty(); + for topic in tedge_config.az.topics.0.clone() { + if topics.add(&topic).is_err() { + warn!("The configured topic '{topic}' is invalid and ignored."); + } + } + topics +} diff --git a/crates/extensions/az_mapper_ext/src/converter.rs b/crates/extensions/az_mapper_ext/src/converter.rs index 74ccc9d712c..7e52f37a91c 100644 --- a/crates/extensions/az_mapper_ext/src/converter.rs +++ b/crates/extensions/az_mapper_ext/src/converter.rs @@ -7,13 +7,11 @@ use tedge_actors::Converter; use tedge_api::serialize::ThinEdgeJsonSerializer; use tedge_mqtt_ext::MqttMessage; use tedge_mqtt_ext::Topic; -use tedge_mqtt_ext::TopicFilter; const AZ_MQTT_THRESHOLD: usize = 1024 * 128; #[derive(Debug)] pub struct MapperConfig { - pub in_topic_filter: TopicFilter, pub out_topic: Topic, pub errors_topic: Topic, } @@ -28,7 +26,6 @@ pub struct AzureConverter { impl AzureConverter { pub fn new(add_timestamp: bool, clock: Box) -> Self { let mapper_config = MapperConfig { - in_topic_filter: Self::in_topic_filter(), out_topic: Topic::new_unchecked("az/messages/events/"), errors_topic: Topic::new_unchecked("tedge/errors"), }; @@ -49,12 +46,6 @@ impl AzureConverter { } } - pub fn in_topic_filter() -> TopicFilter { - vec!["tedge/measurements", "tedge/measurements/+"] - .try_into() - .unwrap() - } - fn try_convert(&mut self, input: &MqttMessage) -> Result, ConversionError> { self.size_threshold.validate(input)?; let default_timestamp = self.add_timestamp.then(|| self.clock.now()); From 1aad44838deb8cab16c6ee4759b7ee7234a40a0b Mon Sep 17 00:00:00 2001 From: Rina Fujino <18257209+rina23q@users.noreply.github.com> Date: Wed, 14 Jun 2023 18:28:53 +0200 Subject: [PATCH 3/7] Make tedge external topics configurable to subscribe for aws-mapper Some users want aws-mapper to subscribe selected topics. Introduce `aws.topics` tedge config key to support such use-case. Change those topics to be configurable, and they are the default value of `aws.topics`. - tedge/measurements - tedge/measurements/+ - tedge/alarms/+/+ - tedge/alarms/+/+/+ - tedge/events/+ - tedge/events/+/+ - tedge/health - tedge/health/+ Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com> --- .../tedge_config/src/tedge_config_cli/new.rs | 7 ++++++- crates/core/tedge_mapper/src/aws/mapper.rs | 14 +++++++++++++- .../extensions/aws_mapper_ext/src/converter.rs | 16 ---------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/crates/common/tedge_config/src/tedge_config_cli/new.rs b/crates/common/tedge_config/src/tedge_config_cli/new.rs index 53586dfcf9c..41085d5c199 100644 --- a/crates/common/tedge_config/src/tedge_config_cli/new.rs +++ b/crates/common/tedge_config/src/tedge_config_cli/new.rs @@ -400,7 +400,12 @@ define_tedge_config! { #[tedge_config(example = "true")] #[tedge_config(default(value = true))] timestamp: bool, - } + }, + + /// Set of MQTT topics the AWS IoT mapper should subscribe to + #[tedge_config(example = "tedge/measurements,tedge/measurements/+")] + #[tedge_config(default(value = "tedge/measurements,tedge/measurements/+,tedge/alarms/+/+,tedge/alarms/+/+/+,tedge/events/+,tedge/events/+/+,tedge/health,tedge/health/+"))] + topics: TemplatesSet, }, mqtt: { diff --git a/crates/core/tedge_mapper/src/aws/mapper.rs b/crates/core/tedge_mapper/src/aws/mapper.rs index aa1efefc831..60f11a304d3 100644 --- a/crates/core/tedge_mapper/src/aws/mapper.rs +++ b/crates/core/tedge_mapper/src/aws/mapper.rs @@ -3,12 +3,14 @@ use crate::core::mapper::start_basic_actors; use async_trait::async_trait; use aws_mapper_ext::converter::AwsConverter; use clock::WallClock; +use mqtt_channel::TopicFilter; use std::path::Path; use tedge_actors::ConvertingActor; use tedge_actors::MessageSink; use tedge_actors::MessageSource; use tedge_actors::NoConfig; use tedge_config::new::TEdgeConfig; +use tracing::warn; const AWS_MAPPER_NAME: &str = "tedge-mapper-aws"; @@ -32,7 +34,7 @@ impl TEdgeComponent for AwsMapper { let mut aws_converting_actor = ConvertingActor::builder( "AwsConverter", aws_converter, - AwsConverter::in_topic_filter(), + get_topic_filter(&tedge_config), ); aws_converting_actor.add_input(&mut mqtt_actor); @@ -44,3 +46,13 @@ impl TEdgeComponent for AwsMapper { Ok(()) } } + +fn get_topic_filter(tedge_config: &TEdgeConfig) -> TopicFilter { + let mut topics = TopicFilter::empty(); + for topic in tedge_config.aws.topics.0.clone() { + if topics.add(&topic).is_err() { + warn!("The configured topic '{topic}' is invalid and ignored."); + } + } + topics +} diff --git a/crates/extensions/aws_mapper_ext/src/converter.rs b/crates/extensions/aws_mapper_ext/src/converter.rs index 06b977e9522..ba759312a2e 100644 --- a/crates/extensions/aws_mapper_ext/src/converter.rs +++ b/crates/extensions/aws_mapper_ext/src/converter.rs @@ -7,7 +7,6 @@ use tedge_actors::Converter; use tedge_api::serialize::ThinEdgeJsonSerializer; use tedge_mqtt_ext::MqttMessage; use tedge_mqtt_ext::Topic; -use tedge_mqtt_ext::TopicFilter; use crate::error::ConversionError; use crate::size_threshold::SizeThreshold; @@ -37,21 +36,6 @@ impl AwsConverter { } } - pub fn in_topic_filter() -> TopicFilter { - vec![ - "tedge/measurements", - "tedge/measurements/+", - "tedge/health", - "tedge/health/+", - "tedge/events/+", - "tedge/events/+/+", - "tedge/alarms/+/+", - "tedge/alarms/+/+/+", - ] - .try_into() - .unwrap() - } - fn try_convert(&mut self, input: &MqttMessage) -> Result, ConversionError> { let default_timestamp = self.add_timestamp.then(|| self.clock.now()); From fbc10fdd4483e25bcee9442f47463c867b9caa56 Mon Sep 17 00:00:00 2001 From: Rina Fujino <18257209+rina23q@users.noreply.github.com> Date: Mon, 19 Jun 2023 15:43:26 +0200 Subject: [PATCH 4/7] Change the default of .topics to subscribe health topics All cloud mappers subscribe to - tedge/health/+ - tedge/health/+/+ Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com> --- crates/common/tedge_config/src/tedge_config_cli/new.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/common/tedge_config/src/tedge_config_cli/new.rs b/crates/common/tedge_config/src/tedge_config_cli/new.rs index 41085d5c199..355d951f9ce 100644 --- a/crates/common/tedge_config/src/tedge_config_cli/new.rs +++ b/crates/common/tedge_config/src/tedge_config_cli/new.rs @@ -380,7 +380,7 @@ define_tedge_config! { /// Set of MQTT topics the Azure IoT mapper should subscribe to #[tedge_config(example = "tedge/measurements,tedge/measurements/+")] - #[tedge_config(default(value = "tedge/measurements,tedge/measurements/+"))] + #[tedge_config(default(value = "tedge/measurements,tedge/measurements/+,tedge/health/+,tedge/health/+/+"))] topics: TemplatesSet, }, @@ -404,7 +404,7 @@ define_tedge_config! { /// Set of MQTT topics the AWS IoT mapper should subscribe to #[tedge_config(example = "tedge/measurements,tedge/measurements/+")] - #[tedge_config(default(value = "tedge/measurements,tedge/measurements/+,tedge/alarms/+/+,tedge/alarms/+/+/+,tedge/events/+,tedge/events/+/+,tedge/health,tedge/health/+"))] + #[tedge_config(default(value = "tedge/measurements,tedge/measurements/+,tedge/alarms/+/+,tedge/alarms/+/+/+,tedge/events/+,tedge/events/+/+,tedge/health/+,tedge/health/+/+"))] topics: TemplatesSet, }, From e240a4eb3bb56995a96c19490b1609e5644bddcf Mon Sep 17 00:00:00 2001 From: Rina Fujino <18257209+rina23q@users.noreply.github.com> Date: Tue, 20 Jun 2023 21:45:15 +0200 Subject: [PATCH 5/7] Load topics from operation files only when operations/c8y dir exists Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com> --- crates/extensions/c8y_mapper_ext/src/config.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/extensions/c8y_mapper_ext/src/config.rs b/crates/extensions/c8y_mapper_ext/src/config.rs index dd515a83bc5..83c751bd633 100644 --- a/crates/extensions/c8y_mapper_ext/src/config.rs +++ b/crates/extensions/c8y_mapper_ext/src/config.rs @@ -63,7 +63,7 @@ impl C8yMapperConfig { // The topics to subscribe = default internal topics + user configurable external topics let mut topics = Self::internal_topic_filter(&config_dir)?; for topic in tedge_config.c8y.topics.0.clone() { - if let Err(_) = topics.add(&topic) { + if topics.add(&topic).is_err() { warn!("The configured topic '{topic}' is invalid and ignored."); } } @@ -80,7 +80,6 @@ impl C8yMapperConfig { } pub fn internal_topic_filter(config_dir: &Path) -> Result { - let operations = Operations::try_new(config_dir.join("operations/c8y"))?; let mut topic_filter: TopicFilter = vec![ "c8y-internal/alarms/+/+", "c8y-internal/alarms/+/+/+", @@ -92,8 +91,10 @@ impl C8yMapperConfig { .try_into() .expect("topics that mapper should subscribe to"); - for topic in operations.topics_for_operations() { - topic_filter.add(&topic)?; + if let Ok(operations) = Operations::try_new(config_dir.join("operations").join("c8y")) { + for topic in operations.topics_for_operations() { + topic_filter.add(&topic)?; + } } Ok(topic_filter) From fee60182c5a2903bd474baaa3464c4cf82e6041e Mon Sep 17 00:00:00 2001 From: Rina Fujino <18257209+rina23q@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:18:35 +0000 Subject: [PATCH 6/7] Add system tests for .topics keys Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com> --- .../custom_sub_topics_tedge-mapper-aws.robot | 33 +++ .../custom_sub_topics_tedge-mapper-az.robot | 33 +++ .../custom_sub_topics_tedge-mapper-c8y.robot | 33 +++ .../tests/tedge/call_tedge_config_list.robot | 242 ++++++++++++------ .../tests/tedge/tedge_config_get.robot | 15 +- 5 files changed, 274 insertions(+), 82 deletions(-) create mode 100644 tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-aws.robot create mode 100644 tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-az.robot create mode 100644 tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-c8y.robot diff --git a/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-aws.robot b/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-aws.robot new file mode 100644 index 00000000000..f6803b564d7 --- /dev/null +++ b/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-aws.robot @@ -0,0 +1,33 @@ +*** Settings *** +Documentation Purpose of this test is to verify that tedge-mapper-aws subscribes the topics that are configured as aws.topics + +Resource ../../resources/common.resource +Library ThinEdgeIO + +Suite Setup Custom Setup +Suite Teardown Custom Teardown + +Test Tags theme:mqtt theme:aws + + +*** Test Cases *** +Publish events to subscribed topic + Execute Command tedge mqtt pub tedge/events/event-type '{"text": "Event"}' + Should Have MQTT Messages aws/td/events/event-type + +Publish measurements to unsubscribed topic + Execute Command tedge mqtt pub tedge/measurements '{"temperature": 10}' + Sleep 5s reason=If a message is not published in 5s, it will never be published. + Should Have MQTT Messages aws/td/measurements minimum=0 maximum=0 + + +*** Keywords *** +Custom Setup + Setup + Execute Command sudo tedge config set aws.topics "tedge/events/+" + Execute Command sudo systemctl start tedge-mapper-aws.service + ThinEdgeIO.Service Health Status Should Be Up tedge-mapper-aws + +Custom Teardown + Get Logs + Execute Command sudo tedge config unset aws.topics diff --git a/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-az.robot b/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-az.robot new file mode 100644 index 00000000000..089c1b454b1 --- /dev/null +++ b/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-az.robot @@ -0,0 +1,33 @@ +*** Settings *** +Documentation Purpose of this test is to verify that tedge-mapper-az subscribes the topics that are configured as az.topics + +Resource ../../resources/common.resource +Library ThinEdgeIO + +Suite Setup Custom Setup +Suite Teardown Custom Teardown + +Test Tags theme:mqtt theme:az + + +*** Test Cases *** +Publish measurements to subscribed topic + Execute Command tedge mqtt pub tedge/measurements/child '{"temperature": 10}' + Should Have MQTT Messages az/messages/events/# + +Publish measurements to unsubscribed topic + Execute Command tedge mqtt pub tedge/measurements '{"temperature": 10}' + Sleep 5s reason=If a message is not published in 5s, it will never be published. + Should Have MQTT Messages az/messages/events/# minimum=0 maximum=0 + + +*** Keywords *** +Custom Setup + Setup + Execute Command sudo tedge config set az.topics tedge/measurements/+ + Execute Command sudo systemctl restart tedge-mapper-az.service + ThinEdgeIO.Service Health Status Should Be Up tedge-mapper-az + +Custom Teardown + Get Logs + Execute Command sudo tedge config unset az.topics diff --git a/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-c8y.robot b/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-c8y.robot new file mode 100644 index 00000000000..d30f723e7f0 --- /dev/null +++ b/tests/RobotFramework/tests/mqtt/custom_sub_topics_tedge-mapper-c8y.robot @@ -0,0 +1,33 @@ +*** Settings *** +Documentation Purpose of this test is to verify that tedge-mapper-c8y subscribes the topics that are configured as c8y.topics + +Resource ../../resources/common.resource +Library ThinEdgeIO + +Suite Setup Custom Setup +Suite Teardown Custom Teardown + +Test Tags theme:mqtt theme:c8y + + +*** Test Cases *** +Publish events to subscribed topic + Execute Command tedge mqtt pub tedge/events/event-type '{"text": "Event"}' + Should Have MQTT Messages c8y/s/us message_pattern=400,event-type,"Event",* + +Publish measurements to unsubscribed topic + Execute Command tedge mqtt pub tedge/measurements '{"temperature": 10}' + Sleep 5s reason=If a message is not published in 5s, it will never be published. + Should Have MQTT Messages c8y/measurement/measurements/create minimum=0 maximum=0 + + +*** Keywords *** +Custom Setup + Setup + Execute Command sudo tedge config set c8y.topics tedge/events/+ + Execute Command sudo systemctl restart tedge-mapper-c8y.service + ThinEdgeIO.Service Health Status Should Be Up tedge-mapper-c8y + +Custom Teardown + Get Logs + Execute Command sudo tedge config unset c8y.topics diff --git a/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot b/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot index d1357fc6e3d..21fc236a540 100644 --- a/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot +++ b/tests/RobotFramework/tests/tedge/call_tedge_config_list.robot @@ -6,8 +6,11 @@ Documentation Purpose of this test is to verify that the tedge config list ... Set new cert path and return to default value ... Set new c8y.root_cert_path and return to default value ... Set new c8y.smartrest.templates and return to default value +... Set new c8y.topics and return to default value ... Set new az.root_cert_path and return to default value ... Set new az.mapper.timestamp and return to default value +... Set new az.topics and return to default value +... Set new aws.topics and return to default value ... Set new mqtt.bind.address and return to default value ... Set new mqtt.bind.port and return to default value ... Set new tmp.path and return to default value @@ -31,263 +34,342 @@ tedge config list --all Execute Command tedge config list --all set/unset device.type - Execute Command sudo tedge config set device.type changed-type #Changing device.type to "changed-type" + Execute Command sudo tedge config set device.type changed-type # Changing device.type to "changed-type" ${set} Execute Command tedge config list Should Contain ${set} device.type=changed-type - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset device.type ${unset} Execute Command tedge config list Should Contain ${unset} device.type=thin-edge.io set/unset device.key_path - #Changing device.key_path + # Changing device.key_path Execute Command ... sudo tedge config set device.key_path /etc/tedge/device-certs1/tedge-private-key.pem ${set} Execute Command tedge config list Should Contain ${set} device.key_path=/etc/tedge/device-certs1/tedge-private-key.pem - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset device.key_path ${unset} Execute Command tedge config list Should Contain ${unset} device.key_path=/etc/tedge/device-certs/tedge-private-key.pem set/unset device.cert_path - #Changing device.cert_path + # Changing device.cert_path Execute Command ... sudo tedge config set device.cert_path /etc/tedge/device-certs1/tedge-certificate.pem ${set} Execute Command tedge config list Should Contain ${set} device.cert_path=/etc/tedge/device-certs1/tedge-certificate.pem - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset device.cert_path ${unset} Execute Command tedge config list Should Contain ${unset} device.cert_path=/etc/tedge/device-certs/tedge-certificate.pem set/unset c8y.root_cert_path - Execute Command sudo tedge config set c8y.root_cert_path /etc/ssl/certs1 #Changing c8y.root_cert_path + Execute Command sudo tedge config set c8y.root_cert_path /etc/ssl/certs1 # Changing c8y.root_cert_path ${set} Execute Command tedge config list Should Contain ${set} c8y.root_cert_path=/etc/ssl/certs1 - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset c8y.root_cert_path ${unset} Execute Command tedge config list Should Contain ${unset} c8y.root_cert_path=/etc/ssl/certs set/unset c8y.smartrest.templates - Execute Command sudo tedge config set c8y.smartrest.templates 1 #Changing c8y.smartrest.templates + Execute Command sudo tedge config set c8y.smartrest.templates 1 # Changing c8y.smartrest.templates ${set} Execute Command tedge config list Should Contain ${set} c8y.smartrest.templates=["1"] - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset c8y.smartrest.templates ${unset} Execute Command tedge config list Should Contain ${unset} c8y.smartrest.templates=[] +set/unset c8y.topics + Execute Command sudo tedge config set c8y.topics topic1,topic2 # Changing c8y.topics + ${set} Execute Command tedge config list + Should Contain ${set} c8y.topics=["topic1", "topic2"] + + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset c8y.topics + ${unset} Execute Command tedge config list + Should Contain + ... ${unset} + ... c8y.topics=["tedge/measurements", "tedge/measurements/+", "tedge/alarms/+/+", "tedge/alarms/+/+/+", "tedge/events/+", "tedge/events/+/+", "tedge/health/+", "tedge/health/+/+"] + set/unset az.root_cert_path - Execute Command sudo tedge config set az.root_cert_path /etc/ssl/certs1 #Changing az.root_cert_path + Execute Command sudo tedge config set az.root_cert_path /etc/ssl/certs1 # Changing az.root_cert_path ${set} Execute Command tedge config list Should Contain ${set} az.root_cert_path=/etc/ssl/certs1 - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset az.root_cert_path ${unset} Execute Command tedge config list Should Contain ${unset} az.root_cert_path=/etc/ssl/certs +set/unset az.topics + Execute Command sudo tedge config set az.topics topic1,topic2 # Changing az.topics + ${set} Execute Command tedge config list + Should Contain ${set} az.topics=["topic1", "topic2"] + + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset az.topics + ${unset} Execute Command tedge config list + Should Contain + ... ${unset} + ... az.topics=["tedge/measurements", "tedge/measurements/+", "tedge/health/+", "tedge/health/+/+"] + +set/unset aws.topics + Execute Command sudo tedge config set aws.topics topic1,topic2 # Changing aws.topics + ${set} Execute Command tedge config list + Should Contain ${set} aws.topics=["topic1", "topic2"] + + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset aws.topics + ${unset} Execute Command tedge config list + Should Contain + ... ${unset} + ... aws.topics=["tedge/measurements", "tedge/measurements/+", "tedge/alarms/+/+", "tedge/alarms/+/+/+", "tedge/events/+", "tedge/events/+/+", "tedge/health/+", "tedge/health/+/+"] + set/unset aws.url - Execute Command sudo tedge config set aws.url your-endpoint.amazonaws.com #Changing aws.url - ${set} Execute Command tedge config list + Execute Command sudo tedge config set aws.url your-endpoint.amazonaws.com # Changing aws.url + ${set} Execute Command tedge config list Should Contain ${set} aws.url=your-endpoint.amazonaws.com - Execute Command sudo tedge config unset aws.url #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset aws.url + ${unset} Execute Command tedge config list Should not Contain ${unset} aws.url= set/unset aws.root_cert_path - Execute Command sudo tedge config set aws.root_cert_path /etc/ssl/certs1 #Changing aws.aws.root_cert_path - ${set} Execute Command tedge config list + Execute Command sudo tedge config set aws.root_cert_path /etc/ssl/certs1 # Changing aws.aws.root_cert_path + ${set} Execute Command tedge config list Should Contain ${set} aws.root_cert_path=/etc/ssl/certs1 - Execute Command sudo tedge config unset aws.root_cert_path #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset aws.root_cert_path + ${unset} Execute Command tedge config list Should Contain ${unset} aws.root_cert_path=/etc/ssl/certs set/unset aws.mapper.timestamp - Execute Command sudo tedge config set aws.mapper.timestamp false #Changing aws.mapper.timestamp - ${set} Execute Command tedge config list + Execute Command sudo tedge config set aws.mapper.timestamp false # Changing aws.mapper.timestamp + ${set} Execute Command tedge config list Should Contain ${set} aws.mapper.timestamp=false - Execute Command sudo tedge config unset aws.mapper.timestamp #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset aws.mapper.timestamp + ${unset} Execute Command tedge config list Should Contain ${unset} aws.mapper.timestamp=true set/unset az.mapper.timestamp - Execute Command sudo tedge config set az.mapper.timestamp false #Changing az.mapper.timestamp + Execute Command sudo tedge config set az.mapper.timestamp false # Changing az.mapper.timestamp ${set} Execute Command tedge config list Should Contain ${set} az.mapper.timestamp=false - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset az.mapper.timestamp ${unset} Execute Command tedge config list Should Contain ${unset} az.mapper.timestamp=true set/unset mqtt.bind.address - Execute Command sudo tedge config set mqtt.bind.address 127.1.1.1 #Changing mqtt.bind.address + Execute Command sudo tedge config set mqtt.bind.address 127.1.1.1 # Changing mqtt.bind.address ${set} Execute Command tedge config list Should Contain ${set} mqtt.bind.address=127.1.1.1 - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset mqtt.bind.address ${unset} Execute Command tedge config list Should Contain ${unset} mqtt.bind.address=127.0.0.1 set/unset mqtt.bind.port - Execute Command sudo tedge config set mqtt.bind.port 8888 #Changing mqtt.bind.port + Execute Command sudo tedge config set mqtt.bind.port 8888 # Changing mqtt.bind.port ${set} Execute Command tedge config list Should Contain ${set} mqtt.bind.port=8888 - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset mqtt.bind.port ${unset} Execute Command tedge config list Should Contain ${unset} mqtt.bind.port=1883 set/unset http.bind.port - Execute Command sudo tedge config set http.bind.port 7777 #Changing http.bind.port - ${set} Execute Command tedge config list + Execute Command sudo tedge config set http.bind.port 7777 # Changing http.bind.port + ${set} Execute Command tedge config list Should Contain ${set} http.bind.port=7777 - Execute Command sudo tedge config unset http.bind.port #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset http.bind.port + ${unset} Execute Command tedge config list Should Contain ${unset} http.bind.port=8000 set/unset tmp.path - Execute Command sudo tedge config set tmp.path /tmp1 #Changing tmp.path + Execute Command sudo tedge config set tmp.path /tmp1 # Changing tmp.path ${set} Execute Command tedge config list Should Contain ${set} tmp.path=/tmp1 - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset tmp.path ${unset} Execute Command tedge config list Should Contain ${unset} tmp.path=/tmp set/unset logs.path - Execute Command sudo tedge config set logs.path /var/log1 #Changing logs.path + Execute Command sudo tedge config set logs.path /var/log1 # Changing logs.path ${set} Execute Command tedge config list Should Contain ${set} logs.path=/var/log1 - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset logs.path ${unset} Execute Command tedge config list Should Contain ${unset} logs.path=/var/log set/unset run.path - Execute Command sudo tedge config set run.path /run1 #Changing run.path + Execute Command sudo tedge config set run.path /run1 # Changing run.path ${set} Execute Command tedge config list Should Contain ${set} run.path=/run1 - #Undo the change by using the 'unset' command, value returns to default one + # Undo the change by using the 'unset' command, value returns to default one Execute Command ... sudo tedge config unset run.path ${unset} Execute Command tedge config list Should Contain ${unset} run.path=/run set/unset firmware.child.update.timeout - Execute Command sudo tedge config set firmware.child.update.timeout 4000 #Changing firmware.child.update.timeout - ${set} Execute Command tedge config list + # Changing firmware.child.update.timeout + Execute Command + ... sudo tedge config set firmware.child.update.timeout 4000 + ${set} Execute Command tedge config list Should Contain ${set} firmware.child.update.timeout=4000 - Execute Command sudo tedge config unset firmware.child.update.timeout #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset firmware.child.update.timeout + ${unset} Execute Command tedge config list Should Contain ${unset} firmware.child.update.timeout=3600 set/unset c8y.url - Execute Command sudo tedge config set c8y.url your-tenant.cumulocity.com #Changing c8y.url - ${set} Execute Command tedge config list + Execute Command sudo tedge config set c8y.url your-tenant.cumulocity.com # Changing c8y.url + ${set} Execute Command tedge config list Should Contain ${set} c8y.url=your-tenant.cumulocity.com - Execute Command sudo tedge config unset c8y.url #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset c8y.url + ${unset} Execute Command tedge config list Should not Contain ${unset} c8y.url= set/unset az.url - Execute Command sudo tedge config set az.url MyAzure.azure-devices.net #Changing az.url - ${set} Execute Command tedge config list + Execute Command sudo tedge config set az.url MyAzure.azure-devices.net # Changing az.url + ${set} Execute Command tedge config list Should Contain ${set} az.url=MyAzure.azure-devices.net - Execute Command sudo tedge config unset az.url #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset az.url + ${unset} Execute Command tedge config list Should not Contain ${unset} az.url= set/unset mqtt.external.bind.port - Execute Command sudo tedge config set mqtt.external.bind.port 8888 #Changing mqtt.external.bind.port - ${set} Execute Command tedge config list + Execute Command sudo tedge config set mqtt.external.bind.port 8888 # Changing mqtt.external.bind.port + ${set} Execute Command tedge config list Should Contain ${set} mqtt.external.bind.port=8888 - Execute Command sudo tedge config unset mqtt.external.bind.port #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset mqtt.external.bind.port + ${unset} Execute Command tedge config list Should Not Contain ${unset} mqtt.external.bind.port= mqtt.external.bind.address - Execute Command sudo tedge config set mqtt.external.bind.address 0.0.0.0 #Changing mqtt.external.bind.address - ${set} Execute Command tedge config list + # Changing mqtt.external.bind.address + Execute Command + ... sudo tedge config set mqtt.external.bind.address 0.0.0.0 + ${set} Execute Command tedge config list Should Contain ${set} mqtt.external.bind.address=0.0.0.0 - Execute Command sudo tedge config unset mqtt.external.bind.address #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset mqtt.external.bind.address + ${unset} Execute Command tedge config list Should Not Contain ${unset} mqtt.external.bind.address= mqtt.external.bind.interface - Execute Command sudo tedge config set mqtt.external.bind.interface wlan0 #Changing mqtt.external.bind.interface - ${set} Execute Command tedge config list + # Changing mqtt.external.bind.interface + Execute Command + ... sudo tedge config set mqtt.external.bind.interface wlan0 + ${set} Execute Command tedge config list Should Contain ${set} mqtt.external.bind.interface=wlan0 - Execute Command sudo tedge config unset mqtt.external.bind.interface #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset mqtt.external.bind.interface + ${unset} Execute Command tedge config list Should Not Contain ${unset} mqtt.external.bind.interface= set/unset mqtt.external.ca_path - Execute Command sudo tedge config set mqtt.external.ca_path /etc/ssl/certsNote #Changing mqtt.external.ca_path - ${set} Execute Command tedge config list + # Changing mqtt.external.ca_path + Execute Command + ... sudo tedge config set mqtt.external.ca_path /etc/ssl/certsNote + ${set} Execute Command tedge config list Should Contain ${set} mqtt.external.ca_path=/etc/ssl/certsNote - Execute Command sudo tedge config unset mqtt.external.ca_path #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset mqtt.external.ca_path + ${unset} Execute Command tedge config list Should Not Contain ${unset} mqtt.external.ca_path= set/unset mqtt.external.cert_file - Execute Command sudo tedge config set mqtt.external.cert_file /etc/tedge/device-certs/tedge-certificate.pemNote #Changing mqtt.external.cert_file - ${set} Execute Command tedge config list + # Changing mqtt.external.cert_file + Execute Command + ... sudo tedge config set mqtt.external.cert_file /etc/tedge/device-certs/tedge-certificate.pemNote + ${set} Execute Command tedge config list Should Contain ${set} mqtt.external.cert_file=/etc/tedge/device-certs/tedge-certificate.pemNote - Execute Command sudo tedge config unset mqtt.external.cert_file #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset mqtt.external.cert_file + ${unset} Execute Command tedge config list Should Not Contain ${unset} mqtt.external.cert_file= set/unset mqtt.external.key_file - Execute Command sudo tedge config set mqtt.external.key_file /etc/tedge/device-certs/tedge-private-key.pemNote #Changing mqtt.external.key_file - ${set} Execute Command tedge config list + # Changing mqtt.external.key_file + Execute Command + ... sudo tedge config set mqtt.external.key_file /etc/tedge/device-certs/tedge-private-key.pemNote + ${set} Execute Command tedge config list Should Contain ${set} mqtt.external.key_file=/etc/tedge/device-certs/tedge-private-key.pemNote - Execute Command sudo tedge config unset mqtt.external.key_file #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset mqtt.external.key_file + ${unset} Execute Command tedge config list Should Not Contain ${unset} mqtt.external.key_file= set/unset software.plugin.default - Execute Command sudo tedge config set software.plugin.default apt #Changing software.plugin.default - ${set} Execute Command tedge config list + Execute Command sudo tedge config set software.plugin.default apt # Changing software.plugin.default + ${set} Execute Command tedge config list Should Contain ${set} software.plugin.default=apt - Execute Command sudo tedge config unset software.plugin.default #Undo the change by using the 'unset' command, value returns to default one - ${unset} Execute Command tedge config list + # Undo the change by using the 'unset' command, value returns to default one + Execute Command + ... sudo tedge config unset software.plugin.default + ${unset} Execute Command tedge config list Should Not Contain ${unset} software.plugin.default= diff --git a/tests/RobotFramework/tests/tedge/tedge_config_get.robot b/tests/RobotFramework/tests/tedge/tedge_config_get.robot index 580cc13d88f..352327e44db 100644 --- a/tests/RobotFramework/tests/tedge/tedge_config_get.robot +++ b/tests/RobotFramework/tests/tedge/tedge_config_get.robot @@ -37,9 +37,15 @@ Set configuration via environment variables TEDGE_MQTT_CLIENT_HOST mqtt.client.host custom_host_name TEDGE_MQTT_CLIENT_PORT mqtt.client.port 8888 +Set configuration via environment variables for topics + [Template] Check known tedge environment settings for topics + TEDGE_AWS_TOPICS aws.topics + TEDGE_AZ_TOPICS az.topics + TEDGE_C8Y_TOPICS c8y.topics + Set unknown configuration via environment variables ${stdout} ${stderr}= Execute Command - ... env TEDGE_C8Y_UNKNOWN_CONFIGURATION\=dummy TEDGE_C8Y_URL\=example.com tedge config get c8y.url + ... cmd=env TEDGE_C8Y_UNKNOWN_CONFIGURATION=dummy TEDGE_C8Y_URL=example.com tedge config get c8y.url ... stdout=${True} ... stderr=${True} Should Be Equal ${stdout} example.com\n @@ -55,5 +61,10 @@ Custom Setup Check known tedge environment settings [Arguments] ${ENV_NAME} ${KEY_NAME} ${VALUE} - ${output}= Execute Command env ${ENV_NAME}\=${VALUE} tedge config get ${KEY_NAME} + ${output}= Execute Command cmd=env ${ENV_NAME}=${VALUE} tedge config get ${KEY_NAME} Should Be Equal ${output} ${VALUE}\n + +Check known tedge environment settings for topics + [Arguments] ${ENV_NAME} ${KEY_NAME} + ${output}= Execute Command cmd=env ${ENV_NAME}=topic/1,topic/2/+,topic/3/# tedge config get ${KEY_NAME} + Should Be Equal ${output} ["topic/1", "topic/2/+", "topic/3/#"]\n From e56f6e3e0004818b1d1291e5eb61cc8fb1cef90a Mon Sep 17 00:00:00 2001 From: Rina Fujino <18257209+rina23q@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:05:45 +0000 Subject: [PATCH 7/7] Add how-to-guide for configurable mqtt topics for mappers Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com> --- .../config-mapper-mqtt-topics.md | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 docs/src/operate/configuration/config-mapper-mqtt-topics.md diff --git a/docs/src/operate/configuration/config-mapper-mqtt-topics.md b/docs/src/operate/configuration/config-mapper-mqtt-topics.md new file mode 100644 index 00000000000..25269f0d70f --- /dev/null +++ b/docs/src/operate/configuration/config-mapper-mqtt-topics.md @@ -0,0 +1,73 @@ +--- +title: Mapper Configuration +tags: [Operate, Configuration, Cloud, MQTT] +--- + +# How to control which MQTT topics the mappers subscribe to + +The cloud-specific mappers subscribe to the reserved MQTT topics and convert incoming MQTT messages to cloud-specific messages. +In an advanced use case, such as using more than one cloud mappers for the same device, +you may want to customize the external tedge MQTT topics that each cloud mapper subscribes to. + +The `tedge config` command and the keys `c8y.topics`, `az.topics`, and `aws.topics` are usable for this use-case. + +| Cloud | tedge config key | Environmental variable | systemctl service | +|----------------|------------------|------------------------|-------------------| +| Cumulocity IoT | c8y.topics | TEDGE_C8Y_TOPICS | tedge-mapper-c8y | +| Azure IoT | az.topics | TEDGE_AZ_TOPICS | tedge-mapper-az | +| AWS IoT | aws.topics | TEDGE_AWS_TOPICS | tedge-mapper-aws | + +:::note +This guide uses `c8y.topics`, `TEDGE_C8Y_TOPICS`, and `tedge-mapper-c8y` as an example. +For other cloud mappers, use the keys in the table. +::: + +## Check the subscribed MQTT topics + +First, check which MQTT topics are subscribed by a cloud mapper. Run: + +```sh +tedge config get c8y.topics +``` + +```sh title="Output" +["tedge/measurements", "tedge/measurements/+", "tedge/alarms/+/+", "tedge/alarms/+/+/+", "tedge/events/+", "tedge/events/+/+", "tedge/health/+", "tedge/health/+/+"] +``` + +## Set the desired new MQTT topics + +If you want to change the subscribed MQTT topics, use `tedge config set`. +For example, if you want the Cumulocity IoT mapper to subscribe only `tedge/measurements` and `tedge/measurements/+` topics, +the command to run should be as below. + +```sh +sudo tedge config set c8y.topics tedge/measurements,tedge/measurements/+ +``` + +Alternatively, the same setting can be controlled via environment variables. +The environment variable settings will override any values set by the tedge config command. + +```sh +export TEDGE_C8Y_TOPICS=tedge/measurements,tedge/measurements/+ +``` + +:::note +If an invalid MQTT topic is given, the mapper will ignore it. +::: + +The service must be restarted for the setting to take effect. +The following command shows how to restart the Cumulocity IoT mapper on a device using systemd as the init system. + +```sh +sudo systemctl restart tedge-mapper-c8y +``` + +## Change back to the default topics + +If you want a mapper to subscribe back to the default MQTT topics, run: + +```sh +sudo tedge config unset c8y.topics +``` + +Then restart the corresponding mapper.