Skip to content

Commit

Permalink
Use '-o' for recovery export. (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Jun 28, 2024
1 parent 39bd257 commit 5b23fbd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
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'.
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
5 changes: 3 additions & 2 deletions tests/host-recovery-test-slow.toit
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ main args:
fleet.run ["fleet", "roll-out"]

// Create recovery information for it.
fleet.run ["fleet", "recovery", "export", "--directory", fleet.test-cli.tmp-dir]
recovery-info := file.read-content "$fleet.test-cli.tmp-dir/recover-$(fleet.id).json"
recovery-path := "$fleet.test-cli.tmp-dir/recover-$(fleet.id).json"
fleet.run ["fleet", "recovery", "export", "-o", recovery-path]
recovery-info := file.read-content recovery-path
recovery-server.recovery-info = recovery-info

test-device.wait-for-synchronized // Still on the old broker.
Expand Down

0 comments on commit 5b23fbd

Please sign in to comment.