def test_libvirt_quobyte_driver_qcow2(self, mock_mount_volume, mock_validate_volume, mock_umount): mnt_base = '/mnt' self.flags(quobyte_mount_point_base=mnt_base, group='libvirt') libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_host) export_string = 'quobyte://192.168.1.1/volume-00001' name = 'volume-00001' image_format = 'qcow2' quobyte_volume = '192.168.1.1/volume-00001' connection_info = {'data': {'export': export_string, 'name': name, 'format': image_format}} export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(quobyte_volume)) mock_validate_volume.side_effect = [nova_exception.StaleVolumeMount( "This shall fail."), True, True] libvirt_driver.connect_volume(connection_info, mock.sentinel.instance) conf = libvirt_driver.get_config(connection_info, self.disk_info) tree = conf.format_dom() self.assertEqual('file', tree.get('type')) self.assertEqual('qcow2', tree.find('./driver').get('type')) (mock_mount_volume. assert_called_once_with('192.168.1.1/volume-00001', export_mnt_base, mock.ANY)) mock_validate_volume.assert_called_with(export_mnt_base) libvirt_driver.disconnect_volume(connection_info, mock.sentinel.instance) mock_umount.assert_has_calls([mock.call(export_mnt_base), mock.call(export_mnt_base)])
def validate_volume(mount_path): """Determine if the volume is a valid Quobyte mount. Runs a number of tests to be sure this is a (working) Quobyte mount """ partitions = psutil.disk_partitions(all=True) for p in partitions: if mount_path != p.mountpoint: continue if p.device.startswith("quobyte@") or p.fstype == "fuse.quobyte": statresult = os.stat(mount_path) # Note(kaisers): Quobyte always shows mount points with size 0 if statresult.st_size == 0: # client looks healthy return # we're happy here else: msg = (_("The mount %(mount_path)s is not a " "valid Quobyte volume. Stale mount?") % { 'mount_path': mount_path }) raise nova_exception.StaleVolumeMount(msg, mount_path=mount_path) else: msg = (_("The mount %(mount_path)s is not a valid " "Quobyte volume according to partition list.") % { 'mount_path': mount_path }) raise nova_exception.InvalidVolume(msg) msg = (_("No matching Quobyte mount entry for %(mount_path)s" " could be found for validation in partition list.") % { 'mount_path': mount_path }) raise nova_exception.InvalidVolume(msg)
def test_libvirt_quobyte_driver_mount(self, mock_is_mounted, mock_mount_volume, mock_validate_volume, mock_umount_volume ): mnt_base = '/mnt' self.flags(quobyte_mount_point_base=mnt_base, group='libvirt') libvirt_driver = quobyte.LibvirtQuobyteVolumeDriver(self.fake_host) export_string = 'quobyte://192.168.1.1/volume-00001' quobyte_volume = '192.168.1.1/volume-00001' export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(quobyte_volume)) file_path = os.path.join(export_mnt_base, self.name) connection_info = {'data': {'export': export_string, 'name': self.name}} mock_validate_volume.side_effect = [nova_exception.StaleVolumeMount( "This shall fail."), True, True] libvirt_driver.connect_volume(connection_info, mock.sentinel.instance) conf = libvirt_driver.get_config(connection_info, self.disk_info) tree = conf.format_dom() self._assertFileTypeEquals(tree, file_path) mock_mount_volume.assert_called_once_with(quobyte_volume, export_mnt_base, mock.ANY) mock_validate_volume.assert_called_with(export_mnt_base) mock_umount_volume.assert_called_once_with( libvirt_driver._get_mount_path(connection_info))