-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dynamic host volumes: client state (#24595)
store dynamic host volume creations in client state, so they can be "restored" on agent restart. restore works by repeating the same Create operation as initial creation, and expecting the plugin to be idempotent. this is (potentially) especially important after host restarts, which may have dropped mount points or such.
- Loading branch information
Showing
13 changed files
with
323 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package hostvolumemanager | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
cstate "github.com/hashicorp/nomad/client/state" | ||
cstructs "github.com/hashicorp/nomad/client/structs" | ||
"github.com/hashicorp/nomad/helper/testlog" | ||
"github.com/shoenig/test/must" | ||
) | ||
|
||
// db TODO(1.10.0): improve hostvolumemanager tests. | ||
|
||
func TestNewHostVolumeManager_restoreState(t *testing.T) { | ||
log := testlog.HCLogger(t) | ||
vol := &cstructs.HostVolumeState{ | ||
ID: "test-vol-id", | ||
CreateReq: &cstructs.ClientHostVolumeCreateRequest{ | ||
ID: "test-vol-id", | ||
PluginID: "mkdir", | ||
}, | ||
} | ||
|
||
t.Run("happy", func(t *testing.T) { | ||
// put our volume in state | ||
state := cstate.NewMemDB(log) | ||
must.NoError(t, state.PutDynamicHostVolume(vol)) | ||
|
||
// new volume manager should load it from state and run Create, | ||
// resulting in a volume directory in this mountDir. | ||
mountDir := t.TempDir() | ||
|
||
_, err := NewHostVolumeManager(log, state, time.Second, "/wherever", mountDir) | ||
must.NoError(t, err) | ||
|
||
volPath := filepath.Join(mountDir, vol.ID) | ||
must.DirExists(t, volPath) | ||
}) | ||
|
||
t.Run("get error", func(t *testing.T) { | ||
state := &cstate.ErrDB{} | ||
_, err := NewHostVolumeManager(log, state, time.Second, "/wherever", "/wherever") | ||
// error loading state should break the world | ||
must.ErrorIs(t, err, cstate.ErrDBError) | ||
}) | ||
|
||
// db TODO: test plugin error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.