From 138117f2f48c4cca014334b4547b229c1f05807e Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Tue, 14 Apr 2020 22:46:54 +0530 Subject: [PATCH] mgr/status: Fix "ceph fs status" json format writing to stderr "ceph fs status" json format outputs to stderr instead of stdout. This patch fixes the same. Fixes: https://tracker.ceph.com/issues/44962 Signed-off-by: Kotresh HR --- qa/tasks/cephfs/test_admin.py | 9 +++++++++ src/pybind/mgr/status/module.py | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/qa/tasks/cephfs/test_admin.py b/qa/tasks/cephfs/test_admin.py index 374f75a72cf..60a1f7e2c9a 100644 --- a/qa/tasks/cephfs/test_admin.py +++ b/qa/tasks/cephfs/test_admin.py @@ -1,3 +1,5 @@ +import json + from teuthology.orchestra.run import CommandFailedError from tasks.cephfs.cephfs_test_case import CephFSTestCase @@ -5,6 +7,7 @@ from tasks.cephfs.fuse_mount import FuseMount from tasks.cephfs.filesystem import FileLayout + class TestAdminCommands(CephFSTestCase): """ Tests for administration command. @@ -21,6 +24,12 @@ class TestAdminCommands(CephFSTestCase): s = self.fs.mon_manager.raw_cluster_cmd("fs", "status") self.assertTrue("active" in s) + mdsmap = json.loads(self.fs.mon_manager.raw_cluster_cmd("fs", "status", "--format=json-pretty"))["mdsmap"] + self.assertEqual(mdsmap[0]["state"], "active") + + mdsmap = json.loads(self.fs.mon_manager.raw_cluster_cmd("fs", "status", "--format=json"))["mdsmap"] + self.assertEqual(mdsmap[0]["state"], "active") + def _setup_ec_pools(self, n, metadata=True, overwrites=True): if metadata: self.fs.mon_manager.raw_cluster_cmd('osd', 'pool', 'create', n+"-meta", "8") diff --git a/src/pybind/mgr/status/module.py b/src/pybind/mgr/status/module.py index 3a0c3c2c918..a53edc0e389 100644 --- a/src/pybind/mgr/status/module.py +++ b/src/pybind/mgr/status/module.py @@ -12,7 +12,7 @@ import prettytable import six import json -from mgr_module import MgrModule +from mgr_module import MgrModule, HandleCommandResult class Module(MgrModule): @@ -260,11 +260,11 @@ class Module(MgrModule): output += version_table.get_string() + "\n" if output_format == "json": - return 0, "", json.dumps(json_output, sort_keys=True) + return HandleCommandResult(stdout=json.dumps(json_output, sort_keys=True)) elif output_format == "json-pretty": - return 0, "", json.dumps(json_output, sort_keys=True, indent=4, separators=(',', ': ')) + return HandleCommandResult(stdout=json.dumps(json_output, sort_keys=True, indent=4, separators=(',', ': '))) else: - return 0, output, "" + return HandleCommandResult(stdout=output) def handle_osd_status(self, cmd): osd_table = PrettyTable(['ID', 'HOST', 'USED', 'AVAIL', 'WR OPS', -- 2.39.5