vitastor-disk: Exit with 1 if prepare fails to initialize an OSD, list skipped disks #137
Reference in New Issue
Block a user
No description provided.
Delete Branch "koolkhel/vitastor:prepare-exit-code"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
vitastor-disk preparewith a device list always exited with 0, also when an OSD failed to initialize. The failure was only visible in stderr, so a script that looks at the exit code took it for success. For example,vitastor-disk prepare --block_size 4M --data_csum_type crc32c --csum_block_size 4k /dev/sdXprints "Metadata entry size (4396 bytes) exceeds meta_block_size (4096 bytes) ..." and exits with 0.Commits:
--data_device) already returned the code ofprepare_one().skippedkey of the JSON output:{"osds": [...], "errors": [...], "skipped": [{"device_path": "/dev/sdb", "reason": "already_partitioned"}]}. Reasons:not_dev_path,not_found,partition,contains_data,already_partitioned. This commit also made prepare exit with 1 when it created no OSD; commit 5 takes that back.--dry-run --jsonand no suitable disk, print{"devices": []}instead of the JSON of a real run.skipped. "No suitable devices found" still exits with 1, as on master.collect_devices()now resolves symlinks, so a skipped disk was listed by its real device name. It is listed by the path the caller gave, like/dev/disk/by-id/*, so the caller can match it to its arguments. The dry-rundeviceslist keeps the resolved path, as master's test expects.Not covered here: a failed partition creation in
get_new_data_parts()still does not change the exit code.Tested:
test_resize_auto.shandOLD=1 test_resize_auto.shpass on loop devices. The checks: a prepare refused by the parameter check exits with non-zero; a prepare on a fully used disk, given through a symlink, exits with 0 and lists the symlink inskipped; a prepare of that disk and a fresh one creates one OSD and lists the other.Rebased onto master after #134. Merges cleanly with #139.
Contributor Name
Yury Luneff (MIND Software LLC, https://mindsw.io)
CLA
vitastor-disk: Exit with 1 if prepare fails to initialize an OSDto vitastor-disk: Exit with 1 if prepare fails to initialize an OSD or creates noneWith --dry-run --json and no suitable disk, prepare printed the JSON of a real run instead of {"devices": []}. Also test the JSON output and the exit code when no disk is suitable.@@ -832,2 +854,3 @@printf("%s\n", json11::Json(json11::Json::object{ { "osds", all_results }, { "errors", errors }, { "skipped", skipped_devices } }).dump().c_str());}return 0;return prepare_failed || !created ? 1 : 0;Тут нужно не возвращать ошибку, если !created
vitastor-disk: Exit with 1 if prepare fails to initialize an OSD or creates noneto vitastor-disk: Exit with 1 if prepare fails to initialize an OSD, list skipped disksСделал в
fd21c3fc, как вы и писали в Telegram (идемпотентно: если всё уже создано, создавать нечего, и это не ошибка): если не создан ни один OSD, потому что все диски пропущены, prepare завершается с 0, а пропущенные диски видны вskippedв JSON. Код 1 остался для OSD, который не удалось инициализировать, и для "No suitable devices found", как в master.@@ -347,1 +347,4 @@{auto skip = [this](const std::string & dev, const char *reason){skipped_devices.push_back(json11::Json::object{ { "device_path", dev }, { "reason", reason } });можно этот враппер убрать плиз, строчки кода он как-то не экономит)
fd21c3fcb0to03a51506c8Убрал в
da3b509a: обёрткиskip()больше нет, записи вskippedдобавляются на месте. Заодно ветка перебазирована на master после #134, и пропущенные диски теперь пишутся вskippedпо пути в том виде, в каком его передали (03a51506), а не по разрешённому/dev/sdX.Added
e648aa91: the--fast-devicesoverlap test from #135 now gives the fast device as a symlink to the data disk and fails on a zero exit (before,prepare … 2>&1 | grepdropped the exit code, so it passed without thereturn 1).