Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Provide optional extra command to be executed before bazel test
Browse files Browse the repository at this point in the history
Reviewers: naphat

Reviewed By: naphat

Subscribers: changesbot, wwu, kylec

Differential Revision: https://tails.corp.dropbox.com/D233785
  • Loading branch information
Anup Chenthamarakshan committed Oct 3, 2016
1 parent f8e1545 commit 159a041
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
3 changes: 3 additions & 0 deletions changes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ def create_app(_read_config=True, **config):
# Debug config entries passed to every autobazel jobstep
app.config['BAZEL_DEBUG_CONFIG'] = {}

# Extra test setup commands to be executed before collect-targets or `bazel test` invocations.
app.config['BAZEL_EXTRA_SETUP_CMD'] = ['exit 0']

# Jobsteps go from 'pending_allocation' to 'allocated' once an external scheduler claims them, and
# once they begin running they're updated to 'in_progress'. If the scheduler somehow fails or drops
# the task, this value is used to time out the 'allocated' status and revert back to 'pending_allocation'.
Expand Down
3 changes: 2 additions & 1 deletion changes/models/jobplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from changes.db.types.guid import GUID
from changes.db.types.json import JSONEncodedDict
from changes.db.utils import model_repr
from changes.utils.bazel_setup import get_bazel_setup, collect_bazel_targets, sync_encap_pkgs
from changes.utils.bazel_setup import collect_bazel_targets, extra_setup_cmd, get_bazel_setup, sync_encap_pkgs
from changes.utils.imports import import_string


Expand Down Expand Up @@ -241,6 +241,7 @@ def get_build_step_for_job(cls, job_id):
commands=[
{'script': get_bazel_setup(), 'type': 'setup'},
{'script': sync_encap_pkgs(project_config), 'type': 'setup'}, # TODO(anupc): Make this optional
{'script': extra_setup_cmd(), 'type': 'setup'}, # TODO(anupc): Make this optional
{
'script': collect_bazel_targets(
collect_targets_executable=os.path.join(LXCBuildStep.custom_bin_path(), 'collect-targets'),
Expand Down
4 changes: 4 additions & 0 deletions changes/utils/bazel_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ def sync_pkg(pkg):
encap_dir=encap_dir,
)
return '\n'.join(['sudo mkdir -p ' + encap_dir] + map(sync_pkg, encap_pkgs))


def extra_setup_cmd():
return '#!/bin/bash -eux\n' + '\n'.join(current_app.config['BAZEL_EXTRA_SETUP_CMD'])
33 changes: 21 additions & 12 deletions tests/changes/models/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def test_autogenerated_commands(self, get_config):
"/var/changes/input/collect-targets" --output-user-root="/bazel/root/path" --target-patterns=//aa/bb/cc/... --target-patterns=//aa/abc/... --test-flags=--spawn_strategy=sandboxed --test-flags=--genrule_strategy=sandboxed --test-flags=--keep_going --jobs="8" 2> /dev/null
""".strip()

assert len(implementation.commands) == 3
extra_setup_expected = """#!/bin/bash -eux
exit 0
""".strip()

assert len(implementation.commands) == 4

assert implementation.max_executors == 1

Expand All @@ -87,11 +91,14 @@ def test_autogenerated_commands(self, get_config):
assert implementation.commands[1].type == CommandType.setup
assert implementation.commands[1].script == sync_encap_expected

assert implementation.commands[2].type == CommandType.collect_bazel_targets
assert implementation.commands[2].script == collect_targets_expected
assert implementation.commands[2].env['VCS_CHECKOUT_TARGET_REVISION_CMD'] == 'git checkout master'
assert implementation.commands[2].env['VCS_CHECKOUT_PARENT_REVISION_CMD'] == 'git checkout master^'
assert implementation.commands[2].env['VCS_GET_CHANGED_FILES_CMD'] == 'git diff --name-only master^..master'
assert implementation.commands[2].type == CommandType.setup
assert implementation.commands[2].script == extra_setup_expected

assert implementation.commands[3].type == CommandType.collect_bazel_targets
assert implementation.commands[3].script == collect_targets_expected
assert implementation.commands[3].env['VCS_CHECKOUT_TARGET_REVISION_CMD'] == 'git checkout master'
assert implementation.commands[3].env['VCS_CHECKOUT_PARENT_REVISION_CMD'] == 'git checkout master^'
assert implementation.commands[3].env['VCS_GET_CHANGED_FILES_CMD'] == 'git diff --name-only master^..master'

@mock.patch('changes.models.project.Project.get_config')
def test_autogenerated_commands_with_exclusions(self, get_config):
Expand Down Expand Up @@ -133,12 +140,13 @@ def test_autogenerated_commands_with_exclusions(self, get_config):
assert implementation.resources['cpus'] == 2
assert implementation.resources['mem'] == 1234

assert len(implementation.commands) == 3
assert len(implementation.commands) == 4

assert implementation.commands[0].type == CommandType.setup
assert implementation.commands[1].type == CommandType.setup
assert implementation.commands[2].type == CommandType.collect_bazel_targets
assert implementation.commands[2].script == collect_tests_expected
assert implementation.commands[2].type == CommandType.setup
assert implementation.commands[3].type == CommandType.collect_bazel_targets
assert implementation.commands[3].script == collect_tests_expected

@mock.patch('changes.models.project.Project.get_config')
def test_autogenerated_commands_with_additional_test_flags(self, get_config):
Expand Down Expand Up @@ -177,12 +185,13 @@ def test_autogenerated_commands_with_additional_test_flags(self, get_config):
assert implementation.resources['cpus'] == 2
assert implementation.resources['mem'] == 1234

assert len(implementation.commands) == 3
assert len(implementation.commands) == 4

assert implementation.commands[0].type == CommandType.setup
assert implementation.commands[1].type == CommandType.setup
assert implementation.commands[2].type == CommandType.collect_bazel_targets
assert implementation.commands[2].script == collect_tests_expected
assert implementation.commands[2].type == CommandType.setup
assert implementation.commands[3].type == CommandType.collect_bazel_targets
assert implementation.commands[3].script == collect_tests_expected

@mock.patch('changes.models.project.Project.get_config')
def test_autogenerated_commands_with_additional_test_flags_invalid(self, get_config):
Expand Down

0 comments on commit 159a041

Please sign in to comment.