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
This commit is contained in:
Tobias Urdin 2021-05-03 17:25:43 +02:00
parent 8b647f1b3f
commit 86af7feed0
2 changed files with 14 additions and 1 deletions

View File

@ -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.

View File

@ -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