Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions openstack/networking/v2/extensions/lbaas_v2/l7policies/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type RuleType string
type CompareType string

const (
ActionRedirectToPool Action = "REDIRECT_TO_POOL"
ActionRedirectToURL Action = "REDIRECT_TO_URL"
ActionReject Action = "REJECT"
ActionRedirectToPool Action = "REDIRECT_TO_POOL"
ActionRedirectToListener Action = "REDIRECT_TO_LISTENER"
ActionReject Action = "REJECT"

TypeCookie RuleType = "COOKIE"
TypeFileType RuleType = "FILE_TYPE"
Expand Down Expand Up @@ -59,9 +59,9 @@ type CreateOpts struct {
// Only valid if action is REDIRECT_TO_POOL.
RedirectPoolID string `json:"redirect_pool_id,omitempty"`

// Requests matching this policy will be redirected to this URL.
// Only valid if action is REDIRECT_TO_URL.
RedirectURL string `json:"redirect_url,omitempty"`
// Requests matching this policy will be redirected to this Listener.
// Only valid if action is REDIRECT_TO_LISTENER.
RedirectListenerID string `json:"redirect_listener_id,omitempty"`

// The administrative state of the Loadbalancer. A valid value is true (UP)
// or false (DOWN).
Expand Down Expand Up @@ -93,20 +93,20 @@ type ListOptsBuilder interface {
// ListOpts allows the filtering and sorting of paginated collections through
// the API.
type ListOpts struct {
Name string `q:"name"`
Description string `q:"description"`
ListenerID string `q:"listener_id"`
Action string `q:"action"`
TenantID string `q:"tenant_id"`
RedirectPoolID string `q:"redirect_pool_id"`
RedirectURL string `q:"redirect_url"`
Position int32 `q:"position"`
AdminStateUp bool `q:"admin_state_up"`
ID string `q:"id"`
Limit int `q:"limit"`
Marker string `q:"marker"`
SortKey string `q:"sort_key"`
SortDir string `q:"sort_dir"`
Name string `q:"name"`
Description string `q:"description"`
ListenerID string `q:"listener_id"`
Action string `q:"action"`
TenantID string `q:"tenant_id"`
RedirectPoolID string `q:"redirect_pool_id"`
RedirectListenerID string `q:"redirect_listener_id"`
Position int32 `q:"position"`
AdminStateUp bool `q:"admin_state_up"`
ID string `q:"id"`
Limit int `q:"limit"`
Marker string `q:"marker"`
SortKey string `q:"sort_key"`
SortDir string `q:"sort_dir"`
}

// ToL7PolicyListQuery formats a ListOpts into a query string.
Expand Down Expand Up @@ -172,9 +172,9 @@ type UpdateOpts struct {
// Only valid if action is REDIRECT_TO_POOL.
RedirectPoolID *string `json:"redirect_pool_id,omitempty"`

// Requests matching this policy will be redirected to this URL.
// Only valid if action is REDIRECT_TO_URL.
RedirectURL *string `json:"redirect_url,omitempty"`
// Requests matching this policy will be redirected to this LISTENER.
// Only valid if action is REDIRECT_TO_LISTENER.
RedirectListenerID *string `json:"redirect_listener_id,omitempty"`

// The administrative state of the Loadbalancer. A valid value is true (UP)
// or false (DOWN).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type L7Policy struct {
// Only valid if action is REDIRECT_TO_POOL.
RedirectPoolID string `json:"redirect_pool_id"`

// Requests matching this policy will be redirected to this URL.
// Only valid if action is REDIRECT_TO_URL.
RedirectURL string `json:"redirect_url"`
// Requests matching this policy will be redirected to this Listener.
// Only valid if action is REDIRECT_TO_LISTENER.
RedirectListenerID string `json:"redirect_listener_id"`

// The administrative state of the L7 policy, which is up (true) or down (false).
AdminStateUp bool `json:"admin_state_up"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const SingleL7PolicyBody = `
"description": "",
"admin_state_up": true,
"redirect_pool_id": null,
"redirect_url": "http://www.example.com",
"action": "REDIRECT_TO_URL",
"redirect_listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"action": "REDIRECT_TO_LISTENER",
"position": 1,
"tenant_id": "e3cd678b11784734bc366148aa37580e",
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
Expand All @@ -30,57 +30,44 @@ const SingleL7PolicyBody = `
`

var (
L7PolicyToURL = l7policies.L7Policy{
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "redirect-example.com",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_URL",
Position: 1,
Description: "",
TenantID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectURL: "http://www.example.com",
AdminStateUp: true,
Rules: []l7policies.Rule{},
L7PolicyToListener = l7policies.L7Policy{
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "redirect-example.com",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_LISTENER",
Position: 1,
Description: "",
TenantID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
L7PolicyToPool = l7policies.L7Policy{
ID: "964f4ba4-f6cd-405c-bebd-639460af7231",
Name: "redirect-pool",
ListenerID: "be3138a3-5cf7-4513-a4c2-bb137e668bab",
Action: "REDIRECT_TO_POOL",
Position: 1,
Description: "",
TenantID: "c1f7910086964990847dc6c8b128f63c",
RedirectPoolID: "bac433c6-5bea-4311-80da-bd1cd90fbd25",
RedirectURL: "",
AdminStateUp: true,
Rules: []l7policies.Rule{},
ID: "964f4ba4-f6cd-405c-bebd-639460af7231",
Name: "redirect-pool",
ListenerID: "be3138a3-5cf7-4513-a4c2-bb137e668bab",
Action: "REDIRECT_TO_POOL",
Position: 1,
Description: "",
TenantID: "c1f7910086964990847dc6c8b128f63c",
RedirectPoolID: "bac433c6-5bea-4311-80da-bd1cd90fbd25",
RedirectListenerID: "",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
L7PolicyUpdated = l7policies.L7Policy{
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "NewL7PolicyName",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_URL",
Position: 1,
Description: "Redirect requests to example.com",
TenantID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectURL: "http://www.new-example.com",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
L7PolicyNullRedirectURLUpdated = l7policies.L7Policy{
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "NewL7PolicyName",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_URL",
Position: 1,
Description: "Redirect requests to example.com",
TenantID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectURL: "",
AdminStateUp: true,
Rules: []l7policies.Rule{},
ID: "8a1412f0-4c32-4257-8b07-af4770b604fd",
Name: "NewL7PolicyName",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: "REDIRECT_TO_LISTENER",
Position: 1,
Description: "Redirect requests to example.com",
TenantID: "e3cd678b11784734bc366148aa37580e",
RedirectPoolID: "",
RedirectListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
AdminStateUp: true,
Rules: []l7policies.Rule{},
}
RulePath = l7policies.Rule{
ID: "16621dbb-a736-4888-a57a-3ecd53df784c",
Expand Down Expand Up @@ -123,9 +110,9 @@ func HandleL7PolicyCreationSuccessfully(t *testing.T, response string) {
th.TestJSONRequest(t, r, `{
"l7policy": {
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"redirect_url": "http://www.example.com",
"redirect_listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"name": "redirect-example.com",
"action": "REDIRECT_TO_URL"
"action": "REDIRECT_TO_LISTENER"
}
}`)

Expand All @@ -146,8 +133,8 @@ const L7PoliciesListBody = `
"rules": [],
"tenant_id": "e3cd678b11784734bc366148aa37580e",
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"redirect_url": "http://www.example.com",
"action": "REDIRECT_TO_URL",
"redirect_listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"action": "REDIRECT_TO_LISTENER",
"position": 1,
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
"name": "redirect-example.com"
Expand Down Expand Up @@ -176,28 +163,8 @@ const PostUpdateL7PolicyBody = `
"description": "Redirect requests to example.com",
"admin_state_up": true,
"redirect_pool_id": null,
"redirect_url": "http://www.new-example.com",
"action": "REDIRECT_TO_URL",
"position": 1,
"tenant_id": "e3cd678b11784734bc366148aa37580e",
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
"name": "NewL7PolicyName",
"rules": []
}
}
`

// PostUpdateL7PolicyNullRedirectURLBody is the canned response body of a Update request
// on an existing l7policy with a null redirect_url .
const PostUpdateL7PolicyNullRedirectURLBody = `
{
"l7policy": {
"listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"description": "Redirect requests to example.com",
"admin_state_up": true,
"redirect_pool_id": null,
"redirect_url": null,
"action": "REDIRECT_TO_URL",
"redirect_listener_id": "023f2e34-7806-443b-bfae-16c324569a3d",
"action": "REDIRECT_TO_LISTENER",
"position": 1,
"tenant_id": "e3cd678b11784734bc366148aa37580e",
"id": "8a1412f0-4c32-4257-8b07-af4770b604fd",
Expand Down Expand Up @@ -258,33 +225,14 @@ func HandleL7PolicyUpdateSuccessfully(t *testing.T) {
th.TestJSONRequest(t, r, `{
"l7policy": {
"name": "NewL7PolicyName",
"action": "REDIRECT_TO_URL",
"redirect_url": "http://www.new-example.com"
"action": "REDIRECT_TO_LISTENER",
}
}`)

fmt.Fprintf(w, PostUpdateL7PolicyBody)
})
}

// HandleL7PolicyUpdateNullRedirectURLSuccessfully sets up the test server to respond to a l7policy Update request.
func HandleL7PolicyUpdateNullRedirectURLSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/v2.0/lbaas/l7policies/8a1412f0-4c32-4257-8b07-af4770b604fd", 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, `{
"l7policy": {
"name": "NewL7PolicyName",
"redirect_url": null
}
}`)

fmt.Fprintf(w, PostUpdateL7PolicyNullRedirectURLBody)
})
}

// SingleRuleBody is the canned body of a Get request on an existing rule.
const SingleRuleBody = `
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ func TestCreateL7Policy(t *testing.T) {
HandleL7PolicyCreationSuccessfully(t, SingleL7PolicyBody)

actual, err := l7policies.Create(fake.ServiceClient(), l7policies.CreateOpts{
Name: "redirect-example.com",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: l7policies.ActionRedirectToURL,
RedirectURL: "http://www.example.com",
Name: "redirect-example.com",
ListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
Action: l7policies.ActionRedirectToListener,
RedirectListenerID: "023f2e34-7806-443b-bfae-16c324569a3d",
}).Extract()

th.AssertNoErr(t, err)
th.CheckDeepEquals(t, L7PolicyToURL, *actual)
th.CheckDeepEquals(t, L7PolicyToListener, *actual)
}

func TestRequiredL7PolicyCreateOpts(t *testing.T) {
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestListL7Policies(t *testing.T) {
if len(actual) != 2 {
t.Fatalf("Expected 2 l7policies, got %d", len(actual))
}
th.CheckDeepEquals(t, L7PolicyToURL, actual[0])
th.CheckDeepEquals(t, L7PolicyToListener, actual[0])
th.CheckDeepEquals(t, L7PolicyToPool, actual[1])

return true, nil
Expand All @@ -81,7 +81,7 @@ func TestListAllL7Policies(t *testing.T) {
th.AssertNoErr(t, err)
actual, err := l7policies.ExtractL7Policies(allPages)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, L7PolicyToURL, actual[0])
th.CheckDeepEquals(t, L7PolicyToListener, actual[0])
th.CheckDeepEquals(t, L7PolicyToPool, actual[1])
}

Expand All @@ -96,7 +96,7 @@ func TestGetL7Policy(t *testing.T) {
t.Fatalf("Unexpected Get error: %v", err)
}

th.CheckDeepEquals(t, L7PolicyToURL, *actual)
th.CheckDeepEquals(t, L7PolicyToListener, *actual)
}

func TestDeleteL7Policy(t *testing.T) {
Expand All @@ -108,47 +108,6 @@ func TestDeleteL7Policy(t *testing.T) {
th.AssertNoErr(t, res.Err)
}

func TestUpdateL7Policy(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleL7PolicyUpdateSuccessfully(t)

client := fake.ServiceClient()
newName := "NewL7PolicyName"
redirectURL := "http://www.new-example.com"
actual, err := l7policies.Update(client, "8a1412f0-4c32-4257-8b07-af4770b604fd",
l7policies.UpdateOpts{
Name: &newName,
Action: l7policies.ActionRedirectToURL,
RedirectURL: &redirectURL,
}).Extract()
if err != nil {
t.Fatalf("Unexpected Update error: %v", err)
}

th.CheckDeepEquals(t, L7PolicyUpdated, *actual)
}

func TestUpdateL7PolicyNullRedirectURL(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleL7PolicyUpdateNullRedirectURLSuccessfully(t)

client := fake.ServiceClient()
newName := "NewL7PolicyName"
redirectURL := ""
actual, err := l7policies.Update(client, "8a1412f0-4c32-4257-8b07-af4770b604fd",
l7policies.UpdateOpts{
Name: &newName,
RedirectURL: &redirectURL,
}).Extract()
if err != nil {
t.Fatalf("Unexpected Update error: %v", err)
}

th.CheckDeepEquals(t, L7PolicyNullRedirectURLUpdated, *actual)
}

func TestUpdateL7PolicyWithInvalidOpts(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
Expand Down