-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03ec5c2
commit c9a3586
Showing
10 changed files
with
300 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package er | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" | ||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" | ||
tag "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/er/v3/instance" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/er/v3/route_table" | ||
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" | ||
) | ||
|
||
var ( | ||
rtName = tools.RandomString("acctest_route-table-", 4) | ||
descriptionRt = "test vpc attachment" | ||
) | ||
|
||
func TestRouteTableLifeCycle(t *testing.T) { | ||
if os.Getenv("RUN_ER_LIFECYCLE") == "" { | ||
t.Skip("too slow to run in zuul") | ||
} | ||
client, err := clients.NewERClient() | ||
th.AssertNoErr(t, err) | ||
|
||
createOpts := instance.CreateOpts{ | ||
Name: tools.RandomString("acctest_er_router-", 4), | ||
Asn: 64512, | ||
AutoAcceptSharedAttachments: pointerto.Bool(true), | ||
AvailabilityZoneIDs: []string{ | ||
"eu-de-01", | ||
"eu-de-02", | ||
}, | ||
} | ||
|
||
t.Logf("Attempting to create enterprise router") | ||
|
||
createResp, err := instance.Create(client, createOpts) | ||
th.AssertNoErr(t, err) | ||
|
||
err = waitForInstanceAvailable(client, 100, createResp.Instance.ID) | ||
th.AssertNoErr(t, err) | ||
|
||
defer func(client *golangsdk.ServiceClient, id string) { | ||
t.Logf("Attempting to delete enterprise router") | ||
err = instance.Delete(client, id) | ||
th.AssertNoErr(t, err) | ||
err = waitForInstanceDeleted(client, 500, createResp.Instance.ID) | ||
}(client, createResp.Instance.ID) | ||
|
||
createRouteTableOpts := route_table.CreateOpts{ | ||
Name: rtName, | ||
RouterID: createResp.Instance.ID, | ||
Description: &descriptionRt, | ||
Tags: []tag.ResourceTag{ | ||
{ | ||
Key: "muh", | ||
Value: "muh", | ||
}, | ||
{ | ||
Key: "test", | ||
Value: "test", | ||
}, | ||
}, | ||
} | ||
|
||
t.Logf("Attempting to create route table") | ||
createRtResp, err := route_table.Create(client, createRouteTableOpts) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, createRouteTableOpts.Name, createRtResp.Name) | ||
th.AssertEquals(t, *createRouteTableOpts.Description, createRtResp.Description) | ||
|
||
err = waitForRouteTableAvailable(client, 300, createResp.Instance.ID, createRtResp.ID) | ||
th.AssertNoErr(t, err) | ||
|
||
defer func(client *golangsdk.ServiceClient, erId, rtId string) { | ||
t.Logf("Attempting to delete route table") | ||
err = route_table.Delete(client, erId, rtId) | ||
th.AssertNoErr(t, err) | ||
err = waitForRouteTableDeleted(client, 500, erId, rtId) | ||
}(client, createResp.Instance.ID, createRtResp.ID) | ||
|
||
t.Logf("Attempting to update route table") | ||
updateRtResp, err := route_table.Update(client, route_table.UpdateOpts{ | ||
RouterID: createResp.Instance.ID, | ||
RouteTableId: createRtResp.ID, | ||
Name: rtName + "-updated", | ||
}) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, updateRtResp.Name, rtName+"-updated") | ||
|
||
t.Logf("Attempting to list route table") | ||
listResp, err := route_table.List(client, route_table.ListOpts{ | ||
RouterId: createResp.Instance.ID, | ||
}) | ||
th.AssertNoErr(t, err) | ||
tools.PrintResource(t, listResp) | ||
} | ||
|
||
func waitForRouteTableAvailable(client *golangsdk.ServiceClient, secs int, erId, routeTableId string) error { | ||
return golangsdk.WaitFor(secs, func() (bool, error) { | ||
rtInstance, err := route_table.Get(client, erId, routeTableId) | ||
if err != nil { | ||
return false, err | ||
} | ||
if rtInstance.State == "available" { | ||
return true, nil | ||
} | ||
return false, nil | ||
}) | ||
} | ||
|
||
func waitForRouteTableDeleted(client *golangsdk.ServiceClient, secs int, erId, rtId string) error { | ||
return golangsdk.WaitFor(secs, func() (bool, error) { | ||
_, err := route_table.Get(client, erId, rtId) | ||
if err != nil { | ||
if _, ok := err.(golangsdk.ErrDefault404); ok { | ||
return true, nil | ||
} | ||
return false, err | ||
} | ||
|
||
return false, nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package route_table | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" | ||
) | ||
|
||
type CreateOpts struct { | ||
RouterID string `json:"-" required:"true"` | ||
Name string `json:"name" required:"true"` | ||
Description *string `json:"description,omitempty"` | ||
// parameter not supported ☻ | ||
// BgpOptions *BgpOptions `json:"bgp_options,omitempty"` | ||
Tags []tags.ResourceTag `json:"tags,omitempty"` | ||
} | ||
|
||
type BgpOptions struct { | ||
LoadBalancingAsPathIgnore *bool `json:"load_balancing_as_path_ignore,omitempty"` | ||
LoadBalancingAsPathRelax *bool `json:"load_balancing_as_path_relax,omitempty"` | ||
} | ||
|
||
func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*RouteTable, error) { | ||
b, err := build.RequestBody(opts, "route_table") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
raw, err := client.Post(client.ServiceURL("enterprise-router", opts.RouterID, "route-tables"), b, nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{202}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res RouteTable | ||
return &res, extract.IntoStructPtr(raw.Body, &res, "route_table") | ||
} | ||
|
||
type RouteTable struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
IsDefaultAssociation bool `json:"is_default_association"` | ||
State string `json:"state"` | ||
Tags []tags.ResourceTag `json:"tags"` | ||
BgpOptions *BgpOptions `json:"bgp_options"` | ||
CreatedAt string `json:"created_at"` | ||
UpdatedAt string `json:"updated_at"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package route_table | ||
|
||
import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
|
||
func Delete(client *golangsdk.ServiceClient, erId, routeTableId string) (err error) { | ||
_, err = client.Delete(client.ServiceURL("enterprise-router", erId, "route-tables", routeTableId), &golangsdk.RequestOpts{ | ||
OkCodes: []int{202}, | ||
}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package route_table | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func Get(client *golangsdk.ServiceClient, erID, routeTableId string) (*RouteTable, error) { | ||
raw, err := client.Get(client.ServiceURL("enterprise-router", erID, "route-tables", routeTableId), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res RouteTable | ||
err = extract.IntoStructPtr(raw.Body, &res, "route_table") | ||
return &res, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package route_table | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
type ListOpts struct { | ||
RouterId string `json:"-"` | ||
Marker string `q:"marker"` | ||
Limit int `q:"limit"` | ||
State []string `q:"state"` | ||
SortKey []string `q:"sort_key"` | ||
SortDir []string `q:"sort_dir"` | ||
} | ||
|
||
func List(client *golangsdk.ServiceClient, opts ListOpts) (*ListRouteTables, error) { | ||
url, err := golangsdk.NewURLBuilder().WithEndpoints("enterprise-router", opts.RouterId, "route-tables").WithQueryParams(&opts).Build() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
raw, err := client.Get(client.ServiceURL(url.String()), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res ListRouteTables | ||
err = extract.Into(raw.Body, &res) | ||
return &res, err | ||
} | ||
|
||
type ListRouteTables struct { | ||
RouteTables []RouteTable `json:"route_tables"` | ||
PageInfo *PageInfo `json:"page_info"` | ||
RequestId string `json:"request_id"` | ||
} | ||
|
||
type PageInfo struct { | ||
NextMarker string `json:"next_marker"` | ||
CurrentCount int `json:"current_count"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package route_table | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
type UpdateOpts struct { | ||
RouterID string `json:"-"` | ||
RouteTableId string `json:"-"` | ||
Name string `json:"name,omitempty"` | ||
Description *string `json:"description,omitempty"` | ||
// parameter not supported ☻ | ||
// BgpOptions *BgpOptions `json:"bgp_options,omitempty"` | ||
} | ||
|
||
func Update(client *golangsdk.ServiceClient, opts UpdateOpts) (*RouteTable, error) { | ||
b, err := build.RequestBody(opts, "route_table") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
raw, err := client.Put(client.ServiceURL("enterprise-router", opts.RouterID, "route-tables", opts.RouteTableId), b, nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{200}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res RouteTable | ||
return &res, extract.IntoStructPtr(raw.Body, &res, "route_table") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters