github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/dataarts/v1.1/clusters_test.go (about)

     1  package v1_1
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     9  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
    10  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto"
    11  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/dataarts/v1.1/cluster"
    12  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    13  )
    14  
    15  func TestDataArtsClusterLifecycle(t *testing.T) {
    16  	if os.Getenv("RUN_DATAART_LIFECYCLE") == "" {
    17  		t.Skip("too slow to run in zuul")
    18  	}
    19  
    20  	vpcID := clients.EnvOS.GetEnv("VPC_ID")
    21  	subnetID := clients.EnvOS.GetEnv("NETWORK_ID")
    22  	secGroupId := clients.EnvOS.GetEnv("SECURITY_GROUP_ID")
    23  
    24  	client, err := clients.NewDataArtsV11Client()
    25  	th.AssertNoErr(t, err)
    26  
    27  	dataStore := cluster.Datastore{
    28  		Type:    "cdm",
    29  		Version: "2.9.1.200",
    30  	}
    31  	instance := cluster.Instance{
    32  		AZ:        "eu-de-01",
    33  		FlavorRef: "a79fd5ae-1833-448a-88e8-3ea2b913e1f6",
    34  		Type:      "cdm",
    35  		Nics: []cluster.Nic{
    36  			{
    37  				SecurityGroupId: secGroupId,
    38  				NetId:           subnetID,
    39  			},
    40  		},
    41  	}
    42  
    43  	createOpts := cluster.CreateOpts{
    44  		Cluster: cluster.Cluster{
    45  			// setting this parameter to true results in 400 error
    46  			IsScheduleBootOff: pointerto.Bool(false),
    47  			VpcId:             vpcID,
    48  			Name:              tools.RandomString("test-dataarts", 5),
    49  			DataStore:         &dataStore,
    50  			Instances: []cluster.Instance{
    51  				instance,
    52  			},
    53  		},
    54  	}
    55  
    56  	createResp, err := cluster.Create(client, createOpts)
    57  	th.AssertNoErr(t, err)
    58  	tools.PrintResource(t, createResp)
    59  
    60  	th.AssertNoErr(t, waitForStateAvailable(client, 1200, createResp.Id))
    61  	t.Cleanup(func() { deleteDataArts(t, client, createResp.Id) })
    62  
    63  	getCluster, err := cluster.Get(client, createResp.Id)
    64  	th.AssertNoErr(t, err)
    65  	tools.PrintResource(t, getCluster)
    66  }
    67  
    68  func waitForStateAvailable(client *golangsdk.ServiceClient, secs int, instanceID string) error {
    69  	jobClient := *client
    70  	jobClient.ResourceBase = jobClient.Endpoint
    71  
    72  	return golangsdk.WaitFor(secs, func() (bool, error) {
    73  		resp, err := cluster.Get(client, instanceID)
    74  		if err != nil {
    75  			return false, err
    76  		}
    77  
    78  		if resp.Status == "200" {
    79  			return true, nil
    80  		}
    81  
    82  		return false, nil
    83  	})
    84  }
    85  
    86  func deleteDataArts(t *testing.T, client *golangsdk.ServiceClient, instanceId string) {
    87  	t.Logf("Attempting to delete DataArts instance: %s", instanceId)
    88  
    89  	err := cluster.Delete(client, instanceId)
    90  	th.AssertNoErr(t, err)
    91  
    92  	t.Logf("DataArts instance deleted: %s", instanceId)
    93  }