'Test that unencrypted volumes are not disconnected with dmcrypt.'

@mock.patch('os.path.getsize', return_value=0)
@mock.patch('nova.virt.libvirt.storage.lvm.get_volume_size', return_value='fake-size')
def test_detach_encrypted_volumes(self, mock_get_volume_size, mock_getsize):

    instance = objects.Instance(**self.test_instance)
    xml = "\n                                                        <domain    type='kvm'>\n                                                                        <devices>\n                                                                                        <disk    type='file'>\n                                                                                                        <driver    name='fake-driver'    type='fake-type'    />\n                                                                                                        <source    file='filename'/>\n                                                                                                        <target    dev='vdc'    bus='virtio'/>\n                                                                                        </disk>\n                                                                                        <disk    type='block'    device='disk'>\n                                                                                                        <driver    name='fake-driver'    type='fake-type'    />\n                                                                                                        <source    dev='/dev/mapper/disk'/>\n                                                                                                        <target    dev='vda'/>\n                                                                                        </disk>\n                                                                                        <disk    type='block'    device='disk'>\n                                                                                                        <driver    name='fake-driver'    type='fake-type'    />\n                                                                                                        <source    dev='/dev/mapper/swap'/>\n                                                                                                        <target    dev='vdb'/>\n                                                                                        </disk>\n                                                                        </devices>\n                                                        </domain>\n                                                        "
    dom = FakeVirtDomain(fake_xml=xml)
    instance.ephemeral_key_uuid = uuids.ephemeral_key_uuid
    conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
    @mock.patch.object(dmcrypt, 'delete_volume')
    @mock.patch.object(conn._host, 'get_domain', return_value=dom)
    def detach_encrypted_volumes(block_device_info, mock_get_domain, mock_delete_volume):
        conn._detach_encrypted_volumes(instance, block_device_info)
        mock_get_domain.assert_called_once_with(instance)
        self.assertFalse(mock_delete_volume.called)
    block_device_info = {'root_device_name': '/dev/vda', 'ephemerals': [], 'block_device_mapping': []}
    detach_encrypted_volumes(block_device_info)
