Skip to content

Commit 5258057

Browse files
author
Giuseppe Maxia
committed
Fix Issue vmware#390: catalog.Delete() ignores task
Signed-off-by: Giuseppe Maxia <gmaxia@vmware.com>
1 parent b6c91e5 commit 5258057

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

govcd/admincatalog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewAdminCatalog(client *Client) *AdminCatalog {
2929
}
3030
}
3131

32-
// Deletes the Catalog, returning an error if the vCD call fails.
32+
// Delete deletes the Catalog, returning an error if the vCD call fails.
3333
// Link to API call: https://code.vmware.com/apis/220/vcloud#/doc/doc/operations/DELETE-Catalog.html
3434
func (adminCatalog *AdminCatalog) Delete(force, recursive bool) error {
3535
catalog := NewCatalog(adminCatalog.client)

govcd/catalog.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewCatalog(client *Client) *Catalog {
4242
}
4343
}
4444

45-
// Deletes the Catalog, returning an error if the vCD call fails.
45+
// Delete deletes the Catalog, returning an error if the vCD call fails.
4646
// Link to API call: https://code.vmware.com/apis/220/vcloud#/doc/doc/operations/DELETE-Catalog.html
4747
func (catalog *Catalog) Delete(force, recursive bool) error {
4848

@@ -52,7 +52,7 @@ func (catalog *Catalog) Delete(force, recursive bool) error {
5252
return err
5353
}
5454
if catalogID == "" {
55-
return fmt.Errorf("empty ID returned for catalog ID %s", catalog.Catalog.ID)
55+
return fmt.Errorf("empty ID returned for catalog %s", catalog.Catalog.Name)
5656
}
5757
adminCatalogHREF.Path += "/admin/catalog/" + catalogID
5858

@@ -61,13 +61,18 @@ func (catalog *Catalog) Delete(force, recursive bool) error {
6161
"recursive": strconv.FormatBool(recursive),
6262
}, http.MethodDelete, adminCatalogHREF, nil)
6363

64-
_, err = checkResp(catalog.client.Http.Do(req))
65-
64+
resp, err := checkResp(catalog.client.Http.Do(req))
6665
if err != nil {
67-
return fmt.Errorf("error deleting Catalog %s: %s", catalog.Catalog.ID, err)
66+
return fmt.Errorf("error deleting Catalog %s: %s", catalog.Catalog.Name, err)
6867
}
69-
70-
return nil
68+
task := NewTask(catalog.client)
69+
if err = decodeBody(types.BodyTypeXML, resp, task.Task); err != nil {
70+
return fmt.Errorf("error decoding task response: %s", err)
71+
}
72+
if task.Task.Status == "error" {
73+
return fmt.Errorf("catalog not properly destroyed")
74+
}
75+
return task.WaitTaskCompletion()
7176
}
7277

7378
// Envelope is a ovf description root element. File contains information for vmdk files.

govcd/catalog_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,6 @@ func cleanupCatalogOrgVdc(check *C, sharedCatalog Catalog, vdc *Vdc, vcd *TestVC
772772
err := sharedCatalog.Delete(true, true)
773773
check.Assert(err, IsNil)
774774

775-
// There are cases where it just takes a a few seconds after catalog deletion when one can delete VDC
776-
time.Sleep(2 * time.Second)
777-
778775
err = vdc.DeleteWait(true, true)
779776
check.Assert(err, IsNil)
780777

govcd/catalogitem.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (catalogItem *CatalogItem) GetVAppTemplate() (VAppTemplate, error) {
3737

3838
}
3939

40-
// Deletes the Catalog Item, returning an error if the vCD call fails.
40+
// Delete deletes the Catalog Item, returning an error if the vCD call fails.
4141
// Link to API call: https://code.vmware.com/apis/220/vcloud#/doc/doc/operations/DELETE-CatalogItem.html
4242
func (catalogItem *CatalogItem) Delete() error {
4343
util.Logger.Printf("[TRACE] Deleting catalog item: %#v", catalogItem.CatalogItem)

0 commit comments

Comments
 (0)