From 66873311e510aea5c349e64f7f9e9e94a662a453 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Mon, 9 Dec 2013 15:34:39 -0500 Subject: [PATCH] NFS/GlusterFS: Skip incorrectly formatted shares Shares should always be of the form address:/volume. If they are not (i.e., are missing the '/'), then skip them and issue a warning message. This will prevent us from sending incorrect connection_info dicts to Nova. Closes-Bug: #1267253 Change-Id: Ic40cd0cdc862b44b0a7d3e5b1d7c4fee8ea1b28d (cherry picked from commit 21ebf2898e2f5fc8127b7a3bdc9743c49933f952) --- cinder/tests/test_glusterfs.py | 1 + cinder/tests/test_nfs.py | 1 + cinder/volume/drivers/nfs.py | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/cinder/tests/test_glusterfs.py b/cinder/tests/test_glusterfs.py index 1b81badd8c0..5560ead3fad 100644 --- a/cinder/tests/test_glusterfs.py +++ b/cinder/tests/test_glusterfs.py @@ -289,6 +289,7 @@ class GlusterFsDriverTestCase(test.TestCase): config_data.append(self.TEST_EXPORT1) config_data.append('#' + self.TEST_EXPORT2) config_data.append(self.TEST_EXPORT2 + ' ' + self.TEST_EXPORT2_OPTIONS) + config_data.append('broken:share_format') config_data.append('') drv._read_config_file(self.TEST_SHARES_CONFIG_FILE).\ AndReturn(config_data) diff --git a/cinder/tests/test_nfs.py b/cinder/tests/test_nfs.py index 1b5117ed0f7..2c7bab01da5 100644 --- a/cinder/tests/test_nfs.py +++ b/cinder/tests/test_nfs.py @@ -280,6 +280,7 @@ class NfsDriverTestCase(test.TestCase): config_data.append('') config_data.append(self.TEST_NFS_EXPORT2 + ' ' + self.TEST_NFS_EXPORT2_OPTIONS) + config_data.append('broken:share_format') drv._read_config_file(self.TEST_SHARES_CONFIG_FILE).\ AndReturn(config_data) mox.ReplayAll() diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py index db97bb328b5..19347738c1b 100644 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -17,6 +17,7 @@ import errno import os +import re from oslo.config import cfg @@ -294,6 +295,11 @@ class RemoteFsDriver(driver.VolumeDriver): share_address = share_info[0].strip().decode('unicode_escape') share_opts = share_info[1].strip() if len(share_info) > 1 else None + if not re.match(r'.+:/.+', share_address): + LOG.warn("Share %s ignored due to invalid format. Must be of " + "form address:/export." % share_address) + continue + self.shares[share_address] = share_opts LOG.debug("shares loaded: %s", self.shares)