コード例 #1
0
func TestSetNetworkDataDirect(t *testing.T) {
	hnic1 := &host.NIC{
		Name:    "eth0",
		Driver:  "tg3",
		Vendor:  "Broadcom",
		Model:   "",
		PCIAddr: "pci@0000:09:00.0",
		Desc:    "test1_direct",
		Type:    host.NicTypePhys,
	}

	gnic1 := guest.NewNIC()
	gnic1.Network = "net1"
	gnic1.PCIAddr.Domain = "0000"
	gnic1.PCIAddr.Slot = "5"
	gnic1.PCIAddr.Bus = "00"
	gnic1.PCIAddr.Function = "0"
	gnic1.HostNIC = hnic1

	list1 := guest.NewNICList()
	list1.Add(gnic1)

	mode1 := new(xmlinput.Mode)
	mode1.Type = xmlinput.ConTypeDirect
	mode1.VnicDriver = "virtio"

	net1 := new(xmlinput.Network)
	net1.Modes = []*xmlinput.Mode{mode1}
	net1.Name = "net1"

	hnic2 := &host.NIC{
		Name:    "eth1",
		Driver:  "tg3",
		Vendor:  "Broadcom",
		Model:   "",
		PCIAddr: "pci@0000:10:00.0",
		Desc:    "test1_direct",
		Type:    host.NicTypePhys,
	}

	gnic2 := guest.NewNIC()
	gnic2.Network = "net1"
	gnic2.PCIAddr.Domain = "0000"
	gnic2.PCIAddr.Slot = "6"
	gnic2.PCIAddr.Bus = "00"
	gnic2.PCIAddr.Function = "0"
	gnic2.HostNIC = hnic2

	list2 := guest.NewNICList()
	list2.Add(gnic2)

	mode2 := new(xmlinput.Mode)
	mode2.Type = xmlinput.ConTypeDirect
	mode2.VnicDriver = "virtio"

	net2 := new(xmlinput.Network)
	net2.Modes = []*xmlinput.Mode{mode2}
	net2.Name = "net2"

	lists := []guest.NICList{list1, list2}
	nets := []*xmlinput.Network{net1, net2}

	c := guest.NewConfig()
	c.NICLists = lists
	c.Networks = nets
	d := new(meta)
	str, err := d.SetNetworkData(c, "")
	if err != nil {
		t.Fatal(err)
	}

	fmt.Printf("Template: %s\n\n", TmpltDirect)
	fmt.Printf("Expected: %s\n", expectedSetNetworkDataDirect)
	fmt.Printf("Generated:%s\n", str)
}
コード例 #2
0
func TestSetNetworkDataOVS(t *testing.T) {
	hnic1 := &host.NIC{
		Name:    "br0-ovs",
		Driver:  "openvswitch",
		Vendor:  "",
		Model:   "",
		PCIAddr: "",
		Desc:    "test1_ovs",
		Type:    host.NicTypeOVS,
	}
	gnic1 := guest.NewNIC()
	gnic1.Network = "net1"
	gnic1.PCIAddr.Domain = "0000"
	gnic1.PCIAddr.Slot = "5"
	gnic1.PCIAddr.Bus = "00"
	gnic1.PCIAddr.Function = "0"
	gnic1.HostNIC = hnic1

	list1 := guest.NewNICList()
	list1.Add(gnic1)

	mode1 := new(xmlinput.Mode)
	mode1.Type = xmlinput.ConTypeOVS
	mode1.VnicDriver = "virtio"

	net1 := new(xmlinput.Network)
	net1.Modes = []*xmlinput.Mode{mode1}
	net1.Name = "net1"

	hnic2 := &host.NIC{
		Name:    "br1-ovs",
		Driver:  "openvswitch",
		Vendor:  "",
		Model:   "",
		PCIAddr: "",
		Desc:    "test1_ovs",
		Type:    host.NicTypeOVS,
	}
	gnic2 := guest.NewNIC()
	gnic2.Network = "net2"
	gnic2.PCIAddr.Domain = "0000"
	gnic2.PCIAddr.Slot = "6"
	gnic2.PCIAddr.Bus = "00"
	gnic2.PCIAddr.Function = "0"
	gnic2.HostNIC = hnic2

	list2 := guest.NewNICList()
	list2.Add(gnic2)

	mode2 := new(xmlinput.Mode)
	mode2.Type = xmlinput.ConTypeOVS
	mode2.VnicDriver = "virtio"

	net2 := new(xmlinput.Network)
	net2.Modes = []*xmlinput.Mode{mode2}
	net2.Name = "net2"

	lists := []guest.NICList{list1, list2}
	nets := []*xmlinput.Network{net1, net2}

	c := guest.NewConfig()
	c.NICLists = lists
	c.Networks = nets
	d := new(meta)
	str, err := d.SetNetworkData(c, "")
	if err != nil {
		t.Fatal(err)
	}

	fmt.Printf("Template: %s\n\n", TmpltBridgedOVS)
	fmt.Printf("Expected: %s\n", expectedSetNetworkDataBridgedOVS)
	fmt.Printf("Generated:%s\n", str)
}