Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add acceptance tests for bundle deploy #2254

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

kanterov
Copy link
Contributor

@kanterov kanterov commented Jan 28, 2025

Changes

Add acceptance tests for bundle deployment. Includes regression test for #2253

Terraform binary is required for deployment. We cache it once at the beginning of tests.

Because fake is stateful and shared between tests running in parallel, it isn't possible to inspect the state after the bundle is deployed. One option is to use different API tokens between tests and handle them as different workspaces. A different alternative is separating tests that rely on state from stateless tests.

Tests

Fake implementation is not tested but has good enough fidelity

t.Fatalf("Failed to download terraform: %v", err)
}

repls.SetPath(tfExecPath, "$DATABRICKS_TF_EXEC_PATH")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it didn't work

http.Error(w, err.Error(), http.StatusInternalServerError)
return
if errors.Is(err, NotFoundError) {
payload := `{"error_code":"RESOURCE_DOES_NOT_EXIST","message":"Does not exist"}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is the correct way. But we need to send the correct payload back, or SDK can't parse it.

@@ -65,6 +66,34 @@ func TestInprocessMode(t *testing.T) {
require.Equal(t, 1, testAccept(t, true, "selftest"))
}

// Cache terraform binary in the temporary directory to avoid downloading it in each test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is indeed a needed feature, both for local tests but most importantly for cloud tests (#2242).

Could you make a separate PR just for cached terraform - it's important that we review it well.

Also, could you not depend on side effect of "bundle validate"? Here some scripts/docs on how to prepare terraform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen instructions for air-gapped environments. I'm not sure I will have enough capacity to do it correctly. I think we need to implement it by relying on caching in GitHub actions and adding a step where we download Terraform. The cache key should be based on Terraform and Terraform provider versions. Right now, we don't even do that in our own GitHub action that we provide.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Github actions cache is nice to have, not a must.

I'm not sure I will have enough capacity to do it correctly.

Let's discuss on Slack -- I can help with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase on top of this #2267


trace $CLI bundle deploy

# FIXME: doesn't work because fake state is shared and tests run in parallel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Badness field in test.toml (git grep for examples).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just fix the fake. It isn't hard

}, nil
path := r.URL.Query().Get("path")

return server.getStatus(path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why extra indirection with getStatus function? I don't see that helper used anywhere else.

Same comment for workspaceMkdirs, jobsCreate, jobsList - those are only used once, can be inlined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a separate PR for jobs API in server_test.go (excluding changes to python mutator and tests for python mutator)?

mode: development
default: true
workspace:
host: $DATABRICKS_HOST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this here? isn't that the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that databricks.yml doesn't have to declare targets if env variables are set? Note that we don't use "bundle init" here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that $DATABRICK_HOST is already what's going to be used (that's how all other tests work), so no need to specify it explicitly and use .tmpl.

That line can just be deleted, it should work.

github-merge-queue bot pushed a commit that referenced this pull request Jan 29, 2025
## Changes

Fix relative path errors in the Python mutator that was failing during
deployment since v0.239.1.

Before that:

```
% databricks bundle deploy  
Deploying resources...
Updating deployment state...
Error: failed to compute relative path for job jobs_as_code_project_job: Rel: can't make resources/jobs_as_code_project_job.py relative to /Users/$USER/jobs_as_code_project
```

As a result, the bundle was deployed, but the deployment state wasn't
updated.

## Tests

Unit tests, adding acceptance tests in
#2254
Copy link

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 2254
  • Commit SHA: db1285fdbf26bf11dfd8749388b1854de040e5c3

Checks will be approved automatically on success.

github-merge-queue bot pushed a commit that referenced this pull request Jan 31, 2025
## Changes
- Add a script install_terraform.py that downloads terraform and
provider and generates a config to use, inspired by
https://gist.github.com/pietern/1cb6b6f3e0a452328e13cdc75031105e
- Make acceptance tests run this script once before running the tests
and set the required env vars to make cli use this terraform
installation.
- Use OS-specific directory for things that are build by acceptance test
runner (CLI and terraform).

This enables acceptance tests against cloud #2242 and local test for
bundle deploy #2254.

## Tests
- Add an acceptance test for standalone terraform. This is useful to
debug terraform with TF_LOG=DEBUG to see that it uses local provider.
- Other acceptance tests are updated with regard to terraform exec path.
- The overall time for tests locally is unchanged (if terraform is
already fetched).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants