From: Shweta Bhosale Date: Mon, 14 Apr 2025 09:30:28 +0000 (+0530) Subject: mgr/nfs: Changes for get QoS command to return bandwidth in GiB instead of GB X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=22c24c4fe59270d71b9da7897eaf9a160da79b25;p=ceph.git mgr/nfs: Changes for get QoS command to return bandwidth in GiB instead of GB Fixes: https://tracker.ceph.com/issues/69458 Signed-off-by: Shweta Bhosale --- diff --git a/src/pybind/mgr/nfs/qos_conf.py b/src/pybind/mgr/nfs/qos_conf.py index 02863a756caf..ea2ccdd5a7ea 100644 --- a/src/pybind/mgr/nfs/qos_conf.py +++ b/src/pybind/mgr/nfs/qos_conf.py @@ -169,7 +169,7 @@ class QOSBandwidthControl(object): @staticmethod def bw_for_to_dict(bandwidth: int, ret_bw_in_bytes: bool = False) -> str: - return bytes_to_human(bandwidth) if not ret_bw_in_bytes else str(bandwidth) + return bytes_to_human(bandwidth, mode='binary') if not ret_bw_in_bytes else str(bandwidth) def to_dict(self, ret_bw_in_bytes: bool = False) -> Dict[str, Any]: r: dict[str, Any] = {} diff --git a/src/pybind/mgr/nfs/tests/test_nfs.py b/src/pybind/mgr/nfs/tests/test_nfs.py index f574f48ecd38..e677086047b8 100644 --- a/src/pybind/mgr/nfs/tests/test_nfs.py +++ b/src/pybind/mgr/nfs/tests/test_nfs.py @@ -178,10 +178,10 @@ QOS_BLOCK { "enable_bw_control": True, "enable_qos": True, "combined_rw_bw_control": False, - "max_client_read_bw": "4.0MB", - "max_client_write_bw": "3.0MB", - "max_export_read_bw": "2.0MB", - "max_export_write_bw": "2.0MB", + "max_client_read_bw": bytes_to_human(4000000, mode='binary'), + "max_client_write_bw": bytes_to_human(3000000, mode='binary'), + "max_export_read_bw": bytes_to_human(2000000, mode='binary'), + "max_export_write_bw": bytes_to_human(2000000, mode='binary'), "qos_type": "PerShare_PerClient", "enable_iops_control": False } @@ -202,10 +202,10 @@ QOS_BLOCK { "enable_bw_control": True, "enable_qos": True, "combined_rw_bw_control": False, - "max_client_read_bw": "4.0MB", - "max_client_write_bw": "3.0MB", - "max_export_read_bw": "2.0MB", - "max_export_write_bw": "2.0MB", + "max_client_read_bw": bytes_to_human(4000000, mode='binary'), + "max_client_write_bw": bytes_to_human(3000000, mode='binary'), + "max_export_read_bw": bytes_to_human(2000000, mode='binary'), + "max_export_write_bw": bytes_to_human(2000000, mode='binary'), "enable_iops_control": False } qos_export_dict_bw_in_bytes = { @@ -1457,22 +1457,10 @@ EXPORT { def test_qos_from_dict(self): qos = QOS.from_dict(self.qos_cluster_dict, True) - assert qos.enable_qos == True - assert qos.bw_obj.enable_bw_ctrl == True - assert isinstance(qos.qos_type, QOSType) - assert qos.bw_obj.export_writebw == 2000000 - assert qos.bw_obj.export_readbw == 2000000 - assert qos.bw_obj.client_writebw == 3000000 - assert qos.bw_obj.client_readbw == 4000000 + assert qos.to_dict() == self.qos_cluster_dict qos = QOS.from_dict(self.qos_export_dict) - assert qos.enable_qos == True - assert qos.bw_obj.enable_bw_ctrl == True - assert qos.qos_type is None - assert qos.bw_obj.export_writebw == 2000000 - assert qos.bw_obj.export_readbw == 2000000 - assert qos.bw_obj.client_writebw == 3000000 - assert qos.bw_obj.client_readbw == 4000000 + assert qos.to_dict() == self.qos_export_dict @pytest.mark.parametrize("qos_block, qos_dict, qos_dict_bw_in_bytes", [ (qos_cluster_block, qos_cluster_dict, qos_cluster_dict_bw_in_bytes), @@ -1500,7 +1488,7 @@ EXPORT { out = cluster.get_cluster_qos(self.cluster_id) expected_out = {"enable_bw_control": True, "enable_qos": True, "combined_rw_bw_control": combined_bw_ctrl, "qos_type": qos_type.name, "enable_iops_control": False} for key in params: - expected_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(params[key])) + expected_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(params[key]), mode='binary') assert out == expected_out cluster.disable_cluster_qos_bw(self.cluster_id) out = cluster.get_cluster_qos(self.cluster_id) @@ -1557,7 +1545,7 @@ EXPORT { out = export_mgr.get_export_qos(self.cluster_id, '/cephfs_a/') expected_out = {"enable_bw_control": True, "enable_qos": True, "combined_rw_bw_control": export_combined_bw_ctrl} for key in export_params: - expected_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(export_params[key])) + expected_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(export_params[key]), mode='binary') expected_out.update(clust_qos_conf) assert out == expected_out export_mgr.disable_export_qos_bw(self.cluster_id, '/cephfs_a/') @@ -1686,7 +1674,7 @@ EXPORT { bw_out = {} ops_out = {} for key in bw_params: - bw_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(bw_params[key])) + bw_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(bw_params[key]), mode='binary') for key in ops_params: ops_out[QOSParams[key].value] = ops_params[key] expected_out.update(bw_out) @@ -1763,7 +1751,7 @@ EXPORT { bw_out = {} ops_out = {} for key in export_bw_params: - bw_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(export_bw_params[key])) + bw_out[QOSParams[key].value] = bytes_to_human(with_units_to_int(export_bw_params[key]), mode='binary') for key in export_ops_params: ops_out[QOSParams[key].value] = export_ops_params[key] expected_out.update(bw_out)