'Test for nova.virt.libvirt.libvirt_driver.LivirtConnection
.migrate_disk_and_power_off.'

@mock.patch('nova.utils.execute')
@mock.patch('nova.virt.libvirt.utils.copy_image')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._destroy')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver.get_host_ip_addr')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_instance_disk_info')
def test_migrate_disk_and_power_off_swap(self, mock_get_disk_info, get_host_ip_addr, mock_destroy, mock_copy_image, mock_execute):

    self.copy_or_move_swap_called = False
    instance = self._create_instance({'flavor': {'root_gb': 10, 'ephemeral_gb': 0}})
    disk_info = list(fake_disk_info_byname(instance).values())
    mock_get_disk_info.return_value = disk_info
    get_host_ip_addr.return_value = '10.0.0.1'
    def fake_copy_image(*args, **kwargs):
        if ('/test/disk.swap' in list(args)):
            self.copy_or_move_swap_called = True
    def fake_execute(*args, **kwargs):
        if set(['mv', '/test/disk.swap']).issubset(list(args)):
            self.copy_or_move_swap_called = True
    mock_copy_image.side_effect = fake_copy_image
    mock_execute.side_effect = fake_execute
    drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
    flavor = {'root_gb': 20, 'ephemeral_gb': 0, 'swap': 1024}
    flavor_obj = objects.Flavor(**flavor)
    out = drvr.migrate_disk_and_power_off(context.get_admin_context(), instance, '10.0.0.1', flavor_obj, None)
    mock_get_disk_info.assert_called_once_with(instance, None)
    self.assertTrue(get_host_ip_addr.called)
    mock_destroy.assert_called_once_with(instance)
    self.assertFalse(self.copy_or_move_swap_called)
    disk_info_text = jsonutils.dumps(disk_info)
    self.assertEqual(disk_info_text, out)
