summaryrefslogtreecommitdiff
path: root/glance_store/tests
diff options
context:
space:
mode:
authorRajat Dhasmana <rajatdhasmana@gmail.com>2022-12-28 14:30:18 +0530
committerwhoami-rajat <rajatdhasmana@gmail.com>2023-01-18 15:46:49 +0530
commita7edc87b0e97d537c1b26ca521e18605a352cdfa (patch)
tree92d9f04d1ff728008b3d528a74695a5941593d73 /glance_store/tests
parentd0733a0f4f0c803ca0333605a21552dba1da931e (diff)
downloadglance_store-a7edc87b0e97d537c1b26ca521e18605a352cdfa.tar.gz
Cinder: Add support to extend attached volumes
While creating an image, if we want to extend the volume (to accomodate the image), we need to first detach the volume, perform the extend and attach it again. This is inefficient for backends that support extending attached volumes since we are performing 3 cinder operations (the attachment call includes 3 API calls which sum to a total of 5 API calls for 3 operations) instead of directly extending it which requires only 1 API call to cinder. The support for extending attached volumes was added in cinder microversion 3.42. This patch adds a new boolean config option ``cinder_do_extend_attached`` which allows operators to specify if the cinder backend they are using supports extending attached (in-use) volumes. By default this will be ``false``. Based on the parameter, we will perform the extend operation, online (if cinder_do_extend_attached is true) and offline otherwise. Spec: https://review.opendev.org/c/openstack/glance-specs/+/868901 Depends-On: https://review.opendev.org/c/openstack/glance/+/869021 Depends-On: https://review.opendev.org/c/openstack/cinder/+/869051 Change-Id: I5e70824e9abc5277ea25ba95704b358fe3686037
Diffstat (limited to 'glance_store/tests')
-rw-r--r--glance_store/tests/unit/cinder/test_base.py6
-rw-r--r--glance_store/tests/unit/cinder/test_cinder_base.py34
-rw-r--r--glance_store/tests/unit/cinder/test_cinder_store.py3
-rw-r--r--glance_store/tests/unit/cinder/test_multistore_cinder.py3
-rw-r--r--glance_store/tests/unit/cinder/test_nfs.py3
-rw-r--r--glance_store/tests/unit/test_opts.py1
6 files changed, 41 insertions, 9 deletions
diff --git a/glance_store/tests/unit/cinder/test_base.py b/glance_store/tests/unit/cinder/test_base.py
index cc57f56..488cf1a 100644
--- a/glance_store/tests/unit/cinder/test_base.py
+++ b/glance_store/tests/unit/cinder/test_base.py
@@ -104,6 +104,12 @@ class TestBaseBrickConnectorInterface(test_base.StoreBaseTest):
self.connector.conn.disconnect_volume.assert_called_once_with(
self.connection_info, fake_device)
+ def test_extend_volume(self):
+ self.mock_object(self.connector.conn, 'extend_volume')
+ self.connector.extend_volume()
+ self.connector.conn.extend_volume.assert_called_once_with(
+ self.connection_info)
+
def test_yield_path(self):
fake_vol = mock.MagicMock()
fake_device = 'fake_dev_path'
diff --git a/glance_store/tests/unit/cinder/test_cinder_base.py b/glance_store/tests/unit/cinder/test_cinder_base.py
index d94782f..acdb70b 100644
--- a/glance_store/tests/unit/cinder/test_cinder_base.py
+++ b/glance_store/tests/unit/cinder/test_cinder_base.py
@@ -582,7 +582,7 @@ class TestCinderStoreBase(object):
fake_image_id, image_file, expected_size, self.hash_algo,
self.context, None)
- def _test_cinder_add_extend(self, is_multi_store=False):
+ def _test_cinder_add_extend(self, is_multi_store=False, online=False):
expected_volume_size = 2 * units.Gi
expected_multihash = 'fake_hash'
@@ -619,6 +619,11 @@ class TestCinderStoreBase(object):
backend = 'cinder1'
expected_location = 'cinder://%s/%s' % (backend, fake_volume.id)
self.config(cinder_volume_type='some_type', group=backend)
+ if online:
+ self.config(cinder_do_extend_attached=True, group=backend)
+ fake_connector = mock.MagicMock()
+ fake_vol_connector_map = {expected_volume_id: fake_connector}
+ self.store.volume_connector_map = fake_vol_connector_map
fake_client = mock.MagicMock(auth_token=None, management_url=None)
fake_volume.manager.get.return_value = fake_volume
@@ -635,9 +640,12 @@ class TestCinderStoreBase(object):
side_effect=fake_open), \
mock.patch.object(cinder.utils, 'get_hasher') as fake_hasher, \
mock.patch.object(cinder.Store, '_wait_volume_status',
- return_value=fake_volume) as mock_wait:
- mock_cc.return_value = mock.MagicMock(client=fake_client,
- volumes=fake_volumes)
+ return_value=fake_volume) as mock_wait, \
+ mock.patch.object(cinder_utils.API,
+ 'extend_volume') as extend_vol:
+ mock_cc_return_val = mock.MagicMock(client=fake_client,
+ volumes=fake_volumes)
+ mock_cc.return_value = mock_cc_return_val
fake_hasher.side_effect = get_fake_hash
loc, size, checksum, multihash, metadata = self.store.add(
@@ -656,11 +664,19 @@ class TestCinderStoreBase(object):
volume_type='some_type')
if is_multi_store:
self.assertEqual(backend, metadata["store"])
- fake_volume.extend.assert_called_once_with(
- fake_volume, expected_volume_size // units.Gi)
- mock_wait.assert_has_calls(
- [mock.call(fake_volume, 'creating', 'available'),
- mock.call(fake_volume, 'extending', 'available')])
+ if online:
+ extend_vol.assert_called_once_with(
+ mock_cc_return_val, fake_volume,
+ expected_volume_size // units.Gi)
+ mock_wait.assert_has_calls(
+ [mock.call(fake_volume, 'creating', 'available'),
+ mock.call(fake_volume, 'extending', 'in-use')])
+ else:
+ fake_volume.extend.assert_called_once_with(
+ fake_volume, expected_volume_size // units.Gi)
+ mock_wait.assert_has_calls(
+ [mock.call(fake_volume, 'creating', 'available'),
+ mock.call(fake_volume, 'extending', 'available')])
def test_cinder_add_extend_storage_full(self):
diff --git a/glance_store/tests/unit/cinder/test_cinder_store.py b/glance_store/tests/unit/cinder/test_cinder_store.py
index a2b5af7..184acde 100644
--- a/glance_store/tests/unit/cinder/test_cinder_store.py
+++ b/glance_store/tests/unit/cinder/test_cinder_store.py
@@ -138,6 +138,9 @@ class TestCinderStore(base.StoreBaseTest,
def test_cinder_add_extend(self):
self._test_cinder_add_extend()
+ def test_cinder_add_extend_online(self):
+ self._test_cinder_add_extend(online=True)
+
def test_cinder_delete(self):
self._test_cinder_delete()
diff --git a/glance_store/tests/unit/cinder/test_multistore_cinder.py b/glance_store/tests/unit/cinder/test_multistore_cinder.py
index 01b27f2..f40965b 100644
--- a/glance_store/tests/unit/cinder/test_multistore_cinder.py
+++ b/glance_store/tests/unit/cinder/test_multistore_cinder.py
@@ -276,6 +276,9 @@ class TestMultiCinderStore(base.MultiStoreBaseTest,
def test_cinder_add_extend(self):
self._test_cinder_add_extend(is_multi_store=True)
+ def test_cinder_add_extend_online(self):
+ self._test_cinder_add_extend(is_multi_store=True, online=True)
+
def test_cinder_delete(self):
self._test_cinder_delete(is_multi_store=True)
diff --git a/glance_store/tests/unit/cinder/test_nfs.py b/glance_store/tests/unit/cinder/test_nfs.py
index d0f7d91..aa040ce 100644
--- a/glance_store/tests/unit/cinder/test_nfs.py
+++ b/glance_store/tests/unit/cinder/test_nfs.py
@@ -91,3 +91,6 @@ class TestNfsBrickConnector(
nfs.mount.umount.assert_called_once_with(
vol_name, mount_path, self.connector.host,
self.connector.root_helper)
+
+ def test_extend_volume(self):
+ self.assertRaises(NotImplementedError, self.connector.extend_volume)
diff --git a/glance_store/tests/unit/test_opts.py b/glance_store/tests/unit/test_opts.py
index bfb9bce..073b782 100644
--- a/glance_store/tests/unit/test_opts.py
+++ b/glance_store/tests/unit/test_opts.py
@@ -84,6 +84,7 @@ class OptsTestCase(base.StoreBaseTest):
'cinder_volume_type',
'cinder_use_multipath',
'cinder_enforce_multipath',
+ 'cinder_do_extend_attached',
'default_swift_reference',
'https_insecure',
'filesystem_store_chunk_size',