Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
sukantoraymond committed Aug 23, 2024
1 parent 69f2cb4 commit 5a207c6
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions node/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package node
import (
"context"
"fmt"
"github.com/stretchr/testify/require"

Check failure on line 9 in node/create_test.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)
"testing"
"time"

Check failure on line 11 in node/create_test.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 12 in node/create_test.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
Expand All @@ -15,28 +16,26 @@ import (
"github.com/ava-labs/avalanche-tooling-sdk-go/utils"
)

func TestCreateNodes(_ *testing.T) {
func TestCreateNodes(t *testing.T) {
require := require.New(t)
ctx := context.Background()
// Get the default cloud parameters for AWS
cp, err := GetDefaultCloudParams(ctx, AWSCloud)
if err != nil {
panic(err)
}
require.NoError(err)

securityGroupName := "SECURITY_GROUP_NAME"
sgID, err := awsAPI.CreateSecurityGroup(ctx, securityGroupName, cp.AWSConfig.AWSProfile, cp.Region)
if err != nil {
panic(err)
}
require.NoError(err)

// Set the security group we are using when creating our Avalanche Nodes
cp.AWSConfig.AWSSecurityGroupID = sgID
cp.AWSConfig.AWSSecurityGroupName = securityGroupName

keyPairName := "KEY_PAIR_NAME"
sshPrivateKeyPath := utils.ExpandHome("PRIVATE_KEY_FILEPATH")
if err := awsAPI.CreateSSHKeyPair(ctx, cp.AWSConfig.AWSProfile, cp.Region, keyPairName, sshPrivateKeyPath); err != nil {
panic(err)
}
err = awsAPI.CreateSSHKeyPair(ctx, cp.AWSConfig.AWSProfile, cp.Region, keyPairName, sshPrivateKeyPath)
require.NoError(err)

// Set the key pair we are using when creating our Avalanche Nodes
cp.AWSConfig.AWSKeyPair = keyPairName

Expand Down Expand Up @@ -64,9 +63,7 @@ func TestCreateNodes(_ *testing.T) {
UseStaticIP: false,
SSHPrivateKeyPath: sshPrivateKeyPath,
})
if err != nil {
panic(err)
}
require.NoError(err)

fmt.Println("Successfully created Avalanche Validators")

Expand All @@ -80,20 +77,20 @@ func TestCreateNodes(_ *testing.T) {
// Wait for the host to be ready (only needs to be done once for newly created nodes)
fmt.Println("Waiting for SSH shell")
if err := h.WaitForSSHShell(sshTimeout); err != nil {
panic(err)
require.NoError(err)
}
fmt.Println("SSH shell ready to execute commands")
// Run a command on the host
if output, err := h.Commandf(nil, sshCommandTimeout, "echo 'Hello, %s!'", "World"); err != nil {
panic(err)
require.NoError(err)
} else {
fmt.Println(string(output))
}
// sleep for 10 seconds allowing AvalancheGo container to start
time.Sleep(10 * time.Second)
// check if avalanchego is running
if output, err := h.Commandf(nil, sshCommandTimeout, "docker ps"); err != nil {
panic(err)
require.NoError(err)
} else {
fmt.Println(string(output))
}
Expand All @@ -112,30 +109,23 @@ func TestCreateNodes(_ *testing.T) {
UseStaticIP: false,
SSHPrivateKeyPath: sshPrivateKeyPath,
})
if err != nil {
panic(err)
}
require.NoError(err)

fmt.Println("Successfully created monitoring node")
fmt.Println("Linking monitoring node with Avalanche Validator nodes ...")
// Link the 2 validator nodes previously created with the monitoring host so that
// the monitoring host can start tracking the validator nodes metrics and collecting their logs
if err := monitoringHosts[0].MonitorNodes(ctx, hosts, ""); err != nil {
panic(err)
}
err = monitoringHosts[0].MonitorNodes(ctx, hosts, "")
require.NoError(err)
fmt.Println("Successfully linked monitoring node with Avalanche Validator nodes")

fmt.Println("Terminating all created nodes ...")
// Destroy all created nodes
for _, h := range hosts {
err = h.Destroy(ctx)
if err != nil {
panic(err)
}
require.NoError(err)
}
err = monitoringHosts[0].Destroy(ctx)
if err != nil {
panic(err)
}
require.NoError(err)
fmt.Println("All nodes terminated")
}

0 comments on commit 5a207c6

Please sign in to comment.