mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
fix netsh checkIPExists in Chinese
Signed-off-by: sakeven <jc5930@sina.cn>
This commit is contained in:
parent
d945927077
commit
c45a7ba4e5
@ -190,9 +190,8 @@ func checkIPExists(ipToCheck string, args []string, runner *runner) (bool, error
|
||||
glog.V(3).Infof("Searching for IP: %v in IP dump: %v", ipToCheck, ipAddressString)
|
||||
showAddressArray := strings.Split(ipAddressString, "\n")
|
||||
for _, showAddress := range showAddressArray {
|
||||
if strings.Contains(showAddress, "IP Address:") {
|
||||
ipFromNetsh := strings.TrimLeft(showAddress, "IP Address:")
|
||||
ipFromNetsh = strings.TrimSpace(ipFromNetsh)
|
||||
if strings.Contains(showAddress, "IP") {
|
||||
ipFromNetsh := getIP(showAddress)
|
||||
if ipFromNetsh == ipToCheck {
|
||||
return true, nil
|
||||
}
|
||||
@ -201,3 +200,12 @@ func checkIPExists(ipToCheck string, args []string, runner *runner) (bool, error
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// getIP gets ip from showAddress (e.g. "IP Address: 10.96.0.4").
|
||||
func getIP(showAddress string) string {
|
||||
list := strings.SplitN(showAddress, ":", 2)
|
||||
if len(list) != 2 {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(list[1])
|
||||
}
|
||||
|
@ -438,3 +438,30 @@ func TestCheckIPExists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIP(t *testing.T) {
|
||||
testcases := []struct {
|
||||
showAddress string
|
||||
expectAddress string
|
||||
}{
|
||||
{
|
||||
showAddress: "IP 地址: 10.96.0.2",
|
||||
expectAddress: "10.96.0.2",
|
||||
},
|
||||
{
|
||||
showAddress: "IP Address: 10.96.0.3",
|
||||
expectAddress: "10.96.0.3",
|
||||
},
|
||||
{
|
||||
showAddress: "IP Address:10.96.0.4",
|
||||
expectAddress: "10.96.0.4",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
address := getIP(tc.showAddress)
|
||||
if address != tc.expectAddress {
|
||||
t.Errorf("expected address=%q, got %q", tc.expectAddress, address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user