Coverage for nova/virt/libvirt/volume/iscsi.py: 82%

43 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +0000

1# Licensed under the Apache License, Version 2.0 (the "License"); you may 

2# not use this file except in compliance with the License. You may obtain 

3# a copy of the License at 

4# 

5# http://www.apache.org/licenses/LICENSE-2.0 

6# 

7# Unless required by applicable law or agreed to in writing, software 

8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

10# License for the specific language governing permissions and limitations 

11# under the License. 

12"""Libvirt volume driver for iSCSI""" 

13 

14from os_brick import exception as os_brick_exception 

15from os_brick import initiator 

16from os_brick.initiator import connector 

17from oslo_log import log as logging 

18 

19import nova.conf 

20from nova import utils 

21from nova.virt.libvirt.volume import volume as libvirt_volume 

22 

23LOG = logging.getLogger(__name__) 

24 

25CONF = nova.conf.CONF 

26 

27 

28class LibvirtISCSIVolumeDriver(libvirt_volume.LibvirtBaseVolumeDriver): 

29 """Driver to attach Network volumes to libvirt.""" 

30 

31 def __init__(self, host): 

32 super(LibvirtISCSIVolumeDriver, self).__init__(host, 

33 is_block_dev=True) 

34 

35 # Call the factory here so we can support 

36 # more than x86 architectures. 

37 self.connector = connector.InitiatorConnector.factory( 

38 initiator.ISCSI, utils.get_root_helper(), 

39 use_multipath=CONF.libvirt.volume_use_multipath, 

40 device_scan_attempts=CONF.libvirt.num_volume_scan_tries, 

41 transport=self._get_transport(), 

42 enforce_multipath=CONF.libvirt.volume_enforce_multipath) 

43 

44 def _get_transport(self): 

45 if CONF.libvirt.iscsi_iface: 45 ↛ 46line 45 didn't jump to line 46 because the condition on line 45 was never true

46 transport = CONF.libvirt.iscsi_iface 

47 else: 

48 transport = 'default' 

49 

50 return transport 

51 

52 def get_config(self, connection_info, disk_info): 

53 """Returns xml for libvirt.""" 

54 conf = super(LibvirtISCSIVolumeDriver, 

55 self).get_config(connection_info, disk_info) 

56 conf.source_type = "block" 

57 conf.source_path = connection_info['data']['device_path'] 

58 conf.driver_io = "native" 

59 return conf 

60 

61 def connect_volume(self, connection_info, instance): 

62 """Attach the volume to instance_name.""" 

63 

64 LOG.debug("Calling os-brick to attach iSCSI Volume", instance=instance) 

65 device_info = self.connector.connect_volume(connection_info['data']) 

66 LOG.debug("Attached iSCSI volume %s", device_info, instance=instance) 

67 

68 connection_info['data']['device_path'] = device_info['path'] 

69 

70 def disconnect_volume(self, connection_info, instance, force=False): 

71 """Detach the volume from instance_name.""" 

72 

73 LOG.debug("calling os-brick to detach iSCSI Volume", instance=instance) 

74 try: 

75 self.connector.disconnect_volume( 

76 connection_info['data'], None, force=force) 

77 except os_brick_exception.VolumeDeviceNotFound as exc: 

78 LOG.warning('Ignoring VolumeDeviceNotFound: %s', exc) 

79 return 

80 LOG.debug("Disconnected iSCSI Volume", instance=instance) 

81 

82 super(LibvirtISCSIVolumeDriver, 

83 self).disconnect_volume(connection_info, instance, force=force) 

84 

85 def extend_volume(self, connection_info, instance, requested_size): 

86 """Extend the volume.""" 

87 LOG.debug("calling os-brick to extend iSCSI Volume", instance=instance) 

88 new_size = self.connector.extend_volume(connection_info['data']) 

89 LOG.debug("Extend iSCSI Volume: new_size=%s", 

90 new_size, instance=instance) 

91 return new_size