mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-11 01:01:05 +08:00
fix integration tests
This commit is contained in:
parent
7e0ff17420
commit
d21411392b
2 changed files with 25 additions and 3 deletions
|
|
@ -21,6 +21,10 @@ var linuxHost models.Host
|
||||||
func TestCreateEgressGateway(t *testing.T) {
|
func TestCreateEgressGateway(t *testing.T) {
|
||||||
var gateway models.EgressGatewayRequest
|
var gateway models.EgressGatewayRequest
|
||||||
gateway.Ranges = []string{"10.100.100.0/24"}
|
gateway.Ranges = []string{"10.100.100.0/24"}
|
||||||
|
gateway.RangesWithMetric = append(gateway.RangesWithMetric, models.EgressRangeMetric{
|
||||||
|
Network: "10.100.100.0/24",
|
||||||
|
RouteMetric: 256,
|
||||||
|
})
|
||||||
gateway.NetID = "skynet"
|
gateway.NetID = "skynet"
|
||||||
deleteAllNetworks()
|
deleteAllNetworks()
|
||||||
createNet()
|
createNet()
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,14 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
|
||||||
if host.FirewallInUse == models.FIREWALL_NONE {
|
if host.FirewallInUse == models.FIREWALL_NONE {
|
||||||
return models.Node{}, errors.New("please install iptables or nftables on the device")
|
return models.Node{}, errors.New("please install iptables or nftables on the device")
|
||||||
}
|
}
|
||||||
|
if len(gateway.RangesWithMetric) == 0 && len(gateway.Ranges) > 0 {
|
||||||
|
for _, rangeI := range gateway.Ranges {
|
||||||
|
gateway.RangesWithMetric = append(gateway.RangesWithMetric, models.EgressRangeMetric{
|
||||||
|
Network: rangeI,
|
||||||
|
RouteMetric: 256,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
for i := len(gateway.Ranges) - 1; i >= 0; i-- {
|
for i := len(gateway.Ranges) - 1; i >= 0; i-- {
|
||||||
// check if internet gateway IPv4
|
// check if internet gateway IPv4
|
||||||
if gateway.Ranges[i] == "0.0.0.0/0" || gateway.Ranges[i] == "::/0" {
|
if gateway.Ranges[i] == "0.0.0.0/0" || gateway.Ranges[i] == "::/0" {
|
||||||
|
|
@ -105,9 +113,19 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
|
||||||
node.EgressGatewayRanges = gateway.Ranges
|
node.EgressGatewayRanges = gateway.Ranges
|
||||||
node.EgressGatewayNatEnabled = models.ParseBool(gateway.NatEnabled)
|
node.EgressGatewayNatEnabled = models.ParseBool(gateway.NatEnabled)
|
||||||
rangesWithMetric := []string{}
|
rangesWithMetric := []string{}
|
||||||
for i, rangeI := range gateway.RangesWithMetric {
|
for i := len(gateway.RangesWithMetric) - 1; i >= 0; i-- {
|
||||||
rangesWithMetric = append(rangesWithMetric, rangeI.Network)
|
if gateway.RangesWithMetric[i].Network == "0.0.0.0/0" || gateway.RangesWithMetric[i].Network == "::/0" {
|
||||||
if rangeI.RouteMetric <= 0 || rangeI.RouteMetric > 999 {
|
// remove inet range
|
||||||
|
gateway.RangesWithMetric = append(gateway.RangesWithMetric[:i], gateway.RangesWithMetric[i+1:]...)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
normalized, err := NormalizeCIDR(gateway.Ranges[i])
|
||||||
|
if err != nil {
|
||||||
|
return models.Node{}, err
|
||||||
|
}
|
||||||
|
gateway.RangesWithMetric[i].Network = normalized
|
||||||
|
rangesWithMetric = append(rangesWithMetric, gateway.RangesWithMetric[i].Network)
|
||||||
|
if gateway.RangesWithMetric[i].RouteMetric <= 0 || gateway.RangesWithMetric[i].RouteMetric > 999 {
|
||||||
gateway.RangesWithMetric[i].RouteMetric = 256
|
gateway.RangesWithMetric[i].RouteMetric = 256
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue