Move openAsStreamOptimizedVmdk() into importable package
so it can be used later within tests
This commit is contained in:
parent
5803abfeee
commit
e7aa9c10c2
2 changed files with 28 additions and 22 deletions
|
|
@ -11,7 +11,6 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
|
|
@ -21,6 +20,7 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/awsupload"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/azure"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/vmware"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
)
|
||||
|
||||
|
|
@ -67,26 +67,6 @@ func (e *TargetsError) Error() string {
|
|||
return errString
|
||||
}
|
||||
|
||||
func openAsStreamOptimizedVmdk(imagePath string) (*os.File, error) {
|
||||
newPath := imagePath + ".stream"
|
||||
cmd := exec.Command(
|
||||
"/usr/bin/qemu-img", "convert", "-O", "vmdk", "-o", "subformat=streamOptimized",
|
||||
imagePath, newPath)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := os.Open(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = os.Remove(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f, err
|
||||
}
|
||||
|
||||
func RunJob(job *worker.Job, store string, uploadFunc func(uuid.UUID, string, io.Reader) error) (*osbuild.Result, error) {
|
||||
outputDirectory, err := ioutil.TempDir("/var/tmp", "osbuild-worker-*")
|
||||
if err != nil {
|
||||
|
|
@ -112,7 +92,7 @@ func RunJob(job *worker.Job, store string, uploadFunc func(uuid.UUID, string, io
|
|||
var f *os.File
|
||||
imagePath := path.Join(outputDirectory, options.Filename)
|
||||
if options.StreamOptimized {
|
||||
f, err = openAsStreamOptimizedVmdk(imagePath)
|
||||
f, err = vmware.OpenAsStreamOptimizedVmdk(imagePath)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
|
|
|
|||
26
internal/upload/vmware/vmware.go
Normal file
26
internal/upload/vmware/vmware.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package vmware
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func OpenAsStreamOptimizedVmdk(imagePath string) (*os.File, error) {
|
||||
newPath := imagePath + ".stream"
|
||||
cmd := exec.Command(
|
||||
"/usr/bin/qemu-img", "convert", "-O", "vmdk", "-o", "subformat=streamOptimized",
|
||||
imagePath, newPath)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := os.Open(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = os.Remove(newPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue