Mark faulty devices

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
Maksym Pavlenko
2019-08-05 12:05:36 -07:00
parent 3741fd8591
commit 0a4bf1bd1e
4 changed files with 122 additions and 2 deletions

View File

@@ -154,6 +154,41 @@ func TestPoolDevice(t *testing.T) {
})
}
func TestPoolDeviceMarkFaulty(t *testing.T) {
tempDir, store := createStore(t)
defer cleanupStore(t, tempDir, store)
err := store.AddDevice(testCtx, &DeviceInfo{Name: "1", State: Unknown})
assert.NilError(t, err)
err = store.AddDevice(testCtx, &DeviceInfo{Name: "2", State: Activated})
assert.NilError(t, err)
pool := &PoolDevice{metadata: store}
err = pool.ensureDeviceStates(testCtx)
assert.NilError(t, err)
called := 0
err = pool.metadata.WalkDevices(testCtx, func(info *DeviceInfo) error {
called++
switch called {
case 1:
assert.Equal(t, Faulty, info.State)
assert.Equal(t, "1", info.Name)
case 2:
assert.Equal(t, Activated, info.State)
assert.Equal(t, "2", info.Name)
default:
t.Error("unexpected walk call")
}
return nil
})
assert.NilError(t, err)
assert.Equal(t, 2, called)
}
func testCreateThinDevice(t *testing.T, pool *PoolDevice) {
ctx := context.Background()