Skip to content

Commit dd3f103

Browse files
authored
Merge pull request #3361 from gophercloud/bp-v2-9337a4f
[v2] octavia: fix http_version type to float
2 parents af09823 + 56c2851 commit dd3f103

5 files changed

Lines changed: 87 additions & 3 deletions

File tree

internal/acceptance/openstack/loadbalancer/v2/loadbalancer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func CreateLoadBalancerFullyPopulated(t *testing.T, client *gophercloud.ServiceC
213213
MaxRetries: 5,
214214
MaxRetriesDown: 4,
215215
Type: monitors.TypeHTTP,
216+
HTTPVersion: "1.0",
216217
},
217218
},
218219
L7Policies: []l7policies.CreateOpts{{
@@ -271,6 +272,13 @@ func CreateLoadBalancerFullyPopulated(t *testing.T, client *gophercloud.ServiceC
271272
th.AssertEquals(t, lb.Pools[0].Members[0].ProtocolPort, memberPort)
272273
th.AssertEquals(t, lb.Pools[0].Members[0].Weight, memberWeight)
273274

275+
th.AssertEquals(t, lb.Pools[0].Monitor.Delay, 10)
276+
th.AssertEquals(t, lb.Pools[0].Monitor.Timeout, 5)
277+
th.AssertEquals(t, lb.Pools[0].Monitor.MaxRetries, 5)
278+
th.AssertEquals(t, lb.Pools[0].Monitor.MaxRetriesDown, 4)
279+
th.AssertEquals(t, lb.Pools[0].Monitor.Type, string(monitors.TypeHTTP))
280+
th.AssertEquals(t, lb.Pools[0].Monitor.HTTPVersion, "1.0")
281+
274282
if len(tags) > 0 {
275283
th.AssertDeepEquals(t, lb.Tags, tags)
276284
}
@@ -332,6 +340,7 @@ func CreateMonitor(t *testing.T, client *gophercloud.ServiceClient, lb *loadbala
332340
MaxRetries: 5,
333341
MaxRetriesDown: 4,
334342
Type: monitors.TypePING,
343+
HTTPVersion: "1.1",
335344
}
336345

337346
monitor, err := monitors.Create(context.TODO(), client, createOpts).Extract()
@@ -351,6 +360,7 @@ func CreateMonitor(t *testing.T, client *gophercloud.ServiceClient, lb *loadbala
351360
th.AssertEquals(t, monitor.Timeout, 5)
352361
th.AssertEquals(t, monitor.MaxRetries, 5)
353362
th.AssertEquals(t, monitor.MaxRetriesDown, 4)
363+
th.AssertEquals(t, monitor.HTTPVersion, "1.1")
354364

355365
return monitor, nil
356366
}

openstack/loadbalancer/v2/monitors/requests.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package monitors
22

33
import (
44
"context"
5+
"strconv"
56

67
"github.com/gophercloud/gophercloud/v2"
78
"github.com/gophercloud/gophercloud/v2/pagination"
@@ -153,7 +154,25 @@ type CreateOpts struct {
153154

154155
// ToMonitorCreateMap builds a request body from CreateOpts.
155156
func (opts CreateOpts) ToMonitorCreateMap() (map[string]any, error) {
156-
return gophercloud.BuildRequestBody(opts, "healthmonitor")
157+
b, err := gophercloud.BuildRequestBody(opts, "healthmonitor")
158+
if err != nil {
159+
return nil, err
160+
}
161+
162+
if v, ok := b["healthmonitor"]; ok {
163+
if m, ok := v.(map[string]any); ok {
164+
if v, ok := m["http_version"]; ok {
165+
if v, ok := v.(string); ok {
166+
m["http_version"], err = strconv.ParseFloat(v, 64)
167+
if err != nil {
168+
return nil, err
169+
}
170+
}
171+
}
172+
}
173+
}
174+
175+
return b, nil
157176
}
158177

159178
/*
@@ -247,7 +266,25 @@ type UpdateOpts struct {
247266

248267
// ToMonitorUpdateMap builds a request body from UpdateOpts.
249268
func (opts UpdateOpts) ToMonitorUpdateMap() (map[string]any, error) {
250-
return gophercloud.BuildRequestBody(opts, "healthmonitor")
269+
b, err := gophercloud.BuildRequestBody(opts, "healthmonitor")
270+
if err != nil {
271+
return nil, err
272+
}
273+
274+
if v, ok := b["healthmonitor"]; ok {
275+
if m, ok := v.(map[string]any); ok {
276+
if v, ok := m["http_version"]; ok {
277+
if v, ok := v.(string); ok {
278+
m["http_version"], err = strconv.ParseFloat(v, 64)
279+
if err != nil {
280+
return nil, err
281+
}
282+
}
283+
}
284+
}
285+
}
286+
287+
return b, nil
251288
}
252289

253290
// Update is an operation which modifies the attributes of the specified

openstack/loadbalancer/v2/monitors/results.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package monitors
22

33
import (
4+
"encoding/json"
5+
"strconv"
6+
47
"github.com/gophercloud/gophercloud/v2"
58
"github.com/gophercloud/gophercloud/v2/pagination"
69
)
@@ -61,7 +64,7 @@ type Monitor struct {
6164
HTTPMethod string `json:"http_method"`
6265

6366
// The HTTP version that the monitor uses for requests.
64-
HTTPVersion string `json:"http_version"`
67+
HTTPVersion string `json:"-"`
6568

6669
// The HTTP path of the request sent by the monitor to test the health of a
6770
// member. Must be a string beginning with a forward slash (/).
@@ -96,6 +99,26 @@ type Monitor struct {
9699
Tags []string `json:"tags"`
97100
}
98101

102+
func (r *Monitor) UnmarshalJSON(b []byte) error {
103+
type tmp Monitor
104+
var s struct {
105+
tmp
106+
HTTPVersion float64 `json:"http_version"`
107+
}
108+
109+
err := json.Unmarshal(b, &s)
110+
if err != nil {
111+
return err
112+
}
113+
114+
*r = Monitor(s.tmp)
115+
if s.HTTPVersion != 0 {
116+
r.HTTPVersion = strconv.FormatFloat(s.HTTPVersion, 'f', 1, 64)
117+
}
118+
119+
return nil
120+
}
121+
99122
// MonitorPage is the page returned by a pager when traversing over a
100123
// collection of health monitors.
101124
type MonitorPage struct {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ const HealthmonitorsListBody = `
3131
"admin_state_up":true,
3232
"project_id":"83657cfcdfe44cd5920adaf26c48ceea",
3333
"delay":5,
34+
"domain_name": "www.example.com",
3435
"name":"db",
3536
"expected_codes":"200",
3637
"max_retries":2,
3738
"max_retries_down":4,
3839
"http_method":"GET",
40+
"http_version": 1.1,
3941
"timeout":2,
4042
"url_path":"/",
4143
"type":"HTTP",
@@ -54,11 +56,13 @@ const SingleHealthmonitorBody = `
5456
"admin_state_up":true,
5557
"project_id":"83657cfcdfe44cd5920adaf26c48ceea",
5658
"delay":5,
59+
"domain_name": "www.example.com",
5760
"name":"db",
5861
"expected_codes":"200",
5962
"max_retries":2,
6063
"max_retries_down":4,
6164
"http_method":"GET",
65+
"http_version": 1.1,
6266
"timeout":2,
6367
"url_path":"/",
6468
"type":"HTTP",
@@ -76,11 +80,13 @@ const PostUpdateHealthmonitorBody = `
7680
"admin_state_up":true,
7781
"project_id":"83657cfcdfe44cd5920adaf26c48ceea",
7882
"delay":3,
83+
"domain_name": "www.example.com",
7984
"name":"NewHealthmonitorName",
8085
"expected_codes":"301",
8186
"max_retries":10,
8287
"max_retries_down":8,
8388
"http_method":"GET",
89+
"http_version": 1.1,
8490
"timeout":20,
8591
"url_path":"/another_check",
8692
"type":"HTTP",
@@ -107,6 +113,7 @@ var (
107113
}
108114
HealthmonitorDb = monitors.Monitor{
109115
AdminStateUp: true,
116+
DomainName: "www.example.com",
110117
Name: "db",
111118
ProjectID: "83657cfcdfe44cd5920adaf26c48ceea",
112119
Delay: 5,
@@ -117,12 +124,14 @@ var (
117124
URLPath: "/",
118125
Type: "HTTP",
119126
HTTPMethod: "GET",
127+
HTTPVersion: "1.1",
120128
ID: "5d4b5228-33b0-4e60-b225-9b727c1a20e7",
121129
Pools: []monitors.PoolID{{ID: "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}},
122130
Tags: []string{},
123131
}
124132
HealthmonitorUpdated = monitors.Monitor{
125133
AdminStateUp: true,
134+
DomainName: "www.example.com",
126135
Name: "NewHealthmonitorName",
127136
ProjectID: "83657cfcdfe44cd5920adaf26c48ceea",
128137
Delay: 3,
@@ -133,6 +142,7 @@ var (
133142
URLPath: "/another_check",
134143
Type: "HTTP",
135144
HTTPMethod: "GET",
145+
HTTPVersion: "1.1",
136146
ID: "5d4b5228-33b0-4e60-b225-9b727c1a20e7",
137147
Pools: []monitors.PoolID{{ID: "d459f7d8-c6ee-439d-8713-d3fc08aeed8d"}},
138148
Tags: []string{},
@@ -173,7 +183,9 @@ func HandleHealthmonitorCreationSuccessfully(t *testing.T, response string) {
173183
"pool_id":"84f1b61f-58c4-45bf-a8a9-2dafb9e5214d",
174184
"project_id":"453105b9-1754-413f-aab1-55f1af620750",
175185
"delay":20,
186+
"domain_name": "www.example.com",
176187
"name":"db",
188+
"http_version": 1.1,
177189
"timeout":10,
178190
"max_retries":5,
179191
"max_retries_down":4,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ func TestCreateHealthmonitor(t *testing.T) {
6060

6161
actual, err := monitors.Create(context.TODO(), fake.ServiceClient(), monitors.CreateOpts{
6262
Type: "HTTP",
63+
DomainName: "www.example.com",
6364
Name: "db",
6465
PoolID: "84f1b61f-58c4-45bf-a8a9-2dafb9e5214d",
6566
ProjectID: "453105b9-1754-413f-aab1-55f1af620750",
6667
Delay: 20,
6768
Timeout: 10,
6869
MaxRetries: 5,
6970
MaxRetriesDown: 4,
71+
HTTPVersion: "1.1",
7072
Tags: []string{},
7173
URLPath: "/check",
7274
ExpectedCodes: "200-299",

0 commit comments

Comments
 (0)