Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Update & Refactor] ELB #522

Open
wants to merge 55 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
abe705b
ELB
Aloento Apr 13, 2023
0d151a8
Move
Aloento Apr 13, 2023
0e367a6
CreateOpts
Aloento Apr 14, 2023
eb224cd
Create
Aloento Apr 14, 2023
38eb831
Get
Aloento Apr 14, 2023
40727de
Delete
Aloento Apr 14, 2023
5648490
List
Aloento Apr 14, 2023
a321d88
Update
Aloento Apr 14, 2023
28858f5
Get
Aloento Apr 14, 2023
1039d1e
List
Aloento Apr 14, 2023
4eef813
Create
Aloento Apr 14, 2023
092f723
List
Aloento Apr 14, 2023
db36ee3
UpdateIpList
Aloento Apr 14, 2023
610639a
ipgroups
Aloento Apr 14, 2023
64a7228
Create
Aloento Apr 14, 2023
d72fa6c
Merge branch 'devel' into elb
Aloento May 10, 2023
45851b8
Delete
Aloento May 10, 2023
29422be
Get
Aloento May 10, 2023
049227a
List
Aloento May 10, 2023
1be0427
Update
Aloento May 10, 2023
34183ac
ACC
Aloento May 10, 2023
c269d2f
Create
Aloento May 10, 2023
e74fce4
LoadBalancer
Aloento May 10, 2023
ca4da36
GetStatuses
Aloento May 11, 2023
389019d
todo
Aloento May 12, 2023
c098263
List
Aloento May 16, 2023
080b8d3
Update
Aloento May 16, 2023
c657385
Update
Aloento May 16, 2023
b23f2e8
loadbalancers
Aloento May 16, 2023
2e23795
Get
Aloento May 16, 2023
748441c
List
Aloento May 16, 2023
9afec52
Delete
Aloento May 16, 2023
496a804
Update
Aloento May 16, 2023
b21b7d2
member
Aloento May 16, 2023
1d5425e
Create
Aloento Jun 28, 2023
111c190
Get
Aloento Jun 28, 2023
712f304
List
Aloento Jun 28, 2023
74f9f8e
Update
Aloento Jun 28, 2023
6cd075e
Create
Aloento Jun 29, 2023
676e073
List
Aloento Jun 29, 2023
ec30638
Update
Aloento Jun 29, 2023
9fd6f83
Create
Aloento Jun 29, 2023
fe32c36
List
Aloento Jun 29, 2023
055f3da
Update
Aloento Jun 29, 2023
2a8dad0
Update
Aloento Jun 29, 2023
12c50ba
Create
Aloento Jun 29, 2023
837aa13
ListOpts
Aloento Jun 29, 2023
8c155ac
Update
Aloento Jun 29, 2023
13f337c
Update
Aloento Jun 29, 2023
7839e32
List
Aloento Jun 29, 2023
c3048ae
ListSystemPolicies
Aloento Jun 29, 2023
1f0a4c1
Test
Aloento Jun 29, 2023
d298f71
clean
Aloento Jun 29, 2023
997986b
clean
Aloento Jun 29, 2023
8ba0e6f
clean
Aloento Jun 29, 2023
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
13 changes: 7 additions & 6 deletions acceptance/openstack/elb/v3/certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ func TestCertificateLifecycle(t *testing.T) {
th.AssertNoErr(t, err)

certificateID := createCertificate(t, client)
defer deleteCertificate(t, client, certificateID)
t.Cleanup(func() {
deleteCertificate(t, client, certificateID)
})

t.Logf("Attempting to update ELBv3 certificate: %s", certificateID)
certName := tools.RandomString("update-cert-", 3)
emptyDescription := ""
updateOpts := certificates.UpdateOpts{
Name: certName,
Description: &emptyDescription,
Description: "",
}

_, err = certificates.Update(client, certificateID, updateOpts).Extract()
_, err = certificates.Update(client, certificateID, updateOpts)
th.AssertNoErr(t, err)
t.Logf("Updated ELBv3 certificate: %s", certificateID)

newCertificate, err := certificates.Get(client, certificateID).Extract()
newCertificate, err := certificates.Get(client, certificateID)
th.AssertNoErr(t, err)
th.AssertEquals(t, updateOpts.Name, newCertificate.Name)
th.AssertEquals(t, emptyDescription, newCertificate.Description)
th.AssertEquals(t, "", newCertificate.Description)
}
2 changes: 1 addition & 1 deletion acceptance/openstack/elb/v3/flavors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestFlavorsList(t *testing.T) {
flavorsList, err := flavors.ExtractFlavors(flavorsPages)
th.AssertNoErr(t, err)

zeroFlavor, err := flavors.Get(client, flavorsList[0].ID).Extract()
zeroFlavor, err := flavors.Get(client, flavorsList[0].ID)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, zeroFlavor, &flavorsList[0])
}
42 changes: 21 additions & 21 deletions acceptance/openstack/elb/v3/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func createLoadBalancer(t *testing.T, client *golangsdk.ServiceClient) string {
IpTargetEnable: &ipTargetEnable,
}

loadbalancer, err := loadbalancers.Create(client, createOpts).Extract()
loadbalancer, err := loadbalancers.Create(client, createOpts)
th.AssertNoErr(t, err)
th.AssertEquals(t, createOpts.Name, loadbalancer.Name)
th.AssertEquals(t, createOpts.Description, loadbalancer.Description)
Expand All @@ -61,7 +61,7 @@ func createLoadBalancer(t *testing.T, client *golangsdk.ServiceClient) string {

func deleteLoadbalancer(t *testing.T, client *golangsdk.ServiceClient, loadbalancerID string) {
t.Logf("Attempting to delete ELBv3 LoadBalancer: %s", loadbalancerID)
err := loadbalancers.Delete(client, loadbalancerID).ExtractErr()
err := loadbalancers.Delete(client, loadbalancerID)
th.AssertNoErr(t, err)
t.Logf("Deleted ELBv3 LoadBalancer: %s", loadbalancerID)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ i1YhgnQbn5E0hz55OLu5jvOkKQjPCW+8Kg==
Certificate: cert,
}

certificate, err := certificates.Create(client, createOpts).Extract()
certificate, err := certificates.Create(client, createOpts)
th.AssertNoErr(t, err)
th.AssertEquals(t, createOpts.Name, certificate.Name)
th.AssertEquals(t, createOpts.Description, certificate.Description)
Expand All @@ -141,7 +141,7 @@ i1YhgnQbn5E0hz55OLu5jvOkKQjPCW+8Kg==

func deleteCertificate(t *testing.T, client *golangsdk.ServiceClient, certificateID string) {
t.Logf("Attempting to delete ELBv3 certificate: %s", certificateID)
err := certificates.Delete(client, certificateID).ExtractErr()
err := certificates.Delete(client, certificateID)
th.AssertNoErr(t, err)
t.Logf("Deleted ELBv3 certificate: %s", certificateID)
}
Expand All @@ -151,46 +151,46 @@ func createPool(t *testing.T, client *golangsdk.ServiceClient, loadbalancerID st
vpcID := clients.EnvOS.GetEnv("VPC_ID")
poolName := tools.RandomString("create-pool-", 3)
createOpts := pools.CreateOpts{
LBMethod: "LEAST_CONNECTIONS",
Protocol: "HTTP",
LoadbalancerID: loadbalancerID,
Name: poolName,
Description: "some interesting description",
VpcId: vpcID,
Type: "instance",
DeletionProtectionEnable: pointerto.Bool(true),
LbAlgorithm: "LEAST_CONNECTIONS",
Protocol: "HTTP",
LoadbalancerId: loadbalancerID,
Name: poolName,
Description: "some interesting description",
VpcId: vpcID,
Type: "instance",
MemberDeletionProtectionEnable: pointerto.Bool(true),
}

pool, err := pools.Create(client, createOpts).Extract()
pool, err := pools.Create(client, createOpts)
th.AssertNoErr(t, err)
th.AssertEquals(t, createOpts.Name, pool.Name)
th.AssertEquals(t, createOpts.Description, pool.Description)
th.AssertEquals(t, createOpts.LBMethod, pool.LBMethod)
th.AssertEquals(t, true, pool.DeletionProtectionEnable)
th.AssertEquals(t, createOpts.LbAlgorithm, pool.LbAlgorithm)
th.AssertEquals(t, true, pool.MemberDeletionProtectionEnable)
th.AssertEquals(t, createOpts.Type, pool.Type)
th.AssertEquals(t, createOpts.VpcId, pool.VpcId)
t.Logf("Created ELBv3 Pool: %s", pool.ID)
t.Logf("Created ELBv3 Pool: %s", pool.Id)

return pool.ID
return pool.Id
}

func deletePool(t *testing.T, client *golangsdk.ServiceClient, poolID string) {
t.Logf("Attempting to delete ELBv3 Pool: %s", poolID)
err := pools.Delete(client, poolID).ExtractErr()
err := pools.Delete(client, poolID)
th.AssertNoErr(t, err)
t.Logf("Deleted ELBv3 Pool: %s", poolID)
}

func createListener(t *testing.T, client *golangsdk.ServiceClient, loadbalancerID string) string {
listener, err := listeners.Create(client, listeners.CreateOpts{
LoadbalancerID: loadbalancerID,
Protocol: listeners.ProtocolHTTP,
Protocol: "HTTP",
ProtocolPort: 80,
}).Extract()
})
th.AssertNoErr(t, err)
return listener.ID
}

func deleteListener(t *testing.T, client *golangsdk.ServiceClient, listenerID string) {
th.AssertNoErr(t, listeners.Delete(client, listenerID).ExtractErr())
th.AssertNoErr(t, listeners.Delete(client, listenerID))
}
52 changes: 27 additions & 25 deletions acceptance/openstack/elb/v3/ipgroups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ func TestIpGroupList(t *testing.T) {
client, err := clients.NewElbV3Client()
th.AssertNoErr(t, err)

listOpts := ipgroups.ListOpts{}
ipgroupsList, err := ipgroups.List(client, listOpts)
ipgroupsLists, err := ipgroups.List(client, ipgroups.ListOpts{}).AllPages()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why extract here? Previously it works without it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

th.AssertNoErr(t, err)
ipgroupsList, err := ipgroups.ExtractIpGroups(ipgroupsLists)
th.AssertNoErr(t, err)

for _, gr := range ipgroupsList {
Expand All @@ -29,20 +30,19 @@ func TestIpGroupsLifecycle(t *testing.T) {
th.AssertNoErr(t, err)

loadbalancerID := createLoadBalancer(t, client)
defer deleteLoadbalancer(t, client, loadbalancerID)
t.Cleanup(func() {
deleteLoadbalancer(t, client, loadbalancerID)
})

ipGroupOpts := ipgroups.IpGroupOption{
Ip: "192.168.10.10",
Description: "first",
}
ipGroupName := tools.RandomString("create-ip-group-", 3)
createOpts := ipgroups.CreateOpts{
Description: "some interesting description",
Name: ipGroupName,
IpList: []ipgroups.IpGroupOption{ipGroupOpts},
}
t.Logf("Attempting to create ELBv3 IpGroup")
ipGroup, err := ipgroups.Create(client, createOpts)
ipGroup, err := ipgroups.Create(client, ipgroups.CreateOpts{
Description: "some interesting description",
Name: tools.RandomString("create-ip-group-", 3),
IpList: []ipgroups.IpGroupOption{ipgroups.IpGroupOption{
Ip: "192.168.10.10",
Description: "first",
}},
})
th.AssertNoErr(t, err)

t.Cleanup(func() {
Expand All @@ -52,9 +52,8 @@ func TestIpGroupsLifecycle(t *testing.T) {
})

t.Logf("Attempting to update ELBv3 IpGroup: %s", ipGroup.ID)
ipGroupNameUpdate := tools.RandomString("update-ip-group-", 3)
updateOpts := ipgroups.UpdateOpts{
Name: ipGroupNameUpdate,
_, err = ipgroups.Update(client, ipGroup.ID, ipgroups.UpdateOpts{
Name: tools.RandomString("update-ip-group-", 3),
IpList: []ipgroups.IpGroupOption{
{
Ip: "192.168.10.12",
Expand All @@ -65,34 +64,37 @@ func TestIpGroupsLifecycle(t *testing.T) {
Description: "fourth",
},
},
}
err = ipgroups.Update(client, ipGroup.ID, updateOpts)
})
th.AssertNoErr(t, err)
t.Logf("Updated ELBv3 ipGroup: %s", ipGroup.ID)

updatedIpGroup, err := ipgroups.Get(client, ipGroup.ID)
th.AssertNoErr(t, err)
th.AssertEquals(t, ipGroupNameUpdate, updatedIpGroup.Name)
th.AssertEquals(t, tools.RandomString("update-ip-group-", 3), updatedIpGroup.Name)

listOpts := ipgroups.ListOpts{}
ipGroupsSlice, err := ipgroups.List(client, listOpts)
ipGroupsSlices, err := ipgroups.List(client, ipgroups.ListOpts{}).AllPages()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract and paging should be inside list func

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you change that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

th.AssertNoErr(t, err)
ipGroupsSlice, err := ipgroups.ExtractIpGroups(ipGroupsSlices)
th.AssertNoErr(t, err)

th.AssertEquals(t, 1, len(ipGroupsSlice))
th.AssertDeepEquals(t, *updatedIpGroup, ipGroupsSlice[0])

t.Logf("Attempting to create ELBv3 Listener with ipGroup association")
listener, err := listeners.Create(client, listeners.CreateOpts{
LoadbalancerID: loadbalancerID,
Protocol: listeners.ProtocolHTTP,
Protocol: "HTTP",
ProtocolPort: 80,
EnhanceL7policy: pointerto.Bool(true),
IpGroup: &listeners.IpGroup{
IpGroupID: ipGroup.ID,
Enable: pointerto.Bool(true),
},
}).Extract()
})
th.AssertNoErr(t, err)
defer deleteListener(t, client, listener.ID)
t.Cleanup(func() {
deleteListener(t, client, listener.ID)
})

updatedIpList, err := ipgroups.UpdateIpList(client, ipGroup.ID, ipgroups.UpdateOpts{
IpList: []ipgroups.IpGroupOption{
Expand Down
18 changes: 10 additions & 8 deletions acceptance/openstack/elb/v3/listeners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ func TestListenerLifecycle(t *testing.T) {
th.AssertNoErr(t, err)

loadbalancerID := createLoadBalancer(t, client)
defer deleteLoadbalancer(t, client, loadbalancerID)
t.Cleanup(func() {
deleteLoadbalancer(t, client, loadbalancerID)
})

certificateID := createCertificate(t, client)
defer deleteCertificate(t, client, certificateID)
t.Cleanup(func() { deleteCertificate(t, client, certificateID) })

t.Logf("Attempting to create ELBv3 Listener")
listenerName := tools.RandomString("create-listener-", 3)
Expand All @@ -38,13 +40,13 @@ func TestListenerLifecycle(t *testing.T) {
},
}

listener, err := listeners.Create(client, createOpts).Extract()
defer func() {
listener, err := listeners.Create(client, createOpts)
t.Cleanup(func() {
t.Logf("Attempting to delete ELBv3 Listener: %s", listener.ID)
err := listeners.Delete(client, listener.ID).ExtractErr()
err := listeners.Delete(client, listener.ID)
th.AssertNoErr(t, err)
t.Logf("Deleted ELBv3 Listener: %s", listener.ID)
}()
})
th.AssertNoErr(t, err)
th.AssertEquals(t, createOpts.Name, listener.Name)
th.AssertEquals(t, createOpts.Description, listener.Description)
Expand All @@ -58,11 +60,11 @@ func TestListenerLifecycle(t *testing.T) {
Name: &listenerName,
SniMatchAlgo: "longest_suffix",
}
_, err = listeners.Update(client, listener.ID, updateOpts).Extract()
_, err = listeners.Update(client, listener.ID, updateOpts)
th.AssertNoErr(t, err)
t.Logf("Updated ELBv3 Listener: %s", listener.ID)

newListener, err := listeners.Get(client, listener.ID).Extract()
newListener, err := listeners.Get(client, listener.ID)
th.AssertNoErr(t, err)
th.AssertEquals(t, listenerName, newListener.Name)
th.AssertEquals(t, emptyDescription, newListener.Description)
Expand Down
18 changes: 10 additions & 8 deletions acceptance/openstack/elb/v3/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLoadBalancerList(t *testing.T) {
loadbalancerPages, err := loadbalancers.List(client, listOpts).AllPages()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract and paging should be inside list func again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently no. have to change how the Page struct works.

th.AssertNoErr(t, err)

loadbalancerList, err := loadbalancers.ExtractLoadbalancers(loadbalancerPages)
loadbalancerList, err := loadbalancers.ExtractLoadBalancers(loadbalancerPages)
th.AssertNoErr(t, err)

for _, lb := range loadbalancerList {
Expand All @@ -31,35 +31,37 @@ func TestLoadBalancerLifecycle(t *testing.T) {
th.AssertNoErr(t, err)

loadbalancerID := createLoadBalancer(t, client)
defer deleteLoadbalancer(t, client, loadbalancerID)
t.Cleanup(func() {
deleteLoadbalancer(t, client, loadbalancerID)
})

t.Logf("Attempting to update ELBv3 LoadBalancer: %s", loadbalancerID)
lbName := tools.RandomString("update-lb-", 3)
emptyDescription := ""
updateOptsDpE := loadbalancers.UpdateOpts{
Name: lbName,
Description: &emptyDescription,
Description: emptyDescription,
DeletionProtectionEnable: pointerto.Bool(true),
}
_, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpE).Extract()
_, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpE)
th.AssertNoErr(t, err)
t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID)

err = loadbalancers.Delete(client, loadbalancerID).ExtractErr()
err = loadbalancers.Delete(client, loadbalancerID)
if err != nil {
t.Logf("Cannot delete, Deletion Protection enabled for ELBv3 LoadBalancer: %s", loadbalancerID)
}

updateOptsDpD := loadbalancers.UpdateOpts{
Name: lbName,
Description: &emptyDescription,
Description: emptyDescription,
DeletionProtectionEnable: pointerto.Bool(false),
}
_, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpD).Extract()
_, err = loadbalancers.Update(client, loadbalancerID, updateOptsDpD)
th.AssertNoErr(t, err)
t.Logf("Updated ELBv3 LoadBalancer: %s", loadbalancerID)

newLoadbalancer, err := loadbalancers.Get(client, loadbalancerID).Extract()
newLoadbalancer, err := loadbalancers.Get(client, loadbalancerID)
th.AssertNoErr(t, err)
th.AssertEquals(t, updateOptsDpD.Name, newLoadbalancer.Name)
th.AssertEquals(t, emptyDescription, newLoadbalancer.Description)
Expand Down
Loading