def _test_update_vif_xml(self, conf, original_xml, expected_xml): """Simulates updating the guest xml for live migrating from a host using OVS to a host using vhostuser as the networking backend. """ vif_ovs = network_model.VIF(id=uuids.vif, address='DE:AD:BE:EF:CA:FE', details={'port_filter': False}, devname='tap-xxx-yyy-zzz', ovs_interfaceid=uuids.ovs) source_vif = vif_ovs migrate_vifs = [ objects.VIFMigrateData( port_id=uuids.port_id, vnic_type=network_model.VNIC_TYPE_NORMAL, vif_type=network_model.VIF_TYPE_VHOSTUSER, vif_details={'vhostuser_socket': '/vhost-user/test.sock'}, profile={}, host='dest.host', source_vif=source_vif) ] data = objects.LibvirtLiveMigrateData(vifs=migrate_vifs) get_vif_config = mock.MagicMock(return_value=conf) doc = etree.fromstring(original_xml) updated_xml = etree.tostring(migration._update_vif_xml( doc, data, get_vif_config), encoding='unicode') self.assertThat(updated_xml, matchers.XMLMatches(expected_xml))
def _test_update_vif_xml(self, conf, original_xml, expected_xml): """Simulates updating the guest xml for live migrating from a host using OVS to a host using vhostuser as the networking backend. """ vif_ovs = network_model.VIF(id=uuids.vif, address='DE:AD:BE:EF:CA:FE', details={'port_filter': False}, devname='tap-xxx-yyy-zzz', ovs_interfaceid=uuids.ovs) source_vif = vif_ovs migrate_vifs = [ objects.VIFMigrateData( port_id=uuids.port_id, vnic_type=network_model.VNIC_TYPE_NORMAL, vif_type=network_model.VIF_TYPE_VHOSTUSER, vif_details={ 'vhostuser_socket': '/vhost-user/test.sock' }, profile={}, host='dest.host', source_vif=source_vif) ] data = objects.LibvirtLiveMigrateData(vifs=migrate_vifs) get_vif_config = mock.MagicMock(return_value=conf) doc = etree.fromstring(original_xml) updated_xml = etree.tostring( migration._update_vif_xml(doc, data, get_vif_config), encoding='unicode') self.assertXmlEqual(updated_xml, expected_xml)
def test_update_vif_xml(self): """Simulates updating the guest xml for live migrating from a host using OVS to a host using vhostuser as the networking backend. """ vif_ovs = network_model.VIF(id=uuids.vif, address='DE:AD:BE:EF:CA:FE', details={'port_filter': False}, devname='tap-xxx-yyy-zzz', ovs_interfaceid=uuids.ovs) source_vif = vif_ovs migrate_vifs = [ objects.VIFMigrateData( port_id=uuids.port_id, vnic_type=network_model.VNIC_TYPE_NORMAL, vif_type=network_model.VIF_TYPE_VHOSTUSER, vif_details={'vhostuser_socket': '/vhost-user/test.sock'}, profile={}, host='dest.host', source_vif=source_vif) ] data = objects.LibvirtLiveMigrateData(vifs=migrate_vifs) original_xml = """<domain> <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid> <devices> <interface type="bridge"> <mac address="DE:AD:BE:EF:CA:FE"/> <model type="virtio"/> <source bridge="qbra188171c-ea"/> <target dev="tapa188171c-ea"/> <virtualport type="openvswitch"> <parameters interfaceid="%s"/> </virtualport> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </interface> </devices> </domain>""" % uuids.ovs conf = vconfig.LibvirtConfigGuestInterface() conf.net_type = "vhostuser" conf.vhostuser_type = "unix" conf.vhostuser_mode = "server" conf.mac_addr = "DE:AD:BE:EF:CA:FE" conf.vhostuser_path = "/vhost-user/test.sock" conf.model = "virtio" get_vif_config = mock.MagicMock(return_value=conf) doc = etree.fromstring(original_xml) updated_xml = etree.tostring(migration._update_vif_xml( doc, data, get_vif_config), encoding='unicode') # Note that <target> and <virtualport> are dropped from the ovs source # interface xml since they aren't applicable to the vhostuser # destination interface xml. The type attribute value changes and the # hardware address element is retained. expected_xml = """<domain> <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid> <devices> <interface type="vhostuser"> <mac address="DE:AD:BE:EF:CA:FE"/> <model type="virtio"/> <source mode="server" path="/vhost-user/test.sock" type="unix"/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </interface> </devices> </domain>""" self.assertThat(updated_xml, matchers.XMLMatches(expected_xml))
def test_update_vif_xml(self): """Simulates updating the guest xml for live migrating from a host using OVS to a host using vhostuser as the networking backend. """ vif_ovs = network_model.VIF(id=uuids.vif, address='DE:AD:BE:EF:CA:FE', details={'port_filter': False}, devname='tap-xxx-yyy-zzz', ovs_interfaceid=uuids.ovs) source_vif = vif_ovs migrate_vifs = [ objects.VIFMigrateData( port_id=uuids.port_id, vnic_type=network_model.VNIC_TYPE_NORMAL, vif_type=network_model.VIF_TYPE_VHOSTUSER, vif_details={ 'vhostuser_socket': '/vhost-user/test.sock' }, profile={}, host='dest.host', source_vif=source_vif) ] data = objects.LibvirtLiveMigrateData(vifs=migrate_vifs) original_xml = """<domain> <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid> <devices> <interface type="bridge"> <mac address="DE:AD:BE:EF:CA:FE"/> <model type="virtio"/> <source bridge="qbra188171c-ea"/> <target dev="tapa188171c-ea"/> <virtualport type="openvswitch"> <parameters interfaceid="%s"/> </virtualport> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </interface> </devices> </domain>""" % uuids.ovs conf = vconfig.LibvirtConfigGuestInterface() conf.net_type = "vhostuser" conf.vhostuser_type = "unix" conf.vhostuser_mode = "server" conf.mac_addr = "DE:AD:BE:EF:CA:FE" conf.vhostuser_path = "/vhost-user/test.sock" conf.model = "virtio" get_vif_config = mock.MagicMock(return_value=conf) doc = etree.fromstring(original_xml) updated_xml = etree.tostring( migration._update_vif_xml(doc, data, get_vif_config), encoding='unicode') # Note that <target> and <virtualport> are dropped from the ovs source # interface xml since they aren't applicable to the vhostuser # destination interface xml. The type attribute value changes and the # hardware address element is retained. expected_xml = """<domain> <uuid>3de6550a-8596-4937-8046-9d862036bca5</uuid> <devices> <interface type="vhostuser"> <mac address="DE:AD:BE:EF:CA:FE"/> <model type="virtio"/> <source mode="server" path="/vhost-user/test.sock" type="unix"/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </interface> </devices> </domain>""" self.assertThat(updated_xml, matchers.XMLMatches(expected_xml))