Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dagnello committed May 26, 2016
1 parent 8ff5e0e commit ec93445
Show file tree
Hide file tree
Showing 22 changed files with 2,359 additions and 1,678 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestLoadbalancers(t *testing.T) {
getLoadbalancerWaitActive(t, loadbalancerID)

// create listener
listenerID := createListener(t, "HTTP", 80, loadbalancerID)
listenerID := createListener(t, listeners.ProtocolHTTP, 80, loadbalancerID)

// list listeners
listListeners(t)
Expand All @@ -91,7 +91,7 @@ func TestLoadbalancers(t *testing.T) {
getLoadbalancerWaitActive(t, loadbalancerID)

// create pool
poolID := createPool(t, "HTTP", listenerID, pools.LBMethodRoundRobin)
poolID := createPool(t, pools.ProtocolHTTP, listenerID, pools.LBMethodRoundRobin)

// list pools
listPools(t)
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestLoadbalancers(t *testing.T) {
getLoadbalancerWaitActive(t, loadbalancerID)

// create monitor
monitorID := createMonitor(t, poolID, monitors.TypeHTTP, 10, 10, 3, "/login", "GET", "200")
monitorID := createMonitor(t, poolID, monitors.TypePING, 10, 10, 3)

// list monitors
listMonitors(t)
Expand All @@ -141,6 +141,29 @@ func TestLoadbalancers(t *testing.T) {
// get monitor
getMonitor(t, monitorID)

// get loadbalancer statuses tree
rawStatusTree, err := loadbalancers.GetStatuses(base.Client, loadbalancerID).ExtractStatuses()
if err == nil {
// verify statuses tree ID's of relevant objects
if rawStatusTree.Loadbalancer.ID != loadbalancerID {
t.Errorf("Loadbalancer ID did not match")
}
if rawStatusTree.Loadbalancer.Listeners[0].ID != listenerID {
t.Errorf("Listner ID did not match")
}
if rawStatusTree.Loadbalancer.Listeners[0].Pools[0].ID != poolID {
t.Errorf("Pool ID did not match")
}
if rawStatusTree.Loadbalancer.Listeners[0].Pools[0].Members[0].ID != memberID {
t.Errorf("Member ID did not match")
}
if rawStatusTree.Loadbalancer.Listeners[0].Pools[0].Monitor.ID != monitorID {
t.Errorf("Monitor ID did not match")
}
} else {
t.Errorf("Failed to extract Loadbalancer statuses tree: %v", err)
}

getLoadbalancerWaitActive(t, loadbalancerID)
deleteMonitor(t, monitorID)
getLoadbalancerWaitActive(t, loadbalancerID)
Expand Down Expand Up @@ -244,7 +267,7 @@ func updateLoadbalancer(t *testing.T, loadbalancerID string) {
}

func listListeners(t *testing.T) {
err := listeners.List(base.Client, listeners.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
err := listeners.List(base.Client, listeners.ListOpts{Name: "tmp_listener"}).EachPage(func(page pagination.Page) (bool, error) {
listenerList, err := listeners.ExtractListeners(page)
if err != nil {
t.Errorf("Failed to extract Listeners: %v", err)
Expand All @@ -262,7 +285,7 @@ func listListeners(t *testing.T) {
th.AssertNoErr(t, err)
}

func createListener(t *testing.T, protocol string, protocolPort int, loadbalancerID string) string {
func createListener(t *testing.T, protocol listeners.Protocol, protocolPort int, loadbalancerID string) string {
l, err := listeners.Create(base.Client, listeners.CreateOpts{
Protocol: protocol,
ProtocolPort: protocolPort,
Expand Down Expand Up @@ -317,7 +340,7 @@ func listPools(t *testing.T) {
th.AssertNoErr(t, err)
}

func createPool(t *testing.T, protocol string, listenerID string, lbMethod string) string {
func createPool(t *testing.T, protocol pools.Protocol, listenerID string, lbMethod pools.LBMethod) string {
p, err := pools.Create(base.Client, pools.CreateOpts{
LBMethod: lbMethod,
Protocol: protocol,
Expand Down Expand Up @@ -411,17 +434,14 @@ func updateMember(t *testing.T, poolID string, memberID string) {
t.Logf("Updated Member, ID [%s], in Pool, ID [%s]", memberID, poolID)
}

func createMonitor(t *testing.T, poolID string, checkType string, delay int, timeout int,
maxRetries int, urlPath string, httpMethod string, expectedCodes string) string {
func createMonitor(t *testing.T, poolID string, checkType string, delay int, timeout int, maxRetries int) string {
m, err := monitors.Create(base.Client, monitors.CreateOpts{
PoolID: poolID,
Delay: delay,
Timeout: timeout,
MaxRetries: maxRetries,
Type: checkType,
ExpectedCodes: expectedCodes,
URLPath: expectedCodes,
HTTPMethod: httpMethod,
PoolID: poolID,
Name: "tmp_monitor",
Delay: delay,
Timeout: timeout,
MaxRetries: maxRetries,
Type: checkType,
}).Extract()

th.AssertNoErr(t, err)
Expand Down
3 changes: 3 additions & 0 deletions openstack/networking/v2/extensions/lbaas/monitors/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type Monitor struct {
// The unique ID for the VIP.
ID string

// Monitor name. Does not have to be unique.
Name string

// Owner of the VIP. Only an administrative user can specify a tenant ID
// other than its own.
TenantID string `json:"tenant_id" mapstructure:"tenant_id"`
Expand Down
2 changes: 2 additions & 0 deletions openstack/networking/v2/extensions/lbaas_v2/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package lbaas_v2 provides information and interaction with the Load Balancer
// as a Service v2 extension for the OpenStack Networking service.
// lbaas v2 api docs: http://developer.openstack.org/api-ref-networking-v2-ext.html#lbaas-v2.0
// lbaas v2 api schema: https://github.com/openstack/neutron-lbaas/blob/master/neutron_lbaas/extensions/loadbalancerv2.py
package lbaas_v2
213 changes: 213 additions & 0 deletions openstack/networking/v2/extensions/lbaas_v2/listeners/fixtures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
// +build fixtures
package listeners

import (
"fmt"
"net/http"
"testing"

th "github.com/rackspace/gophercloud/testhelper"
"github.com/rackspace/gophercloud/testhelper/client"
)

// ListenersListBody contains the canned body of a listeners list response.
const ListenersListBody = `
{
"listeners":[
{
"id": "db902c0c-d5ff-4753-b465-668ad9656918",
"tenant_id": "310df60f-2a10-4ee5-9554-98393092194c",
"name": "web",
"description": "listener config for the web tier",
"loadbalancers": [{"id": "53306cda-815d-4354-9444-59e09da9c3c5"}],
"protocol": "HTTP",
"protocol_port": 80,
"default_pool_id": "fad389a3-9a4a-4762-a365-8c7038508b5d",
"admin_state_up": true,
"default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76",
"sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"]
},
{
"id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
"tenant_id": "310df60f-2a10-4ee5-9554-98393092194c",
"name": "db",
"description": "listener config for the db tier",
"loadbalancers": [{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}],
"protocol": "TCP",
"protocol_port": 3306,
"default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e",
"connection_limit": 2000,
"admin_state_up": true,
"default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76",
"sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"]
}
]
}
`

// SingleServerBody is the canned body of a Get request on an existing listener.
const SingleListenerBody = `
{
"listener": {
"id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
"tenant_id": "310df60f-2a10-4ee5-9554-98393092194c",
"name": "db",
"description": "listener config for the db tier",
"loadbalancers": [{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}],
"protocol": "TCP",
"protocol_port": 3306,
"default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e",
"connection_limit": 2000,
"admin_state_up": true,
"default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76",
"sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"]
}
}
`

// PostUpdateListenerBody is the canned response body of a Update request on an existing listener.
const PostUpdateListenerBody = `
{
"listener": {
"id": "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
"tenant_id": "310df60f-2a10-4ee5-9554-98393092194c",
"name": "NewListenerName",
"description": "listener config for the db tier",
"loadbalancers": [{"id": "79e05663-7f03-45d2-a092-8b94062f22ab"}],
"protocol": "TCP",
"protocol_port": 3306,
"default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e",
"connection_limit": 1000,
"admin_state_up": true,
"default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76",
"sni_container_refs": ["3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"]
}
}
`

var (
ListenerWeb = Listener{
ID: "db902c0c-d5ff-4753-b465-668ad9656918",
TenantID: "310df60f-2a10-4ee5-9554-98393092194c",
Name: "web",
Description: "listener config for the web tier",
Loadbalancers: []LoadBalancerID{{ID: "53306cda-815d-4354-9444-59e09da9c3c5"}},
Protocol: "HTTP",
ProtocolPort: 80,
DefaultPoolID: "fad389a3-9a4a-4762-a365-8c7038508b5d",
AdminStateUp: true,
DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76",
SniContainerRefs: []string{"3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"},
}
ListenerDb = Listener{
ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
TenantID: "310df60f-2a10-4ee5-9554-98393092194c",
Name: "db",
Description: "listener config for the db tier",
Loadbalancers: []LoadBalancerID{{ID: "79e05663-7f03-45d2-a092-8b94062f22ab"}},
Protocol: "TCP",
ProtocolPort: 3306,
DefaultPoolID: "41efe233-7591-43c5-9cf7-923964759f9e",
ConnLimit: 2000,
AdminStateUp: true,
DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76",
SniContainerRefs: []string{"3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"},
}
ListenerUpdated = Listener{
ID: "36e08a3e-a78f-4b40-a229-1e7e23eee1ab",
TenantID: "310df60f-2a10-4ee5-9554-98393092194c",
Name: "NewListenerName",
Description: "listener config for the db tier",
Loadbalancers: []LoadBalancerID{{ID: "79e05663-7f03-45d2-a092-8b94062f22ab"}},
Protocol: "TCP",
ProtocolPort: 3306,
DefaultPoolID: "41efe233-7591-43c5-9cf7-923964759f9e",
ConnLimit: 1000,
AdminStateUp: true,
DefaultTlsContainerRef: "2c433435-20de-4411-84ae-9cc8917def76",
SniContainerRefs: []string{"3d328d82-2547-4921-ac2f-61c3b452b5ff", "b3cfd7e3-8c19-455c-8ebb-d78dfd8f7e7d"},
}
)

// HandleListenerListSuccessfully sets up the test server to respond to a listener List request.
func HandleListenerListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/listeners", 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, ListenersListBody)
case "45e08a3e-a78f-4b40-a229-1e7e23eee1ab":
fmt.Fprintf(w, `{ "listeners": [] }`)
default:
t.Fatalf("/v2.0/lbaas/listeners invoked with unexpected marker=[%s]", marker)
}
})
}

// HandleListenerCreationSuccessfully sets up the test server to respond to a listener creation request
// with a given response.
func HandleListenerCreationSuccessfully(t *testing.T, response string) {
th.Mux.HandleFunc("/v2.0/lbaas/listeners", 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, `{
"listener": {
"loadbalancer_id": "79e05663-7f03-45d2-a092-8b94062f22ab",
"protocol": "TCP",
"name": "db",
"admin_state_up": true,
"default_tls_container_ref": "2c433435-20de-4411-84ae-9cc8917def76",
"default_pool_id": "41efe233-7591-43c5-9cf7-923964759f9e",
"protocol_port": 3306
}
}`)

w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, response)
})
}

// HandleListenerGetSuccessfully sets up the test server to respond to a listener Get request.
func HandleListenerGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/listeners/4ec89087-d057-4e2c-911f-60a3b47ee304", 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, SingleListenerBody)
})
}

// HandleListenerDeletionSuccessfully sets up the test server to respond to a listener deletion request.
func HandleListenerDeletionSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/listeners/4ec89087-d057-4e2c-911f-60a3b47ee304", 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)
})
}

// HandleListenerUpdateSuccessfully sets up the test server to respond to a listener Update request.
func HandleListenerUpdateSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/listeners/4ec89087-d057-4e2c-911f-60a3b47ee304", 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, `{
"listener": {
"name": "NewListenerName",
"connection_limit": 1001
}
}`)

fmt.Fprintf(w, PostUpdateListenerBody)
})
}
Loading

0 comments on commit ec93445

Please sign in to comment.