def disk_scsi(self, info, disk_unit): # The driver is responsible to create the SCSI controller # at index 0. info.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive() info.device_addr.controller = 0 if disk_unit is not None: # In order to allow up to 256 disks handled by one # virtio-scsi controller, the device addr should be # specified. info.device_addr.unit = disk_unit
def disk_scsi(self, info, disk_unit): # NOTE(melwitt): We set the device address unit number manually in the # case of the virtio-scsi controller, in order to allow attachment of # up to 256 devices. So, we should only be setting the address tag # if we intend to set the unit number. Otherwise, we will let libvirt # handle autogeneration of the address tag. # See https://bugs.launchpad.net/nova/+bug/1792077 for details. if disk_unit is not None: # The driver is responsible to create the SCSI controller # at index 0. info.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive() info.device_addr.controller = 0 # In order to allow up to 256 disks handled by one # virtio-scsi controller, the device addr should be # specified. info.device_addr.unit = disk_unit
def test_update_volume_xml_update_encryption(self): connection_info = { 'driver_volume_type': 'rbd', 'serial': 'd299a078-f0db-4993-bf03-f10fe44fd192', 'data': { 'access_mode': 'rw', 'secret_type': 'ceph', 'name': 'cinder-volumes/volume-d299a078', 'encrypted': False, 'discard': True, 'cluster_name': 'ceph', 'secret_uuid': '1a790a26-dd49-4825-8d16-3dd627cf05a9', 'qos_specs': None, 'auth_enabled': True, 'volume_id': 'd299a078-f0db-4993-bf03-f10fe44fd192', 'hosts': ['172.16.128.101', '172.16.128.121'], 'auth_username': '******', 'ports': ['6789', '6789', '6789'] } } bdm = objects.LibvirtLiveMigrateBDMInfo( serial='d299a078-f0db-4993-bf03-f10fe44fd192', bus='scsi', type='disk', dev='sdb', connection_info=connection_info, encryption_secret_uuid=uuids.encryption_secret_uuid_new) data = objects.LibvirtLiveMigrateData(target_connect_addr=None, bdms=[bdm], block_migration=False) xml = """<domain> <devices> <disk type='network' device='disk'> <driver name='qemu' type='raw' cache='writeback' discard='unmap'/> <auth username='******'> <secret type='ceph' uuid='1a790a26-dd49-4825-8d16-3dd627cf05a9'/> </auth> <source protocol='rbd' name='cinder-volumes/volume-d299a078'> <host name='172.16.128.101' port='6789'/> <host name='172.16.128.121' port='6789'/> </source> <backingStore/> <target dev='sdb' bus='scsi'/> <serial>d299a078-f0db-4993-bf03-f10fe44fd192</serial> <alias name='scsi0-0-0-1'/> <encryption format='luks'> <secret type='passphrase' uuid='%(encryption_secret_uuid)s'/> </encryption> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> </devices> </domain>""" % { 'encryption_secret_uuid': uuids.encryption_secret_uuid_old } conf = vconfig.LibvirtConfigGuestDisk() conf.source_device = bdm.type conf.driver_name = "qemu" conf.driver_format = "raw" conf.driver_cache = "writeback" conf.target_dev = bdm.dev conf.target_bus = bdm.bus conf.serial = bdm.connection_info.get('serial') conf.source_type = "network" conf.driver_discard = 'unmap' conf.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive() conf.device_addr.controller = 0 get_volume_config = mock.MagicMock(return_value=conf) doc = etree.fromstring(xml) res = etree.tostring(migration._update_volume_xml( doc, data, get_volume_config), encoding='unicode') new_xml = xml.replace(uuids.encryption_secret_uuid_old, uuids.encryption_secret_uuid_new) self.assertThat(res, matchers.XMLMatches(new_xml))
def get_config(self, connection_info, disk_info): """Returns xml for libvirt.""" conf = vconfig.LibvirtConfigGuestDisk() conf.driver_name = libvirt_utils.pick_disk_driver_name( self.host.get_version(), self.is_block_dev) conf.source_device = disk_info['type'] conf.driver_format = "raw" conf.driver_cache = "none" conf.target_dev = disk_info['dev'] conf.target_bus = disk_info['bus'] conf.serial = connection_info.get('serial') # Support for block size tuning data = {} if 'data' in connection_info: data = connection_info['data'] if 'logical_block_size' in data: conf.logical_block_size = data['logical_block_size'] if 'physical_block_size' in data: conf.physical_block_size = data['physical_block_size'] # Extract rate_limit control parameters if 'qos_specs' in data and data['qos_specs']: tune_opts = [ 'total_bytes_sec', 'read_bytes_sec', 'write_bytes_sec', 'total_iops_sec', 'read_iops_sec', 'write_iops_sec' ] specs = data['qos_specs'] if isinstance(specs, dict): for k, v in specs.items(): if k in tune_opts: new_key = 'disk_' + k setattr(conf, new_key, v) else: LOG.warning( 'Unknown content in connection_info/' 'qos_specs: %s', specs) # Extract access_mode control parameters if 'access_mode' in data and data['access_mode']: access_mode = data['access_mode'] if access_mode in ('ro', 'rw'): conf.readonly = access_mode == 'ro' else: LOG.error( 'Unknown content in ' 'connection_info/access_mode: %s', access_mode) raise exception.InvalidVolumeAccessMode( access_mode=access_mode) # Configure usage of discard if data.get('discard', False) is True: conf.driver_discard = 'unmap' if disk_info['bus'] == 'scsi': # The driver is responsible to create the SCSI controller # at index 0. conf.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive() conf.device_addr.controller = 0 if 'unit' in disk_info: # In order to allow up to 256 disks handled by one # virtio-scsi controller, the device addr should be # specified. conf.device_addr.unit = disk_info['unit'] if connection_info.get('multiattach', False): # Note that driver_cache should be disabled (none) when using # a shareable disk. conf.shareable = True volume_id = connection_info.get('data', {}).get('volume_id') volume_secret = None if volume_id: volume_secret = self.host.find_secret('volume', volume_id) if volume_secret: conf.encryption = vconfig.LibvirtConfigGuestDiskEncryption() secret = vconfig.LibvirtConfigGuestDiskEncryptionSecret() secret.type = 'passphrase' secret.uuid = volume_secret.UUIDString() conf.encryption.format = 'luks' conf.encryption.secret = secret return conf
def get_config(self, connection_info, disk_info): """Returns xml for libvirt.""" conf = vconfig.LibvirtConfigGuestDisk() conf.source_device = disk_info['type'] conf.driver_format = "raw" conf.driver_cache = "none" conf.target_dev = disk_info['dev'] conf.target_bus = disk_info['bus'] conf.serial = connection_info.get('serial') if CONF.libvirt.virt_type in ('qemu', 'kvm'): # the QEMU backend supports multiple backends, so tell libvirt # which one to use conf.driver_name = 'qemu' # Support for block size tuning data = {} if 'data' in connection_info: data = connection_info['data'] if 'logical_block_size' in data: conf.logical_block_size = data['logical_block_size'] if 'physical_block_size' in data: conf.physical_block_size = data['physical_block_size'] # Extract rate_limit control parameters if 'qos_specs' in data and data['qos_specs']: tune_opts = [ 'total_bytes_sec', 'read_bytes_sec', 'write_bytes_sec', 'total_iops_sec', 'read_iops_sec', 'write_iops_sec', 'read_bytes_sec_max', 'read_iops_sec_max', 'write_bytes_sec_max', 'write_iops_sec_max', 'total_bytes_sec_max', 'total_iops_sec_max', 'size_iops_sec' ] specs = data['qos_specs'] if isinstance(specs, dict): for k, v in specs.items(): if k in tune_opts: new_key = 'disk_' + k setattr(conf, new_key, v) else: LOG.warning( 'Unknown content in connection_info/' 'qos_specs: %s', specs) # Extract access_mode control parameters if 'access_mode' in data and data['access_mode']: access_mode = data['access_mode'] if access_mode in ('ro', 'rw'): conf.readonly = access_mode == 'ro' else: LOG.error( 'Unknown content in ' 'connection_info/access_mode: %s', access_mode) raise exception.InvalidVolumeAccessMode( access_mode=access_mode) # Configure usage of discard if data.get('discard', False) is True: conf.driver_discard = 'unmap' # NOTE(melwitt): We set the device address unit number manually in the # case of the virtio-scsi controller, in order to allow attachment of # up to 256 devices. So, we should only be setting the address tag # if we intend to set the unit number. Otherwise, we will let libvirt # handle autogeneration of the address tag. # See https://bugs.launchpad.net/nova/+bug/1792077 for details. if disk_info['bus'] == 'scsi' and 'unit' in disk_info: # The driver is responsible to create the SCSI controller # at index 0. conf.device_addr = vconfig.LibvirtConfigGuestDeviceAddressDrive() conf.device_addr.controller = 0 # In order to allow up to 256 disks handled by one # virtio-scsi controller, the device addr should be # specified. conf.device_addr.unit = disk_info['unit'] if connection_info.get('multiattach', False): # Note that driver_cache should be disabled (none) when using # a shareable disk. conf.shareable = True volume_id = driver_block_device.get_volume_id(connection_info) volume_secret = None if volume_id: volume_secret = self.host.find_secret('volume', volume_id) if volume_secret: conf.encryption = vconfig.LibvirtConfigGuestDiskEncryption() secret = vconfig.LibvirtConfigGuestDiskEncryptionSecret() secret.type = 'passphrase' secret.uuid = volume_secret.UUIDString() conf.encryption.format = 'luks' conf.encryption.secret = secret return conf