mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 10:05:19 +00:00
* fix #1706 - failover should disregard disabled routes during failover * fixe tests for failover; all current tests assume routes to be enabled * add testcase for #1706 - failover to disabled route
This commit is contained in:
parent
b4210e2c90
commit
4ea12f472a
@ -585,6 +585,10 @@ func (hsdb *HSDatabase) failoverRoute(r *types.Route) ([]key.MachinePublic, erro
|
||||
continue
|
||||
}
|
||||
|
||||
if !route.Enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
if hsdb.notifier.IsConnected(route.Node.MachineKey) {
|
||||
newPrimary = &routes[idx]
|
||||
break
|
||||
|
@ -371,6 +371,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
routes: types.Routes{
|
||||
types.Route{
|
||||
@ -382,6 +383,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
types.Route{
|
||||
Model: gorm.Model{
|
||||
@ -392,6 +394,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[1],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
want: []key.MachinePublic{
|
||||
@ -411,6 +414,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: true,
|
||||
},
|
||||
routes: types.Routes{
|
||||
types.Route{
|
||||
@ -422,6 +426,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
types.Route{
|
||||
Model: gorm.Model{
|
||||
@ -432,6 +437,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[1],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
want: nil,
|
||||
@ -448,6 +454,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[1],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
routes: types.Routes{
|
||||
types.Route{
|
||||
@ -459,6 +466,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: true,
|
||||
},
|
||||
types.Route{
|
||||
Model: gorm.Model{
|
||||
@ -469,6 +477,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[1],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
types.Route{
|
||||
Model: gorm.Model{
|
||||
@ -479,6 +488,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[2],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
want: []key.MachinePublic{
|
||||
@ -498,6 +508,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
routes: types.Routes{
|
||||
types.Route{
|
||||
@ -509,6 +520,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
// Offline
|
||||
types.Route{
|
||||
@ -520,6 +532,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[3],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
want: nil,
|
||||
@ -536,6 +549,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
routes: types.Routes{
|
||||
types.Route{
|
||||
@ -547,6 +561,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
// Offline
|
||||
types.Route{
|
||||
@ -558,6 +573,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[3],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: true,
|
||||
},
|
||||
types.Route{
|
||||
Model: gorm.Model{
|
||||
@ -568,6 +584,7 @@ func TestFailoverRoute(t *testing.T) {
|
||||
MachineKey: machineKeys[1],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
want: []key.MachinePublic{
|
||||
@ -576,6 +593,47 @@ func TestFailoverRoute(t *testing.T) {
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "failover-primary-none-enabled",
|
||||
failingRoute: types.Route{
|
||||
Model: gorm.Model{
|
||||
ID: 1,
|
||||
},
|
||||
Prefix: ipp("10.0.0.0/24"),
|
||||
Node: types.Node{
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
routes: types.Routes{
|
||||
types.Route{
|
||||
Model: gorm.Model{
|
||||
ID: 1,
|
||||
},
|
||||
Prefix: ipp("10.0.0.0/24"),
|
||||
Node: types.Node{
|
||||
MachineKey: machineKeys[0],
|
||||
},
|
||||
IsPrimary: true,
|
||||
Enabled: true,
|
||||
},
|
||||
// not enabled
|
||||
types.Route{
|
||||
Model: gorm.Model{
|
||||
ID: 2,
|
||||
},
|
||||
Prefix: ipp("10.0.0.0/24"),
|
||||
Node: types.Node{
|
||||
MachineKey: machineKeys[1],
|
||||
},
|
||||
IsPrimary: false,
|
||||
Enabled: false,
|
||||
},
|
||||
},
|
||||
want: nil,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user