-
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
feat: Support multiple cloud profiles #3278
feat: Support multiple cloud profiles #3278
Conversation
@@ -79,17 +75,13 @@ Setup Second Device | |||
Execute Command tedge config set [email protected]_prefix c8y-second | |||
Execute Command tedge config set [email protected] "$(tedge config get c8y.url)" | |||
|
|||
Execute Command tedge cert create c8y@second --device-id ${child_sn} | |||
Execute Command tedge cert create c8y@second --device-id ${second_device_sn} | |||
Execute Command | |||
... cmd=sudo env C8Y_USER='${C8Y_CONFIG.username}' C8Y_PASSWORD='${C8Y_CONFIG.password}' tedge cert upload c8y@second | |||
|
|||
Execute Command tedge connect c8y@second |
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.
@albinsuresh pointed out doing this will bypass the automatic cleanup we get for the devices we create. I'm not sure exactly how best to perform this clean-up. @reubenmiller are you able to help with this?
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.
We can ignore the cleanup for now (for this PR). We can easily add a new keyword to register a device for cleanup once the suite has finished.
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
Robot Results
|
|
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.
Approved.
crates/core/tedge/src/cli/common.rs
Outdated
|
||
pub type Cloud = MaybeBorrowedCloud<'static>; | ||
#[derive(clap::Args, PartialEq, Eq, Debug, Clone)] | ||
pub struct CloudArgs { |
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.
A comment would help to understand when to use CloudArgs
vs OptionalCloudArgs
vs Option<ProfileName>
as a clap argument.
tedge cert create
usesOptionalCloudArgs
letting the user creates a certificate for a specific cloud profile as well as a generic one not specifically attached to some cloud profile.tedge connect
usesCloudArgs
because a cloud is required, possibly with a specific profile.tedge cert upload c8y
usesOption<ProfileName>
because this feature is only available for Cumulocity.
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.
I've now fixed this by changing this to be a subcommand, so we can wrap the result is in Option
. I guess the point around cert upload
is still relevant, but I think it's fairly obvious why that is a special case.
6603b01
to
ef9abe7
Compare
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.
Really nice feature. Just a few open todos:
Summary
- Item 1: Help for tedge cert create help text has duplicate --device-id entries
- Item 4: Add TEDGE_CLOUD_PROFILE variable to the command's help text
- Item 6: Remove references to
@
syntax in error message and config list
In Follow-up PR
- Item 2: include mapper config when testing the cloud connection (same as tedge connect c8y)
- Item 3: add cloud profile information into the tedge connect output
- Item 5: Add maintainer script snippets to handle systemd template certificates - @reubenmiller
See the following sections for the addition details.
Action item details
Item 1: Help for tedge cert create help text has duplicate --device-id entries
tedge cert create c8y --help
Usage: tedge cert create --device-id <ID> c8y [OPTIONS] --device-id <ID>
Ideally the following should be supported:
tedge cert create c8y [OPTIONS] --device-id <ID>
tedge cert create c8y --device-id bar0001 --profile staging-latest
Item 2: include mapper config when testing the cloud connection (same as tedge connect c8y)
The test command would be more useful if it showed the configuration details as well during the test.
The following only shows that the connect to the "cloud" is ok, but not the url of the cloud (and not the tenant).
$ tedge connect c8y --profile staging-latest --test
Verifying device is connected to cloud... ✓
Checking Cumulocity is connected to intended tenant... ✓
Connection check to c8y cloud is successful.
Item 3: add cloud profile information into the tedge connect output
tedge reconnect c8y --profile staging-latest
Disconnecting from Cumulocity
Removing bridge config file... ✓
Restarting mosquitto to apply configuration... ✓
Disabling tedge-mapper-c8y@staging-latest... ✓
Reconnecting with config:
device id: TST_develop_refined_assurance
cloud host: iot.latest.stage.c8y.io:8883
certificate file: /etc/tedge/device-certs/tedge-certificate.pem
bridge: mosquitto
service manager: systemd
mosquitto version: 2.0.11
For example:
Reconnecting with config:
device id: TST_develop_refined_assurance
cloud host: iot.latest.stage.c8y.io:8883
cloud profile: staging-latest
cloud type: c8y
certificate file: /etc/tedge/device-certs/tedge-certificate.pem
bridge: mosquitto
service manager: systemd
mosquitto version: 2.0.11
Item 4: Add TEDGE_CLOUD_PROFILE variable to the command's help text
For example, add the env:
section to the flag's help text (you may have to do this manually).
$ tedge connect c8y --help
Usage: tedge connect c8y [OPTIONS]
Options:
--profile <PROFILE>
The cloud profile you wish to use
[env: TEDGE_CLOUD_PROFILE]
If it is too much effort, then we can add this in the next release (as we're having a bit of feature creep)
Item 5: Add maintainer script snippets to handle systemd template services
The systemd template services (e.g. [email protected]
) are not correctly stopped/started/enabled in deb and rpm maintainer scripts (e.g. preinst, prerm, postinst).
Example snippet:
systemctl show "tedge-mapper-c8y@*" --state=loaded --property=Id --value --no-pager | while read -r UNIT; do
echo "Restart service: $UNIT" >&2
systemctl restart "$UNIT"
done
Item 6: Remove references to @
syntax in error message and config list
Remove guidance using the @
suffix syntax from error messages.
$ tedge connect c8y --profile staging-latest
error: The configurations: c8y.bridge.topic_prefix, [email protected]_prefix should be set to different values before connecting, but are currently set to the same value
Why is the @
syntax shown in the config list
$ tedge config list 'c8y@'
Why can't it following the tedge.toml data format?
For example, given:
[c8y.profiles.staging-latest]
url = "iot.latest.stage.c8y.io"
Then just support the syntax as follows:
c8y.profiles.staging-latest.url
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.
Approved.
Thank you for your sustained effort on improving the UX experience of users and devs using tedge config.
4737a68
to
02a73aa
Compare
02a73aa
to
4daefdb
Compare
4daefdb
to
7cb04c5
Compare
7cb04c5
to
1a3782e
Compare
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.
Retested the changes and everything looks great. I'll create a follow up PR to address the packaging changes (e.g. maintainer script changes regarding the service management).
…tion Signed-off-by: James Rhodes <[email protected]>
1a3782e
to
c077ab0
Compare
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.
LGTM.
if display_name == format!("mosquitto-{prefix}-bridge") && status == Status::Up { | ||
// Receiving this message indicates mosquitto has reconnected (following a | ||
// disconnection) to the cloud. We need to re-request operations in case any | ||
// were triggered while we were down | ||
value.push(create_get_pending_operations_message(prefix)); | ||
} |
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.
Ideally, it would have been better if this was not done from this simple "conversion" function, but done from the calling process_health_status_message
function. But I understand that doing this from here, when you have access to display_name
simplifies the code.
# Get configuration | ||
# | ||
|
||
*** Test Cases *** |
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.
*** Test Cases *** | |
*** Test Cases *** | |
# Since the test framework does not have access to multiple cloud tenants, | |
# multi cloud profile support is tested by connecting the same device to the same cloud | |
# using different external identities configured using different profiles. | |
# This setup results in a single "device" having two device twin identities in the cloud. | |
# That same "device" can be controlled via either twins. |
Adding some commentary would be nice to help others looking at this test and going: "where are those multiple cloud connections?"
Proposed changes
Following the merging of #3262 early to limit conflicts, there are some outstanding tasks:
Current status:
--profile
argument as an alternative tocloud@profile
syntax to make scripting simplerTypes of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments