1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
// +build fixtures
package loadbalancers
import (
"fmt"
"net/http"
"testing"
th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools"
)
// LoadbalancersListBody contains the canned body of a loadbalancer list response.
const LoadbalancersListBody = `
{
"loadbalancers":[
{
"id": "c331058c-6a40-4144-948e-b9fb1df9db4b",
"tenant_id": "54030507-44f7-473c-9342-b4d14a95f692",
"name": "web_lb",
"description": "lb config for the web tier",
"vip_subnet_id": "8a49c438-848f-467b-9655-ea1548708154",
"vip_address": "10.30.176.47",
"flavor": "small",
"provider": "haproxy",
"admin_state_up": true,
"provisioning_status": "ACTIVE",
"operating_status": "ONLINE"
},
{
"id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
"tenant_id": "54030507-44f7-473c-9342-b4d14a95f692",
"name": "db_lb",
"description": "lb config for the db tier",
"vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
"vip_address": "10.30.176.48",
"flavor": "medium",
"provider": "haproxy",
"admin_state_up": true,
"provisioning_status": "PENDING_CREATE",
"operating_status": "OFFLINE"
}
]
}
`
// SingleLoadbalancerBody is the canned body of a Get request on an existing loadbalancer.
const SingleLoadbalancerBody = `
{
"loadbalancer": {
"id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
"tenant_id": "54030507-44f7-473c-9342-b4d14a95f692",
"name": "db_lb",
"description": "lb config for the db tier",
"vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
"vip_address": "10.30.176.48",
"flavor": "medium",
"provider": "haproxy",
"admin_state_up": true,
"provisioning_status": "PENDING_CREATE",
"operating_status": "OFFLINE"
}
}
`
// PostUpdateLoadbalancerBody is the canned response body of a Update request on an existing loadbalancer.
const PostUpdateLoadbalancerBody = `
{
"loadbalancer": {
"id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
"tenant_id": "54030507-44f7-473c-9342-b4d14a95f692",
"name": "NewLoadbalancerName",
"description": "lb config for the db tier",
"vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
"vip_address": "10.30.176.48",
"flavor": "medium",
"provider": "haproxy",
"admin_state_up": true,
"provisioning_status": "PENDING_CREATE",
"operating_status": "OFFLINE"
}
}
`
// SingleLoadbalancerBody is the canned body of a Get request on an existing loadbalancer.
const LoadbalancerStatuesesTree = `
{
"statuses" : {
"loadbalancer": {
"id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
"name": "db_lb",
"provisioning_status": "PENDING_UPDATE",
"operating_status": "ACTIVE",
"listeners": [{
"id": "db902c0c-d5ff-4753-b465-668ad9656918",
"name": "db",
"pools": [{
"id": "fad389a3-9a4a-4762-a365-8c7038508b5d",
"name": "db",
"healthmonitor": {
"id": "67306cda-815d-4354-9fe4-59e09da9c3c5",
"type":"PING"
},
"members":[{
"id": "2a280670-c202-4b0b-a562-34077415aabf",
"name": "db",
"address": "10.0.2.11",
"protocol_port": 80
}]
}]
}]
}
}
}
`
var (
LoadbalancerWeb = LoadBalancer{
ID: "c331058c-6a40-4144-948e-b9fb1df9db4b",
TenantID: "54030507-44f7-473c-9342-b4d14a95f692",
Name: "web_lb",
Description: "lb config for the web tier",
VipSubnetID: "8a49c438-848f-467b-9655-ea1548708154",
VipAddress: "10.30.176.47",
Flavor: "small",
Provider: "haproxy",
AdminStateUp: true,
ProvisioningStatus: "ACTIVE",
OperatingStatus: "ONLINE",
}
LoadbalancerDb = LoadBalancer{
ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
TenantID: "54030507-44f7-473c-9342-b4d14a95f692",
Name: "db_lb",
Description: "lb config for the db tier",
VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
VipAddress: "10.30.176.48",
Flavor: "medium",
Provider: "haproxy",
AdminStateUp: true,
ProvisioningStatus: "PENDING_CREATE",
OperatingStatus: "OFFLINE",
}
LoadbalancerUpdated = LoadBalancer{
ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
TenantID: "54030507-44f7-473c-9342-b4d14a95f692",
Name: "NewLoadbalancerName",
Description: "lb config for the db tier",
VipSubnetID: "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
VipAddress: "10.30.176.48",
Flavor: "medium",
Provider: "haproxy",
AdminStateUp: true,
ProvisioningStatus: "PENDING_CREATE",
OperatingStatus: "OFFLINE",
}
LoadbalancerStatusesTree = LoadBalancer{
ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
Name: "db_lb",
ProvisioningStatus: "PENDING_UPDATE",
OperatingStatus: "ACTIVE",
Listeners: []listeners.Listener{{
ID: "db902c0c-d5ff-4753-b465-668ad9656918",
Name: "db",
Pools: []pools.Pool{{
ID: "fad389a3-9a4a-4762-a365-8c7038508b5d",
Name: "db",
Monitor: monitors.Monitor{
ID: "67306cda-815d-4354-9fe4-59e09da9c3c5",
Type: "PING",
},
Members: []pools.Member{{
ID: "2a280670-c202-4b0b-a562-34077415aabf",
Name: "db",
Address: "10.0.2.11",
ProtocolPort: 80,
}},
}},
}},
}
)
// HandleLoadbalancerListSuccessfully sets up the test server to respond to a loadbalancer List request.
func HandleLoadbalancerListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
r.ParseForm()
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, LoadbalancersListBody)
case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab":
fmt.Fprintf(w, `{ "loadbalancers": [] }`)
default:
t.Fatalf("/v2.0/lbaas/loadbalancers invoked with unexpected marker=[%s]", marker)
}
})
}
// HandleLoadbalancerCreationSuccessfully sets up the test server to respond to a loadbalancer creation request
// with a given response.
func HandleLoadbalancerCreationSuccessfully(t *testing.T, response string) {
th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `{
"loadbalancer": {
"name": "db_lb",
"vip_subnet_id": "9cedb85d-0759-4898-8a4b-fa5a5ea10086",
"vip_address": "10.30.176.48",
"flavor": "medium",
"provider": "haproxy",
"admin_state_up": true
}
}`)
w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, response)
})
}
// HandleLoadbalancerGetSuccessfully sets up the test server to respond to a loadbalancer Get request.
func HandleLoadbalancerGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
fmt.Fprintf(w, SingleLoadbalancerBody)
})
}
// HandleLoadbalancerGetStatusesTree sets up the test server to respond to a loadbalancer Get statuses tree request.
func HandleLoadbalancerGetStatusesTree(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/statuses", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Accept", "application/json")
fmt.Fprintf(w, LoadbalancerStatuesesTree)
})
}
// HandleLoadbalancerDeletionSuccessfully sets up the test server to respond to a loadbalancer deletion request.
func HandleLoadbalancerDeletionSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
}
// HandleLoadbalancerUpdateSuccessfully sets up the test server to respond to a loadbalancer Update request.
func HandleLoadbalancerUpdateSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab", 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, `{
"loadbalancer": {
"name": "NewLoadbalancerName"
}
}`)
fmt.Fprintf(w, PostUpdateLoadbalancerBody)
})
}
|