File: connect_test.go

package info (click to toggle)
golang-github-packethost-packngo 0.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 440 kB
  • sloc: makefile: 2
file content (127 lines) | stat: -rw-r--r-- 2,714 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package packngo

import (
	"fmt"
	"log"
	"os"
	"testing"
	"time"
)

func waitConnectStatus(connectID, projectID, status string, c *Client) (*Connect, error) {
	// 15 minutes = 180 * 5sec-retry
	for i := 0; i < 180; i++ {
		<-time.After(5 * time.Second)
		co, _, err := c.Connects.Get(connectID, projectID, nil)
		if err != nil {
			return nil, err
		}
		if co.Status == status {
			return co, nil
		}
	}
	return nil, fmt.Errorf("Packet Connect %s is still noti %s after timeout", connectID, status)
}

func TestAccConnectBasic(t *testing.T) {
t.Skip("DM-disabled")

	azureEnvVar := "AZURE_KEY"
	azureKey := os.Getenv(azureEnvVar)
	if len(azureKey) == 0 {
		t.Fatalf("You must set %s", azureEnvVar)
	}

	skipUnlessAcceptanceTestsAllowed(t)

	c, projectID, teardown := setupWithProject(t)
	defer teardown()

	cs, _, err := c.Connects.List(projectID, nil)
	if err != nil {
		t.Fatal(err)
	}

	log.Println(cs)
	if len(cs) != 0 {
		t.Fatalf("There should be no Connect resource")
	}

	vcr := VirtualNetworkCreateRequest{
		ProjectID:   projectID,
		Description: "connectTestVLAN",
		Facility:    "ewr1",
	}
	vlan, _, err := c.ProjectVirtualNetworks.Create(&vcr)
	if err != nil {
		t.Fatal(err)
	}
	defer c.ProjectVirtualNetworks.Delete(vlan.ID)

	ccr := ConnectCreateRequest{
		Name:            "testconn",
		ProjectID:       projectID,
		ProviderID:      AzureProviderID,
		ProviderPayload: azureKey,
		Facility:        "ewr1",
		PortSpeed:       100,
		VLAN:            vlan.VXLAN,
		Description:     "testconn",
		Tags:            []string{"testconn"},
	}

	connect, _, err := c.Connects.Create(&ccr)
	if err != nil {
		t.Fatal(err)
	}
	connect, err = waitConnectStatus(connect.ID, projectID, "PROVISIONED", c)
	if err != nil {
		t.Fatal(err)
	}

	defer c.Connects.Delete(connect.ID, projectID)

	cs, _, err = c.Connects.List(projectID, nil)
	if err != nil {
		t.Fatal(err)
	}

	log.Println(cs)
	if len(cs) != 1 {
		t.Fatalf("There should be only 1 Connect resource")
	}

	time.Sleep(65 * time.Second)

	connect, _, err = c.Connects.Deprovision(connect.ID, projectID, false)
	if err != nil {
		t.Fatal(err)
	}
	connect, err = waitConnectStatus(connect.ID, projectID, "DEPROVISIONED", c)
	if err != nil {
		t.Fatal(err)
	}

	time.Sleep(65 * time.Second)

	connect, _, err = c.Connects.Provision(connect.ID, projectID)
	if err != nil {
		t.Fatal(err)
	}
	connect, err = waitConnectStatus(connect.ID, projectID, "PROVISIONED", c)
	if err != nil {
		t.Fatal(err)
	}

	time.Sleep(65 * time.Second)

	connect, _, err = c.Connects.Deprovision(connect.ID, projectID, false)
	if err != nil {
		t.Fatal(err)
	}
	connect, err = waitConnectStatus(connect.ID, projectID, "DEPROVISIONED", c)
	if err != nil {
		t.Fatal(err)
	}

}