@@ -66,84 +66,112 @@ func TestReconcileNCStatePrimaryIPChangeShouldFail(t *testing.T) {
6666 setOrchestratorTypeInternal (cns .KubernetesCRD )
6767 svc .state .ContainerStatus = make (map [string ]containerstatus )
6868
69- // start with a NC in state
70- ncID := "555ac5c9-89f2-4b5d-b8d0-616894d6d151"
71- svc .state .ContainerStatus [ncID ] = containerstatus {
72- ID : ncID ,
73- VMVersion : "0" ,
74- HostVersion : "0" ,
75- CreateNetworkContainerRequest : cns.CreateNetworkContainerRequest {
76- NetworkContainerid : ncID ,
77- IPConfiguration : cns.IPConfiguration {
78- IPSubnet : cns.IPSubnet {
79- IPAddress : "10.0.1.0" ,
80- PrefixLength : 24 ,
69+ testCases := []struct {
70+ existingIPAddress string
71+ requestIPAddress string
72+ }{
73+ {"" , "10.240.0.0/16" },
74+ {"10.240.0.0" , "2001:db8::/64" },
75+ {"2001:db8::/64" , "10.240.0.0/16" },
76+ {"10.0.1.0/22" , "10.0.2.0/24" },
77+ {"10.0.1.0/21" , "10.0.1.0/23" },
78+ {"10.0.1.0" , "10.0.0.0/15" },
79+ {"10.0.1.0/15" , "10.0.0.0" },
80+ }
81+
82+ // Run test cases
83+ for _ , tc := range testCases {
84+ // start with a NC in state
85+ ncID := "555ac5c9-89f2-4b5d-b8d0-616894d6d151"
86+ svc .state .ContainerStatus [ncID ] = containerstatus {
87+ ID : ncID ,
88+ VMVersion : "0" ,
89+ HostVersion : "0" ,
90+ CreateNetworkContainerRequest : cns.CreateNetworkContainerRequest {
91+ NetworkContainerid : ncID ,
92+ IPConfiguration : cns.IPConfiguration {
93+ IPSubnet : cns.IPSubnet {
94+ IPAddress : tc .existingIPAddress ,
95+ PrefixLength : 24 ,
96+ },
8197 },
8298 },
83- },
84- }
99+ }
85100
86- ncReqs := []* cns.CreateNetworkContainerRequest {
87- {
88- NetworkContainerid : ncID ,
89- IPConfiguration : cns.IPConfiguration {
90- IPSubnet : cns.IPSubnet {
91- IPAddress : "10.0.2.0" , // note this IP has changed
92- PrefixLength : 24 ,
101+ ncReqs := []* cns.CreateNetworkContainerRequest {
102+ {
103+ NetworkContainerid : ncID ,
104+ IPConfiguration : cns.IPConfiguration {
105+ IPSubnet : cns.IPSubnet {
106+ IPAddress : tc .requestIPAddress ,
107+ PrefixLength : 24 ,
108+ },
93109 },
94110 },
95- },
96- }
111+ }
97112
98- // now try to reconcile the state where the NC primary IP has changed
99- resp := svc .ReconcileIPAMStateForSwift (ncReqs , map [string ]cns.PodInfo {}, & v1alpha.NodeNetworkConfig {})
113+ // now try to reconcile the state where the NC primary IP has changed
114+ resp := svc .ReconcileIPAMStateForSwift (ncReqs , map [string ]cns.PodInfo {}, & v1alpha.NodeNetworkConfig {})
115+
116+ assert .Equal (t , types .PrimaryCANotSame , resp )
117+ }
100118
101- assert .Equal (t , types .PrimaryCANotSame , resp )
102119}
103120
104121// TestReconcileNCStatePrimaryIPChangeShouldNotFail tests that reconciling NC state with
105- // a NC whose IP has changed should not fail for overlay clusters
122+ // a NC whose IP has changed should not fail if new IP is superset of old IP
106123func TestReconcileNCStatePrimaryIPChangeShouldNotFail (t * testing.T ) {
107124 restartService ()
108125 setEnv (t )
109126 setOrchestratorTypeInternal (cns .KubernetesCRD )
110127 svc .state .ContainerStatus = make (map [string ]containerstatus )
111128
112- // start with a NC in state
113- ncID := "555ac5c9-89f2-4b5d-b8d0-616894d6d151"
114- svc .state .ContainerStatus [ncID ] = containerstatus {
115- ID : ncID ,
116- VMVersion : "0" ,
117- HostVersion : "0" ,
118- CreateNetworkContainerRequest : cns.CreateNetworkContainerRequest {
119- NetworkContainerid : ncID ,
120- IPConfiguration : cns.IPConfiguration {
121- IPSubnet : cns.IPSubnet {
122- IPAddress : "10.0.1.0" ,
123- PrefixLength : 24 ,
129+ testCases := []struct {
130+ existingIPAddress string
131+ requestIPAddress string
132+ }{
133+ {"10.0.1.0/24" , "10.0.2.0/22" },
134+ {"10.0.1.0/20" , "10.0.1.0/18" },
135+ {"10.0.1.0/19" , "10.0.0.0/15" },
136+ }
137+
138+ // Run test cases
139+ for _ , tc := range testCases {
140+ // start with a NC in state
141+ ncID := "555ac5c9-89f2-4b5d-b8d0-616894d6d151"
142+ svc .state .ContainerStatus [ncID ] = containerstatus {
143+ ID : ncID ,
144+ VMVersion : "0" ,
145+ HostVersion : "0" ,
146+ CreateNetworkContainerRequest : cns.CreateNetworkContainerRequest {
147+ NetworkContainerid : ncID ,
148+ IPConfiguration : cns.IPConfiguration {
149+ IPSubnet : cns.IPSubnet {
150+ IPAddress : tc .existingIPAddress ,
151+ PrefixLength : 24 ,
152+ },
124153 },
125154 },
126- },
127- }
155+ }
128156
129- ncReqs := []* cns.CreateNetworkContainerRequest {
130- {
131- NetworkContainerid : ncID ,
132- IPConfiguration : cns.IPConfiguration {
133- IPSubnet : cns.IPSubnet {
134- IPAddress : "10.0.2.0" , // note this IP has changed
135- PrefixLength : 24 ,
157+ ncReqs := []* cns.CreateNetworkContainerRequest {
158+ {
159+ NetworkContainerid : ncID ,
160+ IPConfiguration : cns.IPConfiguration {
161+ IPSubnet : cns.IPSubnet {
162+ IPAddress : tc .requestIPAddress ,
163+ PrefixLength : 24 ,
164+ },
136165 },
166+ NetworkContainerType : cns .Kubernetes ,
137167 },
138- Scenario : v1alpha .Overlay , // overlay cluster - skip primary CA check
139- NetworkContainerType : cns .Kubernetes ,
140- },
141- }
168+ }
142169
143- // now try to reconcile the state where the NC primary IP has changed
144- resp := svc .ReconcileIPAMStateForSwift (ncReqs , map [string ]cns.PodInfo {}, & v1alpha.NodeNetworkConfig {})
170+ // now try to reconcile the state where the NC primary IP has changed
171+ resp := svc .ReconcileIPAMStateForSwift (ncReqs , map [string ]cns.PodInfo {}, & v1alpha.NodeNetworkConfig {})
145172
146- assert .Equal (t , types .Success , resp )
173+ assert .Equal (t , types .Success , resp )
174+ }
147175}
148176
149177// TestReconcileNCStateGatewayChange tests that NC state gets updated when reconciled
0 commit comments