Skip to content

Commit

Permalink
roachtest: run workload from the tenant node
Browse files Browse the repository at this point in the history
The secure URL refers to paths on disk on the clusters in the
node. Since we only create the tenant-scoped certs on the tenant node,
we need to run workload from that node.

Fixes cockroachdb#82266
Depends on cockroachdb#83703

Release note: None
  • Loading branch information
stevendanna authored and abarganier committed Jul 19, 2022
1 parent 6325616 commit 02b3c97
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/registry/owners.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ const (
OwnerStorage Owner = `storage`
OwnerTestEng Owner = `test-eng`
OwnerDevInf Owner = `dev-inf`
OwnerMultiTenant Owner = `multi-tenant`
)
12 changes: 7 additions & 5 deletions pkg/cmd/roachtest/tests/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ func registerAcceptance(r registry.Registry) {
encryptionSupport: registry.EncryptionAlwaysDisabled,
},
{name: "gossip/locality-address", fn: runCheckLocalityIPAddress},
{
name: "multitenant",
minVersion: "v20.2.0", // multitenancy is introduced in this cycle
fn: runAcceptanceMultitenant,
},
{name: "reset-quorum", fn: runResetQuorum, numNodes: 8},
{
name: "many-splits", fn: runManySplits,
Expand All @@ -65,6 +60,13 @@ func registerAcceptance(r registry.Registry) {
timeout: 30 * time.Minute,
},
},
registry.OwnerMultiTenant: {
{
name: "multitenant",
skip: "https://github.com/cockroachdb/cockroach/issues/81506",
fn: runAcceptanceMultitenant,
},
},
registry.OwnerServer: {
{name: "build-info", fn: RunBuildInfo},
{name: "build-analyze", fn: RunBuildAnalyze},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/roachtest/tests/multitenant_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func registerMultiTenantUpgrade(r registry.Registry) {
r.Add(registry.TestSpec{
Name: "multitenant-upgrade",
Cluster: r.MakeClusterSpec(2),
Owner: registry.OwnerKV,
Owner: registry.OwnerMultiTenant,
NonReleaseBlocker: false,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
runMultiTenantUpgrade(ctx, t, c, *t.BuildVersion())
Expand Down
48 changes: 48 additions & 0 deletions pkg/cmd/roachtest/tests/smoketest_secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ package tests

import (
"context"
gosql "database/sql"
"fmt"

"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
"github.com/cockroachdb/cockroach/pkg/roachprod/install"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/stretchr/testify/require"
)

Expand All @@ -40,4 +42,50 @@ func registerSecure(r registry.Registry) {
},
})
}
r.Add(registry.TestSpec{
Name: "smoketest/secure/multitenant",
Owner: registry.OwnerMultiTenant,
Cluster: r.MakeClusterSpec(2),
Run: multitenantSmokeTest,
})
}

// multitenantSmokeTest verifies that a secure sql pod can connect to kv server
// and that tenant is is properly transmitted via cert.
func multitenantSmokeTest(ctx context.Context, t test.Test, c cluster.Cluster) {
c.Put(ctx, t.Cockroach(), "./cockroach")
settings := install.MakeClusterSettings(install.SecureOption(true))
c.Start(ctx, t.L(), option.DefaultStartOpts(), settings, c.Node(1))

// make sure connections to kvserver work
db := c.Conn(ctx, t.L(), 1)
defer db.Close()
_, err := db.QueryContext(ctx, `SELECT 1`)
require.NoError(t, err)

tenID := 11
ten := createTenantNode(ctx, t, c, c.Node(1), tenID, 2, 8011, 9011)
runner := sqlutils.MakeSQLRunner(c.Conn(ctx, t.L(), 1))
runner.Exec(t, `SELECT crdb_internal.create_tenant($1)`, tenID)
ten.start(ctx, t, c, "./cockroach")

// this doesn't work yet, roachprod knows nothing about tenants
// db = c.Conn(ctx, t.L(), 2)
// defer db.Close()

tdb, err := gosql.Open("postgres", ten.pgURL)
require.NoError(t, err)
_, err = tdb.QueryContext(ctx, `SELECT 1`)
require.NoError(t, err)

// init kv and check new database was done right
cmd := fmt.Sprintf("./cockroach workload init kv '%s'", ten.secureURL())
err = c.RunE(ctx, c.Node(2), cmd)
require.NoError(t, err)

sqlutils.MakeSQLRunner(db).CheckQueryResultsRetry(t, fmt.Sprintf(`
SELECT count(*) > 0
FROM crdb_internal.ranges
WHERE start_pretty LIKE '/Tenant/%d/%%';
`, tenID), [][]string{{"true"}})
}

0 comments on commit 02b3c97

Please sign in to comment.