github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/dcaas/v2/dcaas_acc_test.go (about)

     1  package v2
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     9  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
    10  	dc_endpoint_group "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/dc-endpoint-group"
    11  	direct_connect "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/direct-connect"
    12  	virtual_gateway "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/virtual-gateway"
    13  	virtual_interface "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/virtual-interface"
    14  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    15  )
    16  
    17  func TestDCAASLifecycle(t *testing.T) {
    18  	if os.Getenv("RUN_DCAAS_VIRTUAL_INTERFACE") == "" {
    19  		t.Skip("unstable test")
    20  	}
    21  
    22  	// Create client
    23  	client, err := clients.NewDCaaSV2Client()
    24  	th.AssertNoErr(t, err)
    25  
    26  	// Create a direct connect
    27  	name := strings.ToLower(tools.RandomString("test-direct-connect-", 5))
    28  	createOpts := direct_connect.CreateOpts{
    29  		Name:      name,
    30  		PortType:  "1G",
    31  		Bandwidth: 100,
    32  		Location:  "Biere",
    33  		Provider:  "OTC",
    34  	}
    35  
    36  	dc, err := direct_connect.Create(client, createOpts)
    37  	th.AssertNoErr(t, err)
    38  
    39  	// Get a direct connect
    40  	_, err = direct_connect.Get(client, dc.ID)
    41  	th.AssertNoErr(t, err)
    42  
    43  	// List direct connects
    44  	_, err = direct_connect.List(client, dc.ID)
    45  	th.AssertNoErr(t, err)
    46  
    47  	// Update a direct connect
    48  	updateOpts := direct_connect.UpdateOpts{
    49  		Name:        tools.RandomString(name, 3),
    50  		Description: "Updated description",
    51  	}
    52  	_ = direct_connect.Update(client, dc.ID, updateOpts)
    53  	th.AssertNoErr(t, err)
    54  
    55  	// Create a direct connect endpoint group
    56  	DCegName := strings.ToLower(tools.RandomString("test-direct-connect-endpoint-group-", 5))
    57  
    58  	TenantId := clients.EnvOS.GetEnv("TENANT_ID")
    59  
    60  	DCegCreateOpts := dc_endpoint_group.CreateOpts{
    61  		TenantId:  TenantId,
    62  		Name:      DCegName,
    63  		Endpoints: []string{"10.2.0.0/24", "10.3.0.0/24"},
    64  		Type:      "cidr",
    65  	}
    66  
    67  	dceg, err := dc_endpoint_group.Create(client, DCegCreateOpts)
    68  	th.AssertNoErr(t, err)
    69  
    70  	// Create a virtual gateway
    71  	VgName := strings.ToLower(tools.RandomString("test-virtual-gateway-", 5))
    72  	VgCreateOpts := virtual_gateway.CreateOpts{
    73  		Name:                 VgName,
    74  		VpcId:                clients.EnvOS.GetEnv("VPC_ID"),
    75  		LocalEndpointGroupId: dceg.ID,
    76  		Type:                 "default",
    77  	}
    78  
    79  	vg, err := virtual_gateway.Create(client, VgCreateOpts)
    80  	th.AssertNoErr(t, err)
    81  
    82  	// Create a virtual interface
    83  	ViName := strings.ToLower(tools.RandomString("test-virtual-interface-", 5))
    84  	ViCreateOpts := virtual_interface.CreateOpts{
    85  		Name:              ViName,
    86  		DirectConnectID:   dc.ID,
    87  		VgwID:             vg.ID,
    88  		Type:              "private",
    89  		ServiceType:       "vpc",
    90  		VLAN:              2511,
    91  		Bandwidth:         100,
    92  		LocalGatewayV4IP:  "16.16.16.1/30",
    93  		RemoteGatewayV4IP: "16.16.16.2/30",
    94  		RouteMode:         "static",
    95  		RemoteEPGroupID:   dceg.ID,
    96  		AdminStateUp:      true,
    97  	}
    98  
    99  	vi, err := virtual_interface.Create(client, ViCreateOpts)
   100  	if err != nil {
   101  		t.Fatalf("Unable to create virtual interface: %v", err)
   102  	}
   103  	th.AssertNoErr(t, err)
   104  
   105  	// Cleanup
   106  	t.Cleanup(func() {
   107  		err = virtual_interface.Delete(client, vi.ID)
   108  		err = virtual_gateway.Delete(client, vg.ID)
   109  		err = dc_endpoint_group.Delete(client, dceg.ID)
   110  		err = direct_connect.Delete(client, dc.ID)
   111  		th.AssertNoErr(t, err)
   112  	})
   113  }