From 430f34efc692b7c1a6a6a48376f76ec2b01cf6e9 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 28 Jun 2024 10:06:43 +0200 Subject: [PATCH 1/3] Use '-o' for recovery export. --- src/cli/cmds/fleet.toit | 20 ++++++++++---------- tests/cmd-fleet-recovery-test.toit | 8 +++----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/cli/cmds/fleet.toit b/src/cli/cmds/fleet.toit index c3c6735a..df26c9d6 100644 --- a/src/cli/cmds/fleet.toit +++ b/src/cli/cmds/fleet.toit @@ -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 @@ -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" @@ -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=: diff --git a/tests/cmd-fleet-recovery-test.toit b/tests/cmd-fleet-recovery-test.toit index af6cd5ca..271241ff 100644 --- a/tests/cmd-fleet-recovery-test.toit +++ b/tests/cmd-fleet-recovery-test.toit @@ -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) From c748a305caa05bbc4d5e63ee212ee5562158ccc4 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 28 Jun 2024 10:07:12 +0200 Subject: [PATCH 2/3] Update gold. --- tests/gold/cmd-fleet-recovery-test/050-export.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/gold/cmd-fleet-recovery-test/050-export.txt b/tests/gold/cmd-fleet-recovery-test/050-export.txt index ddbd2a74..722ad426 100644 --- a/tests/gold/cmd-fleet-recovery-test/050-export.txt +++ b/tests/gold/cmd-fleet-recovery-test/050-export.txt @@ -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 From 09704b58ede4bd539b1079d8cbc5352b3517b1d7 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 28 Jun 2024 10:16:48 +0200 Subject: [PATCH 3/3] Fix host test. --- tests/host-recovery-test-slow.toit | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/host-recovery-test-slow.toit b/tests/host-recovery-test-slow.toit index d61a1c75..fda4208c 100644 --- a/tests/host-recovery-test-slow.toit +++ b/tests/host-recovery-test-slow.toit @@ -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.