Skip to content

Commit

Permalink
[Automated] Merged refs/heads/k8s-sync-2024-11-20-1416-e2dcd49aaa474b…
Browse files Browse the repository at this point in the history
…70865f6c51424d3237b4067440 into target main
  • Loading branch information
github-actions[bot] authored Nov 20, 2024
2 parents 42cf7b5 + 13e80a1 commit cf50448
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
60 changes: 25 additions & 35 deletions commands/user_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
package commands

import (
"crypto/rand"
"fmt"
"log"
"math/big"
"os"
"path/filepath"
"strings"
Expand All @@ -29,12 +27,14 @@ import (
"gopkg.in/yaml.v3"
)

var tempConfigFilePath = os.TempDir() + "/test_vertica_cluster.yaml"
var tempConfigFilePath = filepath.Join(os.TempDir(), "test_vertica_cluster.yaml")

const configRecover = "vcluster manage_config recover --db-name test_db "

const ymlExt, yamlExt = ".yml", ".yaml"

const tmpFilePrefixPattern = "test-*"

func simulateVClusterCli(vclusterCmd string) error {
// if no log file is given, the log will go to stdout
dbOptions.LogPath = ""
Expand All @@ -53,25 +53,6 @@ func simulateVClusterCli(vclusterCmd string) error {
return err
}

func generateRandomString(n int) (string, error) {
const letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
ret := make([]byte, n)
for i := 0; i < n; i++ {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
if err != nil {
return "", err
}
ret[i] = letters[num.Int64()]
}
return string(ret), nil
}

func getRandomFileNameFromTmp(ext string, fileNameLen int) string {
var randomStr, _ = generateRandomString(fileNameLen)
var fileName = randomStr + ext
return filepath.Join(os.TempDir(), fileName)
}

func TestConfigRecover(t *testing.T) {
err := simulateVClusterCli("vcluster manage_config recover")
assert.ErrorContains(t, err, `required flag(s) "catalog-path", "db-name", "hosts" not set`)
Expand Down Expand Up @@ -110,7 +91,8 @@ func TestManageReplication(t *testing.T) {
}

func TestCreateConnectionFileWrongFileType(t *testing.T) {
var tempConnFilePath = getRandomFileNameFromTmp(".txt", 8)
// vertica_connection.txt will not be created and a unique name is not required
var tempConnFilePath = filepath.Join(os.TempDir(), "vertica_connection.txt")
err := simulateVClusterCli("vcluster create_connection --db-name test_db1 --conn " + tempConnFilePath + " --hosts 192.168.1.101")
assert.ErrorContains(t, err, `Invalid file type`)
}
Expand All @@ -122,32 +104,40 @@ func TestCreateConnectionFileAbsolutePathChecking(t *testing.T) {
}

func TestCreateConnectionFileRightFileTypes(t *testing.T) {
var tempConnFilePath = getRandomFileNameFromTmp(yamlExt, 9)
err := simulateVClusterCli("vcluster create_connection --db-name test_db3 --conn " + tempConnFilePath + " --hosts vnode3")
defer os.Remove(tempConnFilePath)
tempFile, err := os.CreateTemp("", tmpFilePrefixPattern+yamlExt)
if tempFile != nil {
defer os.Remove(tempFile.Name())
}
assert.NoError(t, err)

err = simulateVClusterCli("vcluster create_connection --db-name test_db3 --conn " + tempFile.Name() + " --hosts vnode3")
assert.NoError(t, err)

tempConnFilePath = getRandomFileNameFromTmp(ymlExt, 10)
err = simulateVClusterCli("vcluster create_connection --db-name test_db4 --conn " + tempConnFilePath + " --hosts vnode4")
defer os.Remove(tempConnFilePath)
tempFile, err = os.CreateTemp("", tmpFilePrefixPattern+ymlExt)
if tempFile != nil {
defer os.Remove(tempFile.Name())
}
assert.NoError(t, err)
err = simulateVClusterCli("vcluster create_connection --db-name test_db4 --conn " + tempFile.Name() + " --hosts vnode4")
assert.NoError(t, err)
}

func TestCreateConnection(t *testing.T) {
var tempConnFilePath = getRandomFileNameFromTmp(yamlExt, 11)
tempFile, err := os.CreateTemp("", tmpFilePrefixPattern+yamlExt)
assert.NoError(t, err)
os.Remove(tempFile.Name()) // clean up before test starts
dbName := "platform_test_db"
hosts := "192.168.1.101"
os.Remove(tempConnFilePath) // clean up before test starts

// vcluster create_connection should succeed
err := simulateVClusterCli("vcluster create_connection --db-name " + dbName + " --hosts " + hosts +
" --conn " + tempConnFilePath)
err = simulateVClusterCli("vcluster create_connection --db-name " + dbName + " --hosts " + hosts +
" --conn " + tempFile.Name())
defer os.Remove(tempFile.Name()) // It may be possible for the simulate to create the file and return an error
assert.NoError(t, err)

// verify the file content
file, err := os.Open(tempConnFilePath)
file, err := os.Open(tempFile.Name())
assert.NoError(t, err)
defer os.Remove(tempConnFilePath)
defer file.Close()

buf := make([]byte, 1024)
Expand Down
7 changes: 6 additions & 1 deletion vclusterops/https_poll_node_state_indirect_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"github.com/vertica/vcluster/vclusterops/util"
)

// httpsPollNodeStateIndirectOp allows polling for the state of nodes when those nodes certainly
// or possibly cannot be polled directly for their state. For example, compute nodes, or nodes of
// unknown type. Instead of calling the nodes endpoint directly on each host for info about only
// that node, it calls the nodes endpoint for all nodes on a separate slice of hosts (e.g. primary
// UP nodes in the same sandbox) which should know the states of all the nodes being checked.
type httpsPollNodeStateIndirectOp struct {
opBase
opHTTPSBase
Expand Down Expand Up @@ -224,7 +229,7 @@ func (op *httpsPollNodeStateIndirectOp) shouldStopPolling() (bool, error) {
return true, err
}

// check which nodes have COMPUTE status
// check which nodes have desired state, e.g. COMPUTE, UP, etc.
upNodeCount := 0
for _, nodeInfo := range nodesInformation.NodeList {
_, ok := op.checkedHostsToState[nodeInfo.Address]
Expand Down

0 comments on commit cf50448

Please sign in to comment.