1#!/usr/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) 2017 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/pool_checkpoint/pool_checkpoint.kshlib
19
20#
21# DESCRIPTION:
22#	Try each 'zpool checkpoint' and relevant 'zpool import' with
23#	invalid inputs to ensure it returns an error. That includes:
24#		* A non-existent pool name or no pool name at all is supplied
25#		* Pool supplied for discarding or rewinding but the pool
26#		  does not have a checkpoint
27#		* A dataset or a file/directory are supplied instead of a pool
28#
29# STRATEGY:
30#	1. Create an array of parameters for the different scenarios
31#	2. For each parameter, execute the scenarios sub-command
32#	3. Verify that an error was returned
33#
34
35verify_runnable "global"
36
37setup_test_pool
38log_onexit cleanup_test_pool
39populate_test_pool
40
41#
42# Argument groups below. Note that all_args also includes
43# an empty string as "run command with no argument".
44#
45set -A all_args "" "-d" "--discard"
46
47#
48# Target groups below. Note that invalid_targets includes
49# an empty string as "do not supply a pool name".
50#
51set -A invalid_targets "" "iDontExist" "$FS0" "$FS0FILE"
52non_checkpointed="$TESTPOOL"
53
54#
55# Scenario 1
56# Trying all checkpoint args with all invalid targets
57#
58typeset -i i=0
59while (( i < ${#invalid_targets[*]} )); do
60	typeset -i j=0
61	while (( j < ${#all_args[*]} )); do
62		log_mustnot zpool checkpoint ${all_args[j]} \
63			${invalid_targets[i]}
64		((j = j + 1))
65	done
66	((i = i + 1))
67done
68
69#
70# Scenario 2
71# If the pool does not have a checkpoint, -d nor import rewind
72# should work with it.
73#
74log_mustnot zpool checkpoint -d $non_checkpointed
75log_must zpool export $non_checkpointed
76log_mustnot zpool import --rewind-to-checkpoint $non_checkpointed
77log_must zpool import $non_checkpointed
78
79log_pass "Badly formed checkpoint related commands with " \
80	"invalid inputs fail as expected."
81