@@ -38,6 +38,8 @@ import (
38
38
"k8s.io/legacy-cloud-providers/azure/clients/interfaceclient/mockinterfaceclient"
39
39
"k8s.io/legacy-cloud-providers/azure/clients/publicipclient/mockpublicipclient"
40
40
"k8s.io/legacy-cloud-providers/azure/clients/vmclient/mockvmclient"
41
+ "k8s.io/legacy-cloud-providers/azure/clients/vmssclient/mockvmssclient"
42
+ "k8s.io/legacy-cloud-providers/azure/clients/vmssvmclient/mockvmssvmclient"
41
43
"k8s.io/legacy-cloud-providers/azure/retry"
42
44
)
43
45
@@ -633,6 +635,58 @@ func TestInstanceExistsByProviderID(t *testing.T) {
633
635
assert .Equal (t , test .expectedErrMsg , err , test .name )
634
636
assert .Equal (t , test .expected , exist , test .name )
635
637
}
638
+
639
+ vmssTestCases := []struct {
640
+ name string
641
+ providerID string
642
+ scaleSet string
643
+ vmList []string
644
+ expected bool
645
+ rerr * retry.Error
646
+ }{
647
+ {
648
+ name : "InstanceExistsByProviderID should return true if VMSS and VM exist" ,
649
+ providerID : "azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/vmssee6c2/virtualMachines/0" ,
650
+ scaleSet : "vmssee6c2" ,
651
+ vmList : []string {"vmssee6c2000000" },
652
+ expected : true ,
653
+ },
654
+ {
655
+ name : "InstanceExistsByProviderID should return false if VMSS exist but VM doesn't" ,
656
+ providerID : "azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/vmssee6c2/virtualMachines/0" ,
657
+ scaleSet : "vmssee6c2" ,
658
+ expected : false ,
659
+ },
660
+ {
661
+ name : "InstanceExistsByProviderID should return false if VMSS doesn't exist" ,
662
+ providerID : "azure:///subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/missing-vmss/virtualMachines/0" ,
663
+ rerr : & retry.Error {HTTPStatusCode : 404 },
664
+ expected : false ,
665
+ },
666
+ }
667
+
668
+ for _ , test := range vmssTestCases {
669
+ ss , err := newTestScaleSet (ctrl )
670
+ assert .NoError (t , err , test .name )
671
+ cloud .VMSet = ss
672
+
673
+ mockVMSSClient := mockvmssclient .NewMockInterface (ctrl )
674
+ mockVMSSVMClient := mockvmssvmclient .NewMockInterface (ctrl )
675
+ ss .cloud .VirtualMachineScaleSetsClient = mockVMSSClient
676
+ ss .cloud .VirtualMachineScaleSetVMsClient = mockVMSSVMClient
677
+
678
+ expectedScaleSet := buildTestVMSS (test .scaleSet , test .scaleSet )
679
+ mockVMSSClient .EXPECT ().List (gomock .Any (), gomock .Any ()).Return ([]compute.VirtualMachineScaleSet {expectedScaleSet }, test .rerr ).AnyTimes ()
680
+
681
+ expectedVMs , _ , _ := buildTestVirtualMachineEnv (ss .cloud , test .scaleSet , "" , 0 , test .vmList , "succeeded" , false )
682
+ mockVMSSVMClient .EXPECT ().List (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Return (expectedVMs , test .rerr ).AnyTimes ()
683
+
684
+ mockVMsClient := ss .cloud .VirtualMachinesClient .(* mockvmclient.MockInterface )
685
+ mockVMsClient .EXPECT ().List (gomock .Any (), gomock .Any ()).Return ([]compute.VirtualMachine {}, nil ).AnyTimes ()
686
+
687
+ exist , _ := cloud .InstanceExistsByProviderID (context .Background (), test .providerID )
688
+ assert .Equal (t , test .expected , exist , test .name )
689
+ }
636
690
}
637
691
638
692
func TestNodeAddressesByProviderID (t * testing.T ) {
0 commit comments