Skip to content

Commit

Permalink
fc: fix version parsing for fc >= 0.25
Browse files Browse the repository at this point in the history
Allows to use firecracker version >=0.25.

Fixes: #2471

Signed-off-by: Bl1tz23 <alex3angle@gmail.com>
  • Loading branch information
Bl1tz23 committed Aug 23, 2021
1 parent af93263 commit 87bbae1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/runtime/virtcontainers/fc.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,18 @@ func (fc *firecracker) getVersionNumber() (string, error) {
return "", fmt.Errorf("Running checking FC version command failed: %v", err)
}

return fc.parseVersion(string(data))
}

func (fc *firecracker) parseVersion(data string) (string, error) {
// Firecracker versions 0.25 and over contains multiline output on "version" command.
// So we have to check it and use first line of output to parse version.
lines := strings.Split(data, "\n")

var version string
fields := strings.Split(string(data), " ")
fields := strings.Split(lines[0], " ")
if len(fields) > 1 {
// The output format of `Firecracker --verion` is as follows
// The output format of `Firecracker --version` is as follows
// Firecracker v0.23.1
version = strings.TrimPrefix(strings.TrimSpace(fields[1]), "v")
return version, nil
Expand Down
12 changes: 12 additions & 0 deletions src/runtime/virtcontainers/fc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@ func TestRevertBytes(t *testing.T) {
num := revertBytes(testNum)
assert.Equal(expectedNum, num)
}

func TestFCParseVersion(t *testing.T) {
assert := assert.New(t)

fc := firecracker{}

for rawVersion, v := range map[string]string{"Firecracker v0.23.1": "0.23.1", "Firecracker v0.25.0\nSupported snapshot data format versions: 0.23.0": "0.25.0"} {
parsedVersion, err := fc.parseVersion(rawVersion)
assert.NoError(err)
assert.Equal(parsedVersion, v)
}
}

0 comments on commit 87bbae1

Please sign in to comment.