f-81: api: default_route sans gateway réservé au mode bridge #81
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
8429dfd7e1
commit
dd9844284d
3 changed files with 49 additions and 3 deletions
|
|
@ -234,7 +234,8 @@ paths:
|
||||||
"400":
|
"400":
|
||||||
description: >
|
description: >
|
||||||
Missing required field; interface_ip missing on a bridge or public_ip subnet, or
|
Missing required field; interface_ip missing on a bridge or public_ip subnet, or
|
||||||
supplied on a vxlan subnet (it is computed)
|
supplied on a vxlan subnet (it is computed); default_route true without gateway on a
|
||||||
|
vxlan or public_ip subnet
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
|
|
@ -408,8 +409,9 @@ components:
|
||||||
description: >
|
description: >
|
||||||
A default route is always advertised via DHCP; this flag only chooses its next-hop.
|
A default route is always advertised via DHCP; this flag only chooses its next-hop.
|
||||||
When false, the next-hop is the subnet interface_ip. When true, it is the `gateway`
|
When false, the next-hop is the subnet interface_ip. When true, it is the `gateway`
|
||||||
field if supplied, otherwise the gateway read from the host routing table.
|
field if supplied, otherwise the gateway read from the host routing table — this last
|
||||||
The route to the VPC CIDR always keeps interface_ip as its next-hop (except in bridge
|
case is bridge mode only (400 in vxlan and public_ip modes, whose guests do not share
|
||||||
|
the L2 segment of the host gateway). The route to the VPC CIDR always keeps interface_ip as its next-hop (except in bridge
|
||||||
mode, which has no VPC route), so VPC traffic never leaves through a public gateway.
|
mode, which has no VPC route), so VPC traffic never leaves through a public gateway.
|
||||||
default: false
|
default: false
|
||||||
gateway:
|
gateway:
|
||||||
|
|
|
||||||
|
|
@ -499,3 +499,42 @@ func TestGetSubnet_RelayIPOnlyForVxlan(t *testing.T) {
|
||||||
t.Errorf("relay_ip inattendus dans la liste : %v", relays)
|
t.Errorf("relay_ip inattendus dans la liste : %v", relays)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostSubnet_DefaultRouteWithoutGatewayOnlyForBridge(t *testing.T) {
|
||||||
|
for _, req := range []SubnetCreateRequest{
|
||||||
|
{Mode: "", CIDR: "10.0.0.0/24"},
|
||||||
|
{Mode: "vxlan", VxlanID: 1101, CIDR: "10.0.0.0/24"},
|
||||||
|
{Mode: "public_ip", InterfaceIP: "203.0.113.254", CIDR: "203.0.113.0/24"},
|
||||||
|
} {
|
||||||
|
s, db := newTestServer(t)
|
||||||
|
kv.AddInDB(db, "vpc/vpc-1/state", "running")
|
||||||
|
req.Name, req.VPC, req.DefaultRoute = "sn-1", "vpc-1", true
|
||||||
|
w := postSubnetRequest(t, s, req)
|
||||||
|
if w.Code != http.StatusBadRequest {
|
||||||
|
t.Errorf("mode %q : attendu 400, obtenu %d : %s", req.Mode, w.Code, w.Body.String())
|
||||||
|
}
|
||||||
|
if !strings.Contains(w.Body.String(), "default_route without gateway is only allowed for bridge subnets") {
|
||||||
|
t.Errorf("mode %q : message %s", req.Mode, w.Body.String())
|
||||||
|
}
|
||||||
|
if _, err := kv.GetFromDB(db, "subnet/sn-1/state"); err == nil {
|
||||||
|
t.Errorf("mode %q : aucun subnet ne doit être créé", req.Mode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostSubnet_DefaultRouteAccepted(t *testing.T) {
|
||||||
|
for _, req := range []SubnetCreateRequest{
|
||||||
|
{Mode: "bridge", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24"},
|
||||||
|
{Mode: "bridge", InterfaceIP: "10.0.0.1", CIDR: "10.0.0.0/24", Gateway: "10.0.0.254"},
|
||||||
|
{Mode: "", CIDR: "10.0.0.0/24", Gateway: "10.0.0.1"},
|
||||||
|
{Mode: "vxlan", VxlanID: 1101, CIDR: "10.0.0.0/24", Gateway: "10.0.0.1"},
|
||||||
|
{Mode: "public_ip", InterfaceIP: "203.0.113.254", CIDR: "203.0.113.0/24", Gateway: "203.0.113.1"},
|
||||||
|
} {
|
||||||
|
s, db := newTestServer(t)
|
||||||
|
kv.AddInDB(db, "vpc/vpc-1/state", "running")
|
||||||
|
req.Name, req.VPC, req.DefaultRoute = "sn-1", "vpc-1", true
|
||||||
|
if w := postSubnetRequest(t, s, req); w.Code != http.StatusAccepted {
|
||||||
|
t.Errorf("mode %q gateway %q : attendu 202, obtenu %d : %s", req.Mode, req.Gateway, w.Code, w.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,11 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(ErrorResponse{Error: "interface_ip is computed for vxlan subnets, do not set it"})
|
json.NewEncoder(w).Encode(ErrorResponse{Error: "interface_ip is computed for vxlan subnets, do not set it"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if req.DefaultRoute && req.Gateway == "" && req.Mode != subnet.ModeBridge {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
json.NewEncoder(w).Encode(ErrorResponse{Error: "default_route without gateway is only allowed for bridge subnets: the host gateway is not on the subnet"})
|
||||||
|
return
|
||||||
|
}
|
||||||
cmd := dispatcher.CreateSubnetCommand{
|
cmd := dispatcher.CreateSubnetCommand{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
VPC: req.VPC,
|
VPC: req.VPC,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue