Skip to content

Commit

Permalink
fix: handle non-zero return code from Azure CLI (#635)
Browse files Browse the repository at this point in the history
When running "om vm-lifecycle create-vm" on Azure, a problem has
recently occurred where querying a blob status using "az storage blob
show" has started to exit with a non-zero code and error "There is
currently a pending copy operation". Because of the error, the command
terminates. It's likely that this is because of a change in the backend
Azure API. As we are trying to determine whether the copy operation has
finished, it's safe to ignore this error and continue polling.

[#187303104](https://www.pivotaltracker.com/story/show/187303104)
  • Loading branch information
blgm authored Apr 11, 2024
1 parent 284d75c commit 36320d4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions vmlifecycle/vmmanagers/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,24 +361,28 @@ func (a *AzureVMManager) copyImageBlob(imageSourceURL string, imageName string)
}

for {
out, _, err := a.runner.ExecuteWithEnvVars(a.addEnvVars(),
[]interface{}{
stdout, stderr, err := a.runner.ExecuteWithEnvVars(
a.addEnvVars(),
[]any{
"storage", "blob", "show",
"--name", imageName + ".vhd",
"--container-name", azure.Container,
"--query", "properties.copy.status",
})
if err != nil {
},
)

switch {
case err != nil && strings.Contains(stderr.String(), "ErrorCode:PendingCopyOperation"):
// Continue polling
case err != nil:
return fmt.Errorf("azure error: %s", err)
case strings.TrimSpace(stdout.String()) == `"success"`:
return nil // Operation is finished
}
if strings.TrimSpace(out.String()) == `"success"` {
break
}

_, _ = a.stderr.Write([]byte(fmt.Sprintf("blob not ready yet, polling in %s\n", a.pollingInterval)))
time.Sleep(a.pollingInterval)
}

return nil
}

func (a *AzureVMManager) addDefaultConfigFields() {
Expand Down

0 comments on commit 36320d4

Please sign in to comment.