-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for default Python bundle initialization
- Loading branch information
Showing
10 changed files
with
638 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package bundle_test | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/databricks/cli/integration/internal/acc" | ||
"github.com/databricks/cli/internal/testcli" | ||
"github.com/databricks/cli/internal/testutil" | ||
"github.com/databricks/cli/libs/python/pythontest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var pythonVersions = []string{ | ||
"3.8", | ||
"3.9", | ||
"3.10", | ||
"3.11", | ||
"3.12", | ||
"3.13", | ||
} | ||
|
||
var pythonVersionsShort = []string{ | ||
"3.9", | ||
"3.12", | ||
} | ||
|
||
var extraInstalls = map[string][]string{ | ||
"3.12": {"setuptools"}, | ||
"3.13": {"setuptools"}, | ||
} | ||
|
||
func TestDefaultPython(t *testing.T) { | ||
versions := pythonVersions | ||
if testing.Short() { | ||
versions = pythonVersionsShort | ||
} | ||
|
||
for _, pythonVersion := range versions { | ||
t.Run(pythonVersion, func(t *testing.T) { | ||
testDefaultPython(t, pythonVersion) | ||
}) | ||
} | ||
} | ||
|
||
func testDefaultPython(t *testing.T, pythonVersion string) { | ||
ctx, wt := acc.WorkspaceTest(t) | ||
|
||
uniqueProjectId := testutil.RandomName("") | ||
ctx, replacements := testcli.WithReplacementsMap(ctx) | ||
replacements.Set(uniqueProjectId, "$UNIQUE_PRJ") | ||
|
||
testcli.PrepareReplacements(t, replacements, wt.W) | ||
|
||
user, err := wt.W.CurrentUser.Me(ctx) | ||
require.NoError(t, err) | ||
if user != nil { | ||
testcli.PrepareReplacementsUser(t, replacements, *user) | ||
} | ||
|
||
tmpDir1 := pythontest.RequirePythonVENV(t, ctx, pythonVersion, true) | ||
extras, ok := extraInstalls[pythonVersion] | ||
if ok { | ||
args := append([]string{"pip", "install"}, extras...) | ||
testutil.RunCommand(t, "uv", args...) | ||
} | ||
|
||
projectName := "project_name_" + uniqueProjectId | ||
|
||
initConfig := map[string]string{ | ||
"project_name": projectName, | ||
"include_notebook": "yes", | ||
"include_python": "yes", | ||
"include_dlt": "yes", | ||
} | ||
b, err := json.Marshal(initConfig) | ||
require.NoError(t, err) | ||
err = os.WriteFile(filepath.Join(tmpDir1, "config.json"), b, 0o644) | ||
require.NoError(t, err) | ||
|
||
testcli.RequireOutput(t, ctx, []string{"bundle", "init", "default-python", "--config-file", "config.json"}, "testdata/default_python/bundle_init.txt") | ||
testutil.Chdir(t, projectName) | ||
|
||
testcli.RequireOutput(t, ctx, []string{"bundle", "validate"}, "testdata/default_python/bundle_validate.txt") | ||
|
||
testcli.RequireOutput(t, ctx, []string{"bundle", "deploy"}, "testdata/default_python/bundle_deploy.txt") | ||
t.Cleanup(func() { | ||
// Delete the stack | ||
testcli.RequireSuccessfulRun(t, ctx, "bundle", "destroy", "--auto-approve") | ||
}) | ||
|
||
ignoredFields := []string{ | ||
"/resources/jobs/project_name_$UNIQUE_PRJ_job/email_notifications", | ||
"/resources/jobs/project_name_$UNIQUE_PRJ_job/job_clusters/0/new_cluster/node_type_id", | ||
"/resources/jobs/project_name_$UNIQUE_PRJ_job/url", | ||
"/resources/pipelines/project_name_$UNIQUE_PRJ_pipeline/catalog", | ||
"/resources/pipelines/project_name_$UNIQUE_PRJ_pipeline/url", | ||
"/workspace/current_user/externalId", | ||
"/workspace/current_user/groups", | ||
"/workspace/current_user/name/familyName", | ||
} | ||
|
||
testcli.RequireOutputJQ(t, ctx, []string{"bundle", "summary", "--output", "json"}, "testdata/default_python/bundle_summary.txt", ignoredFields) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Building project_name_$UNIQUE_PRJ... | ||
Uploading project_name_$UNIQUE_PRJ-0.0.1+<NUMID>.<NUMID>-py3-none-any.whl... | ||
Uploading bundle files to /Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/files... | ||
Deploying resources... | ||
Updating deployment state... | ||
Deployment complete! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
Welcome to the default Python template for Databricks Asset Bundles! | ||
Workspace to use (auto-detected, edit in 'project_name_$UNIQUE_PRJ/databricks.yml'): https://$DATABRICKS_HOST | ||
|
||
✨ Your new project has been created in the 'project_name_$UNIQUE_PRJ' directory! | ||
|
||
Please refer to the README.md file for "getting started" instructions. | ||
See also the documentation at https://docs.databricks.com/dev-tools/bundles/index.html. |
185 changes: 185 additions & 0 deletions
185
integration/bundle/testdata/default_python/bundle_summary.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
{ | ||
"bundle": { | ||
"name": "project_name_$UNIQUE_PRJ", | ||
"target": "dev", | ||
"environment": "dev", | ||
"terraform": { | ||
"exec_path": "/tmp/.../terraform" | ||
}, | ||
"git": { | ||
"bundle_root_path": ".", | ||
"inferred": true | ||
}, | ||
"mode": "development", | ||
"deployment": { | ||
"lock": { | ||
"enabled": false | ||
} | ||
} | ||
}, | ||
"include": [ | ||
"resources/project_name_$UNIQUE_PRJ.job.yml", | ||
"resources/project_name_$UNIQUE_PRJ.pipeline.yml" | ||
], | ||
"workspace": { | ||
"host": "https://$DATABRICKS_HOST", | ||
"current_user": { | ||
"active": true, | ||
"displayName": "$USERNAME", | ||
"emails": [ | ||
{ | ||
"primary": true, | ||
"type": "work", | ||
"value": "$USERNAME" | ||
} | ||
], | ||
"groups": [ | ||
{ | ||
"$ref": "Groups/$USER.Groups[0]", | ||
"display": "team.engineering", | ||
"type": "direct", | ||
"value": "$USER.Groups[0]" | ||
} | ||
], | ||
"id": "$USER.Id", | ||
"name": { | ||
"familyName": "$USERNAME", | ||
"givenName": "$USERNAME" | ||
}, | ||
"schemas": [ | ||
"urn:ietf:params:scim:schemas:core:2.0:User", | ||
"urn:ietf:params:scim:schemas:extension:workspace:2.0:User" | ||
], | ||
"short_name": "$USERNAME", | ||
"userName": "$USERNAME" | ||
}, | ||
"root_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev", | ||
"file_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/files", | ||
"resource_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/resources", | ||
"artifact_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/artifacts", | ||
"state_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/state" | ||
}, | ||
"resources": { | ||
"jobs": { | ||
"project_name_$UNIQUE_PRJ_job": { | ||
"deployment": { | ||
"kind": "BUNDLE", | ||
"metadata_file_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/state/metadata.json" | ||
}, | ||
"edit_mode": "UI_LOCKED", | ||
"email_notifications": { | ||
"on_failure": [ | ||
"$USERNAME" | ||
] | ||
}, | ||
"format": "MULTI_TASK", | ||
"id": "<NUMID>", | ||
"job_clusters": [ | ||
{ | ||
"job_cluster_key": "job_cluster", | ||
"new_cluster": { | ||
"autoscale": { | ||
"max_workers": 4, | ||
"min_workers": 1 | ||
}, | ||
"node_type_id": "i3.xlarge", | ||
"spark_version": "15.4.x-scala2.12" | ||
} | ||
} | ||
], | ||
"max_concurrent_runs": 4, | ||
"name": "[dev $USERNAME] project_name_$UNIQUE_PRJ_job", | ||
"queue": { | ||
"enabled": true | ||
}, | ||
"tags": { | ||
"dev": "$USERNAME" | ||
}, | ||
"tasks": [ | ||
{ | ||
"job_cluster_key": "job_cluster", | ||
"notebook_task": { | ||
"notebook_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/files/src/notebook" | ||
}, | ||
"task_key": "notebook_task" | ||
}, | ||
{ | ||
"depends_on": [ | ||
{ | ||
"task_key": "notebook_task" | ||
} | ||
], | ||
"pipeline_task": { | ||
"pipeline_id": "${resources.pipelines.project_name_$UNIQUE_PRJ_pipeline.id}" | ||
}, | ||
"task_key": "refresh_pipeline" | ||
}, | ||
{ | ||
"depends_on": [ | ||
{ | ||
"task_key": "refresh_pipeline" | ||
} | ||
], | ||
"job_cluster_key": "job_cluster", | ||
"libraries": [ | ||
{ | ||
"whl": "dist/*.whl" | ||
} | ||
], | ||
"python_wheel_task": { | ||
"entry_point": "main", | ||
"package_name": "project_name_$UNIQUE_PRJ" | ||
}, | ||
"task_key": "main_task" | ||
} | ||
], | ||
"trigger": { | ||
"pause_status": "PAUSED", | ||
"periodic": { | ||
"interval": 1, | ||
"unit": "DAYS" | ||
} | ||
}, | ||
"url": "https://$DATABRICKS_HOST/jobs/<NUMID>?o=<NUMID>" | ||
} | ||
}, | ||
"pipelines": { | ||
"project_name_$UNIQUE_PRJ_pipeline": { | ||
"catalog": "main", | ||
"configuration": { | ||
"bundle.sourcePath": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/files/src" | ||
}, | ||
"deployment": { | ||
"kind": "BUNDLE", | ||
"metadata_file_path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/state/metadata.json" | ||
}, | ||
"development": true, | ||
"id": "<UUID>", | ||
"libraries": [ | ||
{ | ||
"notebook": { | ||
"path": "/Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev/files/src/dlt_pipeline" | ||
} | ||
} | ||
], | ||
"name": "[dev $USERNAME] project_name_$UNIQUE_PRJ_pipeline", | ||
"target": "project_name_$UNIQUE_PRJ_dev", | ||
"url": "https://$DATABRICKS_HOST/pipelines/<UUID>?o=<NUMID>" | ||
} | ||
} | ||
}, | ||
"sync": { | ||
"paths": [ | ||
"." | ||
] | ||
}, | ||
"presets": { | ||
"name_prefix": "[dev $USERNAME] ", | ||
"pipelines_development": true, | ||
"trigger_pause_status": "PAUSED", | ||
"jobs_max_concurrent_runs": 4, | ||
"tags": { | ||
"dev": "$USERNAME" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
integration/bundle/testdata/default_python/bundle_validate.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Name: project_name_$UNIQUE_PRJ | ||
Target: dev | ||
Workspace: | ||
Host: https://$DATABRICKS_HOST | ||
User: $USERNAME | ||
Path: /Workspace/Users/$USERNAME/.bundle/project_name_$UNIQUE_PRJ/dev | ||
|
||
Validation OK! |
Oops, something went wrong.