From: simon gao Date: Mon, 20 Jan 2020 10:38:59 +0000 (-0500) Subject: qa : add case to test cephfs-meta-injection X-Git-Tag: v16.1.0~2784^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=53ba9089d8eeae038b2710e1847ef7ab92af3571;p=ceph.git qa : add case to test cephfs-meta-injection Signed-off-by: simon gao --- diff --git a/qa/tasks/cephfs/filesystem.py b/qa/tasks/cephfs/filesystem.py index 7352f12c801b..f48d38f94ed5 100644 --- a/qa/tasks/cephfs/filesystem.py +++ b/qa/tasks/cephfs/filesystem.py @@ -1268,6 +1268,18 @@ class Filesystem(MDSCluster): return key_list_str.split("\n") if key_list_str else [] + def get_meta_of_fs_file(self, dir_ino, obj_name, out): + """ + get metadata from parent to verify the correctness of the data format encoded by the tool, cephfs-meta-injection. + warning : The splitting of directory is not considered here. + """ + dirfrag_obj_name = "{0:x}.00000000".format(dir_ino) + try: + ret = self.rados(["getomapval", dirfrag_obj_name, obj_name+"_head", out]) + except CommandFailedError as e: + log.error(e.__str__()) + raise ObjectNotFound(dir_ino) + def erase_metadata_objects(self, prefix): """ For all objects in the metadata pool matching the prefix, @@ -1350,6 +1362,13 @@ class Filesystem(MDSCluster): fs_rank = self._make_rank(rank) return self._run_tool("cephfs-journal-tool", args, fs_rank, quiet) + def meta_tool(self, args, rank, quiet=False): + """ + Invoke cephfs-meta-injection with the passed arguments for a rank, and return its stdout + """ + fs_rank = self._make_rank(rank) + return self._run_tool("cephfs-meta-injection", args, fs_rank, quiet) + def table_tool(self, args, quiet=False): """ Invoke cephfs-table-tool with the passed arguments, and return its stdout diff --git a/qa/tasks/cephfs/test_meta_injection.py b/qa/tasks/cephfs/test_meta_injection.py new file mode 100644 index 000000000000..8f33aa8ff6b0 --- /dev/null +++ b/qa/tasks/cephfs/test_meta_injection.py @@ -0,0 +1,40 @@ +from tasks.cephfs.cephfs_test_case import CephFSTestCase +import random +import os + +class TestMetaInjection(CephFSTestCase): + def test_meta_injection(self): + conf_ori = self.fs.mds_asok(['config', 'show']) + self.fs.mds_asok(['config', 'set', 'mds_log_max_segments', '1']) + self.mount_a.run_shell(["mkdir", "metadir"]) + self.mount_a.run_shell(["touch", "metadir/metafile1"]) + self.mount_a.run_shell(["touch", "metadir/metafile2"]) + self.fs.mds_asok(['flush', 'journal']) + dirino = self.mount_a.path_to_ino("metadir") + ino = self.mount_a.path_to_ino("metadir/metafile1") + + # export meta of ino + self.fs.meta_tool(['showm', '-i', str(ino), '-o', '/tmp/meta_out'], 0, True) + out = self.mount_a.run_shell(['grep', str(ino),'/tmp/meta_out']).stdout.getvalue().strip() + + # check the metadata of ino + self.assertNotEqual(out.find(u'"ino":'+ str(ino)), -1) + + # amend info of ino + self.fs.get_meta_of_fs_file(dirino, "metafile1", "/tmp/meta_obj") + self.fs.meta_tool(['amend', '-i', str(ino), '--in', '/tmp/meta_out', '--yes-i-really-really-mean-it'], 0, True) + self.fs.get_meta_of_fs_file(dirino, "metafile1", "/tmp/meta_obj_chg") + + # checkout meta_out after import it + ori_mds5 = self.mount_a.run_shell(["md5sum", "/tmp/meta_obj"]).stdout.getvalue().strip().split() + chg_mds5 = self.mount_a.run_shell(["md5sum", "/tmp/meta_obj_chg"]).stdout.getvalue().strip().split() + print ori_mds5," ==> ", chg_mds5 + self.assertEqual(len(ori_mds5), 2) + self.assertEqual(len(chg_mds5), 2) + self.assertEqual(ori_mds5[0], chg_mds5[0]) + + self.mount_a.run_shell(["rm", "metadir", "-rf"]) + self.mount_a.run_shell(["rm", "/tmp/meta_obj"]) + self.mount_a.run_shell(["rm", "/tmp/meta_obj_chg"]) + # restore config of mds_log_max_segments + self.fs.mds_asok(['config', 'set', 'mds_log_max_segments', conf_ori["mds_log_max_segments"]]) diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index 7055ebb7c9d8..efe092159d04 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -1326,7 +1326,7 @@ def exec_test(): # Help developers by stopping up-front if their tree isn't built enough for all the # tools that the tests might want to use (add more here if needed) require_binaries = ["ceph-dencoder", "cephfs-journal-tool", "cephfs-data-scan", - "cephfs-table-tool", "ceph-fuse", "rados"] + "cephfs-table-tool", "ceph-fuse", "rados", "cephfs-meta-injection"] missing_binaries = [b for b in require_binaries if not os.path.exists(os.path.join(BIN_PREFIX, b))] if missing_binaries and not opt_ignore_missing_binaries: log.error("Some ceph binaries missing, please build them: {0}".format(" ".join(missing_binaries))) diff --git a/src/tools/cephfs/MetaTool.cc b/src/tools/cephfs/MetaTool.cc index 1b3660389abb..06357e527f1a 100644 --- a/src/tools/cephfs/MetaTool.cc +++ b/src/tools/cephfs/MetaTool.cc @@ -159,8 +159,8 @@ int MetaTool::main(string& mode, for (auto role : role_selector.get_roles()) { rank = role.rank; - int ret = process(mode, ino, out, in, confirm); - cout << "executing for rank " << rank << " op[" <(manual_rank_num); - int ret = process(mode, ino, out, in, confirm); - cout << "op[" << mode << "] ret : " << ret << std::endl; + r = process(mode, ino, out, in, confirm); + cout << "op[" << mode << "] ret : " << r << std::endl; } return r; } @@ -320,7 +320,7 @@ int MetaTool::_amend_meta(string& k, inode_meta_t& inode_meta, const string& fn, << " You must confirm that all logs of mds have been flushed!!!\n" << " if you want amend it, please add --yes-i-really-really-mean-it!!!" << std::endl; - + return -1; } bufferlist bl; inode_meta.encode(bl, features); @@ -328,7 +328,7 @@ int MetaTool::_amend_meta(string& k, inode_meta_t& inode_meta, const string& fn, to_set[k].swap(bl); inode_backpointer_t bp; if (!op.top_op()->get_ancestor(bp)) - return false; + return -1; frag_t frag; auto item = op.inodes.find(bp.dirino); if (item != op.inodes.end()){ diff --git a/src/tools/cephfs/cephfs-meta-injection.cc b/src/tools/cephfs/cephfs-meta-injection.cc index b93d921ed281..9ccfd0e5dcf7 100644 --- a/src/tools/cephfs/cephfs-meta-injection.cc +++ b/src/tools/cephfs/cephfs-meta-injection.cc @@ -53,7 +53,7 @@ int main(int argc, const char **argv){ all.add(modeoptions).add(general); po::variables_map vm; try{ - po::store(po::command_line_parser(argc, argv).options(all).positional(p).run(), vm); + po::store(po::command_line_parser(argc, argv).options(all).positional(p).allow_unregistered().run(), vm); }catch(exception &e){ cerr << "error : " << e.what() << std::endl; return -1;