summaryrefslogtreecommitdiffstats
path: root/tedge
diff options
context:
space:
mode:
authorPradeepKiruvale <PRADEEPKIRUVALE@gmail.com>2021-09-14 18:08:45 +0530
committerGitHub <noreply@github.com>2021-09-14 18:08:45 +0530
commitac5beefb5d9fae73281b667d6719644691eeef82 (patch)
treee20ecc6c9d678524427ed02a7f9ff2e366d88074 /tedge
parentdf9080d3f966ffc7471a009ec724879947e2f627 (diff)
[CIT-565] tedge connect test c8y/az (#425)
* [CIT-565] return error on check connection failure * [CIT-565] check if device connected * address review comments Co-authored-by: Pradeep Kumar K J <pradeepkumar.kj@sofwareag.com>
Diffstat (limited to 'tedge')
-rw-r--r--tedge/src/cli/connect/command.rs29
-rw-r--r--tedge/src/cli/connect/error.rs6
2 files changed, 30 insertions, 5 deletions
diff --git a/tedge/src/cli/connect/command.rs b/tedge/src/cli/connect/command.rs
index 1dc0bf86..162d8368 100644
--- a/tedge/src/cli/connect/command.rs
+++ b/tedge/src/cli/connect/command.rs
@@ -33,6 +33,7 @@ pub enum DeviceStatus {
Unknown,
}
+#[derive(Debug)]
pub enum Cloud {
Azure,
C8y,
@@ -69,10 +70,18 @@ impl Command for ConnectCommand {
let mut config = self.config_repository.load()?;
if self.is_test_connection {
- return match self.check_connection(&config) {
- Ok(_) => Ok(()),
- Err(err) => Err(err.into()),
- };
+ let br_config = self.bridge_config(&config)?;
+ if self.check_if_bridge_exists(br_config) {
+ return match self.check_connection(&config) {
+ Ok(_) => Ok(()),
+ Err(err) => Err(err.into()),
+ };
+ } else {
+ return Err((ConnectError::DeviceNotConnected {
+ cloud: self.cloud.as_str().into(),
+ })
+ .into());
+ }
}
// XXX: Do we really need to persist the defaults?
@@ -166,6 +175,16 @@ impl ConnectCommand {
Cloud::C8y => check_device_status_c8y(port),
}
}
+
+ fn check_if_bridge_exists(&self, br_config: BridgeConfig) -> bool {
+ let bridge_conf_path = self
+ .config_location
+ .tedge_config_root_path
+ .join(TEDGE_BRIDGE_CONF_DIR_PATH)
+ .join(br_config.config_file);
+
+ Path::new(&bridge_conf_path).exists()
+ }
}
// XXX: Improve naming
@@ -212,7 +231,7 @@ fn check_device_status_c8y(port: u16) -> Result<DeviceStatus, ConnectError> {
println!("... No response. If the device is new, it's normal to get no response in the first try.");
} else {
println!("... No response. ");
- return Ok(DeviceStatus::Unknown);
+ return Err(ConnectError::ConnectionCheckError);
}
}
Err(err) => {
diff --git a/tedge/src/cli/connect/error.rs b/tedge/src/cli/connect/error.rs
index 6be42dc1..b2e21962 100644
--- a/tedge/src/cli/connect/error.rs
+++ b/tedge/src/cli/connect/error.rs
@@ -35,4 +35,10 @@ pub enum ConnectError {
#[error(transparent)]
ConfigLoadError(#[from] tedge_config::TEdgeConfigError),
+
+ #[error("Connection check failed")]
+ ConnectionCheckError,
+
+ #[error("Device is not connected to {cloud} cloud")]
+ DeviceNotConnected { cloud: String },
}