Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup KVS tests #1149

Merged
merged 8 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/man1/flux-kvs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ If 'key' is not provided, "." (root of the namespace) is assumed. If '-R'
is specified, recursively display keys under subdirectories. If '-d' is
specified, do not output key values.

*unlink* [-R] 'key' ['key...']::
*unlink* [-R] [-f] 'key' ['key...']::
Remove 'key' from the KVS and commit the change. If 'key' represents
a directory, specify '-R' to remove all keys underneath it.
a directory, specify '-R' to remove all keys underneath it. If '-f' is
specified, ignore nonexistent files.

*link* 'target' 'linkname'::
Create a new name for 'target', similar to a symbolic link, and commit
Expand Down
27 changes: 21 additions & 6 deletions src/cmd/flux-kvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ static struct optparse_option unlink_opts[] = {
{ .name = "recursive", .key = 'R', .has_arg = 0,
.usage = "Remove directory contents recursively",
},
{ .name = "force", .key = 'f', .has_arg = 0,
.usage = "ignore nonexistent files",
},
OPTPARSE_TABLE_END
};

Expand Down Expand Up @@ -362,19 +365,25 @@ int cmd_put (optparse_t *p, int argc, char **argv)
}

/* Some checks prior to unlinking key:
* - fail if key does not exist (ENOENT) or other fatal lookup error
* - fail if key does not exist (ENOENT) and fopt not specified or
* other fatal lookup error
* - fail if key is a non-empty directory (ENOTEMPTY) and -R was not specified
*/
static int unlink_safety_check (flux_t *h, const char *key, bool Ropt)
static int unlink_safety_check (flux_t *h, const char *key, bool Ropt,
bool fopt, bool *unlinkable)
{
flux_future_t *f;
kvsdir_t *dir = NULL;
const char *json_str;
int rc = -1;

*unlinkable = false;

if (!(f = flux_kvs_lookup (h, FLUX_KVS_READDIR, key)))
goto done;
if (flux_kvs_lookup_get (f, &json_str) < 0) {
if (errno == ENOENT && fopt)
goto out;
if (errno != ENOTDIR)
goto done;
}
Expand All @@ -386,6 +395,8 @@ static int unlink_safety_check (flux_t *h, const char *key, bool Ropt)
goto done;
}
}
*unlinkable = true;
out:
rc = 0;
done:
if (dir)
Expand All @@ -400,22 +411,26 @@ int cmd_unlink (optparse_t *p, int argc, char **argv)
int optindex, i;
flux_future_t *f;
flux_kvs_txn_t *txn;
bool Ropt;
bool Ropt, fopt;

optindex = optparse_option_index (p);
if ((optindex - argc) == 0) {
optparse_print_usage (p);
exit (1);
}
Ropt = optparse_hasopt (p, "recursive");
fopt = optparse_hasopt (p, "force");

if (!(txn = flux_kvs_txn_create ()))
log_err_exit ("flux_kvs_txn_create");
for (i = optindex; i < argc; i++) {
if (unlink_safety_check (h, argv[i], Ropt) < 0)
bool unlinkable;
if (unlink_safety_check (h, argv[i], Ropt, fopt, &unlinkable) < 0)
log_err_exit ("cannot unlink '%s'", argv[i]);
if (flux_kvs_txn_unlink (txn, 0, argv[i]) < 0)
log_err_exit ("%s", argv[i]);
if (unlinkable) {
if (flux_kvs_txn_unlink (txn, 0, argv[i]) < 0)
log_err_exit ("%s", argv[i]);
}
}
if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0)
log_err_exit ("flux_kvs_commit");
Expand Down
8 changes: 4 additions & 4 deletions t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ TESTS = \
t0015-cron.t \
t0016-cron-faketime.t \
t0017-security.t \
t1000-kvs-basic.t \
t1000-kvs.t \
t1001-barrier-basic.t \
t1002-kvs-cmd.t \
t1002-kvs-extra.t \
t1005-cmddriver.t \
t1006-apidisconnect.t \
t1007-kz.t \
Expand Down Expand Up @@ -119,9 +119,9 @@ check_SCRIPTS = \
t0015-cron.t \
t0016-cron-faketime.t \
t0017-security.t \
t1000-kvs-basic.t \
t1000-kvs.t \
t1001-barrier-basic.t \
t1002-kvs-cmd.t \
t1002-kvs-extra.t \
t1005-cmddriver.t \
t1006-apidisconnect.t \
t1007-kz.t \
Expand Down
Loading