Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bundle:
name: dashboards

workspace:
root_path: ~/.bundle/$UNIQUE_NAME

resources:
dashboards:
file_reference:
display_name: test-dashboard-$UNIQUE_NAME
file_path: ./dashboard.lvdash.json
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
56 changes: 56 additions & 0 deletions acceptance/bundle/deploy/dashboard/detect-change/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

=== Assert that the dashboard exists at the expected path and is, indeed, a dashboard:
>>> [CLI] workspace get-status /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/resources/test-dashboard-[UNIQUE_NAME].lvdash.json
{
"object_type": "DASHBOARD",
"path": "/Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/resources/test-dashboard-[UNIQUE_NAME].lvdash.json"
}

=== Load the dashboard by its ID and confirm its display name: {
"display_name": "test-dashboard-[UNIQUE_NAME]",
"serialized_dashboard": "{\"pages\":[{\"name\":\"fdd21a3c\",\"displayName\":\"New Page\",\"layout\":[{\"widget\":{\"name\":\"82eb9107\",\"textbox_spec\":\"# I'm a title\"},\"position\":{\"x\":0,\"y\":0,\"width\":6,\"height\":2}},{\"widget\":{\"name\":\"ffa6de4f\",\"textbox_spec\":\"Text\"},\"position\":{\"x\":0,\"y\":2,\"width\":6,\"height\":2}}],\"pageType\":\"PAGE_TYPE_CANVAS\"}]}"
}

=== Make an out of band modification to the dashboard and confirm that it is detected:
{
"lifecycle_state": "ACTIVE"
}

=== Try to redeploy the bundle and confirm that the out of band modification is detected:
>>> errcode [CLI] bundle deploy
Error: dashboard "file_reference" has been modified remotely
at resources.dashboards.file_reference
in databricks.yml:10:7

This dashboard has been modified remotely since the last bundle deployment.
These modifications are untracked and will be overwritten on deploy.

Make sure that the local dashboard definition matches what you intend to deploy
before proceeding with the deployment.

Run `databricks bundle deploy --force` to bypass this error.


Exit code: 1

=== Redeploy the bundle with the --force flag and confirm that the out of band modification is ignored:
>>> errcode [CLI] bundle deploy --force
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete dashboard file_reference

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]

Deleting files...
Destroy complete!
28 changes: 28 additions & 0 deletions acceptance/bundle/deploy/dashboard/detect-change/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
envsubst < databricks.yml.tmpl > databricks.yml

cleanup() {
trace $CLI bundle destroy --auto-approve
}
trap cleanup EXIT

trace $CLI bundle deploy

title "Assert that the dashboard exists at the expected path and is, indeed, a dashboard:"
RESOURCE_PATH=$($CLI bundle validate -o json | jq -r '.workspace.resource_path')
DASHBOARD_PATH="${RESOURCE_PATH}/test-dashboard-${UNIQUE_NAME}.lvdash.json"
trace $CLI workspace get-status "${DASHBOARD_PATH}" | jq '{object_type,path}'

title "Load the dashboard by its ID and confirm its display name: "
DASHBOARD_ID=$($CLI bundle summary --output json | jq -r '.resources.dashboards.file_reference.id')
$CLI lakeview get $DASHBOARD_ID | jq '{display_name,serialized_dashboard}'

title "Make an out of band modification to the dashboard and confirm that it is detected:\n"
RESOURCE_ID=$($CLI workspace get-status "${DASHBOARD_PATH}" | jq -r '.resource_id')
DASHBOARD_JSON=$($CLI bundle summary --output json | jq '{serialized_dashboard: .resources.dashboards.file_reference.serialized_dashboard}')
$CLI lakeview update "${RESOURCE_ID}" --json "${DASHBOARD_JSON}" | jq '{lifecycle_state}'

title "Try to redeploy the bundle and confirm that the out of band modification is detected:"
trace errcode $CLI bundle deploy

title "Redeploy the bundle with the --force flag and confirm that the out of band modification is ignored:"
trace errcode $CLI bundle deploy --force
16 changes: 16 additions & 0 deletions acceptance/bundle/deploy/dashboard/detect-change/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Local = false
Cloud = true

Ignore = [
"databricks.yml",
]

[Env]
# MSYS2 automatically converts absolute paths like /Users/$username/$UNIQUE_NAME to
# C:/Program Files/Git/Users/$username/UNIQUE_NAME before passing it to the CLI
# Setting this environment variable prevents that conversion on windows.
MSYS_NO_PATHCONV = "1"

[[Repls]]
Old = "[0-9a-z]{16,}"
New = "[ALPHANUMID]"

This file was deleted.

12 changes: 0 additions & 12 deletions integration/bundle/bundles/dashboards/template/databricks.yml.tmpl

This file was deleted.

62 changes: 0 additions & 62 deletions integration/bundle/dashboards_test.go

This file was deleted.

28 changes: 0 additions & 28 deletions integration/bundle/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/internal/testcli"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/cli/libs/cmdctx"
Expand Down Expand Up @@ -72,40 +71,13 @@ func validateBundle(t testutil.TestingT, ctx context.Context, path string) ([]by
return stdout.Bytes(), err
}

func mustValidateBundle(t testutil.TestingT, ctx context.Context, path string) []byte {
data, err := validateBundle(t, ctx, path)
require.NoError(t, err)
return data
}

func unmarshalConfig(t testutil.TestingT, data []byte) *bundle.Bundle {
bundle := &bundle.Bundle{}
err := json.Unmarshal(data, &bundle.Config)
require.NoError(t, err)
return bundle
}

func deployBundle(t testutil.TestingT, ctx context.Context, path string) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
c := testcli.NewRunner(t, ctx, "bundle", "deploy", "--force-lock", "--auto-approve")
_, _, err := c.Run()
require.NoError(t, err)
}

func deployBundleWithArgsErr(t testutil.TestingT, ctx context.Context, path string, args ...string) (string, string, error) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
args = append([]string{"bundle", "deploy"}, args...)
c := testcli.NewRunner(t, ctx, args...)
stdout, stderr, err := c.Run()
return stdout.String(), stderr.String(), err
}

func deployBundleWithArgs(t testutil.TestingT, ctx context.Context, path string, args ...string) (string, string) {
stdout, stderr, err := deployBundleWithArgsErr(t, ctx, path, args...)
require.NoError(t, err)
return stdout, stderr
}

func runResource(t testutil.TestingT, ctx context.Context, path, key string) (string, error) {
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
ctx = cmdio.NewContext(ctx, cmdio.Default())
Expand Down
Loading