fix: routes to private prefixes should be distributed on private nic

This commit is contained in:
Qiu Jian
2021-08-12 22:53:44 +08:00
parent 05f4b1beae
commit 9c0f99d46f
2 changed files with 71 additions and 1 deletions
+1 -1
View File
@@ -234,7 +234,7 @@ func AddNicRoutes(routes *[][]string, nicDesc *types.SServerNic, mainIp string,
}
if len(nicDesc.Routes) > 0 {
extendRoutes(routes, nicDesc.Routes)
} else if len(nicDesc.Gateway) > 0 && isExitAddress(nicDesc.Ip) &&
} else if len(nicDesc.Gateway) > 0 && !isExitAddress(nicDesc.Ip) &&
nicCnt == 2 && nicDesc.Ip != mainIp && isExitAddress(mainIp) {
for _, pref := range GetPrivatePrefixes(privatePrefixes) {
addRoute(routes, pref, nicDesc.Gateway)
+70
View File
@@ -16,6 +16,8 @@ package netutils2
import (
"testing"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
)
func TestNetlen2Mask(t *testing.T) {
@@ -135,3 +137,71 @@ func TestMyDefault(t *testing.T) {
}
}
}
func TestGetMainNicFromDeployApi(t *testing.T) {
nics1 := []*types.SServerNic{
{
Ip: "10.168.222.19",
Gateway: "10.168.222.1",
},
{
Ip: "114.114.114.114",
Gateway: "114.114.114.1",
},
}
nics2 := []*types.SServerNic{
{
Ip: "10.168.222.19",
},
{
Ip: "114.114.114.114",
Gateway: "114.114.114.1",
},
}
nics3 := []*types.SServerNic{
{
Ip: "10.168.222.19",
Gateway: "10.168.222.1",
},
{
Ip: "114.114.114.114",
},
}
nics4 := []*types.SServerNic{
{
Ip: "10.168.222.19",
},
{
Ip: "114.114.114.114",
},
}
cases := []struct {
nics []*types.SServerNic
want *types.SServerNic
}{
{
nics1,
nics1[1],
},
{
nics2,
nics2[1],
},
{
nics3,
nics3[0],
},
{
nics4,
nics4[1],
},
}
for _, c := range cases {
got, err := GetMainNicFromDeployApi(c.nics)
if err != nil {
t.Errorf("error %s", err)
} else if got != c.want {
t.Errorf("error: got %v want %v", got, c.want)
}
}
}