Skip to content

Commit c9703e7

Browse files
committed
[octavia]: allow creating a disabled flavor
Octavia Flavor's `enabled` is true by default
1 parent 470f1bc commit c9703e7

4 files changed

Lines changed: 60 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/gophercloud/gophercloud/v2"
1111
"github.com/gophercloud/gophercloud/v2/internal/acceptance/clients"
1212
"github.com/gophercloud/gophercloud/v2/internal/acceptance/tools"
13+
"github.com/gophercloud/gophercloud/v2/internal/ptr"
1314
"github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/flavorprofiles"
1415
"github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/flavors"
1516
"github.com/gophercloud/gophercloud/v2/openstack/loadbalancer/v2/l7policies"
@@ -724,7 +725,7 @@ func CreateFlavor(t *testing.T, client *gophercloud.ServiceClient, flavorProfile
724725
Name: flavorName,
725726
Description: description,
726727
FlavorProfileId: flavorProfile.ID,
727-
Enabled: true,
728+
Enabled: ptr.To(false),
728729
}
729730

730731
flavor, err := flavors.Create(context.TODO(), client, createOpts).Extract()
@@ -737,7 +738,7 @@ func CreateFlavor(t *testing.T, client *gophercloud.ServiceClient, flavorProfile
737738
th.AssertEquals(t, flavorName, flavor.Name)
738739
th.AssertEquals(t, description, flavor.Description)
739740
th.AssertEquals(t, flavorProfile.ID, flavor.FlavorProfileId)
740-
th.AssertEquals(t, true, flavor.Enabled)
741+
th.AssertEquals(t, false, flavor.Enabled)
741742

742743
return flavor, nil
743744
}

openstack/loadbalancer/v2/flavors/requests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type CreateOpts struct {
6868
FlavorProfileId string `json:"flavor_profile_id" required:"true"`
6969

7070
// If the resource is available for use. The default is True.
71-
Enabled bool `json:"enabled,omitempty"`
71+
Enabled *bool `json:"enabled,omitempty"`
7272
}
7373

7474
// ToFlavorCreateMap builds a request body from CreateOpts.

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ const SingleFlavorBody = `
4444
}
4545
`
4646

47+
const SingleFlavorDisabledBody = `
48+
{
49+
"flavor": {
50+
"id": "5548c807-e6e8-43d7-9ea4-b38d34dd74a0",
51+
"name": "Basic",
52+
"description": "A basic standalone Octavia load balancer.",
53+
"enabled": false,
54+
"flavor_profile_id": "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1"
55+
}
56+
}
57+
`
58+
4759
const PostUpdateFlavorBody = `
4860
{
4961
"flavor": {
@@ -81,6 +93,14 @@ var (
8193
FlavorProfileId: "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1",
8294
}
8395

96+
FlavorDisabled = flavors.Flavor{
97+
ID: "5548c807-e6e8-43d7-9ea4-b38d34dd74a0",
98+
Name: "Basic",
99+
Description: "A basic standalone Octavia load balancer.",
100+
Enabled: false,
101+
FlavorProfileId: "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1",
102+
}
103+
84104
FlavorUpdated = flavors.Flavor{
85105
ID: "5548c807-e6e8-43d7-9ea4-b38d34dd74a0",
86106
Name: "Basic v2",
@@ -130,6 +150,25 @@ func HandleFlavorCreationSuccessfully(t *testing.T, response string) {
130150
})
131151
}
132152

153+
func HandleFlavorCreationSuccessfullyDisabled(t *testing.T, response string) {
154+
th.Mux.HandleFunc("/v2.0/lbaas/flavors", func(w http.ResponseWriter, r *http.Request) {
155+
th.TestMethod(t, r, "POST")
156+
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
157+
th.TestJSONRequest(t, r, `{
158+
"flavor": {
159+
"name": "Basic",
160+
"description": "A basic standalone Octavia load balancer.",
161+
"enabled": false,
162+
"flavor_profile_id": "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1"
163+
}
164+
}`)
165+
166+
w.WriteHeader(http.StatusAccepted)
167+
w.Header().Add("Content-Type", "application/json")
168+
fmt.Fprintf(w, response)
169+
})
170+
}
171+
133172
func HandleFlavorGetSuccessfully(t *testing.T) {
134173
th.Mux.HandleFunc("/v2.0/lbaas/flavors/5548c807-e6e8-43d7-9ea4-b38d34dd74a0", func(w http.ResponseWriter, r *http.Request) {
135174
th.TestMethod(t, r, "GET")

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,30 @@ func TestCreateFlavor(t *testing.T) {
110110
actual, err := flavors.Create(context.TODO(), fake.ServiceClient(), flavors.CreateOpts{
111111
Name: "Basic",
112112
Description: "A basic standalone Octavia load balancer.",
113-
Enabled: true,
113+
Enabled: ptr.To(true),
114114
FlavorProfileId: "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1",
115115
}).Extract()
116116
th.AssertNoErr(t, err)
117117

118118
th.CheckDeepEquals(t, FlavorDb, *actual)
119119
}
120120

121+
func TestCreateFlavorDisabled(t *testing.T) {
122+
th.SetupHTTP()
123+
defer th.TeardownHTTP()
124+
HandleFlavorCreationSuccessfullyDisabled(t, SingleFlavorDisabledBody)
125+
126+
actual, err := flavors.Create(context.TODO(), fake.ServiceClient(), flavors.CreateOpts{
127+
Name: "Basic",
128+
Description: "A basic standalone Octavia load balancer.",
129+
Enabled: ptr.To(false),
130+
FlavorProfileId: "9daa2768-74e7-4d13-bf5d-1b8e0dc239e1",
131+
}).Extract()
132+
th.AssertNoErr(t, err)
133+
134+
th.CheckDeepEquals(t, FlavorDisabled, *actual)
135+
}
136+
121137
func TestRequiredCreateOpts(t *testing.T) {
122138
res := flavors.Create(context.TODO(), fake.ServiceClient(), flavors.CreateOpts{})
123139
if res.Err == nil {

0 commit comments

Comments
 (0)