-
Notifications
You must be signed in to change notification settings - Fork 15
Add exportname option to CLI and interop tests #134
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,18 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Run this script to benchmark the NBD server using nbd-client and hdparm. | ||
| # Run this script to benchmark the NBD server using qemu-img. | ||
|
|
||
| set -eux | ||
|
|
||
| dd if=/dev/zero of=/tmp/test bs=1M count=100 | ||
| _build/default/cli/main.exe serve --no-tls /tmp/test & | ||
| _build/default/cli/main.exe serve --exportname test --no-tls /tmp/test & | ||
| SERVER_PROCESS=$! | ||
| echo $SERVER_PROCESS | ||
| # Wait for the server to start the main loop | ||
| sleep 0.1 | ||
|
|
||
| function stop_server { | ||
| kill $(jobs -p) | ||
| stop_server() { | ||
| kill -9 $SERVER_PROCESS | ||
| } | ||
| trap stop_server EXIT | ||
|
|
||
|
|
||
| sudo modprobe nbd | ||
|
|
||
| sudo nbd-client -N test localhost /dev/nbd0 | ||
|
|
||
| function stop_client { | ||
| sudo nbd-client -d /dev/nbd0 | ||
| stop_server | ||
| } | ||
| trap stop_client EXIT | ||
|
|
||
| sudo hdparm -t /dev/nbd0 | ||
| sudo hdparm -t /dev/nbd0 | ||
| sudo hdparm -t /dev/nbd0 | ||
| sudo hdparm -t /dev/nbd0 | ||
| sudo hdparm -t /dev/nbd0 | ||
| qemu-img bench 'nbd:0.0.0.0:10809:exportname=test' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| (executable | ||
| (name suite) | ||
| (libraries | ||
| alcotest | ||
| alcotest-lwt | ||
| cmdliner | ||
| ) | ||
| ) | ||
|
|
||
| (alias | ||
| (name runtest) | ||
| (package nbd-tool) | ||
| (deps | ||
| (:suite suite.exe) | ||
| (:cli ../cli/main.exe) | ||
| ./test-qemu.sh | ||
| ./test-nbd-client.sh | ||
| ) | ||
| (action (run %{suite} --cli %{cli})) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
|
|
||
| let with_command ~command ~strict test = | ||
| match Sys.command ("command -v " ^ command) with | ||
| | 0 -> test () | ||
| | _ -> | ||
| if strict then failwith ("Command " ^ command ^ " not present") | ||
| else Printf.printf "!!! Skipping test because command %s is not available" command | ||
|
|
||
| let script name ~requires (cli, strict) = | ||
| with_command | ||
| ~command:requires | ||
| ~strict | ||
| (fun () -> | ||
| Alcotest.(check int) | ||
| name | ||
| 0 | ||
| (Sys.command (name ^ " " ^ cli)) | ||
| ) | ||
|
|
||
| let cli = | ||
| let doc = "Path to nbd CLI should be first command-line argument" in | ||
| Cmdliner.Arg.(required & opt ~vopt:None (some string) None & info ["cli"] ~docv:"CLI" ~doc) | ||
|
|
||
| let strict = | ||
| let doc = {|If present, the test will fail when the required program is not | ||
| installed. Otherwise the test will simply be skipped.|} | ||
| in | ||
| Cmdliner.Arg.(value & flag & info ["strict"] ~env:(env_var "STRICT") ~doc) | ||
|
|
||
| let opts = Cmdliner.Term.(const (fun cli strict -> (cli, strict)) $ cli $ strict) | ||
|
|
||
| let () = | ||
| Alcotest.run_with_args | ||
| "Nbd CLI interoperability tests" | ||
| opts | ||
| [ ("compatibility with qemu-img", | ||
| ["data copying", `Slow, script "./test-qemu.sh" ~requires:"qemu-img"] | ||
| ) | ||
| ; ("compatibility with nbd-client", | ||
| ["listing exports", `Slow, script "./test-nbd-client.sh" ~requires:"nbd-client"] | ||
| ) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -eux | ||
|
|
||
| CLI=$1 | ||
|
|
||
| SCRATCH=$(mktemp -d) | ||
| EXPORT=$SCRATCH/test | ||
|
|
||
| # Create a test file | ||
| dd if=/dev/urandom of="$EXPORT" bs=1M count=40 | ||
|
|
||
| # Serve it | ||
| $CLI serve --exportname test --no-tls "$EXPORT" & | ||
| SERVER=$! | ||
| # Wait for the server to start the main loop | ||
| sleep 0.1 | ||
|
|
||
| stop_server() { | ||
| kill -9 $SERVER | ||
| } | ||
| trap stop_server EXIT | ||
|
|
||
| # Try listing the exports | ||
| # This will fail if the server does not implement NBD_OPT_LIST correctly | ||
| nbd-client -l 0.0.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -eux | ||
|
|
||
| CLI=$1 | ||
|
|
||
| SCRATCH=$(mktemp -d) | ||
| EXPORT=$SCRATCH/test | ||
| OUTPUT=$SCRATCH/out | ||
|
|
||
| # Create a test file | ||
| dd if=/dev/urandom of="$EXPORT" bs=1M count=40 | ||
|
|
||
| # Serve it | ||
| $CLI serve --exportname test --no-tls "$EXPORT" & | ||
| SERVER=$! | ||
| # Wait for the server to start the main loop | ||
| sleep 0.1 | ||
|
|
||
| stop_server() { | ||
| kill -9 $SERVER | ||
| } | ||
| trap stop_server EXIT | ||
|
|
||
| # Download it as raw from the server | ||
| qemu-img convert 'nbd:0.0.0.0:10809:exportname=test' -O raw "$OUTPUT" | ||
|
|
||
| # Check that the two files are the same | ||
| cmp --silent "$EXPORT" "$OUTPUT" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Isn't there some way the server could notify that it has started?
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 think there might be, maybe we could wait until something is listening on the 10809 port, but I wanted to keep things simple in the tests.