Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit f2d7bf9

Browse files
yngvar-antonssonLeonidVas
authored andcommitted
app-dependency: support new failover params
1 parent c4f47cb commit f2d7bf9

File tree

7 files changed

+84
-20
lines changed

7 files changed

+84
-20
lines changed

cli/commands/failover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
var (
12-
failoverModes = []string{"stateful", "eventual", "disabled"}
12+
failoverModes = []string{"stateful", "eventual", "disabled", "raft"}
1313
)
1414

1515
func init() {

cli/failover/set_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ func TestBadValidateFailoverSet(t *testing.T) {
1414
ctx := context.Ctx{}
1515
ctx.Failover.Mode = "some-invalid-mode"
1616
_, err := getFailoverOpts(&ctx)
17-
assert.Equal("Failover mode should be `stateful`, `eventual` or `disabled`", err.Error())
17+
assert.Equal("Failover mode should be `stateful`, `eventual`, `raft` or `disabled`", err.Error())
1818

1919
// Specifying no mode
2020
ctx = context.Ctx{}
2121
ctx.Failover.Mode = ""
2222
ctx.Failover.ParamsJSON = `{"fencing_pause": 4}`
2323
_, err = getFailoverOpts(&ctx)
24-
assert.Equal("Failover mode should be `stateful`, `eventual` or `disabled`", err.Error())
24+
assert.Equal("Failover mode should be `stateful`, `eventual`, `raft` or `disabled`", err.Error())
2525

2626
// Eventual mode with with passing state-provider
2727
ctx = context.Ctx{}

cli/failover/status.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ func internalRecFailoverStatusPrettyString(result interface{}, indentCnt int) st
104104
switch value.(type) {
105105
case map[string]interface{}:
106106
status = fmt.Sprintf("%s \n%s", status, internalRecFailoverStatusPrettyString(value, indentCnt+1))
107-
case int, int8:
107+
case int, int8, uint16:
108108
status = fmt.Sprintf("%s %d\n", status, value)
109109
case bool:
110110
status = fmt.Sprintf("%s %t\n", status, value)
111111
case string:
112112
switch value {
113113
case "disabled":
114114
status = fmt.Sprintf("%s %s\n", status, common.ColorRed.Sprintf(value.(string)))
115-
case "eventual", "stateful":
115+
case "eventual", "stateful", "raft":
116116
status = fmt.Sprintf("%s %s\n", status, common.ColorGreen.Sprintf(value.(string)))
117117
default:
118118
status = fmt.Sprintf("%s %s\n", status, value)
@@ -124,7 +124,7 @@ func internalRecFailoverStatusPrettyString(result interface{}, indentCnt int) st
124124

125125
status = fmt.Sprintf("%s\n", status[:len(status)-1])
126126
default:
127-
panic(project.InternalError("Unknown type: %s", reflect.TypeOf(value)))
127+
panic(project.InternalError("Field %s has unknown type: %s", fieldName, reflect.TypeOf(value)))
128128
}
129129
}
130130

cli/failover/validate.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ func validateSetFailoverOpts(opts *FailoverOpts) error {
1919
if err := validateStatefulMode(opts); err != nil {
2020
return err
2121
}
22+
case "raft":
23+
if err := validateEventualMode(opts); err != nil {
24+
return err
25+
}
2226
case "disabled":
2327
return nil
2428
default:
25-
return fmt.Errorf("Failover mode should be `stateful`, `eventual` or `disabled`")
29+
return fmt.Errorf("Failover mode should be `stateful`, `eventual`, `raft` or `disabled`")
2630
}
2731

2832
return nil

test/integration/failover/test_failover.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22

33
import yaml
4-
from integration.failover.utils import (get_etcd2_failover_info,
5-
get_eventual_failover_info,
4+
from integration.failover.utils import (get_common_failover_info,
5+
get_etcd2_failover_info,
66
get_stateboard_failover_info)
77
from utils import run_command_and_get_output
88

@@ -22,6 +22,8 @@ def test_default_app_stateboard_failover(cartridge_cmd, project_with_topology_an
2222
'failover_timeout': 20,
2323
'fencing_pause': 2,
2424
'fencing_timeout': 10,
25+
'autoreturn_delay': 300,
26+
'leader_autoreturn': False,
2527
'tarantool_params': {
2628
'uri': 'localhost:4401', 'password': '******'
2729
},
@@ -42,7 +44,7 @@ def test_setup_eventual_failover(cartridge_cmd, project_with_topology_and_vshard
4244
assert rc == 0
4345
assert "Failover configured successfully" in output
4446

45-
failover_info = get_eventual_failover_info()
47+
failover_info = get_common_failover_info()
4648
assert failover_info == {
4749
# Because this parameter (fencing_enabled) suitable in
4850
# stateful mode only - and we don't check it
@@ -54,6 +56,33 @@ def test_setup_eventual_failover(cartridge_cmd, project_with_topology_and_vshard
5456
}
5557

5658

59+
def test_setup_raft_failover(cartridge_cmd, project_with_topology_and_vshard):
60+
project = project_with_topology_and_vshard
61+
62+
cmd = [
63+
cartridge_cmd, "failover", "set", "raft", "--params",
64+
"{\"fencing_enabled\": true, \"failover_timeout\": 30, \"fencing_pause\": 140, \"fencing_timeout\": 15}",
65+
]
66+
67+
rc, output = run_command_and_get_output(cmd, cwd=project.path)
68+
if rc == 0:
69+
assert "Failover configured successfully" in output
70+
71+
failover_info = get_common_failover_info()
72+
assert failover_info == {
73+
# Because this parameter (fencing_enabled) suitable in
74+
# stateful mode only - and we don't check it
75+
'fencing_enabled': False,
76+
'failover_timeout': 30,
77+
'fencing_pause': 140,
78+
'fencing_timeout': 15,
79+
'mode': 'raft',
80+
}
81+
else:
82+
assert "Your Tarantool version doesn't support raft failover mode, " + \
83+
"need Tarantool 2.10 or higher" in output
84+
85+
5786
def test_setup_etcd2_failover(cartridge_cmd, project_with_topology_and_vshard):
5887
project = project_with_topology_and_vshard
5988

@@ -76,6 +105,8 @@ def test_setup_etcd2_failover(cartridge_cmd, project_with_topology_and_vshard):
76105
'fencing_timeout': 12,
77106
'mode': 'stateful',
78107
'state_provider': 'etcd2',
108+
'autoreturn_delay': 300,
109+
'leader_autoreturn': False,
79110
'etcd2_params': {
80111
'endpoints': ['http://127.0.0.1:4001', 'http://127.0.0.1:2379'],
81112
'lock_delay': 15,
@@ -97,7 +128,7 @@ def test_failover_disabled_command(cartridge_cmd, project_with_topology_and_vsha
97128
assert rc == 0
98129
assert "Failover disabled successfully" in output
99130

100-
failover_info = get_eventual_failover_info()["mode"]
131+
failover_info = get_common_failover_info()["mode"]
101132
assert failover_info == "disabled"
102133

103134

@@ -113,7 +144,7 @@ def test_disable_failover_from_sub_command(cartridge_cmd, project_with_topology_
113144
assert rc == 0
114145
assert "Failover disabled successfully" in output
115146

116-
failover_info = get_eventual_failover_info()
147+
failover_info = get_common_failover_info()
117148
assert failover_info == {
118149
'fencing_enabled': False,
119150
'failover_timeout': 31,
@@ -130,7 +161,7 @@ def test_disable_failover_from_sub_command(cartridge_cmd, project_with_topology_
130161
assert rc == 0
131162
assert "Failover configured successfully" in output
132163

133-
failover_info = get_eventual_failover_info()
164+
failover_info = get_common_failover_info()
134165
assert failover_info == {
135166
'fencing_enabled': False,
136167
'failover_timeout': 31,
@@ -150,7 +181,7 @@ def test_set_invalid_mode(cartridge_cmd, project_without_dependencies):
150181

151182
rc, output = run_command_and_get_output(cmd, cwd=project.path)
152183
assert rc == 1
153-
assert "Failover mode should be `stateful`, `eventual` or `disabled`" in output
184+
assert "Failover mode should be `stateful`, `eventual`, `raft` or `disabled`" in output
154185

155186

156187
def test_set_invalid_provider(cartridge_cmd, project_without_dependencies):

test/integration/failover/test_status.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from integration.failover.utils import (assert_mode_and_params_state,
2+
get_common_failover_info,
23
get_etcd2_failover_info,
3-
get_eventual_failover_info,
44
get_stateboard_failover_info)
55
from utils import run_command_and_get_output
66

@@ -17,7 +17,7 @@ def test_status_eventual(cartridge_cmd, project_with_topology_and_vshard):
1717
assert rc == 0
1818
assert "Failover configured successfully" in output
1919

20-
failover_info = get_eventual_failover_info()
20+
failover_info = get_common_failover_info()
2121

2222
cmd = [cartridge_cmd, "failover", "status"]
2323
rc, output = run_command_and_get_output(cmd, cwd=project.path)
@@ -29,6 +29,31 @@ def test_status_eventual(cartridge_cmd, project_with_topology_and_vshard):
2929
assert "etcd2_params" not in output
3030

3131

32+
def test_status_raft(cartridge_cmd, project_with_topology_and_vshard):
33+
project = project_with_topology_and_vshard
34+
35+
cmd = [
36+
cartridge_cmd, "failover", "set", "raft",
37+
"--params", "{\"fencing_enabled\": true, \"failover_timeout\": 30, \"fencing_timeout\": 12}"
38+
]
39+
40+
rc, output = run_command_and_get_output(cmd, cwd=project.path)
41+
42+
if rc == 0:
43+
assert "Failover configured successfully" in output
44+
45+
failover_info = get_common_failover_info()
46+
47+
cmd = [cartridge_cmd, "failover", "status"]
48+
rc, output = run_command_and_get_output(cmd, cwd=project.path)
49+
50+
assert rc == 0
51+
assert_mode_and_params_state(failover_info, output)
52+
else:
53+
assert "Your Tarantool version doesn't support raft failover mode, " + \
54+
"need Tarantool 2.10 or higher" in output
55+
56+
3257
def test_status_stateful_stateboard(cartridge_cmd, project_with_topology_and_vshard):
3358
project = project_with_topology_and_vshard
3459

@@ -53,7 +78,7 @@ def test_status_stateful_stateboard(cartridge_cmd, project_with_topology_and_vsh
5378

5479
assert "stateboard_params" in output
5580
assert f"uri: {failover_info['tarantool_params']['uri']}" in output
56-
assert f"password: {failover_info['tarantool_params']['password']}" in output
81+
assert "password: pass" in output
5782

5883

5984
def test_status_stateful_etcd2(cartridge_cmd, project_with_topology_and_vshard):
@@ -79,7 +104,7 @@ def test_status_stateful_etcd2(cartridge_cmd, project_with_topology_and_vshard):
79104
assert "stateboard_params" not in output
80105

81106
assert "etcd2_params" in output
82-
assert f"password: {failover_info['etcd2_params']['password']}" in output
107+
assert "password" in output
83108
assert f"lock_delay: {failover_info['etcd2_params']['lock_delay']}" in output
84109
assert f"endpoints: {', '.join(failover_info['etcd2_params']['endpoints'])}" in output
85110
assert f"username: {failover_info['etcd2_params']['username']}" in output
@@ -94,7 +119,7 @@ def test_status_disabled(cartridge_cmd, project_with_topology_and_vshard):
94119
assert rc == 0
95120
assert "Failover disabled successfully" in output
96121

97-
failover_info = get_eventual_failover_info()
122+
failover_info = get_common_failover_info()
98123

99124
cmd = [cartridge_cmd, "failover", "status"]
100125
rc, output = run_command_and_get_output(cmd, cwd=project.path)

test/integration/failover/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def get_stateboard_failover_info():
1717
fencing_enabled
1818
fencing_timeout
1919
fencing_pause
20+
autoreturn_delay
21+
leader_autoreturn
2022
}
2123
}
2224
}
@@ -26,7 +28,7 @@ def get_stateboard_failover_info():
2628
return get_response_data(response)["cluster"]["failover_params"]
2729

2830

29-
def get_eventual_failover_info():
31+
def get_common_failover_info():
3032
query = """
3133
query {
3234
cluster {
@@ -63,6 +65,8 @@ def get_etcd2_failover_info():
6365
fencing_enabled
6466
fencing_timeout
6567
fencing_pause
68+
autoreturn_delay
69+
leader_autoreturn
6670
}
6771
}
6872
}

0 commit comments

Comments
 (0)