Skip to content

Commit 8314cda

Browse files
Merge pull request #411 from sondavidb/engine-io
Added API functionality + testing to change engine IO type
2 parents 77e7d57 + 876156a commit 8314cda

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drives.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,12 @@ func WithCacheType(cacheType string) DriveOpt {
110110
d.CacheType = String(cacheType)
111111
}
112112
}
113+
114+
// WithIoEngine sets the io engine of the drive
115+
// Defaults to Sync, Async is in developer preview at the moment
116+
// https://github.com/firecracker-microvm/firecracker/blob/v1.1.0/docs/api_requests/block-io-engine.md
117+
func WithIoEngine(ioEngine string) DriveOpt {
118+
return func(d *models.Drive) {
119+
d.IoEngine = String(ioEngine)
120+
}
121+
}

drives_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,23 @@ func TestDrivesBuilderAddDrive(t *testing.T) {
155155
t.Errorf("expected drives %+v\n, but received %+v", e, a)
156156
}
157157
}
158+
159+
func TestDrivesBuilderWithIoEngine(t *testing.T) {
160+
expectedPath := "/path/to/rootfs"
161+
expectedVal := "Async"
162+
expectedDrives := []models.Drive{
163+
{
164+
DriveID: String(rootDriveName),
165+
PathOnHost: &expectedPath,
166+
IsRootDevice: Bool(true),
167+
IsReadOnly: Bool(false),
168+
IoEngine: &expectedVal,
169+
},
170+
}
171+
172+
drives := NewDrivesBuilder(expectedPath).WithRootDrive(expectedPath,
173+
WithDriveID(string(rootDriveName)), WithIoEngine(expectedVal)).Build()
174+
if e, a := expectedDrives, drives; !reflect.DeepEqual(e, a) {
175+
t.Errorf("expected drives %+v, but received %+v", e, a)
176+
}
177+
}

0 commit comments

Comments
 (0)