From: Patrick Donnelly Date: Tue, 26 Nov 2019 17:47:40 +0000 (-0800) Subject: Merge PR #27467 into master X-Git-Tag: v15.1.0~746 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f1e3fec83d50f5536870a9055d390a1daaaae942;p=ceph.git Merge PR #27467 into master * refs/pull/27467/head: cephfs-shell: add snapshot management Reviewed-by: Rishabh Dave Reviewed-by: Varsha Rao Reviewed-by: Patrick Donnelly --- f1e3fec83d50f5536870a9055d390a1daaaae942 diff --cc qa/tasks/cephfs/test_cephfs_shell.py index 151a1117edef,742433ba4bda..42137189a17b --- a/qa/tasks/cephfs/test_cephfs_shell.py +++ b/qa/tasks/cephfs/test_cephfs_shell.py @@@ -46,8 -46,13 +46,13 @@@ class TestCephFSShell(CephFSTestCase) log.info("Running command: {}".format(" ".join(args))) return mount_x.client_remote.run(args=args, stdout=StringIO(), - stdin=stdin) + stderr=StringIO(), stdin=stdin) + def get_cephfs_shell_cmd_error(self, cmd, mount_x=None, opts=None, + stdin=None): + return self.run_cephfs_shell_cmd(cmd, mount_x, opts, stdin).stderr.\ + getvalue().strip() + def get_cephfs_shell_cmd_output(self, cmd, mount_x=None, opts=None, stdin=None): return self.run_cephfs_shell_cmd(cmd, mount_x, opts, stdin).stdout.\ diff --cc src/tools/cephfs/cephfs-shell index 7e9ac937e54f,d74a10a0b9a9..1e3d5bca91fd --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@@ -1277,9 -1247,52 +1281,53 @@@ sub-directories, files' poutput('max_files: %s' % max_files) except libcephfs.Error: perror('max_files is not set') + self.exit_code = 1 pass + snap_parser = argparse.ArgumentParser(description='Snapshot Management') + snap_parser.add_argument('op', type=str, + help='Snapshot operation: create or delete') + snap_parser.add_argument('name', type=str, action=path_to_bytes, + help='Name of snapshot') + snap_parser.add_argument('dir', type=str, action=path_to_bytes, + help='Directory for which snapshot ' + 'needs to be created or deleted') + + @with_argparser(snap_parser) + def do_snap(self, args): + """ + Snapshot management for the volume + """ + # setting self.colors to None turns off colorizing and + # perror emits plain text + self.colors = None + + snapdir = '.snap' + conf_snapdir = cephfs.conf_get('client_snapdir') + if conf_snapdir is not None: + snapdir = conf_snapdir + snapdir = to_bytes(snapdir) + if args.op == 'create': + try: + if is_dir_exists(args.dir): + cephfs.mkdir(os.path.join(args.dir, snapdir, args.name), 0o755) + else: + self.perror("'{}': no such directory".format(args.dir.decode('utf-8'))) + except libcephfs.Error: + self.perror("snapshot '{}' already exists".format(args.name.decode('utf-8'))) + elif args.op == 'delete': + snap_dir = os.path.join(args.dir, snapdir, args.name) + try: + if is_dir_exists(snap_dir): + newargs = argparse.Namespace(paths=[snap_dir], parent=False) + self.do_rmdir_helper(newargs) + else: + self.perror("'{}': no such snapshot".format(args.name.decode('utf-8'))) + except libcephfs.Error: + self.perror("error while deleting '{}'".format(snap_dir.decode('utf-8'))) + else: + self.perror("snapshot can only be created or deleted; check - help snap") + def do_help(self, line): """ Get details about a command.