'If the swapped volume is type="block", make sure that we give
libvirt the correct VIR_DOMAIN_BLOCK_REBASE_COPY_DEV flag to ensure the
correct type="block" XML is generated (bug 1691195)'

@mock.patch('nova.virt.libvirt.guest.BlockDevice.is_job_complete')
def test_swap_volume_block(self, mock_is_job_complete):

    drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI())
    mock_dom = mock.MagicMock()
    guest = libvirt_guest.Guest(mock_dom)
    with mock.patch.object(drvr._conn, 'defineXML', create=True) as mock_define:
        xmldoc = '<domain/>'
        srcfile = '/first/path'
        dstfile = '/second/path'
        mock_dom.XMLDesc.return_value = xmldoc
        mock_dom.isPersistent.return_value = True
        mock_is_job_complete.return_value = True
        drvr._swap_volume(guest, srcfile, mock.MagicMock(source_type='block', source_path=dstfile), 1)
        mock_dom.XMLDesc.assert_called_once_with(flags=(fakelibvirt.VIR_DOMAIN_XML_INACTIVE | fakelibvirt.VIR_DOMAIN_XML_SECURE))
        mock_dom.blockRebase.assert_called_once_with(srcfile, dstfile, 0, flags=((fakelibvirt.VIR_DOMAIN_BLOCK_REBASE_COPY | fakelibvirt.VIR_DOMAIN_BLOCK_REBASE_COPY_DEV) | fakelibvirt.VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT))
        mock_dom.blockResize.assert_called_once_with(srcfile, ((1 * units.Gi) / units.Ki))
        mock_define.assert_called_once_with(xmldoc)
