Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix problem with ip concat with warnning messages #4451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions vm/vmware/vmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -108,7 +109,6 @@
}
return nil
}

func (inst *instance) boot() error {
if inst.debug {
log.Logf(0, "starting %v", inst.vmx)
Expand All @@ -119,11 +119,21 @@
if inst.debug {
log.Logf(0, "getting IP of %v", inst.vmx)
}
ip, err := osutil.RunCmd(5*time.Minute, "", "vmrun", "getGuestIPAddress", inst.vmx, "-wait")
ipCmd := exec.Command("vmrun", "getGuestIPAddress", inst.vmx, "-wait")
ipOutput, err := ipCmd.CombinedOutput()
Copy link
Collaborator

@a-nogikh a-nogikh Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the tool print the warning to stderr?

If yes, it might be easier to take the stdout output, i.e. ip, err := ipCmd.Output() instead of ipCmd.CombinedOutput(). Then you won't need to parse out the address.

if err != nil {
return err
return fmt.Errorf("failed to get IP address: %v", err)

Check failure on line 125 in vm/vmware/vmware.go

View workflow job for this annotation

GitHub Actions / build

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
}
inst.ipAddr = strings.TrimSuffix(string(ip), "\n")

// Extract IP address from the output, ignoring the warning message

Check failure on line 128 in vm/vmware/vmware.go

View workflow job for this annotation

GitHub Actions / build

lint: Add a period at the end of the comment
ipRegex := regexp.MustCompile(`(\d+\.\d+\.\d+\.\d+)`)
ipMatches := ipRegex.FindStringSubmatch(string(ipOutput))
if len(ipMatches) < 2 {
return fmt.Errorf("failed to extract IP address from vmrun output")
}
ip := strings.TrimSpace(ipMatches[1])

inst.ipAddr = ip
if inst.debug {
log.Logf(0, "VM %v has IP: %v", inst.vmx, inst.ipAddr)
}
Expand Down
Loading