Cassandra Connect Support (#5952)

* Init cassandra

* Init cassandra

* Initial Cassandra Command Support For cqlsh

* Add Make Gen

* adding cassandra test

* Cleanup cassandra docker setup

* Adding container wait

* Container restart

* Minor Fix

* Cleanup docker and test

* Adding final tests

* Removing comment

* Fixing cleanup (uncomment)

* Removing bad yaml

* Cleanup

* Cleanup

* Adressing PR review comments

* Adding test support

* fix spacing

* Adding changelog

* docs

* docs

* adding cassandra page

* nav

* Versbose commenting

* cleanup naming of file

* updating helper func to return errors

* doc change

* Removed an incorrect comment and now passing the config by reference.

* Comment cleanup

* Fix option warning in cassandra connect command (#5951)

* Add healthcheck to caller function as it's resposible for container health

* Resolve Comments

* Update Log Typo

---------

Co-authored-by: Bharath Gajjala <120367134+bgajjala8@users.noreply.github.com>
This commit is contained in:
Ryan DerrandBharath Gajjala authored and GitHub committed 2025-07-30 16:21:11 -05:00
1 parent 029aa361bd
commit 4d3cb76c28
10 files changed
+504 -1

No files matched your search

@@ -0,0 +1,127 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package base_test
import (
"bytes"
"context"
"fmt"
"io"
"net/url"
"os/exec"
"testing"
"time"
"github.com/creack/pty"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
"github.com/hashicorp/boundary/testing/internal/e2e/infra"
"github.com/ory/dockertest/v3"
"github.com/stretchr/testify/require"
)
// TestCliTcpTargetConnectCassandra uses the boundary cli to connect to a
// target using `connect cassandra`
func TestCliTcpTargetConnectCassandra(t *testing.T) {
e2e.MaybeSkipTest(t)
pool, err := dockertest.NewPool("")
require.NoError(t, err)
// Increase timeout to accommodate Cassandra's longer startup duration due to gossip needing to settle
pool.MaxWait = 90 * time.Second
ctx := context.Background()
// e2e_cluster network is created by the e2e infra setup
network, err := pool.NetworksByName("e2e_cluster")
require.NoError(t, err, "Failed to get e2e_cluster network")
c := infra.StartCassandra(t, pool, &network[0], "cassandra", "latest")
require.NotNil(t, c, "Cassandra container should not be nil")
t.Cleanup(func() {
if err := pool.Purge(c.Resource); err != nil {
t.Logf("Failed to purge Cassandra container: %v", err)
}
})
u, err := url.Parse(c.UriNetwork)
t.Log(u)
require.NoError(t, err, "Failed to parse Cassandra URL")
user, hostname, port, keyspace := u.User.Username(), u.Hostname(), u.Port(), u.Path[1:]
pw, pwSet := u.User.Password()
t.Logf("Cassandra info: user=%s, keyspace=%s, host=%s, port=%s, password-set:%t",
user, keyspace, hostname, port, pwSet)
boundary.AuthenticateAdminCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(
t,
ctx,
projectId,
port,
target.WithAddress(hostname),
)
require.NoError(t, err)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
credentialId, err := boundary.CreateStaticCredentialPasswordCli(
t,
ctx,
storeId,
user,
pw,
)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, credentialId)
require.NoError(t, err)
cmd := exec.CommandContext(ctx,
"boundary",
"connect", "cassandra",
"-target-id", targetId,
"-keyspace", keyspace,
)
f, err := pty.Start(cmd)
require.NoError(t, err)
t.Cleanup(func() {
err := f.Close()
require.NoError(t, err)
})
_, err = f.Write([]byte("DESCRIBE KEYSPACES;\n"))
require.NoError(t, err)
_, err = f.Write([]byte(fmt.Sprintf("SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name = '%s';\n", keyspace)))
require.NoError(t, err)
_, err = f.Write([]byte("exit\n"))
require.NoError(t, err)
var buf bytes.Buffer
_, _ = io.Copy(&buf, f)
output := buf.String()
t.Logf("Cassandra session output: %s", output)
require.Contains(t, output, "keyspace_name")
require.Contains(t, output, keyspace)
t.Log("Successfully connected to Cassandra target")
}