--- /usr/lib/python2.7/site-packages/nova/virt/libvirt/migration.py.orig 2017-12-28 12:29:57.494704942 +0100 +++ /usr/lib/python2.7/site-packages/nova/virt/libvirt/migration.py 2017-12-28 12:37:58.270704942 +0100 @@ -78,7 +78,8 @@ xml_doc = etree.fromstring(guest.get_xml_desc(dump_migratable=True)) xml_doc = _update_graphics_xml(xml_doc, migrate_data) xml_doc = _update_serial_xml(xml_doc, migrate_data) - xml_doc = _update_volume_xml(xml_doc, migrate_data, get_volume_config) + xml_doc, mon_hosts_xml = _update_volume_xml(xml_doc, migrate_data, get_volume_config) + xml_doc = _fix_rbd_monitor_hosts(xml_doc, migrate_data, mon_hosts_xml) xml_doc = _update_perf_events_xml(xml_doc, migrate_data) return etree.tostring(xml_doc) @@ -155,6 +156,15 @@ LOG.debug("Find same serial number: pos=%(pos)s, " "serial=%(num)s", {'pos': pos, 'num': serial_source}) + + # save the monitor nodes + mon_hosts_xml = "\n" + for mon_host in xml_doc2.findall('./source/host'): + h = mon_host.get('name') + p = mon_host.get('port') + mon_hosts_xml += '\n' + mon_hosts_xml += "" + for cnt, item_src in enumerate(disk_dev): # If source and destination have same item, update # the item using destination value. @@ -168,6 +178,32 @@ for item_dst in list(xml_doc2): item_dst.tail = None disk_dev.insert(cnt, item_dst) + return xml_doc, mon_hosts_xml + + +def _fix_rbd_monitor_hosts(xml_doc, migrate_data, mon_hosts_xml): + """Fix the rbd monitor nodes for all rbd disks.""" + + disk_nodes = xml_doc.findall('./devices/disk') + + for pos, disk_dev in enumerate(disk_nodes): + target = disk_dev.find('target') + + for rbd_source in disk_dev.findall('source'): + if rbd_source.get('protocol') == "rbd": + # remove the monitor hosts + mon_hosts = etree.fromstring(mon_hosts_xml) + + for rbd_host in rbd_source.findall('host'): + LOG.debug('Removing rbd_host: (%s)', (rbd_host.attrib)) + rbd_source.remove(rbd_host) + rbd_source.tail = None + + # add the right monitor hosts + for new_rbd_host in mon_hosts.findall('host'): + LOG.debug('Inserting new_rbd_host: (%s)', (new_rbd_host.attrib)) + rbd_source.insert(0, new_rbd_host) + rbd_source.tail = None return xml_doc