Skip to content

Commit c5f44a3

Browse files
address comments and better
1 parent b19c166 commit c5f44a3

File tree

7 files changed

+140
-45
lines changed

7 files changed

+140
-45
lines changed

acceptance/acceptance_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,13 @@ func getSkipReason(config *internal.TestConfig, configPath string) string {
466466
return fmt.Sprintf("Disabled via RequiresCluster setting in %s (TEST_DEFAULT_CLUSTER_ID is empty)", configPath)
467467
}
468468

469+
if isTruePtr(config.RequiresWorkspaceFilesystem) {
470+
isDBR := os.Getenv("DATABRICKS_RUNTIME_VERSION") != ""
471+
if !isDBR || !WorkspaceTmpDir {
472+
return fmt.Sprintf("Disabled via RequiresWorkspaceFilesystem setting in %s (DATABRICKS_RUNTIME_VERSION=%s, WorkspaceTmpDir=%v)", configPath, os.Getenv("DATABRICKS_RUNTIME_VERSION"), WorkspaceTmpDir)
473+
}
474+
}
475+
469476
} else {
470477
// Local run
471478
if !isTruePtr(config.Local) {
@@ -516,7 +523,7 @@ func runTest(t *testing.T,
516523
// If the test is being run on DBR, auth is already configured
517524
// by the dbr_runner notebook by reading a token from the notebook context and
518525
// setting DATABRICKS_TOKEN and DATABRICKS_HOST environment variables.
519-
_, _, tmpDir = workspaceTmpDir(context.Background(), t)
526+
tmpDir = workspaceTmpDir(context.Background(), t)
520527

521528
// Run DBR tests on the workspace file system to mimic usage from
522529
// DABs in the workspace.

acceptance/dbr_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/stretchr/testify/require"
2424
)
2525

26-
func workspaceTmpDir(ctx context.Context, t *testing.T) (*databricks.WorkspaceClient, filer.Filer, string) {
26+
func workspaceTmpDir(ctx context.Context, t *testing.T) string {
2727
w, err := databricks.NewWorkspaceClient()
2828
require.NoError(t, err)
2929

@@ -38,21 +38,17 @@ func workspaceTmpDir(ctx context.Context, t *testing.T) (*databricks.WorkspaceCl
3838
uuid.New().String(),
3939
)
4040

41+
// Create the directory using os.MkdirAll (via FUSE)
42+
err = os.MkdirAll(tmpDir, 0o755)
43+
require.NoError(t, err)
44+
4145
t.Cleanup(func() {
42-
err := w.Workspace.Delete(ctx, workspace.Delete{
43-
Path: tmpDir,
44-
Recursive: true,
45-
})
46+
// Remove the directory using os.RemoveAll (via FUSE)
47+
err := os.RemoveAll(tmpDir)
4648
assert.NoError(t, err)
4749
})
4850

49-
err = w.Workspace.MkdirsByPath(ctx, tmpDir)
50-
require.NoError(t, err)
51-
52-
f, err := filer.NewWorkspaceFilesClient(w, tmpDir)
53-
require.NoError(t, err)
54-
55-
return w, f, tmpDir
51+
return tmpDir
5652
}
5753

5854
// Stable scratch directory to run and iterate on DBR tests.

acceptance/internal/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ type TestConfig struct {
5555
// If true and Cloud=true, run this test only if a default warehouse is available in the cloud environment
5656
RequiresWarehouse *bool
5757

58+
// If true run this test only if running on DBR with workspace filesystem
59+
// Note that this implicitly implies Cloud=true since running on the workspace
60+
// file system is only supported for integration tests.
61+
RequiresWorkspaceFilesystem *bool
62+
5863
// If set, current user will be set to a service principal-like UUID instead of email (default is false)
5964
IsServicePrincipal *bool
6065

acceptance/internal/materialized_config.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@ import (
99
const MaterializedConfigFile = "out.test.toml"
1010

1111
type MaterializedConfig struct {
12-
GOOS map[string]bool `toml:"GOOS,omitempty"`
13-
CloudEnvs map[string]bool `toml:"CloudEnvs,omitempty"`
14-
Local *bool `toml:"Local,omitempty"`
15-
Cloud *bool `toml:"Cloud,omitempty"`
16-
CloudSlow *bool `toml:"CloudSlow,omitempty"`
17-
RequiresUnityCatalog *bool `toml:"RequiresUnityCatalog,omitempty"`
18-
RequiresCluster *bool `toml:"RequiresCluster,omitempty"`
19-
RequiresWarehouse *bool `toml:"RequiresWarehouse,omitempty"`
20-
EnvMatrix map[string][]string `toml:"EnvMatrix,omitempty"`
12+
GOOS map[string]bool `toml:"GOOS,omitempty"`
13+
CloudEnvs map[string]bool `toml:"CloudEnvs,omitempty"`
14+
Local *bool `toml:"Local,omitempty"`
15+
Cloud *bool `toml:"Cloud,omitempty"`
16+
CloudSlow *bool `toml:"CloudSlow,omitempty"`
17+
RequiresUnityCatalog *bool `toml:"RequiresUnityCatalog,omitempty"`
18+
RequiresCluster *bool `toml:"RequiresCluster,omitempty"`
19+
RequiresWarehouse *bool `toml:"RequiresWarehouse,omitempty"`
20+
RequiresWorkspaceFilesystem *bool `toml:"RequiresWorkspaceFilesystem,omitempty"`
21+
EnvMatrix map[string][]string `toml:"EnvMatrix,omitempty"`
2122
}
2223

2324
// GenerateMaterializedConfig creates a TOML representation of the configuration fields
2425
// that determine where and how a test is executed
2526
func GenerateMaterializedConfig(config TestConfig) (string, error) {
2627
materialized := MaterializedConfig{
27-
GOOS: config.GOOS,
28-
CloudEnvs: config.CloudEnvs,
29-
Local: config.Local,
30-
Cloud: config.Cloud,
31-
CloudSlow: config.CloudSlow,
32-
RequiresUnityCatalog: config.RequiresUnityCatalog,
33-
RequiresCluster: config.RequiresCluster,
34-
RequiresWarehouse: config.RequiresWarehouse,
35-
EnvMatrix: config.EnvMatrix,
28+
GOOS: config.GOOS,
29+
CloudEnvs: config.CloudEnvs,
30+
Local: config.Local,
31+
Cloud: config.Cloud,
32+
CloudSlow: config.CloudSlow,
33+
RequiresUnityCatalog: config.RequiresUnityCatalog,
34+
RequiresCluster: config.RequiresCluster,
35+
RequiresWarehouse: config.RequiresWarehouse,
36+
RequiresWorkspaceFilesystem: config.RequiresWorkspaceFilesystem,
37+
EnvMatrix: config.EnvMatrix,
3638
}
3739

3840
var buf bytes.Buffer

acceptance/scratch_dbr_runner.ipynb

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"import tarfile\n",
1111
"from pathlib import Path\n",
1212
"\n",
13+
"\n",
1314
"def extract_cli_archive():\n",
1415
" src = \"archive.tar.gz\"\n",
1516
" dst = Path(\"/tmp/cli_archive\")\n",
@@ -19,6 +20,7 @@
1920
"\n",
2021
" print(f\"Extracted {src} to {dst}\")\n",
2122
"\n",
23+
"\n",
2224
"extract_cli_archive()"
2325
]
2426
},
@@ -46,6 +48,7 @@
4648
"import subprocess\n",
4749
"import multiprocessing\n",
4850
"\n",
51+
"\n",
4952
"class Runner:\n",
5053
" def __init__(self, archive_dir):\n",
5154
" # Load environment variables to set in the test runner.\n",
@@ -73,37 +76,84 @@
7376
" self.terraform_dir = os.getcwd() + \"/terraform\"\n",
7477
"\n",
7578
" def run(self, prefix):\n",
76-
" cmd = [\"go\", \"tool\", \"gotestsum\", \"--format\", \"testname\", \"--no-summary=skipped\", \"--\",\n",
77-
" \"-timeout\", \"7200s\", \"-test.v\", \"-run\", prefix, \"github.com/databricks/cli/acceptance\",\n",
78-
" \"-workspace-tmp-dir\", \"-terraform-dir\", self.terraform_dir, \"-tail\"]\n",
79+
" cmd = [\n",
80+
" \"go\",\n",
81+
" \"tool\",\n",
82+
" \"gotestsum\",\n",
83+
" \"--format\",\n",
84+
" \"testname\",\n",
85+
" \"--no-summary=skipped\",\n",
86+
" \"--\",\n",
87+
" \"-timeout\",\n",
88+
" \"7200s\",\n",
89+
" \"-test.v\",\n",
90+
" \"-run\",\n",
91+
" prefix,\n",
92+
" \"github.com/databricks/cli/acceptance\",\n",
93+
" \"-workspace-tmp-dir\",\n",
94+
" \"-terraform-dir\",\n",
95+
" self.terraform_dir,\n",
96+
" \"-tail\",\n",
97+
" ]\n",
7998
"\n",
8099
" subprocess.run(cmd, env=self.env, check=True, cwd=self.exec_dir)\n",
81100
"\n",
82-
" # Debug helper to run commands and see the output.\n",
101+
" # Debug helper to run commands and see the output.\n",
83102
" def run_script_with_logs(self, name, input_script):\n",
84-
" cmd = [\"go\", \"tool\", \"gotestsum\", \"--format\", \"testname\", \"--no-summary=skipped\", \"--\",\n",
85-
" \"-timeout\", \"7200s\", \"-test.v\", \"-run\", \"TestAccept/\" + name, \"github.com/databricks/cli/acceptance\", \"-workspace-tmp-dir\", \"-terraform-dir\", self.terraform_dir, \"-tail\"]\n",
103+
" cmd = [\n",
104+
" \"go\",\n",
105+
" \"tool\",\n",
106+
" \"gotestsum\",\n",
107+
" \"--format\",\n",
108+
" \"testname\",\n",
109+
" \"--no-summary=skipped\",\n",
110+
" \"--\",\n",
111+
" \"-timeout\",\n",
112+
" \"7200s\",\n",
113+
" \"-test.v\",\n",
114+
" \"-run\",\n",
115+
" \"TestAccept/\" + name,\n",
116+
" \"github.com/databricks/cli/acceptance\",\n",
117+
" \"-workspace-tmp-dir\",\n",
118+
" \"-terraform-dir\",\n",
119+
" self.terraform_dir,\n",
120+
" \"-tail\",\n",
121+
" ]\n",
86122
"\n",
87123
" with open(self.exec_dir / \"acceptance\" / name / \"script\", \"w\") as f:\n",
88124
" f.write(input_script)\n",
89125
"\n",
90126
" subprocess.run(cmd, env=self.env, check=True, cwd=self.exec_dir)\n",
91127
"\n",
92-
" # Debug helper to run commands and see the output.\n",
128+
" # Debug helper to run commands and see the output.\n",
93129
" def run_with_script(self, name, input_script):\n",
94-
" cmd = [\"go\", \"test\",\n",
95-
" \"-timeout\", \"7200s\", \"-test.v\", \"-run\",\"TestAccept/\" + name, \"github.com/databricks/cli/acceptance\", \"-update\", \"-workspace-tmp-dir\", \"-terraform-dir\", self.terraform_dir]\n",
130+
" cmd = [\n",
131+
" \"go\",\n",
132+
" \"test\",\n",
133+
" \"-timeout\",\n",
134+
" \"7200s\",\n",
135+
" \"-test.v\",\n",
136+
" \"-run\",\n",
137+
" \"TestAccept/\" + name,\n",
138+
" \"github.com/databricks/cli/acceptance\",\n",
139+
" \"-update\",\n",
140+
" \"-workspace-tmp-dir\",\n",
141+
" \"-terraform-dir\",\n",
142+
" self.terraform_dir,\n",
143+
" ]\n",
96144
"\n",
97145
" with open(self.exec_dir / \"acceptance\" / name / \"script\", \"w\") as f:\n",
98146
" f.write(input_script)\n",
99147
"\n",
100148
" try:\n",
101-
" subprocess.run(cmd, env=self.env, check=True, cwd=self.exec_dir, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n",
149+
" subprocess.run(\n",
150+
" cmd, env=self.env, check=True, cwd=self.exec_dir, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL\n",
151+
" )\n",
102152
" except subprocess.CalledProcessError:\n",
103153
" pass\n",
104154
"\n",
105155
" with open(self.exec_dir / \"acceptance\" / name / \"output.txt\", \"r\") as f:\n",
106-
" print(f.read())\n"
156+
" print(f.read())"
107157
]
108158
},
109159
{
@@ -114,7 +164,9 @@
114164
"outputs": [],
115165
"source": [
116166
"runner = Runner(\"/tmp/cli_archive\")\n",
117-
"runner.run_with_script(\"bundle/deploy/dashboard/simple_syncroot\", r\"\"\"\n",
167+
"runner.run_with_script(\n",
168+
" \"selftest/dbr\",\n",
169+
" r\"\"\"\n",
118170
"echo \"========================= START OF SCRIPT =====================\"\n",
119171
"DASHBOARD_DISPLAY_NAME=\"test bundle-deploy-dashboard $(uuid)\"\n",
120172
"export DASHBOARD_DISPLAY_NAME\n",
@@ -125,7 +177,8 @@
125177
"\n",
126178
"trace cat databricks.yml\n",
127179
"echo \"========================= END OF SCRIPT =====================\"\n",
128-
"\"\"\")"
180+
"\"\"\",\n",
181+
")"
129182
]
130183
},
131184
{
@@ -139,7 +192,7 @@
139192
"\n",
140193
"# Example:\n",
141194
"runner = Runner(\"/tmp/cli_archive\")\n",
142-
"runner.run(\"TestAccept/bundle/deploy/dashboard/simple_syncroot\")"
195+
"runner.run(\"selftest/dbr\")"
143196
]
144197
}
145198
],

acceptance/selftest/dbr/script

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
printf "=== Verify running on DBR\n"
4+
if [ -z "$DATABRICKS_RUNTIME_VERSION" ]; then
5+
echo "ERROR: DATABRICKS_RUNTIME_VERSION is not set"
6+
exit 1
7+
fi
8+
echo "DATABRICKS_RUNTIME_VERSION is set: $DATABRICKS_RUNTIME_VERSION"
9+
10+
printf "\n=== Verify current directory is on workspace filesystem\n"
11+
trace pwd
12+
13+
current_dir=$(pwd)
14+
if [[ ! "$current_dir" =~ ^/Workspace/Users/ ]]; then
15+
echo "ERROR: Current directory is not in /Workspace/Users/"
16+
echo "Current directory: $current_dir"
17+
exit 1
18+
fi
19+
20+
echo "SUCCESS: Current directory is in workspace filesystem"
21+
22+
printf "\n=== Verify current user matches directory\n"
23+
expected_path="/Workspace/Users/$CURRENT_USER_NAME"
24+
if [[ ! "$current_dir" =~ ^$expected_path ]]; then
25+
echo "ERROR: Current directory does not start with $expected_path"
26+
echo "Current directory: $current_dir"
27+
exit 1
28+
fi
29+
30+
echo "SUCCESS: Current directory is under $expected_path"

acceptance/selftest/dbr/test.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cloud = true
2+
RequiresWorkspaceFilesystem = true

0 commit comments

Comments
 (0)