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
|
package testing
import (
"fmt"
"net/http"
"testing"
"time"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/amphorae"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
// AmphoraeListBody contains the canned body of a amphora list response.
const AmphoraeListBody = `
{
"amphorae": [
{
"cached_zone": "nova",
"cert_busy": false,
"cert_expiration": "2020-08-08T23:44:31",
"compute_id": "667bb225-69aa-44b1-8908-694dc624c267",
"created_at": "2018-08-09T23:44:31",
"ha_ip": "10.0.0.6",
"ha_port_id": "35254b63-9361-4561-9b8f-2bb4e3be60e3",
"id": "45f40289-0551-483a-b089-47214bc2a8a4",
"image_id": "5d1aed06-2624-43f5-a413-9212263c3d53",
"lb_network_ip": "192.168.0.6",
"loadbalancer_id": "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9",
"role": "MASTER",
"status": "READY",
"updated_at": "2018-08-09T23:51:06",
"vrrp_id": 1,
"vrrp_interface": "eth1",
"vrrp_ip": "10.0.0.4",
"vrrp_port_id": "dcf0c8b5-6a08-4658-997d-eac97f2b9bbd",
"vrrp_priority": 100
},
{
"cached_zone": "nova",
"cert_busy": false,
"cert_expiration": "2020-08-08T23:44:30",
"compute_id": "9cd0f9a2-fe12-42fc-a7e3-5b6fbbe20395",
"created_at": "2018-08-09T23:44:31",
"ha_ip": "10.0.0.6",
"ha_port_id": "35254b63-9361-4561-9b8f-2bb4e3be60e3",
"id": "7f890893-ced0-46ed-8697-33415d070e5a",
"image_id": "5d1aed06-2624-43f5-a413-9212263c3d53",
"lb_network_ip": "192.168.0.17",
"loadbalancer_id": "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9",
"role": "BACKUP",
"status": "READY",
"updated_at": "2018-08-09T23:51:06",
"vrrp_id": 1,
"vrrp_interface": "eth1",
"vrrp_ip": "10.0.0.21",
"vrrp_port_id": "13c88c77-207d-4f85-8f7a-84344592e367",
"vrrp_priority": 90
}
],
"amphorae_links": []
}
`
const SingleAmphoraBody = `
{
"amphora": {
"cached_zone": "nova",
"cert_busy": false,
"cert_expiration": "2020-08-08T23:44:31",
"compute_id": "667bb225-69aa-44b1-8908-694dc624c267",
"created_at": "2018-08-09T23:44:31",
"ha_ip": "10.0.0.6",
"ha_port_id": "35254b63-9361-4561-9b8f-2bb4e3be60e3",
"id": "45f40289-0551-483a-b089-47214bc2a8a4",
"image_id": "5d1aed06-2624-43f5-a413-9212263c3d53",
"lb_network_ip": "192.168.0.6",
"loadbalancer_id": "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9",
"role": "MASTER",
"status": "READY",
"updated_at": "2018-08-09T23:51:06",
"vrrp_id": 1,
"vrrp_interface": "eth1",
"vrrp_ip": "10.0.0.4",
"vrrp_port_id": "dcf0c8b5-6a08-4658-997d-eac97f2b9bbd",
"vrrp_priority": 100
}
}
`
// FirstAmphora is the first resource in the List request.
var FirstAmphora = amphorae.Amphora{
CachedZone: "nova",
CertBusy: false,
CertExpiration: time.Date(2020, 8, 8, 23, 44, 31, 0, time.UTC),
ComputeID: "667bb225-69aa-44b1-8908-694dc624c267",
CreatedAt: time.Date(2018, 8, 9, 23, 44, 31, 0, time.UTC),
HAIP: "10.0.0.6",
HAPortID: "35254b63-9361-4561-9b8f-2bb4e3be60e3",
ID: "45f40289-0551-483a-b089-47214bc2a8a4",
ImageID: "5d1aed06-2624-43f5-a413-9212263c3d53",
LBNetworkIP: "192.168.0.6",
LoadbalancerID: "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9",
Role: "MASTER",
Status: "READY",
UpdatedAt: time.Date(2018, 8, 9, 23, 51, 6, 0, time.UTC),
VRRPID: 1,
VRRPInterface: "eth1",
VRRPIP: "10.0.0.4",
VRRPPortID: "dcf0c8b5-6a08-4658-997d-eac97f2b9bbd",
VRRPPriority: 100,
}
// SecondAmphora is the second resource in the List request.
var SecondAmphora = amphorae.Amphora{
CachedZone: "nova",
CertBusy: false,
CertExpiration: time.Date(2020, 8, 8, 23, 44, 30, 0, time.UTC),
ComputeID: "9cd0f9a2-fe12-42fc-a7e3-5b6fbbe20395",
CreatedAt: time.Date(2018, 8, 9, 23, 44, 31, 0, time.UTC),
HAIP: "10.0.0.6",
HAPortID: "35254b63-9361-4561-9b8f-2bb4e3be60e3",
ID: "7f890893-ced0-46ed-8697-33415d070e5a",
ImageID: "5d1aed06-2624-43f5-a413-9212263c3d53",
LBNetworkIP: "192.168.0.17",
LoadbalancerID: "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9",
Role: "BACKUP",
Status: "READY",
UpdatedAt: time.Date(2018, 8, 9, 23, 51, 6, 0, time.UTC),
VRRPID: 1,
VRRPInterface: "eth1",
VRRPIP: "10.0.0.21",
VRRPPortID: "13c88c77-207d-4f85-8f7a-84344592e367",
VRRPPriority: 90,
}
// ExpectedAmphoraeSlice is the slice of amphorae expected to be returned from ListResponse.
var ExpectedAmphoraeSlice = []amphorae.Amphora{FirstAmphora, SecondAmphora}
// HandleAmphoraListSuccessfully sets up the test server to respond to a amphorae List request.
func HandleAmphoraListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/octavia/amphorae", 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, AmphoraeListBody)
case "7f890893-ced0-46ed-8697-33415d070e5a":
fmt.Fprintf(w, `{ "amphorae": [] }`)
default:
t.Fatalf("/v2.0/octavia/amphorae invoked with unexpected marker=[%s]", marker)
}
})
}
// HandleAmphoraGetSuccessfully sets up the test server to respond to am amphora Get request.
func HandleAmphoraGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/octavia/amphorae/45f40289-0551-483a-b089-47214bc2a8a4", 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, SingleAmphoraBody)
})
}
// HandleAmphoraFailoverSuccessfully sets up the test server to respond to an amphora failover request.
func HandleAmphoraFailoverSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/octavia/amphorae/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/failover", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusAccepted)
})
}
|