]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: client: Add multi target MDSs command tests
authorJimyeong Lee <jinmyeong.lee@linecorp.com>
Wed, 2 Aug 2023 00:18:03 +0000 (09:18 +0900)
committerRishabh Dave <ridave@redhat.com>
Wed, 8 Nov 2023 17:25:23 +0000 (22:55 +0530)
Signed-off-by: Jinmyeong Lee <jinmyeong.lee@linecorp.com>
(cherry picked from commit 9c87d7c1bf2d0a6ed9a36ab8a12f110ff5307c2a)

Conflicts:
src/test/client/CMakeLists.txt
-  no modficiations has been made, lines around the patch being
   backported were different.
src/test/pybind/test_cephfs.py
-  no modficiations has been made, lines around the patch being
   backported were different.

src/test/client/CMakeLists.txt
src/test/client/commands.cc [new file with mode: 0644]
src/test/pybind/test_cephfs.py

index 1937bdd0b55423d63adcaa39dfeea3f6e39fedbb..3d3e327f3f8fd89f0eff13eb2760347220629344 100644 (file)
@@ -3,6 +3,7 @@ if(${WITH_CEPHFS})
     main.cc
     alternate_name.cc
     ops.cc
+    commands.cc
     )
   target_link_libraries(ceph_test_client
     client
diff --git a/src/test/client/commands.cc b/src/test/client/commands.cc
new file mode 100644 (file)
index 0000000..c1fe763
--- /dev/null
@@ -0,0 +1,48 @@
+#include <errno.h>
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <unordered_map>
+
+#include <fmt/format.h>
+
+#include "test/client/TestClient.h"
+
+
+TEST_F(TestClient, SingleTargetMdsCommand) {
+    auto mds_spec = "a";
+    auto cmd = "{\"prefix\": \"session ls\", \"format\": \"json\"}";
+    bufferlist inbl;
+    bufferlist outbl;
+    std::string outs;
+    std::vector<std::string> cmdv;
+    C_SaferCond cond;
+
+    cmdv.push_back(cmd);
+    int r = client->mds_command(mds_spec, cmdv, inbl, &outbl, &outs, &cond);
+    r = cond.wait();
+
+    std::cout << "SingleTargetMdsCommand: " << outbl.c_str() << std::endl;
+
+    ASSERT_TRUE(r == 0 || r == -38);
+}
+
+TEST_F(TestClient, MultiTargetMdsCommand) {
+    auto mds_spec = "*";
+    auto cmd = "{\"prefix\": \"session ls\", \"format\": \"json\"}";
+    bufferlist inbl;
+    bufferlist outbl;
+    std::string outs;
+    std::vector<std::string> cmdv;
+    C_SaferCond cond;
+
+    cmdv.push_back(cmd);
+    std::cout << "MultiTargetMds: " << std::endl;
+    int r = client->mds_command(mds_spec, cmdv, inbl, &outbl, &outs, &cond);
+    r = cond.wait();
+
+    std::cout << "MultiTargetMdsCommand: " << outbl.c_str() << std::endl;
+
+    ASSERT_TRUE(r == 0 || r == -38);
+}
index d16807de97d8e4bbd9d9b6fed1fffdf31907c029..42b57576b78261eeb2b10679209ea818881c0835 100644 (file)
@@ -10,6 +10,7 @@ import random
 import time
 import stat
 import uuid
+import json
 from datetime import datetime
 
 cephfs = None
@@ -907,3 +908,37 @@ def test_snapdiff(testdir):
 
     # remove directory
     purge_dir(b"/snapdiff_test");
+
+@with_setup(setup_test)
+def test_single_target_command():
+    command = {'prefix': u'session ls', 'format': 'json'}
+    mds_spec  = "a"
+    inbuf = b''
+    ret, outbl, outs = cephfs.mds_command(mds_spec, json.dumps(command), inbuf)
+    if outbl:
+        session_map = json.loads(outbl)
+    # Standby MDSs will return -38
+    assert(ret == 0 or ret == -38)
+
+@with_setup(setup_test)
+def test_multi_target_command():
+    mds_get_command = {'prefix': 'status', 'format': 'json'}
+    inbuf = b''
+    ret, outbl, outs = cephfs.mds_command('*', json.dumps(mds_get_command), inbuf)
+    print(outbl)
+    mds_status = json.loads(outbl)
+    print(mds_status)
+
+    command = {'prefix': u'session ls', 'format': 'json'}
+    mds_spec  = "*"
+    inbuf = b''
+
+    ret, outbl, outs = cephfs.mds_command(mds_spec, json.dumps(command), inbuf)
+    # Standby MDSs will return -38
+    assert(ret == 0 or ret == -38)
+    print(outbl)
+    session_map = json.loads(outbl)
+
+    if isinstance(mds_status, list): # if multi target command result
+        for mds_sessions in session_map:
+            assert(list(mds_sessions.keys())[0].startswith('mds.'))