summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2018-08-14 08:27:20 -0700
committerDan Smith <dansmith@redhat.com>2018-08-14 08:27:20 -0700
commitdee99b1ed03de4b6ded94f3cf6d2ea7214bca93b (patch)
treedb5c4bd3eceddb8baabc326ad32f5f59790dc621
parentff200e12ef5d61023f94d0e0bab0a0b97a266a98 (diff)
Revert "libvirt: slow live-migration to ensure network is ready"stable/queens
Notes
Notes (review): Code-Review+2: Matt Riedemann <mriedem.os@gmail.com> Code-Review+2: Lee Yarwood <lyarwood@redhat.com> Workflow+1: Lee Yarwood <lyarwood@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 15 Aug 2018 17:32:02 +0000 Reviewed-on: https://review.openstack.org/591761 Project: openstack/nova Branch: refs/heads/stable/queens
-rw-r--r--nova/tests/unit/virt/libvirt/test_driver.py213
-rw-r--r--nova/tests/unit/virt/test_virt_drivers.py2
-rw-r--r--nova/virt/libvirt/driver.py80
3 files changed, 31 insertions, 264 deletions
diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py
index d37c5a6..81b6aaa 100644
--- a/nova/tests/unit/virt/libvirt/test_driver.py
+++ b/nova/tests/unit/virt/libvirt/test_driver.py
@@ -9034,7 +9034,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9034 vdmock = self.mox.CreateMock(fakelibvirt.virDomain) 9034 vdmock = self.mox.CreateMock(fakelibvirt.virDomain)
9035 guest = libvirt_guest.Guest(vdmock) 9035 guest = libvirt_guest.Guest(vdmock)
9036 self.mox.StubOutWithMock(vdmock, "migrateToURI2") 9036 self.mox.StubOutWithMock(vdmock, "migrateToURI2")
9037 _bandwidth = libvirt_driver.MIN_MIGRATION_SPEED_BW 9037 _bandwidth = CONF.libvirt.live_migration_bandwidth
9038 vdmock.XMLDesc(flags=fakelibvirt.VIR_DOMAIN_XML_MIGRATABLE).AndReturn( 9038 vdmock.XMLDesc(flags=fakelibvirt.VIR_DOMAIN_XML_MIGRATABLE).AndReturn(
9039 initial_xml) 9039 initial_xml)
9040 vdmock.migrateToURI2(drvr._live_migration_uri('dest'), 9040 vdmock.migrateToURI2(drvr._live_migration_uri('dest'),
@@ -9056,8 +9056,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9056 self.assertRaises(fakelibvirt.libvirtError, 9056 self.assertRaises(fakelibvirt.libvirtError,
9057 drvr._live_migration_operation, 9057 drvr._live_migration_operation,
9058 self.context, instance_ref, 'dest', 9058 self.context, instance_ref, 'dest',
9059 False, migrate_data, guest, [], 9059 False, migrate_data, guest, [])
9060 _bandwidth)
9061 9060
9062 def test_live_migration_parallels_no_new_xml(self): 9061 def test_live_migration_parallels_no_new_xml(self):
9063 self.flags(virt_type='parallels', group='libvirt') 9062 self.flags(virt_type='parallels', group='libvirt')
@@ -9072,14 +9071,12 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9072 block_migration=False) 9071 block_migration=False)
9073 dom_mock = mock.MagicMock() 9072 dom_mock = mock.MagicMock()
9074 guest = libvirt_guest.Guest(dom_mock) 9073 guest = libvirt_guest.Guest(dom_mock)
9075 _bandwidth = libvirt_driver.MIN_MIGRATION_SPEED_BW
9076 drvr._live_migration_operation(self.context, instance, 'dest', 9074 drvr._live_migration_operation(self.context, instance, 'dest',
9077 False, migrate_data, guest, [], 9075 False, migrate_data, guest, [])
9078 bandwidth=_bandwidth)
9079 # when new xml is not passed we fall back to migrateToURI 9076 # when new xml is not passed we fall back to migrateToURI
9080 dom_mock.migrateToURI.assert_called_once_with( 9077 dom_mock.migrateToURI.assert_called_once_with(
9081 drvr._live_migration_uri('dest'), 9078 drvr._live_migration_uri('dest'),
9082 flags=0, bandwidth=_bandwidth) 9079 flags=0, bandwidth=0)
9083 9080
9084 @mock.patch.object(utils, 'spawn') 9081 @mock.patch.object(utils, 'spawn')
9085 @mock.patch.object(host.Host, 'get_guest') 9082 @mock.patch.object(host.Host, 'get_guest')
@@ -9101,13 +9098,10 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9101 'power_state': power_state.RUNNING, 9098 'power_state': power_state.RUNNING,
9102 'vm_state': vm_states.ACTIVE}) 9099 'vm_state': vm_states.ACTIVE})
9103 instance = objects.Instance(**instance_dict) 9100 instance = objects.Instance(**instance_dict)
9104 instance.info_cache = objects.InstanceInfoCache(
9105 network_info=_fake_network_info(self, 1))
9106 migrate_data = objects.LibvirtLiveMigrateData( 9101 migrate_data = objects.LibvirtLiveMigrateData(
9107 block_migration=True) 9102 block_migration=True)
9108 dom = fakelibvirt.Domain(drvr._get_connection(), '<domain/>', True) 9103 dom = fakelibvirt.Domain(drvr._get_connection(), '<domain/>', True)
9109 guest = libvirt_guest.Guest(dom) 9104 guest = libvirt_guest.Guest(dom)
9110 guest.migrate_configure_max_speed = mock.MagicMock()
9111 mock_guest.return_value = guest 9105 mock_guest.return_value = guest
9112 drvr._live_migration(self.context, instance, 'dest', 9106 drvr._live_migration(self.context, instance, 'dest',
9113 lambda: None, lambda: None, True, 9107 lambda: None, lambda: None, True,
@@ -9116,9 +9110,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9116 mock_thread.assert_called_once_with( 9110 mock_thread.assert_called_once_with(
9117 drvr._live_migration_operation, 9111 drvr._live_migration_operation,
9118 self.context, instance, 'dest', True, 9112 self.context, instance, 'dest', True,
9119 migrate_data, guest, [], libvirt_driver.MIN_MIGRATION_SPEED_BW) 9113 migrate_data, guest, [])
9120 guest.migrate_configure_max_speed.assert_called_once_with(
9121 CONF.libvirt.live_migration_bandwidth)
9122 9114
9123 def test_live_migration_update_volume_xml(self): 9115 def test_live_migration_update_volume_xml(self):
9124 self.compute = manager.ComputeManager() 9116 self.compute = manager.ComputeManager()
@@ -9170,8 +9162,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9170 test_mock.XMLDesc.return_value = target_xml 9162 test_mock.XMLDesc.return_value = target_xml
9171 self.assertFalse(drvr._live_migration_operation( 9163 self.assertFalse(drvr._live_migration_operation(
9172 self.context, instance_ref, 'dest', False, 9164 self.context, instance_ref, 'dest', False,
9173 migrate_data, guest, [], 9165 migrate_data, guest, []))
9174 libvirt_driver.MIN_MIGRATION_SPEED_BW))
9175 mupdate.assert_called_once_with( 9166 mupdate.assert_called_once_with(
9176 guest, migrate_data, mock.ANY) 9167 guest, migrate_data, mock.ANY)
9177 9168
@@ -9211,7 +9202,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9211 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) 9202 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
9212 test_mock = mock.MagicMock() 9203 test_mock = mock.MagicMock()
9213 guest = libvirt_guest.Guest(test_mock) 9204 guest = libvirt_guest.Guest(test_mock)
9214 _bandwidth = libvirt_driver.MIN_MIGRATION_SPEED_BW
9215 9205
9216 with mock.patch.object(libvirt_migrate, 9206 with mock.patch.object(libvirt_migrate,
9217 'get_updated_guest_xml') as mupdate: 9207 'get_updated_guest_xml') as mupdate:
@@ -9219,11 +9209,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9219 test_mock.XMLDesc.return_value = target_xml 9209 test_mock.XMLDesc.return_value = target_xml
9220 drvr._live_migration_operation(self.context, instance_ref, 9210 drvr._live_migration_operation(self.context, instance_ref,
9221 'dest', False, migrate_data, 9211 'dest', False, migrate_data,
9222 guest, [], _bandwidth) 9212 guest, [])
9223 test_mock.migrateToURI2.assert_called_once_with( 9213 test_mock.migrateToURI2.assert_called_once_with(
9224 'qemu+tcp://127.0.0.2/system', 9214 'qemu+tcp://127.0.0.2/system',
9225 miguri='tcp://127.0.0.2', 9215 miguri='tcp://127.0.0.2',
9226 dxml=mupdate(), flags=0, bandwidth=_bandwidth) 9216 dxml=mupdate(), flags=0, bandwidth=0)
9227 9217
9228 def test_update_volume_xml(self): 9218 def test_update_volume_xml(self):
9229 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) 9219 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
@@ -9488,7 +9478,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9488 mock_migrate.side_effect = fakelibvirt.libvirtError("ERR") 9478 mock_migrate.side_effect = fakelibvirt.libvirtError("ERR")
9489 9479
9490 # start test 9480 # start test
9491 bandwidth = libvirt_driver.MIN_MIGRATION_SPEED_BW 9481 bandwidth = CONF.libvirt.live_migration_bandwidth
9492 migrate_data = objects.LibvirtLiveMigrateData( 9482 migrate_data = objects.LibvirtLiveMigrateData(
9493 graphics_listen_addr_vnc='10.0.0.1', 9483 graphics_listen_addr_vnc='10.0.0.1',
9494 graphics_listen_addr_spice='10.0.0.2', 9484 graphics_listen_addr_spice='10.0.0.2',
@@ -9503,8 +9493,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9503 self.assertRaises(fakelibvirt.libvirtError, 9493 self.assertRaises(fakelibvirt.libvirtError,
9504 drvr._live_migration_operation, 9494 drvr._live_migration_operation,
9505 self.context, instance_ref, 'dest', 9495 self.context, instance_ref, 'dest',
9506 False, migrate_data, guest, [], 9496 False, migrate_data, guest, [])
9507 bandwidth=bandwidth)
9508 mock_xml.assert_called_once_with( 9497 mock_xml.assert_called_once_with(
9509 flags=fakelibvirt.VIR_DOMAIN_XML_MIGRATABLE) 9498 flags=fakelibvirt.VIR_DOMAIN_XML_MIGRATABLE)
9510 mock_migrate.assert_called_once_with( 9499 mock_migrate.assert_called_once_with(
@@ -9536,8 +9525,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9536 self.assertRaises(exception.MigrationError, 9525 self.assertRaises(exception.MigrationError,
9537 drvr._live_migration_operation, 9526 drvr._live_migration_operation,
9538 self.context, instance_ref, 'dest', 9527 self.context, instance_ref, 'dest',
9539 False, migrate_data, guest, [], 9528 False, migrate_data, guest, [])
9540 bandwidth=libvirt_driver.MIN_MIGRATION_SPEED_BW)
9541 9529
9542 @mock.patch.object(host.Host, 'has_min_version', return_value=True) 9530 @mock.patch.object(host.Host, 'has_min_version', return_value=True)
9543 @mock.patch.object(fakelibvirt.virDomain, "migrateToURI3") 9531 @mock.patch.object(fakelibvirt.virDomain, "migrateToURI3")
@@ -9552,7 +9540,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9552 disk_paths = ['vda', 'vdb'] 9540 disk_paths = ['vda', 'vdb']
9553 params = { 9541 params = {
9554 'migrate_disks': ['vda', 'vdb'], 9542 'migrate_disks': ['vda', 'vdb'],
9555 'bandwidth': libvirt_driver.MIN_MIGRATION_SPEED_BW, 9543 'bandwidth': CONF.libvirt.live_migration_bandwidth,
9556 'destination_xml': '', 9544 'destination_xml': '',
9557 } 9545 }
9558 mock_migrateToURI3.side_effect = fakelibvirt.libvirtError("ERR") 9546 mock_migrateToURI3.side_effect = fakelibvirt.libvirtError("ERR")
@@ -9574,8 +9562,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9574 self.assertRaises(fakelibvirt.libvirtError, 9562 self.assertRaises(fakelibvirt.libvirtError,
9575 drvr._live_migration_operation, 9563 drvr._live_migration_operation,
9576 self.context, instance, 'dest', 9564 self.context, instance, 'dest',
9577 False, migrate_data, guest, disk_paths, 9565 False, migrate_data, guest, disk_paths)
9578 libvirt_driver.MIN_MIGRATION_SPEED_BW)
9579 mock_migrateToURI3.assert_called_once_with( 9566 mock_migrateToURI3.assert_called_once_with(
9580 drvr._live_migration_uri('dest'), 9567 drvr._live_migration_uri('dest'),
9581 params=params, flags=0) 9568 params=params, flags=0)
@@ -9600,15 +9587,14 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9600 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) 9587 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
9601 drvr._parse_migration_flags() 9588 drvr._parse_migration_flags()
9602 9589
9603 _bandwidth = libvirt_driver.MIN_MIGRATION_SPEED_BW
9604 instance = objects.Instance(**self.test_instance) 9590 instance = objects.Instance(**self.test_instance)
9605 drvr._live_migration_operation(self.context, instance, 'dest', 9591 drvr._live_migration_operation(self.context, instance, 'dest',
9606 True, migrate_data, guest, 9592 True, migrate_data, guest,
9607 device_names, _bandwidth) 9593 device_names)
9608 9594
9609 params = { 9595 params = {
9610 'migrate_disks': device_names, 9596 'migrate_disks': device_names,
9611 'bandwidth': _bandwidth, 9597 'bandwidth': CONF.libvirt.live_migration_bandwidth,
9612 'destination_xml': '<xml/>', 9598 'destination_xml': '<xml/>',
9613 } 9599 }
9614 mock_migrateToURI3.assert_called_once_with( 9600 mock_migrateToURI3.assert_called_once_with(
@@ -9647,9 +9633,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9647 self.flags(live_migration_tunnelled=True, group='libvirt') 9633 self.flags(live_migration_tunnelled=True, group='libvirt')
9648 # Preparing mocks 9634 # Preparing mocks
9649 disk_paths = [] 9635 disk_paths = []
9650 _bandwidth = libvirt_driver.MIN_MIGRATION_SPEED_BW
9651 params = { 9636 params = {
9652 'bandwidth': _bandwidth, 9637 'bandwidth': CONF.libvirt.live_migration_bandwidth,
9653 'destination_xml': '', 9638 'destination_xml': '',
9654 } 9639 }
9655 # Start test 9640 # Start test
@@ -9668,8 +9653,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9668 drvr._parse_migration_flags() 9653 drvr._parse_migration_flags()
9669 instance = objects.Instance(**self.test_instance) 9654 instance = objects.Instance(**self.test_instance)
9670 drvr._live_migration_operation(self.context, instance, 'dest', 9655 drvr._live_migration_operation(self.context, instance, 'dest',
9671 True, migrate_data, guest, disk_paths, 9656 True, migrate_data, guest, disk_paths)
9672 _bandwidth)
9673 expected_flags = (fakelibvirt.VIR_MIGRATE_UNDEFINE_SOURCE | 9657 expected_flags = (fakelibvirt.VIR_MIGRATE_UNDEFINE_SOURCE |
9674 fakelibvirt.VIR_MIGRATE_PERSIST_DEST | 9658 fakelibvirt.VIR_MIGRATE_PERSIST_DEST |
9675 fakelibvirt.VIR_MIGRATE_TUNNELLED | 9659 fakelibvirt.VIR_MIGRATE_TUNNELLED |
@@ -9695,7 +9679,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9695 vdmock = self.mox.CreateMock(fakelibvirt.virDomain) 9679 vdmock = self.mox.CreateMock(fakelibvirt.virDomain)
9696 guest = libvirt_guest.Guest(vdmock) 9680 guest = libvirt_guest.Guest(vdmock)
9697 self.mox.StubOutWithMock(vdmock, "migrateToURI2") 9681 self.mox.StubOutWithMock(vdmock, "migrateToURI2")
9698 _bandwidth = libvirt_driver.MIN_MIGRATION_SPEED_BW 9682 _bandwidth = CONF.libvirt.live_migration_bandwidth
9699 vdmock.XMLDesc(flags=fakelibvirt.VIR_DOMAIN_XML_MIGRATABLE 9683 vdmock.XMLDesc(flags=fakelibvirt.VIR_DOMAIN_XML_MIGRATABLE
9700 ).AndReturn(FakeVirtDomain().XMLDesc(flags=0)) 9684 ).AndReturn(FakeVirtDomain().XMLDesc(flags=0))
9701 vdmock.migrateToURI2(drvr._live_migration_uri('dest'), 9685 vdmock.migrateToURI2(drvr._live_migration_uri('dest'),
@@ -9717,8 +9701,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
9717 self.assertRaises(fakelibvirt.libvirtError, 9701 self.assertRaises(fakelibvirt.libvirtError,
9718 drvr._live_migration_operation, 9702 drvr._live_migration_operation,
9719 self.context, instance_ref, 'dest', 9703 self.context, instance_ref, 'dest',
9720 False, migrate_data, guest, [], 9704 False, migrate_data, guest, [])
9721 _bandwidth)
9722 9705
9723 self.assertEqual(vm_states.ACTIVE, instance_ref.vm_state) 9706 self.assertEqual(vm_states.ACTIVE, instance_ref.vm_state)
9724 self.assertEqual(power_state.RUNNING, instance_ref.power_state) 9707 self.assertEqual(power_state.RUNNING, instance_ref.power_state)
@@ -10753,87 +10736,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
10753 def test_live_migration_main(self, mock_copy_disk_path, mock_running, 10736 def test_live_migration_main(self, mock_copy_disk_path, mock_running,
10754 mock_guest, mock_monitor, mock_thread, 10737 mock_guest, mock_monitor, mock_thread,
10755 mock_conn): 10738 mock_conn):
10756 virtapi = manager.ComputeVirtAPI(mock.MagicMock())
10757 drvr = libvirt_driver.LibvirtDriver(virtapi, False)
10758
10759 instance = objects.Instance(**self.test_instance)
10760 instance.info_cache = objects.InstanceInfoCache(
10761 network_info=network_model.NetworkInfo([
10762 network_model.VIF(id=uuids.vif_1,
10763 type=network_model.VIF_TYPE_BRIDGE)]))
10764
10765 dom = fakelibvirt.Domain(drvr._get_connection(),
10766 "<domain><name>demo</name></domain>", True)
10767 guest = libvirt_guest.Guest(dom)
10768 migrate_data = objects.LibvirtLiveMigrateData(block_migration=True)
10769 disks_to_copy = (['/some/path/one', '/test/path/two'],
10770 ['vda', 'vdb'])
10771 mock_copy_disk_path.return_value = disks_to_copy
10772
10773 mock_guest.return_value = guest
10774 guest.migrate_configure_max_speed = mock.MagicMock()
10775
10776 generated_events = []
10777
10778 def fake_post():
10779 pass
10780
10781 def fake_recover():
10782 pass
10783
10784 def fake_prepare(instance, event_name):
10785 ev = mock.MagicMock(instance=instance, event_name=event_name)
10786 ev.wait.return_value = mock.MagicMock(status='completed')
10787 generated_events.append(ev)
10788 return ev
10789
10790 prepare = virtapi._compute.instance_events.prepare_for_instance_event
10791 prepare.side_effect = fake_prepare
10792
10793 drvr._live_migration(self.context, instance, "fakehost",
10794 fake_post, fake_recover, True,
10795 migrate_data)
10796 mock_copy_disk_path.assert_called_once_with(self.context, instance,
10797 guest)
10798
10799 class AnyEventletEvent(object):
10800 def __eq__(self, other):
10801 return type(other) == eventlet.event.Event
10802
10803 mock_thread.assert_called_once_with(
10804 drvr._live_migration_operation,
10805 self.context, instance, "fakehost", True,
10806 migrate_data, guest, disks_to_copy[1],
10807 libvirt_driver.MIN_MIGRATION_SPEED_BW)
10808 mock_monitor.assert_called_once_with(
10809 self.context, instance, guest, "fakehost",
10810 fake_post, fake_recover, True,
10811 migrate_data, AnyEventletEvent(), disks_to_copy[0])
10812 guest.migrate_configure_max_speed.assert_called_once_with(
10813 CONF.libvirt.live_migration_bandwidth)
10814
10815 prepare.assert_has_calls([
10816 mock.call(instance, 'network-vif-plugged-%s' % uuids.vif_1)])
10817 for event in generated_events:
10818 event.wait.assert_called_once_with()
10819
10820 @mock.patch.object(host.Host, "get_connection")
10821 @mock.patch.object(utils, "spawn")
10822 @mock.patch.object(libvirt_driver.LibvirtDriver, "_live_migration_monitor")
10823 @mock.patch.object(host.Host, "get_guest")
10824 @mock.patch.object(fakelibvirt.Connection, "_mark_running")
10825 @mock.patch.object(libvirt_driver.LibvirtDriver,
10826 "_live_migration_copy_disk_paths")
10827 def test_live_migration_ovs_vif(self, mock_copy_disk_path, mock_running,
10828 mock_guest, mock_monitor, mock_thread,
10829 mock_conn):
10830 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) 10739 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
10831 instance = objects.Instance(**self.test_instance) 10740 instance = objects.Instance(**self.test_instance)
10832 instance.info_cache = objects.InstanceInfoCache(
10833 network_info=network_model.NetworkInfo([
10834 network_model.VIF(id=uuids.vif_1,
10835 type=network_model.VIF_TYPE_OVS)]))
10836
10837 dom = fakelibvirt.Domain(drvr._get_connection(), 10741 dom = fakelibvirt.Domain(drvr._get_connection(),
10838 "<domain><name>demo</name></domain>", True) 10742 "<domain><name>demo</name></domain>", True)
10839 guest = libvirt_guest.Guest(dom) 10743 guest = libvirt_guest.Guest(dom)
@@ -10843,7 +10747,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
10843 mock_copy_disk_path.return_value = disks_to_copy 10747 mock_copy_disk_path.return_value = disks_to_copy
10844 10748
10845 mock_guest.return_value = guest 10749 mock_guest.return_value = guest
10846 guest.migrate_configure_max_speed = mock.MagicMock()
10847 10750
10848 def fake_post(): 10751 def fake_post():
10849 pass 10752 pass
@@ -10864,70 +10767,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
10864 mock_thread.assert_called_once_with( 10767 mock_thread.assert_called_once_with(
10865 drvr._live_migration_operation, 10768 drvr._live_migration_operation,
10866 self.context, instance, "fakehost", True, 10769 self.context, instance, "fakehost", True,
10867 migrate_data, guest, disks_to_copy[1], 10770 migrate_data, guest, disks_to_copy[1])
10868 CONF.libvirt.live_migration_bandwidth)
10869 mock_monitor.assert_called_once_with( 10771 mock_monitor.assert_called_once_with(
10870 self.context, instance, guest, "fakehost", 10772 self.context, instance, guest, "fakehost",
10871 fake_post, fake_recover, True, 10773 fake_post, fake_recover, True,
10872 migrate_data, AnyEventletEvent(), disks_to_copy[0]) 10774 migrate_data, AnyEventletEvent(), disks_to_copy[0])
10873 guest.migrate_configure_max_speed.assert_not_called()
10874
10875 @mock.patch.object(host.Host, "get_connection")
10876 @mock.patch.object(utils, "spawn")
10877 @mock.patch.object(libvirt_driver.LibvirtDriver, "_live_migration_monitor")
10878 @mock.patch.object(host.Host, "get_guest")
10879 @mock.patch.object(fakelibvirt.Connection, "_mark_running")
10880 @mock.patch.object(libvirt_driver.LibvirtDriver,
10881 "_live_migration_copy_disk_paths")
10882 def test_live_migration_bridge_no_events(self, mock_copy_disk_path,
10883 mock_running, mock_guest,
10884 mock_monitor, mock_thread,
10885 mock_conn):
10886 self.flags(vif_plugging_timeout=0)
10887 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
10888 instance = objects.Instance(**self.test_instance)
10889 instance.info_cache = objects.InstanceInfoCache(
10890 network_info=network_model.NetworkInfo([
10891 network_model.VIF(id=uuids.vif_1,
10892 type=network_model.VIF_TYPE_BRIDGE)]))
10893
10894 dom = fakelibvirt.Domain(drvr._get_connection(),
10895 "<domain><name>demo</name></domain>", True)
10896 guest = libvirt_guest.Guest(dom)
10897 migrate_data = objects.LibvirtLiveMigrateData(block_migration=True)
10898 disks_to_copy = (['/some/path/one', '/test/path/two'],
10899 ['vda', 'vdb'])
10900 mock_copy_disk_path.return_value = disks_to_copy
10901
10902 mock_guest.return_value = guest
10903 guest.migrate_configure_max_speed = mock.MagicMock()
10904
10905 def fake_post():
10906 pass
10907
10908 def fake_recover():
10909 pass
10910
10911 drvr._live_migration(self.context, instance, "fakehost",
10912 fake_post, fake_recover, True,
10913 migrate_data)
10914 mock_copy_disk_path.assert_called_once_with(self.context, instance,
10915 guest)
10916
10917 class AnyEventletEvent(object):
10918 def __eq__(self, other):
10919 return type(other) == eventlet.event.Event
10920
10921 mock_thread.assert_called_once_with(
10922 drvr._live_migration_operation,
10923 self.context, instance, "fakehost", True,
10924 migrate_data, guest, disks_to_copy[1],
10925 CONF.libvirt.live_migration_bandwidth)
10926 mock_monitor.assert_called_once_with(
10927 self.context, instance, guest, "fakehost",
10928 fake_post, fake_recover, True,
10929 migrate_data, AnyEventletEvent(), disks_to_copy[0])
10930 guest.migrate_configure_max_speed.assert_not_called()
10931 10775
10932 def _do_test_create_images_and_backing(self, disk_type): 10776 def _do_test_create_images_and_backing(self, disk_type):
10933 instance = objects.Instance(**self.test_instance) 10777 instance = objects.Instance(**self.test_instance)
@@ -16077,8 +15921,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
16077 15921
16078 instance = objects.Instance(vm_state=vm_states.BUILDING, 15922 instance = objects.Instance(vm_state=vm_states.BUILDING,
16079 **self.test_instance) 15923 **self.test_instance)
16080 vifs = [{'id': uuids.vif_1, 'active': False}, 15924 vifs = [{'id': 'vif1', 'active': False},
16081 {'id': uuids.vif_2, 'active': False}] 15925 {'id': 'vif2', 'active': False}]
16082 15926
16083 @mock.patch.object(drvr, 'plug_vifs') 15927 @mock.patch.object(drvr, 'plug_vifs')
16084 @mock.patch.object(drvr, 'firewall_driver') 15928 @mock.patch.object(drvr, 'firewall_driver')
@@ -16104,8 +15948,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
16104 15948
16105 if utils.is_neutron() and CONF.vif_plugging_timeout and power_on: 15949 if utils.is_neutron() and CONF.vif_plugging_timeout and power_on:
16106 prepare.assert_has_calls([ 15950 prepare.assert_has_calls([
16107 mock.call(instance, 'network-vif-plugged-%s' % uuids.vif_1), 15951 mock.call(instance, 'network-vif-plugged-vif1'),
16108 mock.call(instance, 'network-vif-plugged-%s' % uuids.vif_2)]) 15952 mock.call(instance, 'network-vif-plugged-vif2')])
16109 for event in generated_events: 15953 for event in generated_events:
16110 if neutron_failure and generated_events.index(event) != 0: 15954 if neutron_failure and generated_events.index(event) != 0:
16111 self.assertEqual(0, event.call_count) 15955 self.assertEqual(0, event.call_count)
@@ -16344,15 +16188,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
16344 {'bus': 'virtio', 'type': 'disk', 'dev': 'vdc'}) 16188 {'bus': 'virtio', 'type': 'disk', 'dev': 'vdc'})
16345 volume_save.assert_called_once_with() 16189 volume_save.assert_called_once_with()
16346 16190
16347 def test_get_neutron_events_for_live_migration(self):
16348 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
16349 network_info = [network_model.VIF(id=uuids.vif_ovs,
16350 type=network_model.VIF_TYPE_OVS),
16351 network_model.VIF(id=uuids.vif_bridge,
16352 type=network_model.VIF_TYPE_BRIDGE)]
16353 events = drvr._get_neutron_events_for_live_migration(network_info)
16354 self.assertEqual([('network-vif-plugged', uuids.vif_bridge)], events)
16355
16356 def test_get_neutron_events(self): 16191 def test_get_neutron_events(self):
16357 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) 16192 drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
16358 network_info = [network_model.VIF(id='1'), 16193 network_info = [network_model.VIF(id='1'),
diff --git a/nova/tests/unit/virt/test_virt_drivers.py b/nova/tests/unit/virt/test_virt_drivers.py
index 7823291..c256bec 100644
--- a/nova/tests/unit/virt/test_virt_drivers.py
+++ b/nova/tests/unit/virt/test_virt_drivers.py
@@ -654,8 +654,6 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
654 654
655 def test_live_migration(self): 655 def test_live_migration(self):
656 instance_ref, network_info = self._get_running_instance() 656 instance_ref, network_info = self._get_running_instance()
657 instance_ref.info_cache = objects.InstanceInfoCache(
658 network_info=network_info)
659 fake_context = context.RequestContext('fake', 'fake') 657 fake_context = context.RequestContext('fake', 'fake')
660 migration = objects.Migration(context=fake_context, id=1) 658 migration = objects.Migration(context=fake_context, id=1)
661 migrate_data = objects.LibvirtLiveMigrateData( 659 migrate_data = objects.LibvirtLiveMigrateData(
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 907abe7..c8ac4e2 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -321,8 +321,6 @@ MIN_QEMU_LUKS_VERSION = (2, 6, 0)
321 321
322VGPU_RESOURCE_SEMAPHORE = "vgpu_resources" 322VGPU_RESOURCE_SEMAPHORE = "vgpu_resources"
323 323
324MIN_MIGRATION_SPEED_BW = 1 # 1 MiB/s
325
326 324
327class LibvirtDriver(driver.ComputeDriver): 325class LibvirtDriver(driver.ComputeDriver):
328 capabilities = { 326 capabilities = {
@@ -5529,12 +5527,6 @@ class LibvirtDriver(driver.ComputeDriver):
5529 if CONF.vif_plugging_is_fatal: 5527 if CONF.vif_plugging_is_fatal:
5530 raise exception.VirtualInterfaceCreateException() 5528 raise exception.VirtualInterfaceCreateException()
5531 5529
5532 def _neutron_failed_live_migration_callback(self, event_name, instance):
5533 msg = ('Neutron reported failure during live migration '
5534 'with %(event)s for instance %(uuid)s' %
5535 {'event': event_name, 'uuid': instance.uuid})
5536 raise exception.MigrationError(reason=msg)
5537
5538 def _get_neutron_events(self, network_info): 5530 def _get_neutron_events(self, network_info):
5539 # NOTE(danms): We need to collect any VIFs that are currently 5531 # NOTE(danms): We need to collect any VIFs that are currently
5540 # down that we expect a down->up event for. Anything that is 5532 # down that we expect a down->up event for. Anything that is
@@ -5544,16 +5536,6 @@ class LibvirtDriver(driver.ComputeDriver):
5544 return [('network-vif-plugged', vif['id']) 5536 return [('network-vif-plugged', vif['id'])
5545 for vif in network_info if vif.get('active', True) is False] 5537 for vif in network_info if vif.get('active', True) is False]
5546 5538
5547 def _get_neutron_events_for_live_migration(self, network_info):
5548 # Neutron should send events to Nova indicating that the VIFs
5549 # are successfully plugged on destination host.
5550
5551 # TODO(sahid): Currently we only use the mechanism of waiting
5552 # for neutron events during live-migration for linux-bridge.
5553 return [('network-vif-plugged', vif['id'])
5554 for vif in network_info if (
5555 vif.get('type') == network_model.VIF_TYPE_BRIDGE)]
5556
5557 def _cleanup_failed_start(self, context, instance, network_info, 5539 def _cleanup_failed_start(self, context, instance, network_info,
5558 block_device_info, guest, destroy_disks): 5540 block_device_info, guest, destroy_disks):
5559 try: 5541 try:
@@ -6934,7 +6916,7 @@ class LibvirtDriver(driver.ComputeDriver):
6934 6916
6935 def _live_migration_operation(self, context, instance, dest, 6917 def _live_migration_operation(self, context, instance, dest,
6936 block_migration, migrate_data, guest, 6918 block_migration, migrate_data, guest,
6937 device_names, bandwidth): 6919 device_names):
6938 """Invoke the live migration operation 6920 """Invoke the live migration operation
6939 6921
6940 :param context: security context 6922 :param context: security context
@@ -6947,7 +6929,6 @@ class LibvirtDriver(driver.ComputeDriver):
6947 :param guest: the guest domain object 6929 :param guest: the guest domain object
6948 :param device_names: list of device names that are being migrated with 6930 :param device_names: list of device names that are being migrated with
6949 instance 6931 instance
6950 :param bandwidth: MiB/s of bandwidth allowed for the migration at start
6951 6932
6952 This method is intended to be run in a background thread and will 6933 This method is intended to be run in a background thread and will
6953 block that thread until the migration is finished or failed. 6934 block that thread until the migration is finished or failed.
@@ -7021,7 +7002,7 @@ class LibvirtDriver(driver.ComputeDriver):
7021 flags=migration_flags, 7002 flags=migration_flags,
7022 params=params, 7003 params=params,
7023 domain_xml=new_xml_str, 7004 domain_xml=new_xml_str,
7024 bandwidth=bandwidth) 7005 bandwidth=CONF.libvirt.live_migration_bandwidth)
7025 7006
7026 for hostname, port in serial_ports: 7007 for hostname, port in serial_ports:
7027 serial_console.release_port(host=hostname, port=port) 7008 serial_console.release_port(host=hostname, port=port)
@@ -7364,58 +7345,11 @@ class LibvirtDriver(driver.ComputeDriver):
7364 disk_paths, device_names = self._live_migration_copy_disk_paths( 7345 disk_paths, device_names = self._live_migration_copy_disk_paths(
7365 context, instance, guest) 7346 context, instance, guest)
7366 7347
7367 deadline = CONF.vif_plugging_timeout 7348 opthread = utils.spawn(self._live_migration_operation,
7368 if utils.is_neutron() and deadline: 7349 context, instance, dest,
7369 # We don't generate events if CONF.vif_plugging_timeout=0 7350 block_migration,
7370 # meaning that the operator disabled using them. 7351 migrate_data, guest,
7371 7352 device_names)
7372 # In case of Linux Bridge, the agent is waiting for new
7373 # TAP devices on destination node. They are going to be
7374 # created by libvirt at the very beginning of the
7375 # live-migration process. Then receiving the events from
7376 # Neutron will ensure that everything is configured
7377 # correctly.
7378 events = self._get_neutron_events_for_live_migration(
7379 instance.get_network_info())
7380 else:
7381 # TODO(sahid): This 'is_neutron()' condition should be
7382 # removed when nova-network will be erased from the tree
7383 # (Rocky).
7384 events = []
7385
7386 if events:
7387 # We start migration with the minimum bandwidth
7388 # speed. Depending on the VIF type (see:
7389 # _get_neutron_events_for_live_migration) we will wait for
7390 # Neutron to send events that confirm network is setup or
7391 # directly configure QEMU to use the maximun BW allowed.
7392 bandwidth = MIN_MIGRATION_SPEED_BW
7393 else:
7394 bandwidth = CONF.libvirt.live_migration_bandwidth
7395
7396 try:
7397 error_cb = self._neutron_failed_live_migration_callback
7398 with self.virtapi.wait_for_instance_event(instance, events,
7399 deadline=deadline,
7400 error_callback=error_cb):
7401 opthread = utils.spawn(self._live_migration_operation,
7402 context, instance, dest,
7403 block_migration,
7404 migrate_data, guest,
7405 device_names, bandwidth)
7406 except eventlet.timeout.Timeout:
7407 msg = ('Timeout waiting for VIF plugging events, '
7408 'canceling migration')
7409 raise exception.MigrationError(reason=msg)
7410 else:
7411 if utils.is_neutron() and events:
7412 LOG.debug('VIF events received, continuing migration '
7413 'with max bandwidth configured: %d',
7414 CONF.libvirt.live_migration_bandwidth,
7415 instance=instance)
7416 # Configure QEMU to use the maximum bandwidth allowed.
7417 guest.migrate_configure_max_speed(
7418 CONF.libvirt.live_migration_bandwidth)
7419 7353
7420 finish_event = eventlet.event.Event() 7354 finish_event = eventlet.event.Event()
7421 self.active_migrations[instance.uuid] = deque() 7355 self.active_migrations[instance.uuid] = deque()