Skip to content

Commit d8930a7

Browse files
robnlundman
authored andcommitted
tests: add tests for zpool import behaviour when hostid changes
Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Closes openzfs#15290
1 parent 4f184f2 commit d8930a7

8 files changed

+279
-0
lines changed

tests/runfiles/common.run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
415415
'zpool_import_rename_001_pos', 'zpool_import_all_001_pos',
416416
'zpool_import_encrypted', 'zpool_import_encrypted_load',
417417
'zpool_import_errata3', 'zpool_import_errata4',
418+
'zpool_import_hostid_changed',
419+
'zpool_import_hostid_changed_unclean_export',
420+
'zpool_import_hostid_changed_cachefile',
421+
'zpool_import_hostid_changed_cachefile_unclean_export',
418422
'import_cachefile_device_added',
419423
'import_cachefile_device_removed',
420424
'import_cachefile_device_replaced',

tests/zfs-tests/tests/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,10 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
11041104
functional/cli_root/zpool_import/zpool_import_features_001_pos.ksh \
11051105
functional/cli_root/zpool_import/zpool_import_features_002_neg.ksh \
11061106
functional/cli_root/zpool_import/zpool_import_features_003_pos.ksh \
1107+
functional/cli_root/zpool_import/zpool_import_hostid_changed.ksh \
1108+
functional/cli_root/zpool_import/zpool_import_hostid_changed_unclean_export.ksh \
1109+
functional/cli_root/zpool_import/zpool_import_hostid_changed_cachefile.ksh \
1110+
functional/cli_root/zpool_import/zpool_import_hostid_changed_cachefile_unclean_export.ksh \
11071111
functional/cli_root/zpool_import/zpool_import_missing_001_pos.ksh \
11081112
functional/cli_root/zpool_import/zpool_import_missing_002_pos.ksh \
11091113
functional/cli_root/zpool_import/zpool_import_missing_003_pos.ksh \

tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#
2828
# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
29+
# Copyright (c) 2023 by Klara, Inc.
2930
#
3031

3132
. $STF_SUITE/include/libtest.shlib
@@ -63,3 +64,7 @@ export VDEV4=$DEVICE_DIR/${DEVICE_FILE}4
6364
export VDEV5=$DEVICE_DIR/${DEVICE_FILE}5
6465

6566
export ALTER_ROOT=/alter_import-test
67+
68+
export HOSTID_FILE="/etc/hostid"
69+
export HOSTID1=01234567
70+
export HOSTID2=89abcdef

tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.kshlib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#
1313
# Copyright (c) 2016 by Delphix. All rights reserved.
14+
# Copyright (c) 2023 by Klara, Inc.
1415
#
1516

1617
. $STF_SUITE/include/libtest.shlib
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/ksh -p
2+
3+
#
4+
# This file and its contents are supplied under the terms of the
5+
# Common Development and Distribution License ("CDDL"), version 1.0.
6+
# You may only use this file in accordance with the terms of version
7+
# 1.0 of the CDDL.
8+
#
9+
# A full copy of the text of the CDDL should have accompanied this
10+
# source. A copy of the CDDL is also available via the Internet at
11+
# http://www.illumos.org/license/CDDL.
12+
#
13+
14+
#
15+
# Copyright (c) 2021 by Delphix. All rights reserved.
16+
# Copyright (c) 2023 by Klara, Inc.
17+
#
18+
19+
. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
20+
21+
#
22+
# DESCRIPTION:
23+
# A pool that was cleanly exported should be importable without force even if
24+
# the local hostid doesn't match the on-disk hostid.
25+
#
26+
# STRATEGY:
27+
# 1. Set a hostid.
28+
# 2. Create a pool.
29+
# 3. Export the pool.
30+
# 4. Change the hostid.
31+
# 5. Verify that importing the pool without force succeeds.
32+
#
33+
34+
verify_runnable "global"
35+
36+
function custom_cleanup
37+
{
38+
rm -f $HOSTID_FILE
39+
cleanup
40+
}
41+
42+
log_onexit custom_cleanup
43+
44+
# 1. Set a hostid.
45+
log_must zgenhostid -f $HOSTID1
46+
47+
# 2. Create a pool.
48+
log_must zpool create $TESTPOOL1 $VDEV0
49+
50+
# 3. Export the pool.
51+
log_must zpool export $TESTPOOL1
52+
53+
# 4. Change the hostid.
54+
log_must zgenhostid -f $HOSTID2
55+
56+
# 5. Verify that importing the pool without force succeeds.
57+
log_must zpool import -d $DEVICE_DIR $TESTPOOL1
58+
59+
log_pass "zpool import can import cleanly exported pool when hostid changes."
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/ksh -p
2+
3+
#
4+
# This file and its contents are supplied under the terms of the
5+
# Common Development and Distribution License ("CDDL"), version 1.0.
6+
# You may only use this file in accordance with the terms of version
7+
# 1.0 of the CDDL.
8+
#
9+
# A full copy of the text of the CDDL should have accompanied this
10+
# source. A copy of the CDDL is also available via the Internet at
11+
# http://www.illumos.org/license/CDDL.
12+
#
13+
14+
#
15+
# Copyright (c) 2021 by Delphix. All rights reserved.
16+
# Copyright (c) 2023 by Klara, Inc.
17+
#
18+
19+
. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
20+
21+
#
22+
# DESCRIPTION:
23+
# A pool that was cleanly exported should be importable from a cachefile
24+
# without force even if the local hostid doesn't match the on-disk hostid.
25+
#
26+
# STRATEGY:
27+
# 1. Set a hostid.
28+
# 2. Create a pool with a cachefile.
29+
# 3. Backup the cachfile.
30+
# 4. Export the pool.
31+
# 5. Change the hostid.
32+
# 6. Verify that importing the pool from the cachefile succeeds
33+
# without force.
34+
#
35+
36+
verify_runnable "global"
37+
38+
function custom_cleanup
39+
{
40+
rm -f $HOSTID_FILE $CPATH $CPATHBKP
41+
cleanup
42+
}
43+
44+
log_onexit custom_cleanup
45+
46+
# 1. Set a hostid.
47+
log_must zgenhostid -f $HOSTID1
48+
49+
# 2. Create a pool.
50+
log_must zpool create -o cachefile=$CPATH $TESTPOOL1 $VDEV0
51+
52+
# 3. Backup the cachfile.
53+
log_must cp $CPATH $CPATHBKP
54+
55+
# 4. Export the pool.
56+
log_must zpool export $TESTPOOL1
57+
58+
# 5. Change the hostid.
59+
log_must zgenhostid -f $HOSTID2
60+
61+
# 6. Verify that importing the pool from the cachefile succeeds without force.
62+
log_must zpool import -c $CPATHBKP $TESTPOOL1
63+
64+
log_pass "zpool import can import cleanly exported pool from cachefile " \
65+
"when hostid changes."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/ksh -p
2+
3+
#
4+
# This file and its contents are supplied under the terms of the
5+
# Common Development and Distribution License ("CDDL"), version 1.0.
6+
# You may only use this file in accordance with the terms of version
7+
# 1.0 of the CDDL.
8+
#
9+
# A full copy of the text of the CDDL should have accompanied this
10+
# source. A copy of the CDDL is also available via the Internet at
11+
# http://www.illumos.org/license/CDDL.
12+
#
13+
14+
#
15+
# Copyright (c) 2021 by Delphix. All rights reserved.
16+
# Copyright (c) 2023 by Klara, Inc.
17+
#
18+
19+
. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
20+
21+
#
22+
# DESCRIPTION:
23+
# A pool that wasn't cleanly exported should be importable from a cachefile
24+
# without force even if the local hostid doesn't match the on-disk hostid.
25+
#
26+
# STRATEGY:
27+
# 1. Set a hostid.
28+
# 2. Create a pool.
29+
# 3. Backup the cachefile.
30+
# 4. Simulate the pool being torn down without export:
31+
# 4.1. Copy the underlying device state.
32+
# 4.2. Export the pool.
33+
# 4.3. Restore the device state from the copy.
34+
# 5. Change the hostid.
35+
# 6. Verify that importing the pool from the cachefile succeeds
36+
# without force.
37+
#
38+
39+
verify_runnable "global"
40+
41+
function custom_cleanup
42+
{
43+
rm -f $HOSTID_FILE $CPATH $CPATHBKP $VDEV0.bak
44+
cleanup
45+
}
46+
47+
log_onexit custom_cleanup
48+
49+
# 1. Set a hostid.
50+
log_must zgenhostid -f $HOSTID1
51+
52+
# 2. Create a pool.
53+
log_must zpool create -o cachefile=$CPATH $TESTPOOL1 $VDEV0
54+
55+
# 3. Backup the cachfile.
56+
log_must cp $CPATH $CPATHBKP
57+
58+
# 4. Simulate the pool being torn down without export.
59+
log_must cp $VDEV0 $VDEV0.bak
60+
log_must zpool export $TESTPOOL1
61+
log_must cp -f $VDEV0.bak $VDEV0
62+
log_must rm -f $VDEV0.bak
63+
64+
# 5. Change the hostid.
65+
log_must zgenhostid -f $HOSTID2
66+
67+
# 6. Verify that importing the pool from the cachefile succeeds without force.
68+
log_must zpool import -c $CPATHBKP $TESTPOOL1
69+
70+
log_pass "zpool import can import pool from cachefile if not cleanly " \
71+
"exported when hostid changes."
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/ksh -p
2+
3+
#
4+
# This file and its contents are supplied under the terms of the
5+
# Common Development and Distribution License ("CDDL"), version 1.0.
6+
# You may only use this file in accordance with the terms of version
7+
# 1.0 of the CDDL.
8+
#
9+
# A full copy of the text of the CDDL should have accompanied this
10+
# source. A copy of the CDDL is also available via the Internet at
11+
# http://www.illumos.org/license/CDDL.
12+
#
13+
14+
#
15+
# Copyright (c) 2021 by Delphix. All rights reserved.
16+
# Copyright (c) 2023 by Klara, Inc.
17+
#
18+
19+
. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
20+
21+
#
22+
# DESCRIPTION:
23+
# A pool that wasn't cleanly exported should not be importable without force if
24+
# the local hostid doesn't match the on-disk hostid.
25+
#
26+
# STRATEGY:
27+
# 1. Set a hostid.
28+
# 2. Create a pool.
29+
# 3. Simulate the pool being torn down without export:
30+
# 3.1. Copy the underlying device state.
31+
# 3.2. Export the pool.
32+
# 3.3. Restore the device state from the copy.
33+
# 4. Change the hostid.
34+
# 5. Verify that importing the pool fails.
35+
# 6. Verify that importing the pool with force succeeds.
36+
#
37+
38+
verify_runnable "global"
39+
40+
function custom_cleanup
41+
{
42+
rm -f $HOSTID_FILE $VDEV0.bak
43+
cleanup
44+
}
45+
46+
log_onexit custom_cleanup
47+
48+
# 1. Set a hostid.
49+
log_must zgenhostid -f $HOSTID1
50+
51+
# 2. Create a pool.
52+
log_must zpool create $TESTPOOL1 $VDEV0
53+
54+
# 3. Simulate the pool being torn down without export.
55+
log_must cp $VDEV0 $VDEV0.bak
56+
log_must zpool export $TESTPOOL1
57+
log_must cp -f $VDEV0.bak $VDEV0
58+
log_must rm -f $VDEV0.bak
59+
60+
# 4. Change the hostid.
61+
log_must zgenhostid -f $HOSTID2
62+
63+
# 5. Verify that importing the pool fails.
64+
log_mustnot zpool import -d $DEVICE_DIR $TESTPOOL1
65+
66+
# 6. Verify that importing the pool with force succeeds.
67+
log_must zpool import -d $DEVICE_DIR -f $TESTPOOL1
68+
69+
log_pass "zpool import requires force if not cleanly exported " \
70+
"and hostid changed."

0 commit comments

Comments
 (0)