vmwaretest: avoid using the cli

This is not shipped in RHEL, so use the library directly to query the IP
address. This is a massive hack, but let us revisit this after the next
release.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2020-08-19 17:42:52 +02:00
parent 5a395cda38
commit f3cba8ecfc
2 changed files with 29 additions and 17 deletions

View file

@ -4,10 +4,10 @@ package vmwaretest
import (
"errors"
"os"
"os/exec"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
// importing the packages registers these cli commands
@ -21,14 +21,14 @@ import (
const WaitTimeout = 6000 // in seconds
type AuthOptions struct {
Host string
Username string
Password string
Host string
Username string
Password string
Datacenter string
Cluster string
Network string
Datastore string
Folder string
Cluster string
Network string
Datastore string
Folder string
}
func AuthOptionsFromEnv() (*AuthOptions, error) {
@ -121,6 +121,20 @@ func DeleteImage(creds *AuthOptions, directoryName string) error {
return nil
}
func runWithStdout(args []string) ([]byte, int) {
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
retcode := cli.Run(args)
w.Close()
out, _ := ioutil.ReadAll(r)
os.Stdout = oldStdout
return out, retcode
}
func WithBootedImage(creds *AuthOptions, imagePath, imageName, publicKey string, f func(address string) error) (retErr error) {
vmdkBaseName := filepath.Base(imagePath)
@ -159,16 +173,16 @@ func WithBootedImage(creds *AuthOptions, imagePath, imageName, publicKey string,
// note: by default this will wait/block until an IP address is returned
// note: using exec() instead of running the command b/c .Run() returns an int
ipAddress, err := exec.Command(
"/usr/bin/govc",
args = []string{
"vm.ip",
fmt.Sprintf("-u=%s:%s@%s", creds.Username, creds.Password, creds.Host),
"-k=true",
imageName,
).Output()
if err != nil {
fmt.Println("Getting IP address for VM failed:", string(ipAddress))
return err
}
ipAddress, retcode := runWithStdout(args)
if retcode != 0 {
return errors.New("Getting IP address for VM failed")
}
// Disabled b/c of https://github.com/vmware/govmomi/issues/2054
@ -211,7 +225,6 @@ func WithSSHKeyPair(f func(privateKey, publicKey string) error) error {
return f(private, public)
}
func ConvertToStreamOptimizedVmdk(imagePath string) (string, error) {
optimizedVmdk, err := ioutil.TempFile("/var/tmp", "osbuild-composer-stream-optimized-*.vmdk")
if err != nil {

View file

@ -223,7 +223,6 @@ Requires: createrepo_c
Requires: genisoimage
Requires: qemu-kvm-core
Requires: systemd-container
Requires: /usr/bin/govc
%ifarch %{arm}
Requires: edk2-aarch64
%endif