-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Fix remaining test failures from built-in bridge #2879
Changes from all commits
303948a
a22a378
16d65a9
c755244
c99ba66
1c4accc
89db10f
7fb77a9
1d00724
884807b
bbff089
30b0e61
df59548
299627a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use tedge_config::TEdgeConfigLocation; | |
use super::common::Cloud; | ||
use super::connect::ConnectError; | ||
use crate::bridge::BridgeConfig; | ||
use crate::bridge::BridgeLocation; | ||
use crate::bridge::CommonMosquittoConfig; | ||
use crate::bridge::TEDGE_BRIDGE_CONF_DIR_PATH; | ||
use crate::command::BuildContext; | ||
|
@@ -28,19 +29,38 @@ impl Command for RefreshBridgesCmd { | |
fn execute(&self) -> anyhow::Result<()> { | ||
let clouds = established_bridges(&self.config_location); | ||
|
||
if clouds.is_empty() { | ||
if clouds.is_empty() && !self.config.mqtt.bridge.built_in { | ||
println!("No bridges to refresh."); | ||
return Ok(()); | ||
} | ||
|
||
let common_mosquitto_config = CommonMosquittoConfig::from_tedge_config(&self.config); | ||
common_mosquitto_config.save(&self.config_location)?; | ||
|
||
for cloud in clouds { | ||
println!("Refreshing bridge {cloud}"); | ||
if !self.config.mqtt.bridge.built_in { | ||
for cloud in &clouds { | ||
println!("Refreshing bridge {cloud}"); | ||
|
||
let bridge_config = super::connect::bridge_config(&self.config, cloud)?; | ||
refresh_bridge(&bridge_config, &self.config_location)?; | ||
let bridge_config = super::connect::bridge_config(&self.config, *cloud)?; | ||
refresh_bridge(&bridge_config, &self.config_location)?; | ||
} | ||
} | ||
|
||
for cloud in [Cloud::Aws, Cloud::Azure, Cloud::C8y] { | ||
// (attempt to) reassert ownership of the certificate and key | ||
// This is necessary when upgrading from the mosquitto bridge to the built-in bridge | ||
Comment on lines
+49
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will have to find a more dynamic way to handle certificate ownership. But that's okay for now. |
||
if let Ok(bridge_config) = super::connect::bridge_config(&self.config, cloud) { | ||
super::connect::chown_certificate_and_key(&bridge_config); | ||
|
||
if bridge_config.bridge_location == BridgeLocation::BuiltIn | ||
&& clouds.contains(&cloud) | ||
{ | ||
println!( | ||
"Deleting mosquitto bridge configuration for {cloud} in favour of built-in bridge" | ||
); | ||
super::connect::use_built_in_bridge(&self.config_location, &bridge_config)?; | ||
} | ||
} | ||
} | ||
|
||
println!("Restarting mosquitto service.\n"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,11 @@ use tedge_config::TEdgeConfig; | |
use tedge_downloader_ext::DownloaderActor; | ||
use tedge_file_system_ext::FsWatchActorBuilder; | ||
use tedge_http_ext::HttpActor; | ||
use tedge_mqtt_bridge::rumqttc::LastWill; | ||
use tedge_mqtt_bridge::use_key_and_cert; | ||
use tedge_mqtt_bridge::BridgeConfig; | ||
use tedge_mqtt_bridge::MqttBridgeActorBuilder; | ||
use tedge_mqtt_bridge::QoS; | ||
use tedge_mqtt_ext::MqttActorBuilder; | ||
use tedge_timer_ext::TimerActor; | ||
use tedge_uploader_ext::UploaderActor; | ||
|
@@ -72,7 +74,36 @@ impl TEdgeComponent for CumulocityMapper { | |
tc.forward_from_remote(topic, local_prefix.clone(), "")?; | ||
} | ||
|
||
tc.forward_from_local("#", local_prefix, "")?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this was genuinely problematic as Cumulocity doesn't send us our own messages back, but I've changed the config to match the current bridge config in any case |
||
// Templates | ||
tc.forward_from_local("s/ut/#", local_prefix.clone(), "")?; | ||
|
||
// Static templates | ||
tc.forward_from_local("s/us", local_prefix.clone(), "")?; | ||
tc.forward_from_local("s/us/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("t/us/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("q/us/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("c/us/#", local_prefix.clone(), "")?; | ||
|
||
// SmartREST2 | ||
tc.forward_from_local("s/uc/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("t/uc/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("q/uc/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("c/uc/#", local_prefix.clone(), "")?; | ||
|
||
// c8y JSON | ||
tc.forward_from_local( | ||
"inventory/managedObjects/update/#", | ||
local_prefix.clone(), | ||
"", | ||
)?; | ||
tc.forward_from_local( | ||
"measurement/measurements/create/#", | ||
local_prefix.clone(), | ||
"", | ||
)?; | ||
tc.forward_from_local("event/events/create/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("alarm/alarms/create/#", local_prefix.clone(), "")?; | ||
tc.forward_from_local("s/uat", local_prefix.clone(), "")?; | ||
|
||
let c8y = tedge_config.c8y.mqtt.or_config_not_set()?; | ||
let mut cloud_config = tedge_mqtt_bridge::MqttOptions::new( | ||
|
@@ -89,14 +120,68 @@ impl TEdgeComponent for CumulocityMapper { | |
&tedge_config, | ||
)?; | ||
|
||
let bridge_actor = MqttBridgeActorBuilder::new( | ||
&tedge_config, | ||
c8y_mapper_config.bridge_service_name(), | ||
tc, | ||
cloud_config, | ||
) | ||
.await; | ||
runtime.spawn(bridge_actor).await?; | ||
let main_device_xid: EntityExternalId = | ||
tedge_config.device.id.try_read(&tedge_config)?.into(); | ||
let service_type = &tedge_config.service.ty; | ||
let service_type = if service_type.is_empty() { | ||
"service".to_string() | ||
} else { | ||
service_type.to_string() | ||
}; | ||
|
||
// FIXME: this will not work if `mqtt.device_topic_id` is not in default scheme | ||
|
||
// there is one mapper instance per cloud per thin-edge instance, perhaps we should use some | ||
// predefined topic id instead of trying to derive it from current device? | ||
let entity_topic_id: EntityTopicId = tedge_config | ||
.mqtt | ||
.device_topic_id | ||
.clone() | ||
.parse() | ||
.context("Invalid device_topic_id")?; | ||
|
||
let mapper_service_topic_id = entity_topic_id | ||
.default_service_for_device(CUMULOCITY_MAPPER_NAME) | ||
.context("Can't derive service name if device topic id not in default scheme")?; | ||
|
||
let mapper_service_external_id = CumulocityConverter::map_to_c8y_external_id( | ||
&mapper_service_topic_id, | ||
&main_device_xid, | ||
); | ||
|
||
let last_will_message_mapper = | ||
c8y_api::smartrest::inventory::service_creation_message_payload( | ||
mapper_service_external_id.as_ref(), | ||
CUMULOCITY_MAPPER_NAME, | ||
service_type.as_str(), | ||
"down", | ||
)?; | ||
let last_will_message_bridge = | ||
c8y_api::smartrest::inventory::service_creation_message_payload( | ||
mapper_service_external_id.as_ref(), | ||
&c8y_mapper_config.bridge_service_name(), | ||
service_type.as_str(), | ||
"down", | ||
)?; | ||
|
||
cloud_config.set_last_will(LastWill { | ||
topic: "s/us".into(), | ||
qos: QoS::AtLeastOnce, | ||
message: format!("{last_will_message_bridge}\n{last_will_message_mapper}").into(), | ||
retain: false, | ||
}); | ||
|
||
runtime | ||
.spawn( | ||
MqttBridgeActorBuilder::new( | ||
&tedge_config, | ||
c8y_mapper_config.bridge_service_name(), | ||
tc, | ||
cloud_config, | ||
) | ||
.await, | ||
) | ||
.await?; | ||
} | ||
let mut jwt_actor = C8YJwtRetriever::builder( | ||
mqtt_config.clone(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. The directories should be created by
tedge init
andtedge connect
should fail if given a path with unknown parents.