From fc2339e28497c3c6acbeb81b6f74c0ae3ca13a13 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Wed, 14 Aug 2019 14:17:59 -0700 Subject: [PATCH 1/2] Remove/Add ClearContainer/COW Container type --- cns/NetworkContainerContract.go | 4 ++-- cns/restserver/api.go | 1 + cns/restserver/restserver.go | 6 +++--- cns/restserver/restserver_test.go | 27 +++++++++++++++++++++++++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cns/NetworkContainerContract.go b/cns/NetworkContainerContract.go index 6e6fd5272c..1816e5187c 100644 --- a/cns/NetworkContainerContract.go +++ b/cns/NetworkContainerContract.go @@ -23,10 +23,10 @@ const ( const ( AzureContainerInstance = "AzureContainerInstance" WebApps = "WebApps" - ClearContainer = "ClearContainer" Docker = "Docker" Basic = "Basic" JobObject = "JobObject" + COW = "COW" // Container on Windows ) // Orchestrator Types @@ -171,7 +171,7 @@ type AttachContainerToNetworkResponse struct { Response Response } -// DetachNetworkContainerToNetworkResponse specifies response of detaching network container from network. +// DetachContainerFromNetworkResponse specifies response of detaching network container from network. type DetachContainerFromNetworkResponse struct { Response Response } diff --git a/cns/restserver/api.go b/cns/restserver/api.go index de294c3e00..25d60e3ca2 100644 --- a/cns/restserver/api.go +++ b/cns/restserver/api.go @@ -26,6 +26,7 @@ const ( UnexpectedError = 99 ) +// ReturnCodeToString - Converts an error code to appropriate string. func ReturnCodeToString(returnCode int) (s string) { switch returnCode { case Success: diff --git a/cns/restserver/restserver.go b/cns/restserver/restserver.go index 09dc55b80f..9ee6894a09 100644 --- a/cns/restserver/restserver.go +++ b/cns/restserver/restserver.go @@ -191,7 +191,7 @@ func (service *HTTPRestService) Stop() { log.Printf("[Azure CNS] Service stopped.") } -// Get dnc/service partition key +// GetPartitionKey - Get dnc/service partition key func (service *HTTPRestService) GetPartitionKey() (dncPartitionKey string) { service.lock.Lock() dncPartitionKey = service.dncPartitionKey @@ -1025,13 +1025,13 @@ func (service *HTTPRestService) saveNetworkContainerGoalState(req cns.CreateNetw switch req.NetworkContainerType { case cns.AzureContainerInstance: fallthrough - case cns.ClearContainer: - fallthrough case cns.Docker: fallthrough case cns.Basic: fallthrough case cns.JobObject: + fallthrough + case cns.COW: switch service.state.OrchestratorType { case cns.Kubernetes: fallthrough diff --git a/cns/restserver/restserver_test.go b/cns/restserver/restserver_test.go index c787da44e6..0485cc0094 100644 --- a/cns/restserver/restserver_test.go +++ b/cns/restserver/restserver_test.go @@ -596,13 +596,13 @@ func TestCreateNetworkContainer(t *testing.T) { // Test create network container of type WebApps fmt.Println("TestCreateNetworkContainer: WebApps") - err = creatOrUpdateNetworkContainerWithName(t, "ethWebApp", "11.0.0.5", "WebApps") + err = creatOrUpdateNetworkContainerWithName(t, "ethWebApp", "192.0.0.5", "WebApps") if err != nil { t.Errorf("creatOrUpdateWebAppContainerWithName failed Err:%+v", err) t.Fatal(err) } - err = creatOrUpdateNetworkContainerWithName(t, "ethWebApp", "11.0.0.6", "WebApps") + err = creatOrUpdateNetworkContainerWithName(t, "ethWebApp", "192.0.0.6", "WebApps") if err != nil { t.Errorf("Updating interface failed Err:%+v", err) t.Fatal(err) @@ -618,6 +618,29 @@ func TestCreateNetworkContainer(t *testing.T) { } +func TestCreateCOWContainer(t *testing.T) { + fmt.Println("Test: TestCreateCOWContainer") + + setEnv(t) + setOrchestratorType(t, cns.ServiceFabric) + + fmt.Println("TestCreateNetworkContainer: COW") + err := creatOrUpdateNetworkContainerWithName(t, "testContainer", "10.0.0.5", "COW") + if err != nil { + t.Errorf("Failed to save the goal state for network container of type COW"+ + " due to error: %+v", err) + t.Fatal(err) + } + + fmt.Println("Deleting the saved goal state for network container of type COW") + err = deleteNetworkAdapterWithName(t, "testContainer") + if err != nil { + t.Errorf("Failed to delete the saved goal state due to error: %+v", err) + t.Fatal(err) + } + +} + func TestGetNetworkContainerByOrchestratorContext(t *testing.T) { // requires more than 30 seconds to run fmt.Println("Test: TestGetNetworkContainerByOrchestratorContext") From 68663f868dba935f1f45ff0df4daeae01fb26d63 Mon Sep 17 00:00:00 2001 From: Vivek Aggarwal Date: Wed, 14 Aug 2019 15:41:32 -0700 Subject: [PATCH 2/2] Addressed feedback --- cns/restserver/restserver_test.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/cns/restserver/restserver_test.go b/cns/restserver/restserver_test.go index 0485cc0094..98806a21d3 100644 --- a/cns/restserver/restserver_test.go +++ b/cns/restserver/restserver_test.go @@ -580,7 +580,7 @@ func TestCreateNetworkContainer(t *testing.T) { // Test create network container of type JobObject fmt.Println("TestCreateNetworkContainer: JobObject") - err := creatOrUpdateNetworkContainerWithName(t, "testJobObject", "11.0.0.5", "JobObject") + err := creatOrUpdateNetworkContainerWithName(t, "testJobObject", "10.1.0.5", "JobObject") if err != nil { t.Errorf("Failed to save the goal state for network container of type JobObject "+ " due to error: %+v", err) @@ -616,16 +616,8 @@ func TestCreateNetworkContainer(t *testing.T) { t.Fatal(err) } -} - -func TestCreateCOWContainer(t *testing.T) { - fmt.Println("Test: TestCreateCOWContainer") - - setEnv(t) - setOrchestratorType(t, cns.ServiceFabric) - - fmt.Println("TestCreateNetworkContainer: COW") - err := creatOrUpdateNetworkContainerWithName(t, "testContainer", "10.0.0.5", "COW") + // Test create network container of type COW + err = creatOrUpdateNetworkContainerWithName(t, "testCOWContainer", "10.0.0.5", "COW") if err != nil { t.Errorf("Failed to save the goal state for network container of type COW"+ " due to error: %+v", err) @@ -633,7 +625,7 @@ func TestCreateCOWContainer(t *testing.T) { } fmt.Println("Deleting the saved goal state for network container of type COW") - err = deleteNetworkAdapterWithName(t, "testContainer") + err = deleteNetworkAdapterWithName(t, "testCOWContainer") if err != nil { t.Errorf("Failed to delete the saved goal state due to error: %+v", err) t.Fatal(err)