From 86af7feed06f08ddb3ef65122089216708d53a06 Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Mon, 3 May 2021 17:25:43 +0200 Subject: [PATCH] Stop leaking ceph df cmd in RBD utils If the ceph df command fails in the get_pool_info method of RBD utils the actual command executed if seen by the users in the fault error message. This hides the command behind a StorageError exception and logs the exception instead of leaking it to the users. Change-Id: I6e3a73f2e04d1a7636daf96d5af73c9cf2fbe220 Closes-Bug: 1926978 --- nova/storage/rbd_utils.py | 9 ++++++++- nova/tests/unit/storage/test_rbd.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/nova/storage/rbd_utils.py b/nova/storage/rbd_utils.py index d6fc6b8317d9..1e9b9b78fe19 100644 --- a/nova/storage/rbd_utils.py +++ b/nova/storage/rbd_utils.py @@ -425,7 +425,14 @@ class RBDDriver(object): # MAX_AVAIL stat will divide by the replication size when doing the # calculation. args = ['ceph', 'df', '--format=json'] + self.ceph_args() - out, _ = processutils.execute(*args) + + try: + out, _ = processutils.execute(*args) + except processutils.ProcessExecutionError: + LOG.exception('Could not determine disk usage') + raise exception.StorageError( + reason='Could not determine disk usage') + stats = jsonutils.loads(out) # Find the pool for which we are configured. diff --git a/nova/tests/unit/storage/test_rbd.py b/nova/tests/unit/storage/test_rbd.py index f0b3f7053206..65796ebc1fb8 100644 --- a/nova/tests/unit/storage/test_rbd.py +++ b/nova/tests/unit/storage/test_rbd.py @@ -13,6 +13,7 @@ from eventlet import tpool import mock +from oslo_concurrency import processutils from oslo_serialization import jsonutils from oslo_utils.fixture import uuidsentinel as uuids @@ -653,6 +654,11 @@ class RbdTestCase(test.NoDBTestCase): 'used': ceph_df_json['pools'][1]['stats']['bytes_used']} self.assertDictEqual(expected, self.driver.get_pool_info()) + @mock.patch('oslo_concurrency.processutils.execute', autospec=True, + side_effect=processutils.ProcessExecutionError("failed")) + def test_get_pool_info_execute_failed(self, mock_execute): + self.assertRaises(exception.StorageError, self.driver.get_pool_info) + @mock.patch('oslo_concurrency.processutils.execute') def test_get_pool_info_not_found(self, mock_execute): # Make the pool something other than self.rbd_pool so it won't be found