@@ -80,6 +80,21 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName, zone string, faultDomai
80
80
ID : & interfaceID ,
81
81
},
82
82
}
83
+ ipConfigurations := []compute.VirtualMachineScaleSetIPConfiguration {
84
+ {
85
+ Name : to .StringPtr ("ipconfig1" ),
86
+ VirtualMachineScaleSetIPConfigurationProperties : & compute.VirtualMachineScaleSetIPConfigurationProperties {},
87
+ },
88
+ }
89
+ networkConfigurations := []compute.VirtualMachineScaleSetNetworkConfiguration {
90
+ {
91
+ Name : to .StringPtr ("ipconfig1" ),
92
+ ID : to .StringPtr ("fakeNetworkConfiguration" ),
93
+ VirtualMachineScaleSetNetworkConfigurationProperties : & compute.VirtualMachineScaleSetNetworkConfigurationProperties {
94
+ IPConfigurations : & ipConfigurations ,
95
+ },
96
+ },
97
+ }
83
98
vmssVM := compute.VirtualMachineScaleSetVM {
84
99
VirtualMachineScaleSetVMProperties : & compute.VirtualMachineScaleSetVMProperties {
85
100
OsProfile : & compute.OSProfile {
@@ -88,6 +103,9 @@ func setTestVirtualMachineCloud(ss *Cloud, scaleSetName, zone string, faultDomai
88
103
NetworkProfile : & compute.NetworkProfile {
89
104
NetworkInterfaces : & networkInterfaces ,
90
105
},
106
+ NetworkProfileConfiguration : & compute.VirtualMachineScaleSetVMNetworkProfileConfiguration {
107
+ NetworkInterfaceConfigurations : & networkConfigurations ,
108
+ },
91
109
InstanceView : & compute.VirtualMachineScaleSetVMInstanceView {
92
110
PlatformFaultDomain : & faultDomain ,
93
111
},
@@ -307,3 +325,52 @@ func TestGetIPByNodeName(t *testing.T) {
307
325
assert .Equal (t , test .expected , []string {privateIP , publicIP }, test .description )
308
326
}
309
327
}
328
+
329
+ func TestGetNodeNameByIPConfigurationID (t * testing.T ) {
330
+ ipConfigurationIDTemplate := "/subscriptions/script/resourceGroups/rg/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s/networkInterfaces/%s/ipConfigurations/ipconfig1"
331
+
332
+ testCases := []struct {
333
+ description string
334
+ scaleSet string
335
+ vmList []string
336
+ ipConfigurationID string
337
+ expected string
338
+ expectError bool
339
+ }{
340
+ {
341
+ description : "getNodeNameByIPConfigurationID should get node's Name when the node is existing" ,
342
+ scaleSet : "scaleset1" ,
343
+ ipConfigurationID : fmt .Sprintf (ipConfigurationIDTemplate , "scaleset1" , "0" , "scaleset1" ),
344
+ vmList : []string {"vmssee6c2000000" , "vmssee6c2000001" },
345
+ expected : "vmssee6c2000000" ,
346
+ },
347
+ {
348
+ description : "getNodeNameByIPConfigurationID should return error for non-exist nodes" ,
349
+ scaleSet : "scaleset2" ,
350
+ ipConfigurationID : fmt .Sprintf (ipConfigurationIDTemplate , "scaleset2" , "3" , "scaleset1" ),
351
+ vmList : []string {"vmssee6c2000002" , "vmssee6c2000003" },
352
+ expectError : true ,
353
+ },
354
+ {
355
+ description : "getNodeNameByIPConfigurationID should return error for wrong ipConfigurationID" ,
356
+ scaleSet : "scaleset3" ,
357
+ ipConfigurationID : "invalid-configuration-id" ,
358
+ vmList : []string {"vmssee6c2000004" , "vmssee6c2000005" },
359
+ expectError : true ,
360
+ },
361
+ }
362
+
363
+ for _ , test := range testCases {
364
+ ss , err := newTestScaleSet (test .scaleSet , "" , 0 , test .vmList )
365
+ assert .NoError (t , err , test .description )
366
+
367
+ nodeName , err := ss .getNodeNameByIPConfigurationID (test .ipConfigurationID )
368
+ if test .expectError {
369
+ assert .Error (t , err , test .description )
370
+ continue
371
+ }
372
+
373
+ assert .NoError (t , err , test .description )
374
+ assert .Equal (t , test .expected , nodeName , test .description )
375
+ }
376
+ }
0 commit comments