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

Improve deleteVapp() testing function #297

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions govcd/orgvdcnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (orgVdcNet *OrgVDCNetwork) Delete() (Task, error) {
return *task, nil
}

// Looks for an Org Vdc network and, if found, will delete it.
// RemoveOrgVdcNetworkIfExists looks for an Org Vdc network and, if found, will delete it.
func RemoveOrgVdcNetworkIfExists(vdc Vdc, networkName string) error {
network, err := vdc.GetOrgVdcNetworkByName(networkName, true)

Expand All @@ -102,11 +102,11 @@ func RemoveOrgVdcNetworkIfExists(vdc Vdc, networkName string) error {
// The network was found. We attempt deletion
task, err := network.Delete()
if err != nil {
return fmt.Errorf("error deleting network [phase 1] %s", networkName)
return fmt.Errorf("error deleting network '%s' [phase 1]: %s", networkName, err)
}
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("error deleting network [task] %s", networkName)
return fmt.Errorf("error deleting network '%s' [task]: %s", networkName, err)
}
return nil
}
Expand Down
17 changes: 15 additions & 2 deletions govcd/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,13 +1286,26 @@ func (vcd *TestVCD) Test_VmGetParentvAppAndVdc(check *C) {
func deleteVapp(vcd *TestVCD, name string) error {
vapp, err := vcd.vdc.GetVAppByName(name, true)
if err != nil {
return fmt.Errorf("error getting vapp: %s", err)
return fmt.Errorf("error getting vApp: %s", err)
}
task, _ := vapp.Undeploy()
_ = task.WaitTaskCompletion()

// Detach all Org networks during vApp removal because network removal errors if it happens
// very quickly (as the next task) after vApp removal
task, _ = vapp.RemoveAllNetworks()
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("error removing networks from vApp: %s", err)
}

task, err = vapp.Delete()
if err != nil {
return fmt.Errorf("error deleting vapp: %s", err)
return fmt.Errorf("error deleting vApp: %s", err)
}
err = task.WaitTaskCompletion()
if err != nil {
return fmt.Errorf("error waiting for vApp deletion task: %s", err)
}
return nil
}