1# 2# Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6 7ZPOOL_NAME_FILE=zpool_name 8get_zpool_name() 9{ 10 cat $ZPOOL_NAME_FILE 11} 12make_zpool_name() 13{ 14 mktemp -u bectl_test_XXXXXX > $ZPOOL_NAME_FILE 15 get_zpool_name 16} 17 18# Establishes a bectl_create zpool that can be used for some light testing; contains 19# a 'default' BE and not much else. 20bectl_create_setup() 21{ 22 zpool=$1 23 disk=$2 24 mnt=$3 25 26 # Sanity check to make sure `make_zpool_name` succeeded 27 atf_check test -n "$zpool" 28 29 kldload -n -q zfs || atf_skip "ZFS module not loaded on the current system" 30 if ! getconf MIN_HOLE_SIZE "$(pwd)"; then 31 echo "getconf MIN_HOLE_SIZE $(pwd) failed; sparse files " \ 32 "probably not supported by file system" 33 mount 34 atf_skip "Test's work directory does not support sparse files;" \ 35 "try with a different TMPDIR?" 36 fi 37 atf_check mkdir -p ${mnt} 38 atf_check truncate -s 1G ${disk} 39 atf_check zpool create -R ${mnt} ${zpool} ${disk} 40 atf_check zfs create -o mountpoint=none ${zpool}/ROOT 41 atf_check zfs create -o mountpoint=/ -o canmount=noauto \ 42 ${zpool}/ROOT/default 43} 44bectl_create_deep_setup() 45{ 46 zpool=$1 47 disk=$2 48 mnt=$3 49 50 # Sanity check to make sure `make_zpool_name` succeeded 51 atf_check test -n "$zpool" 52 53 bectl_create_setup ${zpool} ${disk} ${mnt} 54 atf_check mkdir -p ${root} 55 atf_check -o ignore bectl -r ${zpool}/ROOT mount default ${root} 56 atf_check mkdir -p ${root}/usr 57 atf_check zfs create -o mountpoint=/usr -o canmount=noauto \ 58 ${zpool}/ROOT/default/usr 59 atf_check -o ignore bectl -r ${zpool}/ROOT umount default 60} 61 62bectl_cleanup() 63{ 64 zpool=$1 65 if [ -z "$zpool" ]; then 66 echo "Skipping cleanup; zpool not set up" 67 elif zpool get health ${zpool} >/dev/null 2>&1; then 68 zpool destroy -f ${zpool} 69 fi 70} 71 72atf_test_case bectl_create cleanup 73bectl_create_head() 74{ 75 atf_set "descr" "Check the various forms of bectl create" 76 atf_set "require.user" root 77 atf_set "require.progs" bectl 78} 79bectl_create_body() 80{ 81 if [ "$(atf_config_get ci false)" = "true" ] && \ 82 [ "$(uname -p)" = "i386" ]; then 83 atf_skip "https://bugs.freebsd.org/249055" 84 fi 85 86 if [ "$(atf_config_get ci false)" = "true" ] && \ 87 [ "$(uname -p)" = "armv7" ]; then 88 atf_skip "https://bugs.freebsd.org/249229" 89 fi 90 91 cwd=$(realpath .) 92 zpool=$(make_zpool_name) 93 disk=${cwd}/disk.img 94 mount=${cwd}/mnt 95 96 bectl_create_setup ${zpool} ${disk} ${mount} 97 98 # Create a child dataset that will be used to test creation 99 # of recursive and non-recursive boot environments. 100 atf_check zfs create -o mountpoint=/usr -o canmount=noauto \ 101 ${zpool}/ROOT/default/usr 102 103 # BE datasets with spaces are not bootable, PR 254441. 104 atf_check -e not-empty -s not-exit:0 \ 105 bectl -r ${zpool}/ROOT create "foo bar" 106 107 # Test standard creation, creation of a snapshot, and creation from a 108 # snapshot. 109 atf_check bectl -r ${zpool}/ROOT create -e default default2 110 atf_check bectl -r ${zpool}/ROOT create default2@test_snap 111 atf_check bectl -r ${zpool}/ROOT create -e default2@test_snap default3 112 113 # Test standard creation, creation of a snapshot, and creation from a 114 # snapshot for recursive boot environments. 115 atf_check bectl -r ${zpool}/ROOT create -r -e default recursive 116 atf_check bectl -r ${zpool}/ROOT create -r recursive@test_snap 117 atf_check bectl -r ${zpool}/ROOT create -r -e recursive@test_snap recursive-snap 118 119 # Test that non-recursive boot environments have no child datasets. 120 atf_check -e not-empty -s not-exit:0 \ 121 zfs list "${zpool}/ROOT/default2/usr" 122 atf_check -e not-empty -s not-exit:0 \ 123 zfs list "${zpool}/ROOT/default3/usr" 124 125 # Test that recursive boot environments have child datasets. 126 atf_check -o not-empty \ 127 zfs list "${zpool}/ROOT/recursive/usr" 128 atf_check -o not-empty \ 129 zfs list "${zpool}/ROOT/recursive-snap/usr" 130 131 # Test creation of an empty BE. 132 atf_check bectl -r ${zpool}/ROOT create -E empty 133 atf_check -o inline:"-\n" zfs get -H -o value origin ${zpool}/ROOT/empty 134 atf_check -e match:"cannot be combined" -s not-exit:0 \ 135 bectl -r ${zpool}/ROOT create -E -e not-allowed empty-existing 136 atf_check -e match:"cannot be combined" -s not-exit:0 \ 137 bectl -r ${zpool}/ROOT create -E -r empty-recursive 138} 139bectl_create_cleanup() 140{ 141 bectl_cleanup $(get_zpool_name) 142} 143 144atf_test_case bectl_destroy cleanup 145bectl_destroy_head() 146{ 147 atf_set "descr" "Check bectl destroy" 148 atf_set "require.user" root 149 atf_set "require.progs" bectl 150} 151bectl_destroy_body() 152{ 153 if [ "$(atf_config_get ci false)" = "true" ] && \ 154 [ "$(uname -p)" = "i386" ]; then 155 atf_skip "https://bugs.freebsd.org/249055" 156 fi 157 158 if [ "$(atf_config_get ci false)" = "true" ] && \ 159 [ "$(uname -p)" = "armv7" ]; then 160 atf_skip "https://bugs.freebsd.org/249229" 161 fi 162 163 cwd=$(realpath .) 164 zpool=$(make_zpool_name) 165 disk=${cwd}/disk.img 166 mount=${cwd}/mnt 167 root=${mount}/root 168 169 bectl_create_setup ${zpool} ${disk} ${mount} 170 atf_check bectl -r ${zpool}/ROOT create -e default default2 171 atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 172 atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 173 atf_check -e not-empty -s not-exit:0 zfs get mountpoint ${zpool}/ROOT/default2 174 175 # Test origin snapshot deletion when the snapshot to be destroyed 176 # belongs to a mounted dataset, see PR 236043. 177 atf_check mkdir -p ${root} 178 atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} 179 atf_check bectl -r ${zpool}/ROOT create -e default default3 180 atf_check bectl -r ${zpool}/ROOT destroy -o default3 181 atf_check bectl -r ${zpool}/ROOT unmount default 182 183 # create two be from the same parent and destroy the parent 184 atf_check bectl -r ${zpool}/ROOT create -e default default2 185 atf_check bectl -r ${zpool}/ROOT create -e default default3 186 atf_check bectl -r ${zpool}/ROOT destroy default 187 atf_check bectl -r ${zpool}/ROOT destroy default2 188 atf_check bectl -r ${zpool}/ROOT rename default3 default 189 190 # Create a BE, have it be the parent for another and repeat, then start 191 # deleting environments. Arbitrarily chose default3 as the first. 192 # Sleeps are required to prevent conflicting snapshots- libbe will 193 # use the time with a serial at the end as needed to prevent collisions, 194 # but as BEs get promoted the snapshot names will convert and conflict 195 # anyways. libbe should perhaps consider adding something extra to the 196 # default name to prevent collisions like this, but the default name 197 # includes down to the second and creating BEs this rapidly is perhaps 198 # uncommon enough. 199 atf_check bectl -r ${zpool}/ROOT create -e default default2 200 sleep 1 201 atf_check bectl -r ${zpool}/ROOT create -e default2 default3 202 sleep 1 203 atf_check bectl -r ${zpool}/ROOT create -e default3 default4 204 atf_check bectl -r ${zpool}/ROOT destroy default3 205 atf_check bectl -r ${zpool}/ROOT destroy default2 206 atf_check bectl -r ${zpool}/ROOT destroy default4 207 208 # Create two BEs, then create an unrelated snapshot on the originating 209 # BE and destroy it. We shouldn't have promoted the second BE, and it's 210 # only possible to tell if we promoted it by making sure we didn't 211 # demote the first BE at some point -- if we did, it's origin will no 212 # longer be empty. 213 atf_check bectl -r ${zpool}/ROOT create -e default default2 214 atf_check bectl -r ${zpool}/ROOT create default@test 215 216 atf_check bectl -r ${zpool}/ROOT destroy default@test 217 atf_check -o inline:"-\n" zfs get -Ho value origin ${zpool}/ROOT/default 218 atf_check bectl -r ${zpool}/ROOT destroy default2 219 220 # As observed by beadm, if we explicitly try to destroy a snapshot that 221 # leads to clones, we shouldn't have allowed it. 222 atf_check bectl -r ${zpool}/ROOT create default@test 223 atf_check bectl -r ${zpool}/ROOT create -e default@test default2 224 225 atf_check -e not-empty -s not-exit:0 bectl -r ${zpool}/ROOT destroy \ 226 default@test 227} 228bectl_destroy_cleanup() 229{ 230 bectl_cleanup $(get_zpool_name) 231} 232 233atf_test_case bectl_export_import cleanup 234bectl_export_import_head() 235{ 236 atf_set "descr" "Check bectl export and import" 237 atf_set "require.user" root 238 atf_set "require.progs" bectl 239} 240bectl_export_import_body() 241{ 242 if [ "$(atf_config_get ci false)" = "true" ] && \ 243 [ "$(uname -p)" = "i386" ]; then 244 atf_skip "https://bugs.freebsd.org/249055" 245 fi 246 247 if [ "$(atf_config_get ci false)" = "true" ] && \ 248 [ "$(uname -p)" = "armv7" ]; then 249 atf_skip "https://bugs.freebsd.org/249229" 250 fi 251 252 cwd=$(realpath .) 253 zpool=$(make_zpool_name) 254 disk=${cwd}/disk.img 255 mount=${cwd}/mnt 256 257 bectl_create_setup ${zpool} ${disk} ${mount} 258 atf_check -o save:exported bectl -r ${zpool}/ROOT export default 259 atf_check -x "bectl -r ${zpool}/ROOT import default2 < exported" 260 atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 261 atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 262 atf_check -e not-empty -s not-exit:0 zfs get mountpoint \ 263 ${zpool}/ROOT/default2 264} 265bectl_export_import_cleanup() 266{ 267 bectl_cleanup $(get_zpool_name) 268} 269 270atf_test_case bectl_list cleanup 271bectl_list_head() 272{ 273 atf_set "descr" "Check bectl list" 274 atf_set "require.user" root 275 atf_set "require.progs" bectl 276} 277bectl_list_body() 278{ 279 if [ "$(atf_config_get ci false)" = "true" ] && \ 280 [ "$(uname -p)" = "i386" ]; then 281 atf_skip "https://bugs.freebsd.org/249055" 282 fi 283 284 if [ "$(atf_config_get ci false)" = "true" ] && \ 285 [ "$(uname -p)" = "armv7" ]; then 286 atf_skip "https://bugs.freebsd.org/249229" 287 fi 288 289 cwd=$(realpath .) 290 zpool=$(make_zpool_name) 291 disk=${cwd}/disk.img 292 mount=${cwd}/mnt 293 294 bectl_create_setup ${zpool} ${disk} ${mount} 295 # Test the list functionality, including that BEs come and go away 296 # as they're created and destroyed. Creation and destruction tests 297 # use the 'zfs' utility to verify that they're actually created, so 298 # these are just light tests that 'list' is picking them up. 299 atf_check -o save:list.out bectl -r ${zpool}/ROOT list 300 atf_check -o not-empty grep 'default' list.out 301 atf_check bectl -r ${zpool}/ROOT create -e default default2 302 atf_check -o save:list.out bectl -r ${zpool}/ROOT list 303 atf_check -o not-empty grep 'default2' list.out 304 atf_check -e ignore bectl -r ${zpool}/ROOT destroy default2 305 atf_check -o save:list.out bectl -r ${zpool}/ROOT list 306 atf_check -s not-exit:0 grep 'default2' list.out 307 # XXX TODO: Formatting checks 308} 309bectl_list_cleanup() 310{ 311 bectl_cleanup $(get_zpool_name) 312} 313 314atf_test_case bectl_mount cleanup 315bectl_mount_head() 316{ 317 atf_set "descr" "Check bectl mount/unmount" 318 atf_set "require.user" root 319 atf_set "require.progs" bectl 320} 321bectl_mount_body() 322{ 323 if [ "$(atf_config_get ci false)" = "true" ] && \ 324 [ "$(uname -p)" = "i386" ]; then 325 atf_skip "https://bugs.freebsd.org/249055" 326 fi 327 328 if [ "$(atf_config_get ci false)" = "true" ] && \ 329 [ "$(uname -p)" = "armv7" ]; then 330 atf_skip "https://bugs.freebsd.org/249229" 331 fi 332 333 cwd=$(realpath .) 334 zpool=$(make_zpool_name) 335 disk=${cwd}/disk.img 336 mount=${cwd}/mnt 337 root=${mount}/root 338 339 bectl_create_deep_setup ${zpool} ${disk} ${mount} 340 atf_check mkdir -p ${root} 341 # Test unmount first... 342 atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} 343 atf_check -o not-empty -x "mount | grep '^${zpool}/ROOT/default'" 344 atf_check bectl -r ${zpool}/ROOT unmount default 345 atf_check -s not-exit:0 -x "mount | grep '^${zpool}/ROOT/default'" 346 # Then umount! 347 atf_check -o not-empty bectl -r ${zpool}/ROOT mount default ${root} 348 atf_check -o not-empty -x "mount | grep '^${zpool}/ROOT/default'" 349 atf_check bectl -r ${zpool}/ROOT umount default 350 atf_check -s not-exit:0 -x "mount | grep '^${zpool}/ROOT/default'" 351} 352bectl_mount_cleanup() 353{ 354 bectl_cleanup $(get_zpool_name) 355} 356 357atf_test_case bectl_rename cleanup 358bectl_rename_head() 359{ 360 atf_set "descr" "Check bectl rename" 361 atf_set "require.user" root 362 atf_set "require.progs" bectl 363} 364bectl_rename_body() 365{ 366 if [ "$(atf_config_get ci false)" = "true" ] && \ 367 [ "$(uname -p)" = "i386" ]; then 368 atf_skip "https://bugs.freebsd.org/249055" 369 fi 370 371 if [ "$(atf_config_get ci false)" = "true" ] && \ 372 [ "$(uname -p)" = "armv7" ]; then 373 atf_skip "https://bugs.freebsd.org/249229" 374 fi 375 376 cwd=$(realpath .) 377 zpool=$(make_zpool_name) 378 disk=${cwd}/disk.img 379 mount=${cwd}/mnt 380 381 bectl_create_setup ${zpool} ${disk} ${mount} 382 atf_check bectl -r ${zpool}/ROOT rename default default2 383 atf_check -o not-empty zfs get mountpoint ${zpool}/ROOT/default2 384 atf_check -e not-empty -s not-exit:0 zfs get mountpoint \ 385 ${zpool}/ROOT/default 386} 387bectl_rename_cleanup() 388{ 389 bectl_cleanup $(get_zpool_name) 390} 391 392atf_test_case bectl_jail cleanup 393bectl_jail_head() 394{ 395 atf_set "descr" "Check bectl rename" 396 atf_set "require.user" root 397 atf_set "require.progs" jail bectl 398} 399bectl_jail_body() 400{ 401 if [ "$(atf_config_get ci false)" = "true" ] && \ 402 [ "$(uname -p)" = "i386" ]; then 403 atf_skip "https://bugs.freebsd.org/249055" 404 fi 405 406 if [ "$(atf_config_get ci false)" = "true" ] && \ 407 [ "$(uname -p)" = "armv7" ]; then 408 atf_skip "https://bugs.freebsd.org/249229" 409 fi 410 411 cwd=$(realpath .) 412 zpool=$(make_zpool_name) 413 disk=${cwd}/disk.img 414 mount=${cwd}/mnt 415 root=${mount}/root 416 417 if [ ! -f /rescue/rescue ]; then 418 atf_skip "This test requires a rescue binary" 419 fi 420 bectl_create_deep_setup ${zpool} ${disk} ${mount} 421 # Prepare our minimal BE... plop a rescue binary into it 422 atf_check mkdir -p ${root} 423 atf_check -o ignore bectl -r ${zpool}/ROOT mount default ${root} 424 atf_check mkdir -p ${root}/rescue 425 atf_check cp /rescue/rescue ${root}/rescue/rescue 426 atf_check bectl -r ${zpool}/ROOT umount default 427 428 # Prepare some more boot environments 429 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT create -e default target 430 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT create -e default 1234 431 432 # Attempt to unjail a BE with numeric name; jail_getid at one point 433 # did not validate that the input was a valid jid before returning the 434 # jid. 435 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT jail -b 1234 436 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT unjail 1234 437 438 # When a jail name is not explicit, it should match the jail id. 439 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT jail -b -o jid=233637 default 440 atf_check -o inline:"233637\n" -s exit:0 -x "jls -j 233637 name" 441 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT unjail default 442 443 # Basic command-mode tests, with and without jail cleanup 444 atf_check -o inline:"rescue\nusr\n" bectl -r ${zpool}/ROOT \ 445 jail default /rescue/rescue ls -1 446 atf_check -o inline:"rescue\nusr\n" bectl -r ${zpool}/ROOT \ 447 jail -Uo path=${root} default /rescue/rescue ls -1 448 atf_check [ -f ${root}/rescue/rescue ] 449 atf_check bectl -r ${zpool}/ROOT ujail default 450 451 # Batch mode tests 452 atf_check bectl -r ${zpool}/ROOT jail -bo path=${root} default 453 atf_check -o not-empty -x "jls | grep -F \"${root}\"" 454 atf_check bectl -r ${zpool}/ROOT ujail default 455 atf_check -s not-exit:0 -x "jls | grep -F \"${root}\"" 456 # 'unjail' naming 457 atf_check bectl -r ${zpool}/ROOT jail -b default 458 atf_check bectl -r ${zpool}/ROOT unjail default 459 atf_check -s not-exit:0 -x "jls | grep -F \"${root}\"" 460 # 'unjail' by BE name. Force bectl to lookup jail id by the BE name. 461 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT jail -b default 462 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT jail -b -o name=bectl_test target 463 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT unjail target 464 atf_check -o empty -s exit:0 bectl -r ${zpool}/ROOT unjail default 465 # cannot unjail an unjailed BE (by either command name) 466 atf_check -e ignore -s not-exit:0 bectl -r ${zpool}/ROOT ujail default 467 atf_check -e ignore -s not-exit:0 bectl -r ${zpool}/ROOT unjail default 468 469 # set+unset 470 atf_check bectl -r ${zpool}/ROOT jail -b -o path=${root} -u path default 471 # Ensure that it didn't mount at ${root} 472 atf_check -s not-exit:0 -x "mount | grep -F '${root}'" 473 atf_check bectl -r ${zpool}/ROOT ujail default 474} 475 476# If a test has failed, it's possible that the boot environment hasn't 477# been 'unjail'ed. We want to remove the jail before 'bectl_cleanup' 478# attempts to destroy the zpool. 479bectl_jail_cleanup() 480{ 481 if [ "$(atf_config_get ci false)" = "true" ] && \ 482 [ "$(uname -p)" = "i386" ]; then 483 atf_skip "https://bugs.freebsd.org/249055" 484 fi 485 486 if [ "$(atf_config_get ci false)" = "true" ] && \ 487 [ "$(uname -p)" = "armv7" ]; then 488 atf_skip "https://bugs.freebsd.org/249229" 489 fi 490 491 zpool=$(get_zpool_name) 492 for bootenv in "default" "target" "1234"; do 493 # mountpoint of the boot environment 494 mountpoint="$(bectl -r ${zpool}/ROOT list -H | grep ${bootenv} | awk '{print $3}')" 495 496 # see if any jail paths match the boot environment mountpoint 497 jailid="$(jls | grep ${mountpoint} | awk '{print $1}')" 498 499 if [ -z "$jailid" ]; then 500 continue; 501 fi 502 jail -r ${jailid} 503 done; 504 505 bectl_cleanup ${zpool} 506} 507 508atf_test_case bectl_promotion cleanup 509bectl_promotion_head() 510{ 511 atf_set "descr" "Check bectl promotion upon activation" 512 atf_set "require.user" root 513 atf_set "require.progs" bectl 514} 515bectl_promotion_body() 516{ 517 if [ "$(atf_config_get ci false)" = "true" ] && \ 518 [ "$(uname -p)" = "i386" ]; then 519 atf_skip "https://bugs.freebsd.org/249055" 520 fi 521 522 if [ "$(atf_config_get ci false)" = "true" ] && \ 523 [ "$(uname -p)" = "armv7" ]; then 524 atf_skip "https://bugs.freebsd.org/249229" 525 fi 526 527 cwd=$(realpath .) 528 zpool=$(make_zpool_name) 529 disk=${cwd}/disk.img 530 mount=${cwd}/mnt 531 root=${mount}/root 532 533 bectl_create_deep_setup ${zpool} ${disk} ${mount} 534 atf_check mkdir -p ${root} 535 536 # Sleeps interspersed to workaround some naming quirks; notably, 537 # bectl will append a serial if two snapshots were created within 538 # the same second, but it can only do that for the one root it's 539 # operating on. It won't check that other roots don't have a snapshot 540 # with the same name, and the promotion will fail. 541 atf_check bectl -r ${zpool}/ROOT rename default A 542 sleep 1 543 atf_check bectl -r ${zpool}/ROOT create -r -e A B 544 sleep 1 545 atf_check bectl -r ${zpool}/ROOT create -r -e B C 546 547 # C should be a clone of B to start with 548 atf_check -o not-inline:"-" zfs list -Hr -o origin ${zpool}/ROOT/C 549 550 # Activating it should then promote it all the way out of clone-hood. 551 # This entails two promotes internally, as the first would promote it to 552 # a snapshot of A before finally promoting it the second time out of 553 # clone status. 554 atf_check -o not-empty bectl -r ${zpool}/ROOT activate C 555 atf_check -o inline:"-\n-\n" zfs list -Hr -o origin ${zpool}/ROOT/C 556} 557bectl_promotion_cleanup() 558{ 559 bectl_cleanup $(get_zpool_name) 560} 561 562atf_test_case bectl_destroy_bootonce cleanup 563bectl_destroy_bootonce_head() 564{ 565 atf_set "descr" "Check bectl destroy (bootonce)" 566 atf_set "require.user" root 567 atf_set "require.progs" bectl 568} 569bectl_destroy_bootonce_body() 570{ 571 if [ "$(atf_config_get ci false)" = "true" ] && \ 572 [ "$(uname -p)" = "i386" ]; then 573 atf_skip "https://bugs.freebsd.org/249055" 574 fi 575 576 if [ "$(atf_config_get ci false)" = "true" ] && \ 577 [ "$(uname -p)" = "armv7" ]; then 578 atf_skip "https://bugs.freebsd.org/249229" 579 fi 580 581 cwd=$(realpath .) 582 zpool=$(make_zpool_name) 583 disk=${cwd}/disk.img 584 mount=${cwd}/mnt 585 root=${mount}/root 586 587 be=default2 588 589 bectl_create_setup ${zpool} ${disk} ${mount} 590 atf_check -s exit:0 -o empty bectl -r ${zpool}/ROOT create -e default ${be} 591 592 # Create boot environment and bootonce activate it 593 atf_check -s exit:0 -o ignore bectl -r ${zpool}/ROOT activate -t ${be} 594 atf_check -s exit:0 -o inline:"zfs:${zpool}/ROOT/${be}:\n" zfsbootcfg -z ${zpool} 595 596 # Destroy it 597 atf_check -s exit:0 -o ignore bectl -r ${zpool}/ROOT destroy ${be} 598 599 # Should be empty 600 atf_check -s exit:0 -o empty zfsbootcfg -z ${zpool} 601} 602bectl_destroy_bootonce_cleanup() 603{ 604 bectl_cleanup $(get_zpool_name) 605} 606 607atf_test_case bectl_rename_bootonce cleanup 608bectl_rename_bootonce_head() 609{ 610 atf_set "descr" "Check bectl destroy (bootonce)" 611 atf_set "require.user" root 612 atf_set "require.progs" bectl 613} 614bectl_rename_bootonce_body() 615{ 616 if [ "$(atf_config_get ci false)" = "true" ] && \ 617 [ "$(uname -p)" = "i386" ]; then 618 atf_skip "https://bugs.freebsd.org/249055" 619 fi 620 621 if [ "$(atf_config_get ci false)" = "true" ] && \ 622 [ "$(uname -p)" = "armv7" ]; then 623 atf_skip "https://bugs.freebsd.org/249229" 624 fi 625 626 cwd=$(realpath .) 627 zpool=$(make_zpool_name) 628 disk=${cwd}/disk.img 629 mount=${cwd}/mnt 630 root=${mount}/root 631 632 be=default2 633 634 bectl_create_setup ${zpool} ${disk} ${mount} 635 atf_check -s exit:0 -o empty bectl -r ${zpool}/ROOT create -e default ${be} 636 637 # Create boot environment and bootonce activate it 638 atf_check -s exit:0 -o ignore bectl -r ${zpool}/ROOT activate -t ${be} 639 atf_check -s exit:0 -o inline:"zfs:${zpool}/ROOT/${be}:\n" zfsbootcfg -z ${zpool} 640 641 # Rename it 642 atf_check -s exit:0 -o ignore bectl -r ${zpool}/ROOT rename ${be} ${be}_renamed 643 644 # Should be renamed 645 atf_check -s exit:0 -o inline:"zfs:${zpool}/ROOT/${be}_renamed:\n" zfsbootcfg -z ${zpool} 646} 647bectl_rename_bootonce_cleanup() 648{ 649 bectl_cleanup $(get_zpool_name) 650} 651 652atf_init_test_cases() 653{ 654 atf_add_test_case bectl_create 655 atf_add_test_case bectl_destroy 656 atf_add_test_case bectl_export_import 657 atf_add_test_case bectl_list 658 atf_add_test_case bectl_mount 659 atf_add_test_case bectl_rename 660 atf_add_test_case bectl_jail 661 atf_add_test_case bectl_promotion 662 atf_add_test_case bectl_destroy_bootonce 663 atf_add_test_case bectl_rename_bootonce 664} 665