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