Update error message when restoring ENT snapshot in OSS (#15066)

This commit is contained in:
Venu Yanamandra 2022-10-24 08:40:26 -07:00 committed by GitHub
parent 61b60a79e1
commit efc813e92d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -197,7 +197,11 @@ func (c *FSM) Restore(old io.ReadCloser) error {
return err
}
default:
return fmt.Errorf("Unrecognized msg type %d", msg)
if msg >= 64 {
return fmt.Errorf("msg type <%d> is a Consul Enterprise log entry. Consul OSS cannot restore it", msg)
} else {
return fmt.Errorf("Unrecognized msg type %d", msg)
}
}
return nil
}

View File

@ -882,6 +882,34 @@ func TestFSM_SnapshotRestore_OSS(t *testing.T) {
default:
require.Fail(t, "Old state not abandoned")
}
// To verify if a proper message is displayed when Consul OSS tries to
// unsuccessfully restore entries from a Consul Ent snapshot.
buf = bytes.NewBuffer(nil)
sink = &MockSink{buf, false}
fsm, _ = New(nil, logger)
type EntMock struct {
ID int
Type string
}
entMockEntry := EntMock{
ID: 65,
Type: "A Consul Ent Log Type",
}
// Write the header
header := SnapshotHeader{
LastIndex: 0,
}
encoder = codec.NewEncoder(sink, structs.MsgpackHandle)
encoder.Encode(&header)
sink.Write([]byte{byte(structs.MessageType(entMockEntry.ID))})
encoder.Encode(entMockEntry)
require.EqualError(t, fsm.Restore(sink), "msg type <65> is a Consul Enterprise log entry. Consul OSS cannot restore it")
sink.Cancel()
}
// convertACLTokenToLegacy attempts to convert an ACLToken into an legacy ACL.