github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/waf-premium/v1/instance_test.go (about) 1 package v1 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" 11 "github.com/opentelekomcloud/gophertelekomcloud/openstack/waf-premium/v1/instances" 12 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 13 ) 14 15 func TestWafPremiumInstanceWorkflow(t *testing.T) { 16 if os.Getenv("RUN_WAFD_INSTANCE_WORKFLOW") == "" { 17 t.Skip("too slow to run in zuul") 18 } 19 region := os.Getenv("OS_REGION_NAME") 20 az := os.Getenv("OS_AVAILABILITY_ZONE") 21 vpcID := os.Getenv("OS_VPC_ID") 22 subnetID := os.Getenv("OS_NETWORK_ID") 23 if vpcID == "" && subnetID == "" && region == "" && az == "" { 24 t.Skip("OS_REGION_NAME, OS_AVAILABILITY_ZONE, OS_VPC_ID and OS_NETWORK_ID env vars is required for this test") 25 } 26 27 client, err := clients.NewWafdV1Client() 28 th.AssertNoErr(t, err) 29 30 architecture := "x86" 31 if region == "eu-ch2" { 32 architecture = "x86_64" 33 } 34 35 opts := instances.CreateOpts{ 36 Count: 1, 37 Region: region, 38 AvailabilityZone: az, 39 Architecture: architecture, 40 InstanceName: tools.RandomString("waf-instance-", 3), 41 Specification: "waf.instance.enterprise", 42 Flavor: "s3.2xlarge.2", 43 VpcId: vpcID, 44 SubnetId: subnetID, 45 ResTenant: pointerto.Bool(true), 46 SecurityGroupsId: []string{openstack.DefaultSecurityGroup(t)}, 47 } 48 49 t.Logf("Attempting to create WAF premium instance") 50 inst, err := instances.Create(client, opts) 51 th.AssertNoErr(t, err) 52 t.Logf("Created WAF instance: %s", inst.Instances[0].Id) 53 instanceId := inst.Instances[0].Id 54 55 th.AssertNoErr(t, waitForInstanceToBeCreated(client, 600, instanceId)) 56 57 t.Cleanup(func() { 58 t.Logf("Attempting to delete WAF Premium instance: %s", instanceId) 59 th.AssertNoErr(t, instances.Delete(client, instanceId)) 60 th.AssertNoErr(t, waitForInstanceToBeDeleted(client, 600, instanceId)) 61 t.Logf("Deleted WAF Premium instance: %s", instanceId) 62 }) 63 64 instance, err := instances.Get(client, instanceId) 65 th.AssertNoErr(t, err) 66 th.AssertEquals(t, instance.ID, instanceId) 67 th.AssertEquals(t, instance.ResourceSpecification, "waf.instance.enterprise") 68 69 instancesList, err := instances.List(client, instances.ListOpts{}) 70 th.AssertNoErr(t, err) 71 72 if len(instancesList) < 1 { 73 t.Fatal("empty WAF instances list") 74 } 75 updatedName := tools.RandomString("waf-instance-updated-", 3) 76 instanceUpdated, err := instances.Update(client, instanceId, instances.UpdateOpts{ 77 Name: updatedName, 78 }) 79 th.AssertNoErr(t, err) 80 th.AssertEquals(t, instanceUpdated.Name, updatedName) 81 }