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

def _test_finish_revert_migration(self, power_on):

    powered_on = power_on
    self.fake_create_domain_called = False
    def fake_execute(*args, **kwargs):
        pass
    def fake_plug_vifs(instance, network_info):
        pass
    def fake_create_domain(context, xml, instance, network_info, block_device_info=None, power_on=None, vifs_already_plugged=None):
        self.fake_create_domain_called = True
        self.assertEqual(powered_on, power_on)
        self.assertTrue(vifs_already_plugged)
        return mock.MagicMock()
    def fake_enable_hairpin():
        pass
    def fake_get_info(instance):
        if powered_on:
            return hardware.InstanceInfo(state=power_state.RUNNING)
        else:
            return hardware.InstanceInfo(state=power_state.SHUTDOWN)
    def fake_to_xml(context, instance, network_info, disk_info, image_meta=None, rescue=None, block_device_info=None):
        return ''
    self.stubs.Set(self.drvr, '_get_guest_xml', fake_to_xml)
    self.stubs.Set(self.drvr, 'plug_vifs', fake_plug_vifs)
    self.stubs.Set(utils, 'execute', fake_execute)
    fw = base_firewall.NoopFirewallDriver()
    self.stubs.Set(self.drvr, 'firewall_driver', fw)
    self.stubs.Set(self.drvr, '_create_domain_and_network', fake_create_domain)
    self.stubs.Set(nova.virt.libvirt.guest.Guest, 'enable_hairpin', fake_enable_hairpin)
    self.stubs.Set(self.drvr, 'get_info', fake_get_info)
    self.stubs.Set(utils, 'get_image_from_system_metadata', (lambda *a: self.test_image_meta))
    with utils.tempdir() as tmpdir:
        self.flags(instances_path=tmpdir)
        ins_ref = self._create_instance()
        os.mkdir(os.path.join(tmpdir, ins_ref['name']))
        libvirt_xml_path = os.path.join(tmpdir, ins_ref['name'], 'libvirt.xml')
        f = open(libvirt_xml_path, 'w')
        f.close()
        self.drvr.finish_revert_migration(context.get_admin_context(), ins_ref, [], None, power_on)
        self.assertTrue(self.fake_create_domain_called)
