Skip to content
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

Use '-o' for recovery export. #1140

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/cli/cmds/fleet.toit
Original file line number Diff line number Diff line change
Expand Up @@ -596,17 +596,18 @@ create-fleet-commands config/Config cache/Cache ui/Ui -> List:

recovery-export-cmd := cli.Command "export"
--help="""
Export the recovery information for this fleet.
Export the current broker of this fleet as recovery information.

The written JSON file should be served on the recovery server(s).
"""
--options=[
cli.Option "directory"
--help="The directory to write the recovery information to.",
cli.Option "output"
--short-name="o"
--help="The file to write the recovery information to."
]
--examples=[
cli.Example "Export the recovery servers to the current directory:"
--arguments="--directory=.",
cli.Example "Export the current broker to 'recovery.json':"
--arguments="-o recovery.json",
]
--run=:: recovery-export it config cache ui
recovery-cmd.add recovery-export-cmd
Expand Down Expand Up @@ -1031,13 +1032,12 @@ recovery-list parsed/cli.Parsed config/Config cache/Cache ui/Ui:
printer.emit --title="Recovery urls" recovery-urls

recovery-export parsed/cli.Parsed config/Config cache/Cache ui/Ui:
directory := parsed["directory"]
output := parsed["output"]

with-devices-fleet parsed config cache ui: | fleet/FleetWithDevices |
recovery-info := fleet.recovery-info
path := fs.join directory (recovery-file-name --fleet-id=fleet.id)
file.write-content --path=path recovery-info
ui.info "Exported recovery information to '$path'."
file.write-content --path=output recovery-info
ui.info "Exported recovery information to '$output'."
recovery-urls := fleet.recovery-urls
if not recovery-urls.is-empty:
ui.info "Devices with the current recovery configuration will try to"
Expand All @@ -1048,7 +1048,7 @@ recovery-export parsed/cli.Parsed config/Config cache/Cache ui/Ui:
ui.do --kind=Ui.RESULT: | printer/Printer |
printer.emit-structured
--json=: {
"path": path,
"path": output,
"recovery-urls": recovery-urls,
}
--stdout=:
Expand Down
8 changes: 3 additions & 5 deletions tests/cmd-fleet-recovery-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ run-test fleet/TestFleet:
"List the recovery servers"
["fleet", "recovery", "list"]

recovery-path := "$fleet.test-cli.tmp-dir/recovery.json"
fleet.test-cli.run-gold "050-export"
"Export the recovery information"
["fleet", "recovery", "export", "--directory", fleet.test-cli.tmp-dir]
--before-gold=: | output |
// In case we are on Windows, change the backslash in the path to a slash.
output.replace --all "\\recover-" "/recover-"
["fleet", "recovery", "export", "-o", recovery-path]

// Just make sure that the file is there and is a valid JSON file with
// some entries.
exported := json.decode (file.read-content "$fleet.test-cli.tmp-dir/recover-$(fleet.id).json")
exported := json.decode (file.read-content recovery-path)
expect (exported is Map)
expect (exported.size > 0)

Expand Down
4 changes: 2 additions & 2 deletions tests/gold/cmd-fleet-recovery-test/050-export.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Export the recovery information
# [fleet, recovery, export, --directory, TMP_DIR]
Exported recovery information to 'TMP_DIR/recover--={|~~~~~~~~~~FLEET_ID~~~~~~~~~~|}=-.json'.
# [fleet, recovery, export, -o, TMP_DIR/recovery.json]
Exported recovery information to 'TMP_DIR/recovery.json'.
Copy link
Member Author

Choose a reason for hiding this comment

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

The discrepancy between the output-file name (recovery.json) and the server URL (3 lines down) is OK. We have set the recovery URLs previously to just use recover.json.

Devices with the current recovery configuration will try to
download it from one of the following URLs:
- http://example.com:1234/recover.json
Expand Down
Loading