@@ -8,14 +8,15 @@ import (
88)
99
1010const (
11- ncID = "160005ba-cd02-11ea-87d0-0242ac130003"
12- ipCIDR = "10.0.0.1/32"
13- ipCIDRString = "10.0.0.1"
14- ipCIDRMaskLength = 32
15- ipNotCIDR = "10.0.0.1"
16- ipMalformed = "10.0.0.0.0"
17- defaultGateway = "10.0.0.2"
18- subnetName = "subnet1"
11+ ncID = "160005ba-cd02-11ea-87d0-0242ac130003"
12+ primaryIp = "10.0.0.1"
13+ ipInCIDR = "10.0.0.1/32"
14+ ipMalformed = "10.0.0.0.0"
15+ defaultGateway = "10.0.0.2"
16+ subnetName = "subnet1"
17+ subnetAddressSpace = "10.0.0.0/24"
18+ subnetPrefixLen = 24
19+ testSecIp1 = "10.0.0.2"
1920)
2021
2122func TestStatusToNCRequestMalformedPrimaryIP (t * testing.T ) {
@@ -32,9 +33,10 @@ func TestStatusToNCRequestMalformedPrimaryIP(t *testing.T) {
3233 IPAssignments : []nnc.IPAssignment {
3334 {
3435 Name : allocatedUUID ,
35- IP : ipCIDR ,
36+ IP : testSecIp1 ,
3637 },
3738 },
39+ SubnetAddressSpace : subnetAddressSpace ,
3840 },
3941 },
4042 }
@@ -56,14 +58,15 @@ func TestStatusToNCRequestMalformedIPAssignment(t *testing.T) {
5658 status = nnc.NodeNetworkConfigStatus {
5759 NetworkContainers : []nnc.NetworkContainer {
5860 {
59- PrimaryIP : ipCIDR ,
61+ PrimaryIP : primaryIp ,
6062 ID : ncID ,
6163 IPAssignments : []nnc.IPAssignment {
6264 {
6365 Name : allocatedUUID ,
6466 IP : ipMalformed ,
6567 },
6668 },
69+ SubnetAddressSpace : subnetAddressSpace ,
6770 },
6871 },
6972 }
@@ -76,7 +79,7 @@ func TestStatusToNCRequestMalformedIPAssignment(t *testing.T) {
7679 }
7780}
7881
79- func TestStatusToNCRequestPrimaryIPNotCIDR (t * testing.T ) {
82+ func TestStatusToNCRequestPrimaryIPInCIDR (t * testing.T ) {
8083 var (
8184 status nnc.NodeNetworkConfigStatus
8285 err error
@@ -85,14 +88,15 @@ func TestStatusToNCRequestPrimaryIPNotCIDR(t *testing.T) {
8588 status = nnc.NodeNetworkConfigStatus {
8689 NetworkContainers : []nnc.NetworkContainer {
8790 {
88- PrimaryIP : ipNotCIDR ,
91+ PrimaryIP : ipInCIDR ,
8992 ID : ncID ,
9093 IPAssignments : []nnc.IPAssignment {
9194 {
9295 Name : allocatedUUID ,
93- IP : ipCIDR ,
96+ IP : testSecIp1 ,
9497 },
9598 },
99+ SubnetAddressSpace : subnetAddressSpace ,
96100 },
97101 },
98102 }
@@ -114,14 +118,45 @@ func TestStatusToNCRequestIPAssignmentNotCIDR(t *testing.T) {
114118 status = nnc.NodeNetworkConfigStatus {
115119 NetworkContainers : []nnc.NetworkContainer {
116120 {
117- PrimaryIP : ipCIDR ,
121+ PrimaryIP : primaryIp ,
118122 ID : ncID ,
119123 IPAssignments : []nnc.IPAssignment {
120124 {
121125 Name : allocatedUUID ,
122- IP : ipNotCIDR ,
126+ IP : ipInCIDR ,
123127 },
124128 },
129+ SubnetAddressSpace : subnetAddressSpace ,
130+ },
131+ },
132+ }
133+
134+ // Test with ip assignment not in CIDR form
135+ _ , err = CRDStatusToNCRequest (status )
136+
137+ if err == nil {
138+ t .Fatalf ("Expected translation of CRD status with ip assignment not CIDR, to fail." )
139+ }
140+ }
141+
142+ func TestStatusToNCRequestWithIncorrectSubnetAddressSpace (t * testing.T ) {
143+ var (
144+ status nnc.NodeNetworkConfigStatus
145+ err error
146+ )
147+
148+ status = nnc.NodeNetworkConfigStatus {
149+ NetworkContainers : []nnc.NetworkContainer {
150+ {
151+ PrimaryIP : primaryIp ,
152+ ID : ncID ,
153+ IPAssignments : []nnc.IPAssignment {
154+ {
155+ Name : allocatedUUID ,
156+ IP : testSecIp1 ,
157+ },
158+ },
159+ SubnetAddressSpace : "10.0.0.0" , // not a cidr range
125160 },
126161 },
127162 }
@@ -147,17 +182,17 @@ func TestStatusToNCRequestSuccess(t *testing.T) {
147182 status = nnc.NodeNetworkConfigStatus {
148183 NetworkContainers : []nnc.NetworkContainer {
149184 {
150- PrimaryIP : ipCIDR ,
185+ PrimaryIP : primaryIp ,
151186 ID : ncID ,
152187 IPAssignments : []nnc.IPAssignment {
153188 {
154189 Name : allocatedUUID ,
155- IP : ipCIDR ,
190+ IP : testSecIp1 ,
156191 },
157192 },
158193 SubnetName : subnetName ,
159194 DefaultGateway : defaultGateway ,
160- SubnetAddressSpace : "" , // Not currently set by DNC Request Controller
195+ SubnetAddressSpace : subnetAddressSpace ,
161196 },
162197 },
163198 }
@@ -169,12 +204,12 @@ func TestStatusToNCRequestSuccess(t *testing.T) {
169204 t .Fatalf ("Expected translation of CRD status to succeed, got error :%v" , err )
170205 }
171206
172- if ncRequest .IPConfiguration .IPSubnet .IPAddress != ipCIDRString {
173- t .Fatalf ("Expected ncRequest's ipconfiguration to have the ip %v but got %v" , ipCIDRString , ncRequest .IPConfiguration .IPSubnet .IPAddress )
207+ if ncRequest .IPConfiguration .IPSubnet .IPAddress != primaryIp {
208+ t .Fatalf ("Expected ncRequest's ipconfiguration to have the ip %v but got %v" , primaryIp , ncRequest .IPConfiguration .IPSubnet .IPAddress )
174209 }
175210
176- if ncRequest .IPConfiguration .IPSubnet .PrefixLength != uint8 (ipCIDRMaskLength ) {
177- t .Fatalf ("Expected ncRequest's ipconfiguration prefix length to be %v but got %v" , ipCIDRMaskLength , ncRequest .IPConfiguration .IPSubnet .PrefixLength )
211+ if ncRequest .IPConfiguration .IPSubnet .PrefixLength != uint8 (subnetPrefixLen ) {
212+ t .Fatalf ("Expected ncRequest's ipconfiguration prefix length to be %v but got %v" , subnetPrefixLen , ncRequest .IPConfiguration .IPSubnet .PrefixLength )
178213 }
179214
180215 if ncRequest .IPConfiguration .GatewayIPAddress != defaultGateway {
@@ -195,8 +230,8 @@ func TestStatusToNCRequestSuccess(t *testing.T) {
195230 t .Fatalf ("Expected there to be a secondary ip with the key %v but found nothing" , allocatedUUID )
196231 }
197232
198- if secondaryIP .IPAddress != ipCIDRString {
199- t .Fatalf ("Expected %v as the secondary IP config but got %v" , ipCIDRString , secondaryIP .IPAddress )
233+ if secondaryIP .IPAddress != testSecIp1 {
234+ t .Fatalf ("Expected %v as the secondary IP config but got %v" , testSecIp1 , secondaryIP .IPAddress )
200235 }
201236}
202237
@@ -229,7 +264,7 @@ func TestSecondaryIPsToCRDSpecSuccess(t *testing.T) {
229264
230265 secondaryIPs = map [string ]cns.SecondaryIPConfig {
231266 allocatedUUID : {
232- IPAddress : ipCIDRString ,
267+ IPAddress : testSecIp1 ,
233268 },
234269 }
235270
0 commit comments