Skip to content
Open
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
10 changes: 9 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@ func (c *clientImpl) DeleteHosts(names []string) error {
wg.Add(1)
go func(name string) {
defer wg.Done()
if err := c.httpHelper.NewDeleteRequest("/hosts/" + name).JSONResDo(nil); err != nil {
var op apiv1.Operation
if err := c.httpHelper.NewDeleteRequest("/hosts/" + name).JSONResDo(&op); err != nil {
mu.Lock()
defer mu.Unlock()
merr = multierror.Append(merr, fmt.Errorf("delete host %q failed: %w", name, err))
return
}
ins := &apiv1.HostInstance{}
if err := c.waitForOperation(&op, ins); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

waiting for a delete host operation should return an empty response: https://github.com/google/cloud-android-orchestration/blob/main/pkg/app/instances/gce.go#L344.

create a new helper: waitForOperation() where you don't have to pass a response argument, after fixing the DockerIM implementation.

mu.Lock()
defer mu.Unlock()
merr = multierror.Append(merr, fmt.Errorf("delete host %q failed: %w", name, err))
Expand Down
23 changes: 10 additions & 13 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"io"
"net/http"
"net/http/httptest"
"regexp"
"testing"

apiv1 "github.com/google/cloud-android-orchestration/api/v1"
Expand All @@ -28,19 +27,17 @@ import (
)

func TestDeleteHosts(t *testing.T) {
existingNames := map[string]struct{}{"bar": {}, "baz": {}}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "DELETE" {
panic("unexpected method: " + r.Method)
}
re := regexp.MustCompile(`^/hosts/(.*)$`)
matches := re.FindStringSubmatch(r.URL.Path)
if len(matches) != 2 {
panic("unexpected path: " + r.URL.Path)
}
if _, ok := existingNames[matches[1]]; ok {
writeOK(w, "")
} else {
switch ep := r.Method + " " + r.URL.Path; ep {
case "DELETE /hosts/bar":
writeOK(w, apiv1.Operation{Name: "deletingbar"})
case "DELETE /hosts/baz":
writeOK(w, apiv1.Operation{Name: "deletingbaz"})
case "POST /operations/deletingbar/:wait":
writeOK(w, apiv1.HostInstance{Name: "bar"})
case "POST /operations/deletingbaz/:wait":
writeOK(w, apiv1.HostInstance{Name: "baz"})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

waiting for a delete host operation should return an empty response: https://github.com/google/cloud-android-orchestration/blob/main/pkg/app/instances/gce.go#L344. Please fix the DockerIM to return an empty response first.

default:
writeErr(w, 404)
}
}))
Expand Down