func applyVerifyRangeTag(t *testing.T, cfgBytes []byte, shouldFail bool) { initFakeStateDriver(t) defer deinitFakeStateDriver() cfg := &intent.Config{} err := json.Unmarshal(cfgBytes, cfg) if err != nil { t.Fatalf("error '%s' parsing config '%s'\n", err, cfgBytes) } _, err = resources.NewStateResourceManager(fakeDriver) if err != nil { log.Fatalf("state store initialization failed. Error: %s", err) } defer func() { resources.ReleaseStateResourceManager() }() // setup global state gCfg := &gstate.Cfg{} gCfg.StateDriver = fakeDriver gCfg.Auto.VLANs = "11-1000" gCfg.Auto.VXLANs = "1001-2000" // setup resources err = gCfg.Process() if err != nil { t.Fatalf("Error updating the config %+v. Error: %s", gCfg, err) } err = gCfg.Write() if err != nil { t.Fatalf("error updating global config.Error: %s", err) } tenant := cfg.Tenants[0] err = CreateTenant(fakeDriver, &tenant) if err != nil { t.Fatalf("error '%s' creating tenant\n", err) } err = CreateNetworks(fakeDriver, &tenant) if shouldFail { var expError string network := tenant.Networks[0] if network.PktTagType == "vlan" { expError = "requested vlan not available" } else { expError = "requested vxlan not available" } if err == nil { t.Fatalf("CreateNetworks did not return error\n") } else if !strings.Contains(err.Error(), expError) { t.Fatalf("CreateNetworks did not return error for OutOfRange\n") } } else if err != nil { t.Fatalf("error '%s' while creating network\n", err) } }
func TestGlobalConfigAutoVXLAN(t *testing.T) { cfgData := []byte(` { "Tenant" : "default", "Auto" : { "SubnetPool" : "11.5.0.0", "SubnetLen" : 16, "AllocSubnetLen" : 24, "VLANs" : "1-10", "VXLANs" : "15000-17000" }, "Deploy" : { "DefaultNetType" : "vxlan" } }`) var vxlan, localVLAN uint gc, err := Parse(cfgData) if err != nil { t.Fatalf("error '%s' parsing config '%s' \n", err, cfgData) } gstateSD.Init(nil) defer func() { gstateSD.Deinit() }() gc.StateDriver = gstateSD _, err = resources.NewStateResourceManager(gstateSD) if err != nil { t.Fatalf("Failed to instantiate resource manager. Error: %s", err) } defer func() { resources.ReleaseStateResourceManager() }() err = gc.Process("vlan") if err != nil { t.Fatalf("error '%s' processing config %v \n", err, gc) } err = gc.Process("vxlan") if err != nil { t.Fatalf("error '%s' processing config %v \n", err, gc) } vxlan, localVLAN, err = gc.AllocVXLAN(uint(0)) if err != nil { t.Fatalf("error - allocating vxlan - %s \n", err) } if vxlan == 0 { t.Fatalf("error - invalid vxlan allocated %d \n", vxlan) } if localVLAN == 0 { t.Fatalf("error - invalid vlan allocated %d \n", localVLAN) } err = gc.FreeVXLAN(vxlan, localVLAN) if err != nil { t.Fatalf("error freeing allocated vxlan %d localvlan %d - err '%s' \n", vxlan, localVLAN, err) } }
func applyConfig(t *testing.T, cfgBytes []byte) { cfg := &intent.Config{} err := json.Unmarshal(cfgBytes, cfg) if err != nil { t.Fatalf("error '%s' parsing config '%s'\n", err, cfgBytes) } _, err = resources.NewStateResourceManager(fakeDriver) if err != nil { log.Fatalf("state store initialization failed. Error: %s", err) } defer func() { resources.ReleaseStateResourceManager() }() // setup global state gCfg := &gstate.Cfg{} gCfg.StateDriver = fakeDriver gCfg.Auto.VLANs = "1-4094" gCfg.Auto.VXLANs = "1-10000" // setup resources err = gCfg.Process("vxlan") if err != nil { t.Fatalf("Error updating the config %+v. Error: %s", gCfg, err) } err = gCfg.Process("vlan") if err != nil { t.Fatalf("Error updating the config %+v. Error: %s", gCfg, err) } err = gCfg.Write() if err != nil { t.Fatalf("error updating global config.Error: %s", err) } for _, tenant := range cfg.Tenants { err = CreateTenant(fakeDriver, &tenant) if err != nil { t.Fatalf("error '%s' creating tenant\n", err) } err = CreateNetworks(fakeDriver, &tenant) if err != nil { t.Fatalf("error '%s' creating networks\n", err) } err = CreateEndpoints(fakeDriver, &tenant) if err != nil { t.Fatalf("error '%s' creating endpoints\n", err) } } fakeDriver.DumpState() }
// TestNetworkDeleteWithEPs // This test creates a network and adds endpoints to it. // It then tries to delete the network, while it has // active endpoints and expects them to fail func TestNetworkDeleteWithEPs(t *testing.T) { cfgBytes := []byte(`{ "Tenants" : [{ "Name" : "tenant-one", "Networks" : [{ "Name" : "orange", "SubnetCIDR" : "10.1.1.1/24", "Gateway" : "10.1.1.254", "Endpoints" : [ { "Container" : "myContainer1" }, { "Container" : "myContainer3" } ] }] }]}`) initFakeStateDriver(t) defer deinitFakeStateDriver() applyConfig(t, cfgBytes) epBindings := []intent.ConfigEP{{ Container: "myContainer1", Host: "host1", }, { Container: "myContainer2", Host: "host1", }, { Container: "myContainer3", Host: "host2", }, { Container: "myContainer4", Host: "host2", }} err := CreateEpBindings(&epBindings) if err != nil { t.Fatalf("error '%s' creating tenant\n", err) } cfg := &intent.Config{} err = json.Unmarshal(cfgBytes, cfg) if err != nil { t.Fatalf("error '%s' parsing config '%s'\n", err, cfgBytes) } _, err = resources.NewStateResourceManager(fakeDriver) if err != nil { log.Fatalf("state store initialization failed. Error: %s", err) } defer func() { resources.ReleaseStateResourceManager() }() for _, tenant := range cfg.Tenants { err = DeleteNetworks(fakeDriver, &tenant) if err == nil || (err != nil && !strings.Contains(err.Error(), "Error: Network has active endpoints")) { t.Fatalf("Network delete did not Fail with Active EPs.") } } }