diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 6c72c970..119ad069 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -1265,6 +1265,24 @@ jobs: echo "" done + test_disk_exec_osd: + runs-on: ubuntu-latest + needs: build + container: ${{env.TEST_IMAGE}}:${{github.sha}} + steps: + - name: Run test + id: test + timeout-minutes: 3 + run: /root/vitastor/tests/test_disk_exec_osd.sh + - name: Print logs + if: always() && steps.test.outcome == 'failure' + run: | + for i in /root/vitastor/testdata/*.log /root/vitastor/testdata/*.txt; do + echo "-------- $i --------" + cat $i + echo "" + done + test_root_node: runs-on: ubuntu-latest needs: build diff --git a/src/disk_tool/disk_tool_udev.cpp b/src/disk_tool/disk_tool_udev.cpp index c9d3a13c..78bb3e06 100644 --- a/src/disk_tool/disk_tool_udev.cpp +++ b/src/disk_tool/disk_tool_udev.cpp @@ -313,16 +313,30 @@ int disk_tool_t::exec_osd(std::string device) return 1; } std::string osd_binary = "vitastor-osd"; - if (options["osd-binary"] != "") + if (options["osd_binary"] != "") { - osd_binary = options["osd-binary"]; + osd_binary = options["osd_binary"]; } + // Pass the nodes checked above, not the by-partuuid links: a link can move to another node meanwhile + std::string real_data = sb["real_data_device"].string_value(); + std::string real_meta = sb["real_meta_device"].string_value() != "" ? sb["real_meta_device"].string_value() : real_data; + std::map real_devices = { + { "data_device", real_data }, + { "meta_device", real_meta }, + { "journal_device", sb["real_journal_device"].string_value() != "" ? sb["real_journal_device"].string_value() : real_meta }, + }; std::vector argstr; argstr.push_back(osd_binary.c_str()); for (auto & kv: sb["params"].object_items()) { + std::string value = kv.second.is_string() ? kv.second.string_value() : kv.second.dump(); + auto real_it = real_devices.find(kv.first); + if (real_it != real_devices.end() && value != "") + { + value = real_it->second; + } argstr.push_back("--"+kv.first); - argstr.push_back(kv.second.is_string() ? kv.second.string_value() : kv.second.dump()); + argstr.push_back(value); } char *argv[argstr.size()+1]; for (int i = 0; i < argstr.size(); i++) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index c29ef29b..24bf22b8 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -102,6 +102,8 @@ OLD=1 SCHEME=ec IMMEDIATE_COMMIT=1 ./test_rebalance_verify.sh ./test_cli_help.sh +./test_disk_exec_osd.sh + ./test_root_node.sh ./test_switch_primary.sh diff --git a/tests/test_disk_exec_osd.sh b/tests/test_disk_exec_osd.sh new file mode 100755 index 00000000..3046ab8b --- /dev/null +++ b/tests/test_disk_exec_osd.sh @@ -0,0 +1,25 @@ +#!/bin/bash -ex + +# vitastor-disk exec-osd must start the binary given with --osd-binary + +. `dirname $0`/common.sh + +[[ -e build/src/disk_tool/vitastor-disk-test ]] || ln -s vitastor-disk build/src/disk_tool/vitastor-disk-test + +dd if=/dev/zero of=./testdata/bin/sb.bin bs=4096 count=8 +echo '{"osd_num":1,"data_device":"'`realpath ./testdata/bin/sb.bin`'"}' | \ + build/src/disk_tool/vitastor-disk-test write-sb --io cached ./testdata/bin/sb.bin + +ARGS=`build/src/disk_tool/vitastor-disk exec-osd --io cached --osd-binary echo ./testdata/bin/sb.bin` || \ + format_error "exec-osd did not run the --osd-binary" +[[ "$ARGS" == "--data_device "*" --osd_num 1" ]] || format_error "exec-osd passed unexpected arguments: $ARGS" + +# exec-osd must pass the device it checked, not the superblock's link: the link can move meanwhile +ln -s `realpath ./testdata/bin/sb.bin` ./testdata/bin/sb-link +echo '{"osd_num":1,"data_device":"'`realpath ./testdata/bin`/sb-link'"}' | \ + build/src/disk_tool/vitastor-disk-test write-sb --io cached ./testdata/bin/sb.bin +ARGS=`build/src/disk_tool/vitastor-disk exec-osd --io cached --osd-binary echo ./testdata/bin/sb.bin` +[[ "$ARGS" == "--data_device `realpath ./testdata/bin/sb.bin` --osd_num 1" ]] || \ + format_error "exec-osd passed the superblock's link instead of the checked device: $ARGS" + +format_green OK