]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Merge PR #27467 into master
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 26 Nov 2019 17:47:40 +0000 (09:47 -0800)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 26 Nov 2019 17:47:40 +0000 (09:47 -0800)
* refs/pull/27467/head:
cephfs-shell: add snapshot management

Reviewed-by: Rishabh Dave <ridave@redhat.com>
Reviewed-by: Varsha Rao <varao@redhat.com>
Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
1  2 
qa/tasks/cephfs/test_cephfs_shell.py
src/tools/cephfs/cephfs-shell

index 151a1117edefaf9c354116f869165f5aed9d8cac,742433ba4bda78f40a0a52f2f9efba0285d90459..42137189a17b5a2c887b78f6746675d481f6a6ea
@@@ -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.\
index 7e9ac937e54f21617a6f55e80604b2027c9b7669,d74a10a0b9a958188848eb20be080e34a955b82b..1e3d5bca91fd33e503b51748a751628c1b26c7b3
@@@ -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.