-
Notifications
You must be signed in to change notification settings - Fork 260
Implement CreateOrUpdateNetworkContainerInternal API. #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9ed3f04
5b2f4ed
ff8d5eb
f02a046
333d801
5c5c1e9
c3786d1
78f7903
459b632
ade9b50
d3f0ce9
fcd061b
9c2de8b
585c5a7
033e23d
2b8ec6f
5c82381
d2f3f87
3b179f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,68 @@ | ||
| package cnsclient | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| "reflect" | ||
| "strconv" | ||
| "testing" | ||
|
|
||
| "github.com/Azure/azure-container-networking/cns" | ||
| "github.com/Azure/azure-container-networking/cns/common" | ||
| "github.com/Azure/azure-container-networking/cns/logger" | ||
| "github.com/Azure/azure-container-networking/cns/restserver" | ||
| "github.com/Azure/azure-container-networking/log" | ||
| "github.com/google/uuid" | ||
| ) | ||
|
|
||
| var ( | ||
| testNCID = "06867cf3-332d-409d-8819-ed70d2c116b0" | ||
| svc *restserver.HTTPRestService | ||
| ) | ||
|
|
||
| testIP1 = "10.0.0.1" | ||
| testPod1GUID = "898fb8f1-f93e-4c96-9c31-6b89098949a3" | ||
| testPod1Info = cns.KubernetesPodInfo{ | ||
| PodName: "testpod1", | ||
| PodNamespace: "testpod1namespace", | ||
| } | ||
| const ( | ||
| primaryIp = "10.0.0.5" | ||
| gatewayIp = "10.0.0.1" | ||
| dockerContainerType = cns.Docker | ||
| ) | ||
|
|
||
| // func addTestStateToRestServer(svc *restserver.HTTPRestService) { | ||
| // // set state as already allocated | ||
| // state1, _ := restserver.NewPodStateWithOrchestratorContext(testIP1, 24, testPod1GUID, testNCID, cns.Available, testPod1Info) | ||
| // ipconfigs := map[string]cns.SecondaryIPConfig{ | ||
| // state1.ID: state1, | ||
| // } | ||
| // nc := cns.CreateNetworkContainerRequest{ | ||
| // SecondaryIPConfigs: ipconfigs, | ||
| // } | ||
| func addTestStateToRestServer(t *testing.T, secondaryIps []string) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can you declare vars at the beginning of the function in one block like this? I picked this up from Mat's code and I think it makes for cleaner functions |
||
| var ipConfig cns.IPConfiguration | ||
| ipConfig.DNSServers = []string{"8.8.8.8", "8.8.4.4"} | ||
| ipConfig.GatewayIPAddress = gatewayIp | ||
| var ipSubnet cns.IPSubnet | ||
| ipSubnet.IPAddress = primaryIp | ||
| ipSubnet.PrefixLength = 32 | ||
| ipConfig.IPSubnet = ipSubnet | ||
| secondaryIPConfigs := make(map[string]cns.SecondaryIPConfig) | ||
|
|
||
| for _, secIpAddress := range secondaryIps { | ||
| secIpConfig := cns.SecondaryIPConfig{ | ||
| IPSubnet: cns.IPSubnet{ | ||
| IPAddress: secIpAddress, | ||
| PrefixLength: 32, | ||
| }, | ||
| } | ||
| ipId := uuid.New() | ||
| secondaryIPConfigs[ipId.String()] = secIpConfig | ||
| } | ||
|
|
||
| // svc.CreateOrUpdateNetworkContainerWithSecondaryIPConfigs(nc) | ||
| // } | ||
| req := cns.CreateNetworkContainerRequest{ | ||
| NetworkContainerType: dockerContainerType, | ||
| NetworkContainerid: "testNcId1", | ||
| IPConfiguration: ipConfig, | ||
| SecondaryIPConfigs: secondaryIPConfigs, | ||
| } | ||
|
|
||
| returnCode := svc.CreateOrUpdateNetworkContainerInternal(req) | ||
| if returnCode != 0 { | ||
| t.Fatalf("Failed to createNetworkContainerRequest, req: %+v, err: %d", req, returnCode) | ||
neaggarwMS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| func getIPConfigFromGetNetworkContainerResponse(resp *cns.GetIPConfigResponse) (net.IPNet, error) { | ||
| var ( | ||
|
|
@@ -52,11 +85,10 @@ func getIPConfigFromGetNetworkContainerResponse(resp *cns.GetIPConfigResponse) ( | |
| return resultIPnet, err | ||
| } | ||
|
|
||
| /* | ||
| func TestMain(m *testing.M) { | ||
| var ( | ||
| info = &cns.SetOrchestratorTypeRequest{ | ||
| OrchestratorType: cns.Kubernetes} | ||
| OrchestratorType: cns.KubernetesCRD} | ||
| body bytes.Buffer | ||
| res *http.Response | ||
| ) | ||
|
|
@@ -80,15 +112,13 @@ func TestMain(m *testing.M) { | |
| config := common.ServiceConfig{} | ||
|
|
||
| httpRestService, err := restserver.NewHTTPRestService(&config) | ||
| svc := httpRestService.(*restserver.HTTPRestService) | ||
| svc = httpRestService.(*restserver.HTTPRestService) | ||
| svc.Name = "cns-test-server" | ||
| if err != nil { | ||
| logger.Errorf("Failed to create CNS object, err:%v.\n", err) | ||
| return | ||
| } | ||
|
|
||
| //addTestStateToRestServer(svc) | ||
|
|
||
| if httpRestService != nil { | ||
| err = httpRestService.Start(&config) | ||
| if err != nil { | ||
|
|
@@ -111,31 +141,37 @@ func TestMain(m *testing.M) { | |
| } | ||
| fmt.Println(res) | ||
|
|
||
| m.Run() | ||
| exitCode := m.Run() | ||
| os.Exit(exitCode) | ||
| } | ||
|
|
||
| func TestCNSClientRequestAndRelease(t *testing.T) { | ||
| podName := "testpodname" | ||
| podNamespace := "testpodnamespace" | ||
| ip := net.ParseIP("10.0.0.1") | ||
| _, ipnet, _ := net.ParseCIDR("10.0.0.1/24") | ||
| desiredIpAddress := "10.0.0.5" | ||
| ip := net.ParseIP(desiredIpAddress) | ||
| _, ipnet, _ := net.ParseCIDR("10.0.0.5/32") | ||
| desired := net.IPNet{ | ||
| IP: ip, | ||
| Mask: ipnet.Mask, | ||
| } | ||
|
|
||
| secondaryIps := make([]string, 0) | ||
| secondaryIps = append(secondaryIps, desiredIpAddress) | ||
| cnsClient, _ := InitCnsClient("") | ||
|
|
||
| addTestStateToRestServer(t, secondaryIps) | ||
|
|
||
| podInfo := cns.KubernetesPodInfo{PodName: podName, PodNamespace: podNamespace} | ||
| orchestratorContext, err := json.Marshal(podInfo) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // no IP reservation found with that context, expect fail | ||
| // no IP reservation found with that context, expect no failure. | ||
| err = cnsClient.ReleaseIPAddress(orchestratorContext) | ||
| if err == nil { | ||
| t.Fatalf("Expected failure to release when no IP reservation found with context: %+v", err) | ||
| if err != nil { | ||
| t.Fatalf("Release ip idempotent call failed: %+v", err) | ||
| } | ||
|
|
||
| // request IP address | ||
|
|
@@ -156,4 +192,3 @@ func TestCNSClientRequestAndRelease(t *testing.T) { | |
| t.Fatalf("Expected to not fail when releasing IP reservation found with context: %+v", err) | ||
| } | ||
| } | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ type xmlDocument struct { | |
|
|
||
| var ( | ||
| service HTTPService | ||
| svc *HTTPRestService | ||
| mux *http.ServeMux | ||
| hostQueryForProgrammedVersionResponse = `{"httpStatusCode":"200","networkContainerId":"eab2470f-test-test-test-b3cd316979d5","version":"1"}` | ||
| hostQueryResponse = xmlDocument{ | ||
|
|
@@ -104,8 +105,7 @@ func TestMain(m *testing.M) { | |
| fmt.Printf("Failed to create CNS object %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| svc := service.(*HTTPRestService) | ||
| svc = service.(*HTTPRestService) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new svc object is being created on line 110 |
||
| svc.Name = "cns-test-server" | ||
| if err != nil { | ||
| logger.Errorf("Failed to create CNS object, err:%v.\n", err) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.