-
Notifications
You must be signed in to change notification settings - Fork 55
/
suite.go
227 lines (221 loc) · 11.2 KB
/
suite.go
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package root
import (
"encoding/json"
"fmt"
"os"
"os/user"
"path/filepath"
"regexp"
"strings"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/utils"
"github.com/ava-labs/avalanche-cli/tests/e2e/commands"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
)
const (
avalanchegoVersion = "v1.10.18"
network = "fuji"
networkCapitalized = "Fuji"
numNodes = 1
exportFileName = "e2e.json"
importClusterName = "e2e_imported"
nodesRelativePath = "nodes"
)
var (
hostName string
NodeID string
)
var _ = ginkgo.Describe("[Node create]", func() {
ginkgo.It("can create a node", func() {
output := commands.NodeCreate(network, avalanchegoVersion, numNodes, false, 0, commands.ExpectSuccess)
fmt.Println(output)
gomega.Expect(output).To(gomega.ContainSubstring("AvalancheGo and Avalanche-CLI installed and node(s) are bootstrapping!"))
// parse hostName
re := regexp.MustCompile(`Generated staking keys for host (\S+)\[NodeID-(\S+)\]`)
match := re.FindStringSubmatch(output)
if len(match) >= 3 {
hostName = match[1]
NodeID = fmt.Sprintf("NodeID-%s", match[2])
} else {
ginkgo.Fail("failed to parse hostName and NodeID")
}
})
ginkgo.It("creates cluster config", func() {
usr, err := user.Current()
gomega.Expect(err).Should(gomega.BeNil())
homeDir := usr.HomeDir
content, err := os.ReadFile(filepath.Join(homeDir, constants.BaseDirName, nodesRelativePath, constants.ClustersConfigFileName))
gomega.Expect(err).Should(gomega.BeNil())
clustersConfig := models.ClustersConfig{}
err = json.Unmarshal(content, &clustersConfig)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(clustersConfig.Clusters).To(gomega.HaveLen(1))
gomega.Expect(clustersConfig.Clusters[constants.E2EClusterName].External).To(gomega.BeFalse())
gomega.Expect(clustersConfig.Clusters[constants.E2EClusterName].Network.Kind.String()).To(gomega.Equal(networkCapitalized))
gomega.Expect(clustersConfig.Clusters[constants.E2EClusterName].Nodes).To(gomega.HaveLen(numNodes))
})
ginkgo.It("creates node config", func() {
fmt.Println("HostName: ", hostName)
usr, err := user.Current()
gomega.Expect(err).Should(gomega.BeNil())
homeDir := usr.HomeDir
content, err := os.ReadFile(filepath.Join(homeDir, constants.BaseDirName, nodesRelativePath, hostName, "node_cloud_config.json"))
gomega.Expect(err).Should(gomega.BeNil())
nodeCloudConfig := models.NodeConfig{}
err = json.Unmarshal(content, &nodeCloudConfig)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(nodeCloudConfig.NodeID).To(gomega.Equal(hostName))
gomega.Expect(nodeCloudConfig.ElasticIP).To(gomega.ContainSubstring(constants.E2ENetworkPrefix))
gomega.Expect(nodeCloudConfig.CertPath).To(gomega.ContainSubstring(homeDir))
gomega.Expect(nodeCloudConfig.UseStaticIP).To(gomega.Equal(false))
})
ginkgo.It("installs and runs avalanchego", func() {
avalancegoProcess := commands.NodeSSH(constants.E2EClusterName, "ps -elf")
gomega.Expect(avalancegoProcess).To(gomega.ContainSubstring("/home/ubuntu/avalanche-node/avalanchego"))
})
ginkgo.It("installs latest version of avalanchego", func() {
avalanchegoVersionClean := strings.TrimPrefix(avalanchegoVersion, "v")
avalancegoVersion := commands.NodeSSH(constants.E2EClusterName, "/home/ubuntu/avalanche-node/avalanchego --version")
gomega.Expect(avalancegoVersion).To(gomega.ContainSubstring("go="))
gomega.Expect(avalancegoVersion).To(gomega.ContainSubstring("avalanchego/" + avalanchegoVersionClean))
})
ginkgo.It("configured avalanchego", func() {
avalancegoConfig := commands.NodeSSH(constants.E2EClusterName, "cat /home/ubuntu/.avalanchego/configs/node.json")
gomega.Expect(avalancegoConfig).To(gomega.ContainSubstring("\"network-id\": \"" + network + "\""))
gomega.Expect(avalancegoConfig).To(gomega.ContainSubstring("public-ip"))
avalancegoConfigCChain := commands.NodeSSH(constants.E2EClusterName, "cat /home/ubuntu/.avalanchego/configs/chains/C/config.json")
gomega.Expect(avalancegoConfigCChain).To(gomega.ContainSubstring("\"state-sync-enabled\": true"))
})
ginkgo.It("can get cluster status", func() {
output := commands.NodeStatus()
fmt.Println(output)
gomega.Expect(output).To(gomega.ContainSubstring("Checking if node(s) are bootstrapped to Primary Network"))
gomega.Expect(output).To(gomega.ContainSubstring("Checking if node(s) are healthy"))
gomega.Expect(output).To(gomega.ContainSubstring("Getting avalanchego version of node(s)"))
gomega.Expect(output).To(gomega.ContainSubstring(constants.E2ENetworkPrefix))
gomega.Expect(output).To(gomega.ContainSubstring(hostName))
gomega.Expect(output).To(gomega.ContainSubstring(NodeID))
gomega.Expect(output).To(gomega.ContainSubstring(networkCapitalized))
})
ginkgo.It("can ssh to a created node", func() {
output := commands.NodeSSH(constants.E2EClusterName, "echo hello")
gomega.Expect(output).To(gomega.ContainSubstring("hello"))
})
ginkgo.It("can list created nodes", func() {
output := commands.NodeList()
fmt.Println(output)
gomega.Expect(output).To(gomega.ContainSubstring(networkCapitalized))
gomega.Expect(output).To(gomega.ContainSubstring("docker1"))
gomega.Expect(output).To(gomega.ContainSubstring("NodeID"))
gomega.Expect(output).To(gomega.ContainSubstring(constants.E2ENetworkPrefix))
})
ginkgo.It("logged operations", func() {
logs := commands.NodeSSH(constants.E2EClusterName, "cat /home/ubuntu/.avalanchego/logs/main.log")
gomega.Expect(logs).To(gomega.ContainSubstring("initializing node"))
gomega.Expect(logs).To(gomega.ContainSubstring("initializing API server"))
gomega.Expect(logs).To(gomega.ContainSubstring("creating leveldb"))
gomega.Expect(logs).To(gomega.ContainSubstring("initializing database"))
gomega.Expect(logs).To(gomega.ContainSubstring("creating proposervm wrapper"))
gomega.Expect(logs).To(gomega.ContainSubstring("check started passing"))
})
ginkgo.It("can upgrade the nodes", func() {
output := commands.NodeUpgrade()
fmt.Println(output)
gomega.Expect(output).To(gomega.ContainSubstring("Upgrading Avalanche Go"))
latestAvagoVersion := strings.TrimPrefix(commands.GetLatestAvagoVersionFromGithub(), "v")
avalanchegoVersion := commands.NodeSSH(constants.E2EClusterName, "/home/ubuntu/avalanche-node/avalanchego --version")
gomega.Expect(avalanchegoVersion).To(gomega.ContainSubstring("go="))
gomega.Expect(avalanchegoVersion).To(gomega.ContainSubstring("avalanchego/" + latestAvagoVersion))
})
ginkgo.It("can whitelist ssh", func() {
output := commands.NodeWhitelistSSH("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC test@localhost")
fmt.Println(output)
gomega.Expect(output).To(gomega.ContainSubstring("Whitelisted SSH public key"))
authorizedFile := commands.NodeSSH(constants.E2EClusterName, "cat /home/ubuntu/.ssh/authorized_keys")
gomega.Expect(authorizedFile).To(gomega.ContainSubstring("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC test@localhost"))
})
ginkgo.It("can export cluster config", func() {
const fileNameWithSecrets = "e2e_with_secrets.json"
output := commands.NodeExport(exportFileName, false)
fmt.Println(output)
gomega.Expect(output).To(gomega.ContainSubstring(fmt.Sprintf("exported cluster [%s] configuration", constants.E2EClusterName)))
gomega.Expect(output).To(gomega.ContainSubstring(fmt.Sprintf("to %s", exportFileName)))
exportFile, err := utils.ReadFile(exportFileName)
gomega.Expect(err).Should(gomega.BeNil())
fmt.Println(exportFile)
content, err := os.ReadFile(exportFileName)
gomega.Expect(err).Should(gomega.BeNil())
exportCluster := models.ExportCluster{}
err = json.Unmarshal(content, &exportCluster)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exportCluster.Nodes).To(gomega.HaveLen(1))
gomega.Expect(exportCluster.Nodes[0].NodeConfig.NodeID).To(gomega.Equal(hostName))
gomega.Expect(exportCluster.Nodes[0].NodeConfig.ElasticIP).To(gomega.ContainSubstring(constants.E2ENetworkPrefix))
gomega.Expect(exportCluster.Nodes[0].StakerCrt).To(gomega.Not(gomega.BeEmpty()))
gomega.Expect(exportCluster.Nodes[0].SignerKey).To(gomega.BeEmpty())
gomega.Expect(exportCluster.Nodes[0].StakerKey).To(gomega.BeEmpty())
gomega.Expect(exportCluster.ClusterConfig.External).To(gomega.BeTrue())
// export with secrets now
output = commands.NodeExport(fileNameWithSecrets, true)
fmt.Println(output)
content, err = os.ReadFile(fileNameWithSecrets)
gomega.Expect(err).Should(gomega.BeNil())
exportCluster = models.ExportCluster{}
err = json.Unmarshal(content, &exportCluster)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(exportCluster.Nodes).To(gomega.HaveLen(1))
gomega.Expect(exportCluster.Nodes[0].StakerCrt).To(gomega.Not(gomega.BeEmpty()))
gomega.Expect(exportCluster.Nodes[0].SignerKey).To(gomega.Not(gomega.BeEmpty()))
gomega.Expect(exportCluster.Nodes[0].StakerKey).To(gomega.Not(gomega.BeEmpty()))
})
ginkgo.It("can import cluster config", func() {
// prepare to reimport the same cluster in different name
commands.DeleteNode(hostName)
commands.DeleteE2EInventory()
// ready to import
output := commands.NodeImport(exportFileName, importClusterName)
fmt.Println(output)
gomega.Expect(output).To(gomega.ContainSubstring(fmt.Sprintf("cluster [%s] imported successfully", importClusterName)))
// check if the cluster is imported now
})
ginkgo.It("imported cluster config", func() {
usr, err := user.Current()
gomega.Expect(err).Should(gomega.BeNil())
homeDir := usr.HomeDir
content, err := os.ReadFile(filepath.Join(homeDir, constants.BaseDirName, nodesRelativePath, constants.ClustersConfigFileName))
gomega.Expect(err).Should(gomega.BeNil())
clustersConfig := models.ClustersConfig{}
err = json.Unmarshal(content, &clustersConfig)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(clustersConfig.Clusters).To(gomega.HaveLen(2))
gomega.Expect(clustersConfig.Clusters[importClusterName].External).To(gomega.BeTrue())
gomega.Expect(clustersConfig.Clusters[importClusterName].Network.Kind.String()).To(gomega.Equal(networkCapitalized))
gomega.Expect(clustersConfig.Clusters[importClusterName].Nodes).To(gomega.HaveLen(numNodes))
})
ginkgo.It("imported node config", func() {
fmt.Println("HostName: ", hostName)
usr, err := user.Current()
gomega.Expect(err).Should(gomega.BeNil())
homeDir := usr.HomeDir
content, err := os.ReadFile(filepath.Join(homeDir, constants.BaseDirName, nodesRelativePath, hostName, "node_cloud_config.json"))
gomega.Expect(err).Should(gomega.BeNil())
nodeCloudConfig := models.NodeConfig{}
err = json.Unmarshal(content, &nodeCloudConfig)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(nodeCloudConfig.NodeID).To(gomega.Equal(hostName))
gomega.Expect(nodeCloudConfig.ElasticIP).To(gomega.ContainSubstring(constants.E2ENetworkPrefix))
gomega.Expect(nodeCloudConfig.CertPath).To(gomega.BeEmpty())
gomega.Expect(nodeCloudConfig.KeyPair).To(gomega.BeEmpty())
gomega.Expect(nodeCloudConfig.SecurityGroup).To(gomega.BeEmpty())
gomega.Expect(nodeCloudConfig.UseStaticIP).To(gomega.Equal(false))
})
ginkgo.It("can cleanup", func() {
commands.DeleteE2EInventory()
commands.DeleteE2ECluster()
commands.DeleteNode(hostName)
})
})