Gitlab runner doesn't parse virtualbox snapshot names properly due to broken regex
Summary
Virtualbox (on windows at least) outputs the snapshot information in a different format than what the code expects, resulting in the report that the snapshot cannot be found
I think this may be related to #3273
Steps to reproduce
- Create VM
- Add snapshot
- register vm with
base_snapshot
set to snapshot name - send a job to it, and see in the job output the warning that the snapshot is not found
Expected behavior
The snapshot to be used in the job
Relevant logs and/or screenshots
The go code for parsing the list of snapshots from vboxmanage:
func HasSnapshot(vmName string, snapshotName string) bool {
output, err := VBoxManage("snapshot", vmName, "list", "--machinereadable")
if err != nil {
return false
}
snapshotRe := regexp.MustCompile(fmt.Sprintf(`(?m)^Snapshot(Name|UUID)[^=]*="%s"$`, regexp.QuoteMeta(snapshotName)))
snapshot := snapshotRe.FindStringSubmatch(output)
return snapshot != nil
}
and a sample list of snapshots from vboxmanage using the above command vboxmanage snapshot {vmname} list --machinereadble
SnapshotName="gitlabrunner"
SnapshotUUID="xxx"
SnapshotName-1="snap1"
SnapshotUUID-1="xxx"
CurrentSnapshotName="snap1"
CurrentSnapshotUUID="xxx"
CurrentSnapshotNode="SnapshotName-1"
I've never coded in go, but I'd guestimate there are missing round brackets for the name / uuid value missing, like so:
snapshotRe := regexp.MustCompile(fmt.Sprintf(`(?m)^Snapshot(Name|UUID)[^=]*="(%s)"$`, regexp.QuoteMeta(snapshotName)))
Looking at the get Current Snapshot code below:
([^"]*)
is used instead of %s
, which is what I'd personally prefer to see
snapshotRe := regexp.MustCompile(fmt.Sprintf(`(?m)^Snapshot(Name|UUID)[^=]*="([^"]+)"$`, regexp.QuoteMeta(snapshotName)))
Environment description
virtualbox executor, on windows host.
Used GitLab Runner version
The code above is pulled from https://gitlab.com/gitlab-org/gitlab-runner/blob/master/helpers/virtualbox/control.go
I'm using 10.7.1