From e500fd8873422d4ee033a8702a2b3241c40c6e9d Mon Sep 17 00:00:00 2001 From: Eric Young Date: Fri, 16 Feb 2018 12:41:30 -0500 Subject: [PATCH] Adding support to extend attached ScaleIO volumes Implementing necessary mathods and rescaning storage as necessary to support extending ScaleIO volumes which are currently attached. Change-Id: Icb9fc4fe1c16c34d8de9287046045d0837b7e80e --- os_brick/initiator/connectors/scaleio.py | 46 ++++++++++++++++++- .../initiator/connectors/test_scaleio.py | 17 +++++-- ...leio-extend-attached-ec44d3a72395882c.yaml | 3 ++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/scaleio-extend-attached-ec44d3a72395882c.yaml diff --git a/os_brick/initiator/connectors/scaleio.py b/os_brick/initiator/connectors/scaleio.py index e07911bdd..0969f29ad 100644 --- a/os_brick/initiator/connectors/scaleio.py +++ b/os_brick/initiator/connectors/scaleio.py @@ -15,6 +15,7 @@ import json import os import requests +import six from six.moves import urllib from oslo_concurrency import lockutils @@ -39,6 +40,7 @@ class ScaleIOConnector(base.BaseLinuxConnector): VOLUME_NOT_MAPPED_ERROR = 84 VOLUME_ALREADY_MAPPED_ERROR = 81 GET_GUID_CMD = ['/opt/emc/scaleio/sdc/bin/drv_cfg', '--query_guid'] + RESCAN_VOLS_CMD = ['/opt/emc/scaleio/sdc/bin/drv_cfg', '--rescan'] def __init__(self, root_helper, driver=None, device_scan_attempts=initiator.DEVICE_SCAN_ATTEMPTS_DEFAULT, @@ -488,5 +490,45 @@ class ScaleIOConnector(base.BaseLinuxConnector): raise exception.BrickException(message=msg) def extend_volume(self, connection_properties): - # TODO(walter-boring): is this possible? - raise NotImplementedError + """Update the local kernel's size information. + + Try and update the local kernel's size information + for a ScaleIO volume. + """ + + LOG.info("ScaleIO rescan volumes: %(cmd)s", + {'cmd': self.RESCAN_VOLS_CMD}) + + try: + (out, err) = self._execute(*self.RESCAN_VOLS_CMD, run_as_root=True, + root_helper=self._root_helper) + + LOG.debug("Rescan volumes %(cmd)s: stdout=%(out)s", + {'cmd': self.RESCAN_VOLS_CMD, 'out': out}) + + except putils.ProcessExecutionError as e: + msg = (_("Error querying volumes: %(err)s") % {'err': e.stderr}) + LOG.error(msg) + raise exception.BrickException(message=msg) + + volume_paths = self.get_volume_paths(connection_properties) + if volume_paths: + return self.get_device_size(volume_paths[0]) + + # if we got here, the volume is not mapped + msg = (_("Error extending ScaleIO volume")) + LOG.error(msg) + raise exception.BrickException(message=msg) + + def get_device_size(self, device): + """Get the size in bytes of a volume.""" + (out, _err) = self._execute('blockdev', '--getsize64', + device, run_as_root=True, + root_helper=self._root_helper) + var = six.text_type(out.strip()) + LOG.debug("Device %(dev)s size: %(var)s", + {'dev': device, 'var': var}) + if var.isnumeric(): + return int(var) + else: + return None diff --git a/os_brick/tests/initiator/connectors/test_scaleio.py b/os_brick/tests/initiator/connectors/test_scaleio.py index 146ed43f8..3a1d87e75 100644 --- a/os_brick/tests/initiator/connectors/test_scaleio.py +++ b/os_brick/tests/initiator/connectors/test_scaleio.py @@ -267,7 +267,16 @@ class ScaleIOConnectorTestCase(test_connector.ConnectorTestCase): self.test_disconnect_volume() - def test_extend_volume(self): - self.assertRaises(NotImplementedError, - self.connector.extend_volume, - self.fake_connection_properties) + @mock.patch.object(os.path, 'exists', return_value=True) + @mock.patch.object(scaleio.ScaleIOConnector, '_find_volume_path') + @mock.patch.object(scaleio.ScaleIOConnector, 'get_device_size') + def test_extend_volume(self, + mock_device_size, + mock_find_volume_path, + mock_exists): + mock_device_size.return_value = 16 + mock_find_volume_path.return_value = "emc-vol-vol1" + extended_size = self.connector.extend_volume( + self.fake_connection_properties) + self.assertEqual(extended_size, + mock_device_size.return_value) diff --git a/releasenotes/notes/scaleio-extend-attached-ec44d3a72395882c.yaml b/releasenotes/notes/scaleio-extend-attached-ec44d3a72395882c.yaml new file mode 100644 index 000000000..7f4151183 --- /dev/null +++ b/releasenotes/notes/scaleio-extend-attached-ec44d3a72395882c.yaml @@ -0,0 +1,3 @@ +--- +features: + - Added ability to extend attached ScaleIO volumes