Пример #1
0
    def test_get_interface_by_cfg_persistent_domain(self):
        self.domain.XMLDesc.return_value = """<domain>
  <devices>
    <interface type="bridge">
      <mac address="fa:16:3e:f9:af:ae"/>
      <model type="virtio"/>
      <driver name="qemu"/>
      <source bridge="qbr84008d03-11"/>
      <target dev="tap84008d03-11"/>
    </interface>
  </devices>
</domain>"""
        cfg = vconfig.LibvirtConfigGuestInterface()
        cfg.parse_str("""
            <interface type="bridge">
              <mac address="fa:16:3e:f9:af:ae"/>
              <model type="virtio"/>
              <driver name="qemu"/>
              <source bridge="qbr84008d03-11"/>
              <target dev="tap84008d03-11"/>
              </interface>""")
        self.assertIsNotNone(
            self.guest.get_interface_by_cfg(cfg, from_persistent_config=True))
        self.assertIsNone(
            self.guest.get_interface_by_cfg(
                vconfig.LibvirtConfigGuestInterface(),
                from_persistent_config=True))
        self.domain.XMLDesc.assert_has_calls([
            mock.call(fakelibvirt.VIR_DOMAIN_XML_INACTIVE),
            mock.call(fakelibvirt.VIR_DOMAIN_XML_INACTIVE),
        ])
Пример #2
0
    def get_base_config(self, instance, vif, image_meta, inst_type, virt_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None
        vhost_queues = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            model = osinfo.HardwareProperties(image_meta).network_model

        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if (model is None and virt_type in ('kvm', 'qemu')
                and CONF.libvirt.use_virtio_for_bridges):
            model = network_model.VIF_MODEL_VIRTIO

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if (model == network_model.VIF_MODEL_VIRTIO and virt_type == "qemu"):
            driver = "qemu"

        if not is_vif_model_valid_for_virt(virt_type, model):
            raise exception.UnsupportedHardware(model=model, virt=virt_type)
        if (virt_type == 'kvm' and model == network_model.VIF_MODEL_VIRTIO):
            vhost_drv, vhost_queues = self._get_virtio_mq_settings(
                image_meta, inst_type)
            driver = vhost_drv or driver

        designer.set_vif_guest_frontend_config(conf, vif['address'], model,
                                               driver, vhost_queues)

        return conf
Пример #3
0
 def test_set_vif_host_backend_bridge_config(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_bridge_config(conf, 'fake-bridge',
                                                 'fake-tap')
     self.assertEqual('bridge', conf.net_type)
     self.assertEqual('fake-bridge', conf.source_dev)
     self.assertEqual('fake-tap', conf.target_dev)
Пример #4
0
 def test_set_vif_host_backend_vdpa_config(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_vdpa_config(conf, '/dev/vdpa_vdpa0')
     self.assertEqual('vdpa', conf.net_type)
     self.assertEqual('/dev/vdpa_vdpa0', conf.source_dev)
     self.assertIsNone(conf.vhost_rx_queue_size)
     self.assertIsNone(conf.vhost_tx_queue_size)
Пример #5
0
    def _get_configurations(self, instance, network, mapping):
        """Get a dictionary of VIF configurations for bridge type."""

        mac_id = mapping['mac'].replace(':', '')

        conf = config.LibvirtConfigGuestInterface()
        conf.net_type = "bridge"
        conf.mac_addr = mapping['mac']
        conf.source_dev = network['bridge']
        conf.script = ""
        if FLAGS.libvirt_use_virtio_for_bridges:
            conf.model = "virtio"

        conf.filtername = "nova-instance-" + instance['name'] + "-" + mac_id
        conf.add_filter_param("IP", mapping['ips'][0]['ip'])
        if mapping['dhcp_server']:
            conf.add_filter_param("DHCPSERVER", mapping['dhcp_server'])

        if FLAGS.use_ipv6:
            conf.add_filter_param("RASERVER",
                                  mapping.get('gateway_v6') + "/128")

        if FLAGS.allow_same_net_traffic:
            net, mask = netutils.get_net_and_mask(network['cidr'])
            conf.add_filter_param("PROJNET", net)
            conf.add_filter_param("PROJMASK", mask)
            if FLAGS.use_ipv6:
                net_v6, prefixlen_v6 = netutils.get_net_and_prefixlen(
                    network['cidr_v6'])
                conf.add_filter_param("PROJNET6", net_v6)
                conf.add_filter_param("PROJMASK6", prefixlen_v6)

        return conf
Пример #6
0
    def test_config_bridge(self):
        obj = config.LibvirtConfigGuestInterface()
        obj.net_type = "bridge"
        obj.source_dev = "br0"
        obj.mac_addr = "DE:AD:BE:EF:CA:FE"
        obj.model = "virtio"
        obj.target_dev = "tap12345678"
        obj.filtername = "clean-traffic"
        obj.filterparams.append({"key": "IP", "value": "192.168.122.1"})
        obj.vif_inbound_average = 1024000
        obj.vif_inbound_peak = 10240000
        obj.vif_inbound_burst = 1024000
        obj.vif_outbound_average = 1024000
        obj.vif_outbound_peak = 10240000
        obj.vif_outbound_burst = 1024000

        xml = obj.to_xml()
        self.assertXmlEqual(
            xml, """
            <interface type="bridge">
              <mac address="DE:AD:BE:EF:CA:FE"/>
              <model type="virtio"/>
              <source bridge="br0"/>
              <target dev="tap12345678"/>
              <filterref filter="clean-traffic">
                <parameter name="IP" value="192.168.122.1"/>
              </filterref>
              <bandwidth>
                <inbound average="1024000" peak="10240000" burst="1024000"/>
                <outbound average="1024000" peak="10240000" burst="1024000"/>
              </bandwidth>
            </interface>""")
Пример #7
0
    def test_config_ethernet(self):
        obj = config.LibvirtConfigGuestInterface()
        obj.net_type = "ethernet"
        obj.mac_addr = "DE:AD:BE:EF:CA:FE"
        obj.model = "virtio"
        obj.target_dev = "vnet0"
        obj.driver_name = "vhost"
        obj.vif_inbound_average = 1024000
        obj.vif_inbound_peak = 10240000
        obj.vif_inbound_burst = 1024000
        obj.vif_outbound_average = 1024000
        obj.vif_outbound_peak = 10240000
        obj.vif_outbound_burst = 1024000

        xml = obj.to_xml()
        self.assertXmlEqual(
            xml, """
            <interface type="ethernet">
              <mac address="DE:AD:BE:EF:CA:FE"/>
              <model type="virtio"/>
              <driver name="vhost"/>
              <target dev="vnet0"/>
              <bandwidth>
                <inbound average="1024000" peak="10240000" burst="1024000"/>
                <outbound average="1024000" peak="10240000" burst="1024000"/>
              </bandwidth>
            </interface>""")
Пример #8
0
    def plug(self, instance, vif):
        network, mapping = vif
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)
        if not linux_net._device_exists(dev):
            # Older version of the command 'ip' from the iproute2 package
            # don't have support for the tuntap option (lp:882568).  If it
            # turns out we're on an old version we work around this by using
            # tunctl.
            try:
                # First, try with 'ip'
                utils.execute('ip',
                              'tuntap',
                              'add',
                              dev,
                              'mode',
                              'tap',
                              run_as_root=True)
            except exception.ProcessExecutionError:
                # Second option: tunctl
                utils.execute('tunctl', '-b', '-t', dev, run_as_root=True)
            utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True)
        utils.execute('ovs-vsctl',
                      '--',
                      '--may-exist',
                      'add-port',
                      FLAGS.libvirt_ovs_bridge,
                      dev,
                      '--',
                      'set',
                      'Interface',
                      dev,
                      "external-ids:iface-id=%s" % iface_id,
                      '--',
                      'set',
                      'Interface',
                      dev,
                      "external-ids:iface-status=active",
                      '--',
                      'set',
                      'Interface',
                      dev,
                      "external-ids:attached-mac=%s" % mapping['mac'],
                      '--',
                      'set',
                      'Interface',
                      dev,
                      "external-ids:vm-uuid=%s" % instance['uuid'],
                      run_as_root=True)

        conf = config.LibvirtConfigGuestInterface()

        if FLAGS.libvirt_use_virtio_for_bridges:
            conf.model = "virtio"
        conf.net_type = "ethernet"
        conf.target_dev = dev
        conf.script = ""
        conf.mac_addr = mapping['mac']

        return conf
Пример #9
0
    def test_get_interface_by_cfg_vhostuser(self):
        self.domain.XMLDesc.return_value = """<domain>
  <devices>
    <interface type="vhostuser">
      <mac address='fa:16:3e:55:3e:e4'/>
      <source type='unix' path='/var/run/openvswitch/vhued80c655-4e'
       mode='server'/>
      <target dev='vhued80c655-4e'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03'
       function='0x0'/>
    </interface>
  </devices>
</domain>"""
        cfg = vconfig.LibvirtConfigGuestInterface()
        cfg.parse_str("""<interface type="vhostuser">
  <mac address='fa:16:3e:55:3e:e4'/>
  <model type="virtio"/>
  <source type='unix' path='/var/run/openvswitch/vhued80c655-4e'
   mode='server'/>
  <alias name='net0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
  </interface>""")
        self.assertIsNotNone(self.guest.get_interface_by_cfg(cfg))
        self.assertIsNone(self.guest.get_interface_by_cfg(None))
Пример #10
0
    def get_config(self, instance, vif, image_meta, inst_type):
        conf = vconfig.LibvirtConfigGuestInterface()
        # Default to letting libvirt / the hypervisor choose the model
        model = None
        driver = None

        # If the user has specified a 'vif_model' against the
        # image then honour that model
        if image_meta:
            vif_model = image_meta.get('properties',
                                       {}).get('hw_vif_model')
            if vif_model is not None:
                model = vif_model

        # Else if the virt type is KVM/QEMU, use virtio according
        # to the global config parameter
        if (model is None and
            CONF.libvirt.virt_type in ('kvm', 'qemu') and
                    CONF.libvirt.use_virtio_for_bridges):
            model = "virtio"

        # Workaround libvirt bug, where it mistakenly
        # enables vhost mode, even for non-KVM guests
        if model == "virtio" and CONF.libvirt.virt_type == "qemu":
            driver = "qemu"

        if not is_vif_model_valid_for_virt(CONF.libvirt.virt_type,
                                           model):
            raise exception.UnsupportedHardware(model=model,
                                                virt=CONF.libvirt.virt_type)

        designer.set_vif_guest_frontend_config(
            conf, vif['address'], model, driver)

        return conf
Пример #11
0
    def test_multiple_nics(self):
        conf = self._get_conf()
        # Tests multiple nic configuration and that target_dev is
        # set for each
        nics = [{'net_type': 'bridge',
                 'mac_addr': '00:00:00:00:00:0b',
                 'source_dev': 'b_source_dev',
                 'target_dev': 'b_target_dev'},
                {'net_type': 'ethernet',
                 'mac_addr': '00:00:00:00:00:0e',
                 'source_dev': 'e_source_dev',
                 'target_dev': 'e_target_dev'},
                {'net_type': 'direct',
                 'mac_addr': '00:00:00:00:00:0d',
                 'source_dev': 'd_source_dev',
                 'target_dev': 'd_target_dev'}]

        for nic in nics:
            nic_conf = vconfig.LibvirtConfigGuestInterface()
            nic_conf.net_type = nic['net_type']
            nic_conf.target_dev = nic['target_dev']
            nic_conf.mac_addr = nic['mac_addr']
            nic_conf.source_dev = nic['source_dev']
            conf.add_device(nic_conf)

        xml = conf.to_xml()
        doc = etree.fromstring(xml)
        for nic in nics:
            path = "./devices/interface/[@type='%s']" % nic['net_type']
            node = doc.find(path)
            self.assertEqual(nic['net_type'], node.get("type"))
            self.assertEqual(nic['mac_addr'],
                             node.find("mac").get("address"))
            self.assertEqual(nic['target_dev'],
                             node.find("target").get("dev"))
Пример #12
0
    def get_config(self, instance, vif, image_meta, inst_type):
        conf = libvirt_config.LibvirtConfigGuestInterface()

        for attr, val in conf.__dict__.iteritems():
            if val is None:
                setattr(conf, attr, 'fake')

        return conf
Пример #13
0
 def test_set_vif_guest_frontend_config(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_guest_frontend_config(conf, 'fake-mac', 'fake-model',
                                            'fake-driver', 'fake-queues')
     self.assertEqual('fake-mac', conf.mac_addr)
     self.assertEqual('fake-model', conf.model)
     self.assertEqual('fake-driver', conf.driver_name)
     self.assertEqual('fake-queues', conf.vhost_queues)
Пример #14
0
 def test_set_vif_host_backend_vhostuser_config(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_vhostuser_config(conf, 'fake-mode',
                                                    'fake-path')
     self.assertEqual('vhostuser', conf.net_type)
     self.assertEqual('unix', conf.vhostuser_type)
     self.assertEqual('fake-mode', conf.vhostuser_mode)
     self.assertEqual('fake-path', conf.vhostuser_path)
Пример #15
0
 def test_set_vif_host_backend_direct_config(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_direct_config(conf, 'fake-devname',
                                                 mode="passthrough")
     self.assertEqual('direct', conf.net_type)
     self.assertEqual('fake-devname', conf.source_dev)
     self.assertEqual('passthrough', conf.source_mode)
     self.assertEqual('virtio', conf.model)
Пример #16
0
 def test_set_vif_host_backend_hostdev_pci_config(self, mock_pci_fields):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_hostdev_pci_config(conf, 'fake-pci-slot')
     self.assertEqual('fake-domain', conf.domain)
     self.assertEqual('fake-bus', conf.bus)
     self.assertEqual('fake-slot', conf.slot)
     self.assertEqual('fake-function', conf.function)
     mock_pci_fields.assert_called_with('fake-pci-slot')
Пример #17
0
    def get_config(self, instance, network, mapping):
        conf = libvirt_config.LibvirtConfigGuestInterface()

        for attr, val in conf.__dict__.iteritems():
            if val is None:
                setattr(conf, attr, 'fake')

        return conf
Пример #18
0
 def test_set_vif_host_backend_ethernet_config_libvirt_pre_1_3_3(self):
     conf = config.LibvirtConfigGuestInterface()
     mock_host = mock.Mock(autospec=host.Host)
     mock_host.has_min_version.return_value = False
     designer.set_vif_host_backend_ethernet_config(conf, 'fake-tap',
                                                   mock_host)
     self.assertEqual('ethernet', conf.net_type)
     self.assertEqual('fake-tap', conf.target_dev)
     self.assertEqual('', conf.script)
Пример #19
0
 def test_set_vif_host_backend_hw_veb_hostdev(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_hw_veb(conf, 'hostdev', 'fake-devname',
                                          'fake-vlan', 'fake-tap')
     self.assertEqual('hostdev', conf.net_type)
     self.assertEqual('fake-devname', conf.source_dev)
     self.assertIsNone(conf.model)
     self.assertEqual('fake-vlan', conf.vlan)
     self.assertEqual('fake-tap', conf.target_dev)
Пример #20
0
 def test_set_vif_host_backend_vhostuser_config_rx_queue_size(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_vhostuser_config(conf, 'fake-mode',
                                                    'fake-path', 512, None)
     self.assertEqual('vhostuser', conf.net_type)
     self.assertEqual('unix', conf.vhostuser_type)
     self.assertEqual('fake-mode', conf.vhostuser_mode)
     self.assertEqual('fake-path', conf.vhostuser_path)
     self.assertEqual(512, conf.vhost_rx_queue_size)
     self.assertIsNone(conf.vhost_tx_queue_size)
Пример #21
0
 def test_set_vif_host_backend_hw_veb_direct(self, mock_pci):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_hw_veb(conf, 'direct', 'fake-pci-dev',
                                          'fake-vlan', 'fake-tap')
     self.assertEqual('direct', conf.net_type)
     self.assertEqual('fake-devname', conf.source_dev)
     self.assertEqual('passthrough', conf.source_mode)
     self.assertEqual('vhost', conf.driver_name)
     self.assertEqual('fake-tap', conf.target_dev)
     mock_pci.assert_called_with('fake-pci-dev')
Пример #22
0
 def test_set_vif_host_backend_802qbh_config_hostdev(self):
     conf = config.LibvirtConfigGuestInterface()
     designer.set_vif_host_backend_802qbh_config(conf, 'hostdev',
                                                 'fake-devname',
                                                 'fake-profileid',
                                                 'fake-tap')
     self.assertEqual('hostdev', conf.net_type)
     self.assertEqual('fake-devname', conf.source_dev)
     self.assertIsNone(conf.model)
     self.assertEqual('802.1Qbh', conf.vporttype)
     self.assertEqual('fake-tap', conf.target_dev)
Пример #23
0
    def get_config(self, instance, network, mapping):
        conf = vconfig.LibvirtConfigGuestInterface()
        conf.mac_addr = mapping['mac']
        if CONF.libvirt_type in ('kvm', 'qemu') and \
                CONF.libvirt_use_virtio_for_bridges:
            conf.model = "virtio"
            # Workaround libvirt bug, where it mistakenly
            # enables vhost mode, even for non-KVM guests
            if CONF.libvirt_type == "qemu":
                conf.driver_name = "qemu"

        return conf
Пример #24
0
Файл: vif.py Проект: scpham/nova
    def plug(self, instance, network, mapping):
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)
        linux_net.QuantumLinuxBridgeInterfaceDriver.create_tap_dev(dev)

        conf = config.LibvirtConfigGuestInterface()

        conf.net_type = "ethernet"
        conf.target_dev = dev
        conf.script = ""
        conf.mac_addr = mapping['mac']

        return conf
Пример #25
0
    def plug(self, instance, network, mapping):
        """ Pass data required to create OVS virtual port element"""

        conf = config.LibvirtConfigGuestInterface()

        conf.net_type = "bridge"
        conf.source_dev = FLAGS.libvirt_ovs_bridge
        conf.mac_addr = mapping['mac']
        if FLAGS.libvirt_use_virtio_for_bridges:
            conf.model = "virtio"
        conf.vporttype = "openvswitch"
        conf.add_vport_param("interfaceid", mapping['vif_uuid'])

        return conf
Пример #26
0
    def test_config_ethernet(self):
        obj = config.LibvirtConfigGuestInterface()
        obj.net_type = "ethernet"
        obj.mac_addr = "DE:AD:BE:EF:CA:FE"
        obj.model = "virtio"
        obj.target_dev = "vnet0"

        xml = obj.to_xml()
        self.assertXmlEqual(xml, """
            <interface type="ethernet">
              <mac address="DE:AD:BE:EF:CA:FE"/>
              <model type="virtio"/>
              <target dev="vnet0"/>
            </interface>""")
Пример #27
0
    def test_config_8021Qbh(self):
        obj = config.LibvirtConfigGuestInterface()
        obj.net_type = "direct"
        obj.mac_addr = "DE:AD:BE:EF:CA:FE"
        obj.model = "virtio"
        obj.source_dev = "eth0"
        obj.vporttype = "802.1Qbh"

        xml = obj.to_xml()
        self.assertXmlEqual(xml, """
            <interface type="direct">
              <mac address="DE:AD:BE:EF:CA:FE"/>
              <model type="virtio"/>
              <source mode="private" dev="eth0"/>
              <virtualport type="802.1Qbh"/>
            </interface>""")
Пример #28
0
    def get_config(self, instance, network, mapping):
        conf = vconfig.LibvirtConfigGuestInterface()
        model = None
        driver = None
        if (CONF.libvirt_type in ('kvm', 'qemu')
                and CONF.libvirt_use_virtio_for_bridges):
            model = "virtio"
            # Workaround libvirt bug, where it mistakenly
            # enables vhost mode, even for non-KVM guests
            if CONF.libvirt_type == "qemu":
                driver = "qemu"

        designer.set_vif_guest_frontend_config(conf, mapping['mac'], model,
                                               driver)

        return conf
Пример #29
0
    def test_update_vif_xml_to_bridge_with_mtu(self):
        """This test validates _update_vif_xml to make sure it maintains the
        interface MTU if it exists in the source XML
        """
        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.vhostuser_path = "/vhost-user/test.sock"
        conf.model = "virtio"
        conf.mtu = 9000

        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"/>
        <mtu size="9000"/>
        <virtualport type="openvswitch">
            <parameters interfaceid="%s"/>
        </virtualport>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04'
                 function='0x0'/>
    </interface>
 </devices>
</domain>""" % uuids.ovs
        expected_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"/>
        <mtu size="9000"/>
        <target dev="tapa188171c-ea"/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04'
                 function='0x0'/>
    </interface>
 </devices>
</domain>"""
        self._test_update_vif_xml(conf, original_xml, expected_xml)
Пример #30
0
    def plug(self, instance, vif):
        network, mapping = vif
        iface_id = mapping['vif_uuid']
        dev = self.get_dev_name(iface_id)

        if FLAGS.libvirt_type != 'xen':
            linux_net.QuantumLinuxBridgeInterfaceDriver.create_tap_dev(dev)

        conf = config.LibvirtConfigGuestInterface()

        if FLAGS.libvirt_use_virtio_for_bridges:
            conf.model = 'virtio'
        conf.net_type = "ethernet"
        conf.target_dev = dev
        conf.script = ""
        conf.mac_addr = mapping['mac']

        return conf