Skip to content

Commit 31b91fe

Browse files
chuliangLudovic Lamarche
authored andcommitted
Set healthmonitor domain name optional
1 parent ba9cc67 commit 31b91fe

File tree

3 files changed

+137
-2
lines changed

3 files changed

+137
-2
lines changed

openstack/loadbalancer/v2/monitors/requests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type CreateOpts struct {
107107

108108
// The domain name, which be injected into the HTTP Host Header to
109109
// the backend server for HTTP health check. New in version 2.10.
110-
DomainName string `json:"domain_name"`
110+
DomainName string `json:"domain_name,omitempty"`
111111

112112
// Maximum number of seconds for a Monitor to wait for a ping reply
113113
// before it times out. The value must be less than the delay value.
@@ -205,7 +205,7 @@ type UpdateOpts struct {
205205

206206
// The domain name, which be injected into the HTTP Host Header to
207207
// the backend server for HTTP health check. New in version 2.10.
208-
DomainName string `json:"domain_name"`
208+
DomainName string `json:"domain_name,omitempty"`
209209

210210
// Maximum number of seconds for a Monitor to wait for a ping reply
211211
// before it times out. The value must be less than the delay value.

openstack/loadbalancer/v2/monitors/testing/fixtures.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ const SingleHealthmonitorBody = `
7070
}
7171
`
7272

73+
// CreatePingHealthmonitorBody is the canned body of a POST request to create a ping healthmonitor.
74+
const CreatePingHealthmonitorBody = `
75+
{
76+
"healthmonitor": {
77+
"admin_state_up":true,
78+
"project_id":"83657cfcdfe44cd5920adaf26c48ceea",
79+
"delay":10,
80+
"name":"web",
81+
"max_retries":1,
82+
"max_retries_down":7,
83+
"timeout":1,
84+
"type":"PING",
85+
"pools": [{"id": "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d"}],
86+
"id":"466c8345-28d8-4f84-a246-e04380b0461d"
87+
}
88+
}
89+
`
90+
7391
// PostUpdateHealthmonitorBody is the canned response body of a Update request on an existing healthmonitor.
7492
const PostUpdateHealthmonitorBody = `
7593
{
@@ -93,6 +111,24 @@ const PostUpdateHealthmonitorBody = `
93111
}
94112
`
95113

114+
// PostUpdatePingHealthmonitorBody is the canned response body of a Update request on an existing healthmonitor.
115+
const PostUpdatePingHealthmonitorBody = `
116+
{
117+
"healthmonitor": {
118+
"admin_state_up":true,
119+
"project_id":"83657cfcdfe44cd5920adaf26c48ceea",
120+
"delay":10,
121+
"name":"web",
122+
"max_retries":1,
123+
"max_retries_down":7,
124+
"timeout":1,
125+
"type":"PING",
126+
"pools": [{"id": "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d"}],
127+
"id":"466c8345-28d8-4f84-a246-e04380b0461d"
128+
}
129+
}
130+
`
131+
96132
var (
97133
HealthmonitorWeb = monitors.Monitor{
98134
AdminStateUp: true,
@@ -140,6 +176,18 @@ var (
140176
ID: "5d4b5228-33b0-4e60-b225-9b727c1a20e7",
141177
Pools: []monitors.PoolID{{ID: "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}},
142178
}
179+
HealthmonitorWebUpdated = monitors.Monitor{
180+
AdminStateUp: true,
181+
Name: "web",
182+
ProjectID: "83657cfcdfe44cd5920adaf26c48ceea",
183+
Delay: 10,
184+
MaxRetries: 1,
185+
MaxRetriesDown: 7,
186+
Timeout: 1,
187+
Type: "PING",
188+
ID: "466c8345-28d8-4f84-a246-e04380b0461d",
189+
Pools: []monitors.PoolID{{ID: "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d"}},
190+
}
143191
)
144192

145193
// HandleHealthmonitorListSuccessfully sets up the test server to respond to a healthmonitor List request.
@@ -191,6 +239,31 @@ func HandleHealthmonitorCreationSuccessfully(t *testing.T, response string) {
191239
})
192240
}
193241

242+
// HandlePingHealthmonitorCreationSuccessfully sets up the test server to respond to a ping healthmonitor creation request
243+
// with a given response.
244+
func HandlePingHealthmonitorCreationSuccessfully(t *testing.T, response string) {
245+
th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors", func(w http.ResponseWriter, r *http.Request) {
246+
th.TestMethod(t, r, "POST")
247+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
248+
th.TestJSONRequest(t, r, `{
249+
"healthmonitor": {
250+
"type":"PING",
251+
"pool_id":"84f1b61f-58c4-45bf-a8a9-2dafb9e5214d",
252+
"project_id":"83657cfcdfe44cd5920adaf26c48ceea",
253+
"delay":10,
254+
"name":"web",
255+
"timeout":1,
256+
"max_retries":1,
257+
"max_retries_down":7
258+
}
259+
}`)
260+
261+
w.WriteHeader(http.StatusAccepted)
262+
w.Header().Add("Content-Type", "application/json")
263+
fmt.Fprintf(w, response)
264+
})
265+
}
266+
194267
// HandleHealthmonitorGetSuccessfully sets up the test server to respond to a healthmonitor Get request.
195268
func HandleHealthmonitorGetSuccessfully(t *testing.T) {
196269
th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors/5d4b5228-33b0-4e60-b225-9b727c1a20e7", func(w http.ResponseWriter, r *http.Request) {
@@ -236,3 +309,24 @@ func HandleHealthmonitorUpdateSuccessfully(t *testing.T) {
236309
fmt.Fprintf(w, PostUpdateHealthmonitorBody)
237310
})
238311
}
312+
313+
// HandlePingHealthmonitorUpdateSuccessfully sets up the test server to respond to a healthmonitor Update request.
314+
func HandlePingHealthmonitorUpdateSuccessfully(t *testing.T) {
315+
th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors/5d4b5228-33b0-4e60-b225-9b727c1a20e7", func(w http.ResponseWriter, r *http.Request) {
316+
th.TestMethod(t, r, "PUT")
317+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
318+
th.TestHeader(t, r, "Accept", "application/json")
319+
th.TestHeader(t, r, "Content-Type", "application/json")
320+
th.TestJSONRequest(t, r, `{
321+
"healthmonitor": {
322+
"delay":3,
323+
"name":"NewHealthmonitorName",
324+
"timeout":20,
325+
"max_retries":10,
326+
"max_retries_down":8
327+
}
328+
}`)
329+
330+
fmt.Fprintf(w, PostUpdatePingHealthmonitorBody)
331+
})
332+
}

openstack/loadbalancer/v2/monitors/testing/requests_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ func TestCreateHealthmonitor(t *testing.T) {
7676
th.CheckDeepEquals(t, HealthmonitorDb, *actual)
7777
}
7878

79+
func TestCreatePingHealthmonitor(t *testing.T) {
80+
th.SetupHTTP()
81+
defer th.TeardownHTTP()
82+
HandlePingHealthmonitorCreationSuccessfully(t, CreatePingHealthmonitorBody)
83+
84+
actual, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{
85+
Type: "PING",
86+
Name: "web",
87+
PoolID: "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d",
88+
ProjectID: "83657cfcdfe44cd5920adaf26c48ceea",
89+
Delay: 10,
90+
Timeout: 1,
91+
MaxRetries: 1,
92+
MaxRetriesDown: 7,
93+
}).Extract()
94+
th.AssertNoErr(t, err)
95+
96+
th.CheckDeepEquals(t, HealthmonitorWeb, *actual)
97+
}
98+
7999
func TestRequiredCreateOpts(t *testing.T) {
80100
res := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{})
81101
if res.Err == nil {
@@ -135,6 +155,27 @@ func TestUpdateHealthmonitor(t *testing.T) {
135155
th.CheckDeepEquals(t, HealthmonitorUpdated, *actual)
136156
}
137157

158+
func TestUpdatePingHealthmonitor(t *testing.T) {
159+
th.SetupHTTP()
160+
defer th.TeardownHTTP()
161+
HandlePingHealthmonitorUpdateSuccessfully(t)
162+
163+
client := fake.ServiceClient()
164+
name := "NewHealthmonitorName"
165+
actual, err := monitors.Update(client, "5d4b5228-33b0-4e60-b225-9b727c1a20e7", monitors.UpdateOpts{
166+
Name: &name,
167+
Delay: 3,
168+
Timeout: 20,
169+
MaxRetries: 10,
170+
MaxRetriesDown: 8,
171+
}).Extract()
172+
if err != nil {
173+
t.Fatalf("Unexpected Update error: %v", err)
174+
}
175+
176+
th.CheckDeepEquals(t, HealthmonitorWebUpdated, *actual)
177+
}
178+
138179
func TestDelayMustBeGreaterOrEqualThanTimeout(t *testing.T) {
139180
_, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{
140181
Type: "HTTP",

0 commit comments

Comments
 (0)