Skip to content

[CIT-300] Add --test option to tedge connect#218

Merged
rina23q merged 3 commits intothin-edge:mainfrom
rina23q:feature/CIT-300/test-cloud-connection
May 7, 2021
Merged

[CIT-300] Add --test option to tedge connect#218
rina23q merged 3 commits intothin-edge:mainfrom
rina23q:feature/CIT-300/test-cloud-connection

Conversation

@rina23q
Copy link
Copy Markdown
Member

@rina23q rina23q commented May 7, 2021

Highlights:

  • Add --test option to tedge connect az/c8y
  • check_connection() returns Err if fails (previously Ok)
  • --test returns exit code 1 if check_connection() fails
  • Without --test returns exit code 0 if check_connection() fails (warning, no change)

Signed-off-by: Rina Fujino 18257209+rina23q@users.noreply.github.com

Proposed changes

Introduce --test option to tedge connect az/c8y.

Usage:
sudo tedge connect c8y --test
sudo tedge connect az --test

Returns
0 (successful)
1 (failed)

It doesn't diagnose why it failed. It could be several reasons, mosquitto is not running, bridge doesn't exists, configuration in bridge file is incorrect, the cloud server is down, the device has no connection to the internet...

Potential improvements are adding small diagnoses. For example, "mosquitto is not running" and "bridge file doesn't exit" can be covered by the existing code.

Types of changes

What types of changes does your code introduce to thin-edge.io?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

Highlights:
- Add `--test` option to tedge connect az/c8y
- check_connection() returns Err if fails (previously Ok)
- `--test` returns exit code 1 if check_connection() fails
- Without `--test` returns exit code 0 if check_connection() fails (warning, no change)

Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2021

Codecov Report

❌ Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tedge/src/cli/connect/command.rs 0.00% 17 Missing ⚠️
tedge/src/cli/connect/cli.rs 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@PradeepKiruvale PradeepKiruvale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM.

Copy link
Copy Markdown
Contributor

@makr11st makr11st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor style / readability suggestions, up to you if you want to change them.

Comment on lines +78 to +87
match self.check_connection() {
Ok(()) => Ok(()),
_ => {
println!(
"Warning: Bridge has been configured, but {} connection check failed.\n",
self.cloud.as_str()
);
Ok(())
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This match is a little hard to read, how about:

Suggested change
match self.check_connection() {
Ok(()) => Ok(()),
_ => {
println!(
"Warning: Bridge has been configured, but {} connection check failed.\n",
self.cloud.as_str()
);
Ok(())
}
}
if self.check_connection().is_err() {
println!(
"Warning: Bridge has been configured, but {} connection check failed.\n",
self.cloud.as_str()
);
}
Ok(())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion! I'll change it to this.

println!("Warning: Bridge has been configured, but Cumulocity connection check failed.\n",);
Ok(())
Err(ConnectError::NoPacketsReceived {
cloud: "Cumulocity".to_string(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to stay consistent with other parts of the code.

Suggested change
cloud: "Cumulocity".to_string(),
cloud: "Cumulocity".into(),

Ok(())
}
_err => Err(ConnectError::NoPacketsReceived {
cloud: "Azure".to_string(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cloud: "Azure".to_string(),
cloud: "Azure".into(),

rina23q added 2 commits May 7, 2021 15:10
Signed-off-by: Rina Fujino <18257209+rina23q@users.noreply.github.com>
@rina23q rina23q merged commit 6a8bfbe into thin-edge:main May 7, 2021
@rina23q rina23q deleted the feature/CIT-300/test-cloud-connection branch April 11, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants