github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/apigw/v2/gateway_test.go (about) 1 package v2 2 3 import ( 4 "fmt" 5 "testing" 6 7 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack" 10 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 11 "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/gateway" 12 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" 13 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 14 ) 15 16 func TestGatewayLifecycle(t *testing.T) { 17 vpcID := clients.EnvOS.GetEnv("VPC_ID") 18 subnetID := clients.EnvOS.GetEnv("NETWORK_ID") 19 20 if vpcID == "" || subnetID == "" { 21 t.Skip("Both `VPC_ID` and `NETWORK_ID` need to be defined") 22 } 23 24 client, err := clients.NewAPIGWClient() 25 th.AssertNoErr(t, err) 26 27 createOpts := gateway.CreateOpts{ 28 VpcID: vpcID, 29 SubnetID: subnetID, 30 InstanceName: tools.RandomString("test-gateway-", 5), 31 SpecID: "PROFESSIONAL", 32 SecGroupID: openstack.DefaultSecurityGroup(t), 33 AvailableZoneIDs: []string{ 34 "eu-de-01", 35 "eu-de-02", 36 }, 37 LoadBalancerProvider: "elb", 38 Description: "All Work And No Play Makes Jack A Dull Boy", 39 IngressBandwidthChargingMode: "bandwidth", 40 IngressBandwidthSize: pointerto.Int(5), 41 // Tags: []tags.ResourceTag{ 42 // { 43 // Key: "TestKey", 44 // Value: "TestValue", 45 // }, 46 // { 47 // Key: "empty", 48 // Value: "", 49 // }, 50 // }, 51 } 52 t.Logf("Attempting to CREATE APIGW Gateway") 53 createResp, err := gateway.Create(client, createOpts) 54 th.AssertNoErr(t, err) 55 56 th.AssertNoErr(t, WaitForJob(client, createResp.InstanceID, 1800)) 57 t.Cleanup(func() { 58 t.Logf("Attempting to DELETE APIGW Gateway: %s", createResp.InstanceID) 59 th.AssertNoErr(t, gateway.Delete(client, createResp.InstanceID)) 60 }) 61 62 updateOpts := gateway.UpdateOpts{ 63 Description: "it's not getting better", 64 MaintainBegin: "22:00:00", 65 MaintainEnd: "02:00:00", 66 InstanceName: createOpts.InstanceName + "updated", 67 ID: createResp.InstanceID, 68 } 69 70 t.Logf("Attempting to UPDATE APIGW Gateway: %s", createResp.InstanceID) 71 _, err = gateway.Update(client, updateOpts) 72 th.AssertNoErr(t, err) 73 74 t.Logf("Attempting to GET APIGW Gateway: %s", createResp.InstanceID) 75 getResp, err := gateway.Get(client, createResp.InstanceID) 76 th.AssertNoErr(t, err) 77 78 tools.PrintResource(t, getResp) 79 80 // API not published yet 81 // t.Logf("Attempting to UPDATE APIGW Gateway tags: %s", createResp.InstanceID) 82 // err = gateway.UpdateTags(client, &gateway.TagsUpdateOpts{ 83 // InstanceId: createResp.InstanceID, 84 // Action: "create", 85 // Tags: []tags.ResourceTag{ 86 // { 87 // Key: "NewKey", 88 // Value: "NewValue", 89 // }, 90 // }, 91 // }) 92 // th.AssertNoErr(t, err) 93 94 // t.Logf("Attempting to GET APIGW Gateway tags list: %s", createResp.InstanceID) 95 // getTags, err := gateway.GetTags(client, createResp.InstanceID) 96 // th.AssertNoErr(t, err) 97 // th.CheckEquals(t, 3, len(getTags)) 98 99 // t.Logf("Attempting to DISABLE APIGW Gateway ELB ingress access: %s", createResp.InstanceID) 100 // err = gateway.DisableElbIngressAccess(client, createResp.InstanceID) 101 // th.AssertNoErr(t, err) 102 // 103 // optsIngressAccess := gateway.ElbIngressAccessOpts{ 104 // InstanceId: createResp.InstanceID, 105 // IngressBandwithSize: 10, 106 // IngressBandwithChargingMode: "traffic", 107 // } 108 // t.Logf("Attempting to ENABLE APIGW Gateway ELB ingress access: %s", createResp.InstanceID) 109 // updateIngress, err := gateway.EnableElbIngressAccess(client, optsIngressAccess) 110 // th.AssertNoErr(t, WaitForJob(client, updateIngress.InstanceID, 1800)) 111 112 t.Logf("Attempting to ENABLE APIGW Gateway EIP: %s", createResp.InstanceID) 113 th.AssertNoErr(t, gateway.EnableEIP(client, gateway.EipOpts{ 114 ID: createResp.InstanceID, 115 BandwidthChargingMode: "traffic", 116 BandwidthSize: "5", 117 })) 118 119 t.Logf("Attempting to UPDATE APIGW Gateway EIP: %s", createResp.InstanceID) 120 th.AssertNoErr(t, gateway.UpdateEIP(client, gateway.EipOpts{ 121 ID: createResp.InstanceID, 122 BandwidthChargingMode: "traffic", 123 BandwidthSize: "10", 124 })) 125 126 t.Logf("Attempting to DISABLE APIGW Gateway EIP: %s", createResp.InstanceID) 127 th.AssertNoErr(t, gateway.DisableEIP(client, createResp.InstanceID)) 128 } 129 130 func TestGatewayList(t *testing.T) { 131 client, err := clients.NewAPIGWClient() 132 th.AssertNoErr(t, err) 133 134 _, err = gateway.List(client, gateway.ListOpts{}) 135 th.AssertNoErr(t, err) 136 } 137 138 func WaitForJob(c *golangsdk.ServiceClient, id string, secs int) error { 139 return golangsdk.WaitFor(secs, func() (bool, error) { 140 current, err := gateway.QueryProgress(c, id) 141 if err != nil { 142 return false, err 143 } 144 145 if current.Status == "success" { 146 return true, nil 147 } 148 149 if current.Status == "failed" { 150 return false, fmt.Errorf("job failed: %s", current.ErrorMsg) 151 } 152 153 return false, nil 154 }) 155 }