diff --git a/nova/tests/unit/virt/libvirt/test_migration.py b/nova/tests/unit/virt/libvirt/test_migration.py
index d4fba48397de..37bc6ad4a4c2 100644
--- a/nova/tests/unit/virt/libvirt/test_migration.py
+++ b/nova/tests/unit/virt/libvirt/test_migration.py
@@ -991,7 +991,48 @@ class UtilityMigrationTestCase(test.NoDBTestCase):
doc = etree.fromstring(original_xml)
ex = self.assertRaises(KeyError, migration._update_vif_xml,
doc, data, get_vif_config)
- self.assertIn("CA:FE:DE:AD:BE:EF", six.text_type(ex))
+ self.assertIn("ca:fe:de:ad:be:ef", six.text_type(ex))
+
+ def test_update_vif_xml_lower_case_mac(self):
+ """Tests that the vif in the migrate data is not found in the existing
+ guest interfaces.
+ """
+ conf = vconfig.LibvirtConfigGuestInterface()
+ conf.net_type = "bridge"
+ conf.source_dev = "qbra188171c-ea"
+ conf.target_dev = "tapa188171c-ea"
+ conf.mac_addr = "DE:AD:BE:EF:CA:FE"
+ conf.model = "virtio"
+ original_xml = """
+ 3de6550a-8596-4937-8046-9d862036bca5
+
+
+
+
+
+
+
+
+
+
+
+
+ """ % uuids.ovs
+ expected_xml = """
+ 3de6550a-8596-4937-8046-9d862036bca5
+
+
+
+
+
+
+
+
+
+ """
+ self._test_update_vif_xml(conf, original_xml, expected_xml)
class MigrationMonitorTestCase(test.NoDBTestCase):
diff --git a/nova/virt/libvirt/migration.py b/nova/virt/libvirt/migration.py
index 9543adda7ad5..e601e46a9ba7 100644
--- a/nova/virt/libvirt/migration.py
+++ b/nova/virt/libvirt/migration.py
@@ -344,14 +344,21 @@ def _update_vif_xml(xml_doc, migrate_data, get_vif_config):
instance_uuid = xml_doc.findtext('uuid')
parser = etree.XMLParser(remove_blank_text=True)
interface_nodes = xml_doc.findall('./devices/interface')
- migrate_vif_by_mac = {vif.source_vif['address']: vif
+ # MAC address stored for port in neutron DB and in domain XML
+ # might be in different cases, so to harmonize that
+ # we convert MAC to lower case for dict key.
+ migrate_vif_by_mac = {vif.source_vif['address'].lower(): vif
for vif in migrate_data.vifs}
for interface_dev in interface_nodes:
mac = interface_dev.find('mac')
mac = mac if mac is not None else {}
mac_addr = mac.get('address')
if mac_addr:
- migrate_vif = migrate_vif_by_mac[mac_addr]
+ # MAC address stored in libvirt should always be normalized
+ # and stored in lower case. But just to be extra safe here
+ # we still normalize MAC retrieved from XML to be absolutely
+ # sure it will be the same with the Neutron provided one.
+ migrate_vif = migrate_vif_by_mac[mac_addr.lower()]
vif = migrate_vif.get_dest_vif()
# get_vif_config is a partial function of
# nova.virt.libvirt.vif.LibvirtGenericVIFDriver.get_config