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