@@ -534,7 +534,7 @@ func validateIpState(t *testing.T, actualIps []cns.IPConfigurationStatus, expect
534534 }
535535}
536536
537- func TestIPAMMarkIPConfigAsPending (t * testing.T ) {
537+ func TestIPAMMarkIPCountAsPending (t * testing.T ) {
538538 svc := getTestService ()
539539 // set state as already allocated
540540 state1 , _ := NewPodStateWithOrchestratorContext (testIP1 , 24 , testPod1GUID , testNCID , cns .Available , testPod1Info )
@@ -574,3 +574,45 @@ func TestIPAMMarkIPConfigAsPending(t *testing.T) {
574574 t .Fatalf ("Unexpected failure releasing IP: %+v" , err )
575575 }
576576}
577+
578+ func TestIPAMMarkExistingIPConfigAsPending (t * testing.T ) {
579+ svc := getTestService ()
580+
581+ // Add already allocated pod ip to state
582+ svc .PodIPIDByOrchestratorContext [testPod1Info .GetOrchestratorContextKey ()] = testPod1GUID
583+ state1 , _ := NewPodStateWithOrchestratorContext (testIP1 , 24 , testPod1GUID , testNCID , cns .Allocated , testPod1Info )
584+ state2 := NewPodState (testIP2 , 24 , testPod2GUID , testNCID , cns .Available )
585+
586+ ipconfigs := map [string ]cns.IPConfigurationStatus {
587+ state1 .ID : state1 ,
588+ state2 .ID : state2 ,
589+ }
590+ err := UpdatePodIpConfigState (t , svc , ipconfigs )
591+ if err != nil {
592+ t .Fatalf ("Expected to not fail adding IP's to state: %+v" , err )
593+ }
594+
595+ // mark available ip as as pending
596+ pendingIPIDs := []string {testPod2GUID }
597+ err = svc .MarkExistingIPsAsPending (pendingIPIDs )
598+ if err != nil {
599+ t .Fatalf ("Expected to successfully mark available ip as pending" )
600+ }
601+
602+ pendingIPConfigs := svc .GetPendingReleaseIPConfigs ()
603+ if pendingIPConfigs [0 ].ID != testPod2GUID {
604+ t .Fatalf ("Expected to see ID %v in pending release ipconfigs, actual %+v" , testPod2GUID , pendingIPConfigs )
605+ }
606+
607+ // attempt to mark allocated ipconfig as pending, expect fail
608+ pendingIPIDs = []string {testPod1GUID }
609+ err = svc .MarkExistingIPsAsPending (pendingIPIDs )
610+ if err == nil {
611+ t .Fatalf ("Expected to fail when marking allocated ip as pending" )
612+ }
613+
614+ allocatedIPConfigs := svc .GetAllocatedIPConfigs ()
615+ if allocatedIPConfigs [0 ].ID != testPod1GUID {
616+ t .Fatalf ("Expected to see ID %v in pending release ipconfigs, actual %+v" , testPod1GUID , allocatedIPConfigs )
617+ }
618+ }
0 commit comments