コード例 #1
0
 def test_build_vm_xml(self, mock_open, mock_write_file,
                       mock_create_snapshot_qemu):
     result = [4]
     with mock.patch("yardstick.ssh.SSH") as ssh:
         ssh_mock = mock.Mock(autospec=ssh.SSH)
         ssh_mock.execute = \
             mock.Mock(return_value=(0, "a", ""))
         ssh.return_value = ssh_mock
     mock_create_snapshot_qemu.return_value = "0.img"
     status = Libvirt.build_vm_xml(ssh_mock, {}, "test", "vm_0", 0)
     self.assertEqual(status[0], result[0])
コード例 #2
0
    def setup_ovs_dpdk_context(self):
        nodes = []

        self.configure_nics_for_ovs_dpdk()

        for index, (key, vnf) in enumerate(OrderedDict(self.servers).items()):
            cfg = '/tmp/vm_ovs_%d.xml' % index
            vm_name = "vm_%d" % index

            # 1. Check and delete VM if already exists
            Libvirt.check_if_vm_exists_and_delete(vm_name, self.connection)

            vcpu, mac = Libvirt.build_vm_xml(self.connection, self.vm_flavor,
                                             cfg, vm_name, index)
            # 2: Cleanup already available VMs
            for idx, (vkey, vfs) in enumerate(
                    OrderedDict(vnf["network_ports"]).items()):
                if vkey == "mgmt":
                    continue
                self._enable_interfaces(index, vfs, cfg)

            # copy xml to target...
            self.connection.put(cfg, cfg)

            #    FIXME: launch through libvirt
            LOG.info("virsh create ...")
            Libvirt.virsh_create_vm(self.connection, cfg)

            #    5: Tunning for better performace
            Libvirt.pin_vcpu_for_perf(self.connection, vm_name, vcpu)
            self.vm_names.append(vm_name)

            # build vnf node details
            nodes.append(
                self.vnf_node.generate_vnf_instance(self.vm_flavor,
                                                    self.networks,
                                                    self.host_mgmt.get('ip'),
                                                    key, vnf, mac))

        return nodes
コード例 #3
0
    def setup_sriov_context(self):
        nodes = []

        #   1 : modprobe host_driver with num_vfs
        self.configure_nics_for_sriov()

        for index, (key, vnf) in enumerate(OrderedDict(self.servers).items()):
            cfg = '/tmp/vm_sriov_%s.xml' % str(index)
            vm_name = "vm_%s" % str(index)

            # 1. Check and delete VM if already exists
            Libvirt.check_if_vm_exists_and_delete(vm_name, self.connection)

            _, mac = Libvirt.build_vm_xml(self.connection, self.vm_flavor, cfg,
                                          vm_name, index)
            # 2: Cleanup already available VMs
            for idx, (vkey, vfs) in enumerate(
                    OrderedDict(vnf["network_ports"]).items()):
                if vkey == "mgmt":
                    continue
                self._enable_interfaces(index, idx, vfs, cfg)

            # copy xml to target...
            self.connection.put(cfg, cfg)

            # NOTE: launch through libvirt
            LOG.info("virsh create ...")
            Libvirt.virsh_create_vm(self.connection, cfg)

            self.vm_names.append(vm_name)

            # build vnf node details
            nodes.append(
                self.vnf_node.generate_vnf_instance(self.vm_flavor,
                                                    self.networks,
                                                    self.host_mgmt.get('ip'),
                                                    key, vnf, mac))

        return nodes