Skip to content

Commit 656aa1c

Browse files
committed
Fixes multi-registry config in Quobyte driver
This closes a bug concerning multi-registry configurations for Quobyte volumes due to no longer using the is_mounted() method that failed in that case. Besides, this adds exception handling for the unmount call that is issued on trying to mount an already mounted volume. NOTE: The original commit also added a new feature (fs type based validation) which is omitted in this backport. Closes-Bug: #1737131 Change-Id: Ia5a23ce1123a68608ee2ec6f2ac5dca02da67c59 (cherry picked from commit 05a73c0)
1 parent b11dd79 commit 656aa1c

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
lines changed

nova/exception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ class InvalidVolumeAccessMode(Invalid):
354354
msg_fmt = _("Invalid volume access mode: %(access_mode)s")
355355

356356

357+
class StaleVolumeMount(InvalidVolume):
358+
msg_fmt = _("The volume mount at %(mount_path)s is unusable.")
359+
360+
357361
class InvalidMetadata(Invalid):
358362
msg_fmt = _("Invalid metadata: %(reason)s")
359363

nova/tests/unit/virt/libvirt/volume/test_quobyte.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,15 @@ class LibvirtQuobyteVolumeDriverTestCase(
293293
test_volume.LibvirtVolumeBaseTestCase):
294294
"""Tests the LibvirtQuobyteVolumeDriver class."""
295295

296+
@mock.patch.object(quobyte, 'umount_volume')
296297
@mock.patch.object(quobyte, 'validate_volume')
297298
@mock.patch.object(quobyte, 'mount_volume')
298299
@mock.patch.object(libvirt_utils, 'is_mounted', return_value=False)
299300
def test_libvirt_quobyte_driver_mount(self,
300301
mock_is_mounted,
301302
mock_mount_volume,
302-
mock_validate_volume
303+
mock_validate_volume,
304+
mock_umount_volume
303305
):
304306
mnt_base = '/mnt'
305307
self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')
@@ -313,6 +315,9 @@ def test_libvirt_quobyte_driver_mount(self,
313315

314316
connection_info = {'data': {'export': export_string,
315317
'name': self.name}}
318+
mock_validate_volume.side_effect = [nova_exception.StaleVolumeMount(
319+
"This shall fail."), True, True]
320+
316321
libvirt_driver.connect_volume(connection_info, mock.sentinel.instance)
317322

318323
conf = libvirt_driver.get_config(connection_info, self.disk_info)
@@ -324,12 +329,12 @@ def test_libvirt_quobyte_driver_mount(self,
324329
export_mnt_base,
325330
mock.ANY)
326331
mock_validate_volume.assert_called_with(export_mnt_base)
332+
mock_umount_volume.assert_called_once_with(
333+
libvirt_driver._get_mount_path(connection_info))
327334

328-
@mock.patch.object(quobyte, 'validate_volume')
335+
@mock.patch.object(quobyte, 'validate_volume', return_value=True)
329336
@mock.patch.object(quobyte, 'umount_volume')
330-
@mock.patch.object(libvirt_utils, 'is_mounted', return_value=True)
331-
def test_libvirt_quobyte_driver_umount(self, mock_is_mounted,
332-
mock_umount_volume,
337+
def test_libvirt_quobyte_driver_umount(self, mock_umount_volume,
333338
mock_validate_volume):
334339
mnt_base = '/mnt'
335340
self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')
@@ -352,7 +357,9 @@ def test_libvirt_quobyte_driver_umount(self, mock_is_mounted,
352357
libvirt_driver.disconnect_volume(connection_info,
353358
mock.sentinel.instance)
354359

355-
mock_validate_volume.assert_called_once_with(export_mnt_base)
360+
mock_validate_volume.assert_has_calls([mock.call(export_mnt_base),
361+
mock.call(export_mnt_base),
362+
mock.call(export_mnt_base)])
356363
mock_umount_volume.assert_called_once_with(export_mnt_base)
357364

358365
@mock.patch.object(quobyte, 'validate_volume')
@@ -385,15 +392,14 @@ def test_libvirt_quobyte_driver_already_mounted(self,
385392
mock.sentinel.instance)
386393

387394
mock_umount_volume.assert_called_once_with(export_mnt_base)
388-
mock_validate_volume.assert_called_once_with(export_mnt_base)
395+
mock_validate_volume.assert_has_calls([mock.call(export_mnt_base),
396+
mock.call(export_mnt_base)])
389397

398+
@mock.patch.object(quobyte, 'umount_volume')
390399
@mock.patch.object(quobyte, 'validate_volume')
391400
@mock.patch.object(quobyte, 'mount_volume')
392-
@mock.patch.object(libvirt_utils, 'is_mounted', return_value=False)
393-
def test_libvirt_quobyte_driver_qcow2(self, mock_is_mounted,
394-
mock_mount_volume,
395-
mock_validate_volume
396-
):
401+
def test_libvirt_quobyte_driver_qcow2(self, mock_mount_volume,
402+
mock_validate_volume, mock_umount):
397403
mnt_base = '/mnt'
398404
self.flags(quobyte_mount_point_base=mnt_base, group='libvirt')
399405
libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_host)
@@ -408,6 +414,8 @@ def test_libvirt_quobyte_driver_qcow2(self, mock_is_mounted,
408414

409415
export_mnt_base = os.path.join(mnt_base,
410416
utils.get_hash_str(quobyte_volume))
417+
mock_validate_volume.side_effect = [nova_exception.StaleVolumeMount(
418+
"This shall fail."), True, True]
411419

412420
libvirt_driver.connect_volume(connection_info, mock.sentinel.instance)
413421
conf = libvirt_driver.get_config(connection_info, self.disk_info)
@@ -423,6 +431,8 @@ def test_libvirt_quobyte_driver_qcow2(self, mock_is_mounted,
423431

424432
libvirt_driver.disconnect_volume(connection_info,
425433
mock.sentinel.instance)
434+
mock_umount.assert_has_calls([mock.call(export_mnt_base),
435+
mock.call(export_mnt_base)])
426436

427437
@mock.patch.object(libvirt_utils, 'is_mounted', return_value=True)
428438
def test_libvirt_quobyte_driver_mount_non_quobyte_volume(self,

nova/virt/libvirt/volume/quobyte.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# License for the specific language governing permissions and limitations
1414
# under the License.
1515

16-
import errno
1716
import os
1817

1918
from oslo_concurrency import processutils
@@ -26,7 +25,6 @@
2625
from nova import exception as nova_exception
2726
from nova.i18n import _
2827
from nova import utils
29-
from nova.virt.libvirt import utils as libvirt_utils
3028
from nova.virt.libvirt.volume import fs
3129

3230
LOG = logging.getLogger(__name__)
@@ -75,7 +73,10 @@ def umount_volume(mnt_base):
7573

7674

7775
def validate_volume(mount_path):
78-
"""Runs a number of tests to be sure this is a (working) Quobyte mount"""
76+
"""Determine if the volume is a valid Quobyte mount.
77+
78+
Runs a number of tests to be sure this is a (working) Quobyte mount
79+
"""
7980
partitions = psutil.disk_partitions(all=True)
8081
for p in partitions:
8182
if mount_path != p.mountpoint:
@@ -90,10 +91,10 @@ def validate_volume(mount_path):
9091
msg = (_("The mount %(mount_path)s is not a "
9192
"valid Quobyte volume. Stale mount?")
9293
% {'mount_path': mount_path})
93-
raise nova_exception.InvalidVolume(msg)
94+
raise nova_exception.StaleVolumeMount(msg, mount_path=mount_path)
9495
else:
95-
msg = (_("The mount %(mount_path)s is not a valid"
96-
" Quobyte volume according to partition list.")
96+
msg = (_("The mount %(mount_path)s is not a valid "
97+
"Quobyte volume according to partition list.")
9798
% {'mount_path': mount_path})
9899
raise nova_exception.InvalidVolume(msg)
99100
msg = (_("No matching Quobyte mount entry for %(mount_path)s"
@@ -128,39 +129,40 @@ def connect_volume(self, connection_info, instance):
128129
data = connection_info['data']
129130
quobyte_volume = self._normalize_export(data['export'])
130131
mount_path = self._get_mount_path(connection_info)
131-
mounted = libvirt_utils.is_mounted(mount_path,
132-
SOURCE_PROTOCOL
133-
+ '@' + quobyte_volume)
134-
if mounted:
135-
try:
136-
os.stat(mount_path)
137-
except OSError as exc:
138-
if exc.errno == errno.ENOTCONN:
139-
mounted = False
140-
LOG.info('Fixing previous mount %s which was not'
141-
' unmounted correctly.', mount_path)
142-
umount_volume(mount_path)
132+
try:
133+
validate_volume(mount_path)
134+
mounted = True
135+
except nova_exception.StaleVolumeMount:
136+
mounted = False
137+
LOG.info('Fixing previous mount %s which was not '
138+
'unmounted correctly.', mount_path)
139+
umount_volume(mount_path)
140+
except nova_exception.InvalidVolume:
141+
mounted = False
143142

144143
if not mounted:
145144
mount_volume(quobyte_volume,
146145
mount_path,
147146
CONF.libvirt.quobyte_client_cfg)
148147

149-
validate_volume(mount_path)
148+
try:
149+
validate_volume(mount_path)
150+
except (nova_exception.InvalidVolume,
151+
nova_exception.StaleVolumeMount) as nex:
152+
LOG.error("Could not mount Quobyte volume: %s", nex)
150153

151154
@utils.synchronized('connect_qb_volume')
152155
def disconnect_volume(self, connection_info, instance):
153156
"""Disconnect the volume."""
154157

155-
quobyte_volume = self._normalize_export(
156-
connection_info['data']['export'])
157158
mount_path = self._get_mount_path(connection_info)
158-
159-
if libvirt_utils.is_mounted(mount_path, 'quobyte@' + quobyte_volume):
160-
umount_volume(mount_path)
159+
try:
160+
validate_volume(mount_path)
161+
except (nova_exception.InvalidVolume,
162+
nova_exception.StaleVolumeMount) as exc:
163+
LOG.warning("Could not disconnect Quobyte volume mount: %s", exc)
161164
else:
162-
LOG.info("Trying to disconnected unmounted volume at %s",
163-
mount_path)
165+
umount_volume(mount_path)
164166

165167
def _normalize_export(self, export):
166168
protocol = SOURCE_PROTOCOL + "://"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes a bug that caused Nova to fail on mounting Quobyte volumes
5+
whose volume URL contained multiple registries.

0 commit comments

Comments
 (0)