Skip to content

Commit

Permalink
Octavia LBaaSv2: Allow setting an empty members list (#1736)
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus authored and jtopjian committed Oct 11, 2019
1 parent 1effcf5 commit f3883c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openstack/loadbalancer/v2/pools/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (opts BatchUpdateMemberOpts) ToBatchMemberUpdateMap() (map[string]interface

// BatchUpdateMembers updates the pool members in batch
func BatchUpdateMembers(c *gophercloud.ServiceClient, poolID string, opts []BatchUpdateMemberOpts) (r UpdateMembersResult) {
var members []map[string]interface{}
members := []map[string]interface{}{}
for _, opt := range opts {
b, err := opt.ToBatchMemberUpdateMap()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions openstack/loadbalancer/v2/pools/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,18 @@ func HandleMembersUpdateSuccessfully(t *testing.T) {
w.WriteHeader(http.StatusAccepted)
})
}

// HandleEmptyMembersUpdateSuccessfully sets up the test server to respond to an empty batch member Update request.
func HandleEmptyMembersUpdateSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestJSONRequest(t, r, `{
"members": []
}`)

w.WriteHeader(http.StatusAccepted)
})
}
9 changes: 9 additions & 0 deletions openstack/loadbalancer/v2/pools/testing/requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ func TestBatchUpdateMembers(t *testing.T) {
th.AssertNoErr(t, res.Err)
}

func TestEmptyBatchUpdateMembers(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleEmptyMembersUpdateSuccessfully(t)

res := pools.BatchUpdateMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", []pools.BatchUpdateMemberOpts{})
th.AssertNoErr(t, res.Err)
}

func TestRequiredBatchUpdateMemberOpts(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down

0 comments on commit f3883c7

Please sign in to comment.