mirror of https://github.com/status-im/consul.git
Adds a check for the minimum version as well.
This commit is contained in:
parent
26095faae0
commit
9f85f7ee1a
|
@ -96,8 +96,8 @@ func ensurePath(path string, dir bool) error {
|
|||
}
|
||||
|
||||
// CanServersUnderstandProtocol checks to see if all the servers in the given
|
||||
// list understand the given protocol version or higher. If there are no servers
|
||||
// in the list then this will return false.
|
||||
// list understand the given protocol version. If there are no servers in the
|
||||
// list then this will return false.
|
||||
func CanServersUnderstandProtocol(members []serf.Member, version uint8) (bool, error) {
|
||||
numServers, numWhoGrok := 0, 0
|
||||
for _, m := range members {
|
||||
|
@ -106,13 +106,18 @@ func CanServersUnderstandProtocol(members []serf.Member, version uint8) (bool, e
|
|||
}
|
||||
numServers++
|
||||
|
||||
vsn_str := m.Tags["vsn_max"]
|
||||
vsn, err := strconv.Atoi(vsn_str)
|
||||
vsn_min, err := strconv.Atoi(m.Tags["vsn_min"])
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if vsn >= int(version) {
|
||||
vsn_max, err := strconv.Atoi(m.Tags["vsn_max"])
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
v := int(version)
|
||||
if (v >= vsn_min) && (v <= vsn_max) {
|
||||
numWhoGrok++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ func TestUtil_CanServersUnderstandProtocol(t *testing.T) {
|
|||
// Add a non-server member.
|
||||
members = append(members, serf.Member{
|
||||
Tags: map[string]string{
|
||||
"vsn_min": fmt.Sprintf("%d", ProtocolVersionMin),
|
||||
"vsn_max": fmt.Sprintf("%d", ProtocolVersionMax),
|
||||
},
|
||||
})
|
||||
|
@ -155,6 +156,7 @@ func TestUtil_CanServersUnderstandProtocol(t *testing.T) {
|
|||
members = append(members, serf.Member{
|
||||
Tags: map[string]string{
|
||||
"role": "consul",
|
||||
"vsn_min": fmt.Sprintf("%d", ProtocolVersionMin),
|
||||
"vsn_max": fmt.Sprintf("%d", ProtocolVersionMax),
|
||||
},
|
||||
})
|
||||
|
@ -185,6 +187,7 @@ func TestUtil_CanServersUnderstandProtocol(t *testing.T) {
|
|||
members = append(members, serf.Member{
|
||||
Tags: map[string]string{
|
||||
"role": "consul",
|
||||
"vsn_min": fmt.Sprintf("%d", ProtocolVersionMin),
|
||||
"vsn_max": fmt.Sprintf("%d", ProtocolVersionMax-1),
|
||||
},
|
||||
})
|
||||
|
@ -200,6 +203,17 @@ func TestUtil_CanServersUnderstandProtocol(t *testing.T) {
|
|||
t.Fatalf("bad: %v != %v", grok, expected)
|
||||
}
|
||||
}
|
||||
|
||||
// Try a version that's too low for the minimum.
|
||||
{
|
||||
grok, err := CanServersUnderstandProtocol(members, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if grok {
|
||||
t.Fatalf("server should not grok")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsConsulServer(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue