From fabee8f75c56f18c949b79dcc751c2855b5c7514 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Thu, 20 Feb 2014 14:00:22 +0530 Subject: cli/snapshot : snapshot delete CLI changes. Syntax: gluster snapshot delete Change-Id: I5de7b9a79eeba12e4f0b8abfbe96a2db738f25c0 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/7144 Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- cli/src/cli-cmd-parser.c | 82 +++++++++++++++++++++++++++++++------------ cli/src/cli-cmd-snapshot.c | 2 +- tests/basic/volume-snapshot.t | 4 +-- tests/bugs/bug-1040934.t | 2 +- tests/bugs/bug-1045333.t | 6 ++-- tests/bugs/bug-1049834.t | 2 +- tests/snapshot.rc | 4 +-- 7 files changed, 70 insertions(+), 32 deletions(-) diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 6b8f2929f..f14fc702c 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -3409,6 +3409,52 @@ out: return ret; } +/* snapshot delete + * @arg-0, dict : Request Dictionary to be sent to server side. + * @arg-1, words : Contains individual words of CLI command. + * @arg-2, wordcount: Contains number of words present in the CLI command. + * @arg-3, cmdi : command index, here cmdi is "2" (gluster snapshot delete) + * + * return value : -1 on failure + * 0 on success + */ +int +cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount, + unsigned int cmdi, struct cli_state *state) { + + int ret = -1; + const char *question = NULL; + gf_answer_t answer = GF_ANSWER_NO; + + question = "Deleting snap will erase all the information about " + "the snap. Do you still want to continue?"; + + GF_ASSERT (words); + GF_ASSERT (dict); + + if (wordcount != 3) { + gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + + ret = dict_set_str (dict, "snap-name", (char *)words[cmdi]); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", + words[cmdi]); + goto out; + } + + answer = cli_cmd_get_confirmation (state, question); + if (GF_ANSWER_NO == answer) { + ret = -1; + gf_log ("cli", GF_LOG_DEBUG, "User cancelled " + "snapshot delete operation"); + goto out; + } +out : + return ret; +} + int32_t cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, @@ -3518,29 +3564,21 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, break; } - case GF_SNAP_OPTION_TYPE_DELETE: - { - /*syntax: - snapshot remove [ -s | -c ] - */ - w = str_getunamb (words[2], opwords); - if (w) { - gf_log ("", GF_LOG_ERROR, "Opword Mismatch"); - goto out; - } - - cmdi = 2; + case GF_SNAP_OPTION_TYPE_DELETE: + { + /* Syntax : + * gluster snapshot delete + */ + ret = cli_snap_delete_parse (dict, words, wordcount, + cmdi, state); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to parse " + "snapshot delete command"); + goto out; + } + break; + } - ret = cli_snap_remove_parse (dict, words, - wordcount, cmdi, state); - if (ret) { - if (ret < 0) - gf_log ("", GF_LOG_ERROR, - "remove command parsing failed."); - goto out; - } - break; - } case GF_SNAP_OPTION_TYPE_CONFIG: { /* snapshot config [snap-max-hard-limit | diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index 4d824a007..93e154eab 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -103,7 +103,7 @@ struct cli_cmd snapshot_cmds[] = { cli_cmd_snapshot_cbk, "Snapshot Config." }, - {"snapshot delete ( -s | -c ) [force]", + {"snapshot delete ", cli_cmd_snapshot_cbk, "Snapshot Delete." }, diff --git a/tests/basic/volume-snapshot.t b/tests/basic/volume-snapshot.t index f6b88068e..4bc0792db 100755 --- a/tests/basic/volume-snapshot.t +++ b/tests/basic/volume-snapshot.t @@ -28,10 +28,10 @@ function create_snapshots() { } function delete_snapshots() { - $CLI_1 snapshot delete $V0 -s ${V0}_snap & + $CLI_1 snapshot delete ${V0}_snap & PID_1=$! - $CLI_1 snapshot delete $V1 -s ${V1}_snap & + $CLI_1 snapshot delete ${V1}_snap & PID_2=$! wait $PID_1 $PID_2 diff --git a/tests/bugs/bug-1040934.t b/tests/bugs/bug-1040934.t index 547f6c3bc..d057f0cb7 100644 --- a/tests/bugs/bug-1040934.t +++ b/tests/bugs/bug-1040934.t @@ -28,7 +28,7 @@ TEST mount -t glusterfs $H1:/snaps/${V0}_snap/$V0 $M0 cd $M0 TEST ! touch a -TEST $CLI_1 snapshot delete $V0 -s ${V0}_snap +TEST $CLI_1 snapshot delete ${V0}_snap PID_1=$! wait $PID_1 diff --git a/tests/bugs/bug-1045333.t b/tests/bugs/bug-1045333.t index c1fd71beb..59ef1c5e7 100644 --- a/tests/bugs/bug-1045333.t +++ b/tests/bugs/bug-1045333.t @@ -38,9 +38,9 @@ TEST mount -t glusterfs $H0:/snaps/$S3/$V0 $M0 TEST umount -f $M0 #Clean up -TEST $CLI snapshot delete $V0 -s $S1 -TEST $CLI snapshot delete $V0 -s $S2 -TEST $CLI snapshot delete $V0 -s $S3 +TEST $CLI snapshot delete $S1 +TEST $CLI snapshot delete $S2 +TEST $CLI snapshot delete $S3 TEST $CLI volume stop $V0 force TEST $CLI volume delete $V0 diff --git a/tests/bugs/bug-1049834.t b/tests/bugs/bug-1049834.t index ea4b3c85d..6587fb765 100755 --- a/tests/bugs/bug-1049834.t +++ b/tests/bugs/bug-1049834.t @@ -31,7 +31,7 @@ TEST snapshot_n_exists $V0 4 $V0_snap #Creating the 5th snapshots on the volume and expecting it not to be created. TEST ! $CLI_1 snapshot create $V0 -n ${V0}_snap5 TEST ! snapshot_exists ${V0}_snap5 -TEST ! $CLI_1 snapshot delete $V0 -s ${V0}_snap5 +TEST ! $CLI_1 snapshot delete ${V0}_snap5 #Deleting the 4 snaps TEST delete_n_snapshots $V0 4 $V0_snap diff --git a/tests/snapshot.rc b/tests/snapshot.rc index 230f62a68..52481b0fb 100755 --- a/tests/snapshot.rc +++ b/tests/snapshot.rc @@ -172,7 +172,7 @@ function _remove_vhd() { ######################################################## function snapshot_exists() { local snapname=$1 - $CLI snapshot list | egrep -q "\s$snapname\b" + $CLI snapshot list | egrep -q "^$snapname\$" return $? } @@ -214,7 +214,7 @@ function delete_n_snapshots() { local snap_name=$3 local ret=0 for i in `seq 1 $snap_count`; do - $CLI_1 snapshot delete ${vol} -s $snap_name$i & + $CLI_1 snapshot delete $snap_name$i & PID_1=$! wait $PID_1 temp=$? -- cgit