diff --git a/physical/raft/fsm.go b/physical/raft/fsm.go index 52fd05d4c3bb..dc924ea5c158 100644 --- a/physical/raft/fsm.go +++ b/physical/raft/fsm.go @@ -86,11 +86,7 @@ type FSM struct { } // NewFSM constructs a FSM using the given directory -func NewFSM(conf map[string]string, logger log.Logger) (*FSM, error) { - path, ok := conf["path"] - if !ok { - return nil, fmt.Errorf("'path' must be set") - } +func NewFSM(path string, logger log.Logger) (*FSM, error) { // Initialize the latest term, index, and config values latestTerm := new(uint64) @@ -101,7 +97,7 @@ func NewFSM(conf map[string]string, logger log.Logger) (*FSM, error) { latestConfig.Store((*ConfigurationValue)(nil)) f := &FSM{ - path: conf["path"], + path: path, logger: logger, latestTerm: latestTerm, diff --git a/physical/raft/fsm_test.go b/physical/raft/fsm_test.go index 7caeeb41c6e4..2603f3690046 100644 --- a/physical/raft/fsm_test.go +++ b/physical/raft/fsm_test.go @@ -25,9 +25,7 @@ func getFSM(t testing.TB) (*FSM, string) { Level: hclog.Trace, }) - fsm, err := NewFSM(map[string]string{ - "path": raftDir, - }, logger) + fsm, err := NewFSM(raftDir, logger) if err != nil { t.Fatal(err) } diff --git a/physical/raft/raft.go b/physical/raft/raft.go index e1120b5ba4f9..a3277c79abe0 100644 --- a/physical/raft/raft.go +++ b/physical/raft/raft.go @@ -219,11 +219,6 @@ func EnsurePath(path string, dir bool) error { // NewRaftBackend constructs a RaftBackend using the given directory func NewRaftBackend(conf map[string]string, logger log.Logger) (physical.Backend, error) { - // Create the FSM. - fsm, err := NewFSM(conf, logger.Named("fsm")) - if err != nil { - return nil, fmt.Errorf("failed to create fsm: %v", err) - } path := os.Getenv(EnvVaultRaftPath) if path == "" { @@ -234,6 +229,12 @@ func NewRaftBackend(conf map[string]string, logger log.Logger) (physical.Backend path = pathFromConfig } + // Create the FSM. + fsm, err := NewFSM(path, logger.Named("fsm")) + if err != nil { + return nil, fmt.Errorf("failed to create fsm: %v", err) + } + // Build an all in-memory setup for dev mode, otherwise prepare a full // disk-based setup. var log raft.LogStore diff --git a/physical/raft/snapshot_test.go b/physical/raft/snapshot_test.go index 4588999c5c56..3186ded443ca 100644 --- a/physical/raft/snapshot_test.go +++ b/physical/raft/snapshot_test.go @@ -590,9 +590,7 @@ func TestBoltSnapshotStore_Listing(t *testing.T) { Level: hclog.Trace, }) - fsm, err := NewFSM(map[string]string{ - "path": parent, - }, logger) + fsm, err := NewFSM(parent, logger) if err != nil { t.Fatal(err) } @@ -657,9 +655,7 @@ func TestBoltSnapshotStore_CreateInstallSnapshot(t *testing.T) { Level: hclog.Trace, }) - fsm, err := NewFSM(map[string]string{ - "path": parent, - }, logger) + fsm, err := NewFSM(parent, logger) if err != nil { t.Fatal(err) } @@ -757,9 +753,7 @@ func TestBoltSnapshotStore_CreateInstallSnapshot(t *testing.T) { t.Fatal("expected snapshot installer object") } - newFSM, err := NewFSM(map[string]string{ - "path": filepath.Dir(installer.Filename()), - }, logger) + newFSM, err := NewFSM(filepath.Dir(installer.Filename()), logger) if err != nil { t.Fatal(err) } @@ -818,9 +812,7 @@ func TestBoltSnapshotStore_CreateInstallSnapshot(t *testing.T) { // Close/Reopen the db and make sure we still match fsm.Close() - fsm, err = NewFSM(map[string]string{ - "path": parent, - }, logger) + fsm, err = NewFSM(parent, logger) if err != nil { t.Fatal(err) }