func TestVIPsCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) pool, err := CreatePool(t, client, subnet.ID) if err != nil { t.Fatalf("Unable to create pool: %v", err) } defer DeletePool(t, client, pool.ID) vip, err := CreateVIP(t, client, subnet.ID, pool.ID) if err != nil { t.Fatalf("Unable to create vip: %v", err) } defer DeleteVIP(t, client, vip.ID) PrintVIP(t, vip) connLimit := 100 updateOpts := vips.UpdateOpts{ ConnLimit: &connLimit, } _, err = vips.Update(client, vip.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to update vip: %v") } newVIP, err := vips.Get(client, vip.ID).Extract() if err != nil { t.Fatalf("Unable to get vip: %v") } PrintVIP(t, newVIP) }
func TestMembersCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) pool, err := CreatePool(t, client, subnet.ID) if err != nil { t.Fatalf("Unable to create pool: %v", err) } defer DeletePool(t, client, pool.ID) member, err := CreateMember(t, client, pool.ID) if err != nil { t.Fatalf("Unable to create member: %v", err) } defer DeleteMember(t, client, member.ID) PrintMember(t, member) updateOpts := members.UpdateOpts{ AdminStateUp: gophercloud.Enabled, } _, err = members.Update(client, member.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to update member: %v") } newMember, err := members.Get(client, member.ID).Extract() if err != nil { t.Fatalf("Unable to get member: %v") } PrintMember(t, newMember) }
func TestPortsbindingCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } // Create Network network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) // Create Subnet subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) // Define a host hostID := "localhost" // Create port port, err := CreatePortsbinding(t, client, network.ID, subnet.ID, hostID) if err != nil { t.Fatalf("Unable to create port: %v", err) } defer networking.DeletePort(t, client, port.ID) PrintPortsbinding(t, port) // Update port newPortName := tools.RandomString("TESTACC-", 8) updateOpts := ports.UpdateOpts{ Name: newPortName, } newPort, err := portsbinding.Update(client, port.ID, updateOpts).Extract() if err != nil { t.Fatalf("Could not update port: %v", err) } PrintPortsbinding(t, newPort) }
func TestPoolsCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) pool, err := CreatePool(t, client, subnet.ID) if err != nil { t.Fatalf("Unable to create pool: %v", err) } defer DeletePool(t, client, pool.ID) PrintPool(t, pool) updateOpts := pools.UpdateOpts{ LBMethod: pools.LBMethodLeastConnections, } _, err = pools.Update(client, pool.ID, updateOpts).Extract() if err != nil { t.Fatalf("Unable to update pool: %v") } newPool, err := pools.Get(client, pool.ID).Extract() if err != nil { t.Fatalf("Unable to get pool: %v") } PrintPool(t, newPool) }
func TestPoolsMonitors(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) pool, err := CreatePool(t, client, subnet.ID) if err != nil { t.Fatalf("Unable to create pool: %v", err) } defer DeletePool(t, client, pool.ID) monitor, err := CreateMonitor(t, client) if err != nil { t.Fatalf("Unable to create monitor: %v", err) } defer DeleteMonitor(t, client, monitor.ID) t.Logf("Associating monitor %s with pool %s", monitor.ID, pool.ID) if res := pools.AssociateMonitor(client, pool.ID, monitor.ID); res.Err != nil { t.Fatalf("Unable to associate monitor to pool") } t.Logf("Disassociating monitor %s with pool %s", monitor.ID, pool.ID) if res := pools.DisassociateMonitor(client, pool.ID, monitor.ID); res.Err != nil { t.Fatalf("Unable to disassociate monitor from pool") } }
func TestNetworksProviderCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } // Create a network network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) getResult := networks.Get(client, network.ID) newNetwork, err := provider.ExtractGet(getResult) if err != nil { t.Fatalf("Unable to extract network: %v", err) } PrintNetworkExtAttrs(t, newNetwork) }
func TestSecurityGroupsPort(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) group, err := CreateSecurityGroup(t, client) if err != nil { t.Fatalf("Unable to create security group: %v", err) } defer DeleteSecurityGroup(t, client, group.ID) rule, err := CreateSecurityGroupRule(t, client, group.ID) if err != nil { t.Fatalf("Unable to create security group rule: %v", err) } defer DeleteSecurityGroupRule(t, client, rule.ID) port, err := CreatePortWithSecurityGroup(t, client, network.ID, subnet.ID, group.ID) if err != nil { t.Fatalf("Unable to create port: %v", err) } defer networking.DeletePort(t, client, port.ID) networking.PrintPort(t, port) }
func TestLoadbalancersCRUD(t *testing.T) { client, err := clients.NewNetworkV2Client() if err != nil { t.Fatalf("Unable to create a network client: %v", err) } network, err := networking.CreateNetwork(t, client) if err != nil { t.Fatalf("Unable to create network: %v", err) } defer networking.DeleteNetwork(t, client, network.ID) subnet, err := networking.CreateSubnet(t, client, network.ID) if err != nil { t.Fatalf("Unable to create subnet: %v", err) } defer networking.DeleteSubnet(t, client, subnet.ID) lb, err := CreateLoadBalancer(t, client, subnet.ID) if err != nil { t.Fatalf("Unable to create loadbalancer: %v", err) } defer DeleteLoadBalancer(t, client, lb.ID) newLB, err := loadbalancers.Get(client, lb.ID).Extract() if err != nil { t.Fatalf("Unable to get loadbalancer: %v", err) } PrintLoadBalancer(t, newLB) // Because of the time it takes to create a loadbalancer, // this test will include some other resources. // Listener listener, err := CreateListener(t, client, lb) if err != nil { t.Fatalf("Unable to create listener: %v", err) } defer DeleteListener(t, client, lb.ID, listener.ID) updateListenerOpts := listeners.UpdateOpts{ Description: "Some listener description", } _, err = listeners.Update(client, listener.ID, updateListenerOpts).Extract() if err != nil { t.Fatalf("Unable to update listener") } if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { t.Fatalf("Timed out waiting for loadbalancer to become active") } newListener, err := listeners.Get(client, listener.ID).Extract() if err != nil { t.Fatalf("Unable to get listener") } PrintListener(t, newListener) // Pool pool, err := CreatePool(t, client, lb) if err != nil { t.Fatalf("Unable to create pool: %v", err) } defer DeletePool(t, client, lb.ID, pool.ID) updatePoolOpts := pools.UpdateOpts{ Description: "Some pool description", } _, err = pools.Update(client, pool.ID, updatePoolOpts).Extract() if err != nil { t.Fatalf("Unable to update pool") } if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { t.Fatalf("Timed out waiting for loadbalancer to become active") } newPool, err := pools.Get(client, pool.ID).Extract() if err != nil { t.Fatalf("Unable to get pool") } PrintPool(t, newPool) // Member member, err := CreateMember(t, client, lb, newPool, subnet.ID, subnet.CIDR) if err != nil { t.Fatalf("Unable to create member: %v", err) } defer DeleteMember(t, client, lb.ID, pool.ID, member.ID) newWeight := tools.RandomInt(11, 100) updateMemberOpts := pools.UpdateMemberOpts{ Weight: newWeight, } _, err = pools.UpdateMember(client, pool.ID, member.ID, updateMemberOpts).Extract() if err != nil { t.Fatalf("Unable to update pool") } if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { t.Fatalf("Timed out waiting for loadbalancer to become active") } newMember, err := pools.GetMember(client, pool.ID, member.ID).Extract() if err != nil { t.Fatalf("Unable to get member") } PrintMember(t, newMember) // Monitor monitor, err := CreateMonitor(t, client, lb, newPool) if err != nil { t.Fatalf("Unable to create monitor: %v", err) } defer DeleteMonitor(t, client, lb.ID, monitor.ID) newDelay := tools.RandomInt(20, 30) updateMonitorOpts := monitors.UpdateOpts{ Delay: newDelay, } _, err = monitors.Update(client, monitor.ID, updateMonitorOpts).Extract() if err != nil { t.Fatalf("Unable to update monitor") } if err := WaitForLoadBalancerState(client, lb.ID, "ACTIVE", loadbalancerActiveTimeoutSeconds); err != nil { t.Fatalf("Timed out waiting for loadbalancer to become active") } newMonitor, err := monitors.Get(client, monitor.ID).Extract() if err != nil { t.Fatalf("Unable to get monitor") } PrintMonitor(t, newMonitor) }