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

Commit

Permalink
Pass in bazel test flags from Changes. By default, run all tests in a…
Browse files Browse the repository at this point in the history
… Bazel sandbox.

Test Plan: To be fixed

Reviewers: naphat

Reviewed By: naphat

Subscribers: changesbot, kylec, wwu

Differential Revision: https://tails.corp.dropbox.com/D229607
  • Loading branch information
Anup Chenthamarakshan committed Sep 19, 2016
1 parent 62aa42a commit eb1d550
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions changes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ def create_app(_read_config=True, **config):
# Bazel will create parent directories (if the user has appropriate permissions), if missing.
app.config['BAZEL_ROOT_PATH'] = '/tmp/bazel_changes'

# List of mandatory flags to be passed to `bazel test`
app.config['BAZEL_MANDATORY_TEST_FLAGS'] = [
'--spawn_strategy=sandboxed',
'--genrule_strategy=sandboxed'
]

# 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
7 changes: 6 additions & 1 deletion changes/models/jobplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def get_build_step_for_job(cls, job_id):
logging.error('Project config for project %s requests invalid number of executors: constraint 1 <= %d <= %d', job.project.slug, bazel_max_executors, current_app.config['MAX_EXECUTORS'])
return jobplan, None

bazel_test_flags = current_app.config['BAZEL_MANDATORY_TEST_FLAGS']
# TODO(anupc): Allow additional flags to be passed in via project config.

implementation = LXCBuildStep(
cluster=current_app.config['DEFAULT_CLUSTER'],
commands=[
Expand All @@ -231,7 +234,9 @@ def get_build_step_for_job(cls, job_id):
collect_targets_executable=os.path.join(LXCBuildStep.custom_bin_path(), 'collect-targets'),
bazel_targets=project_config['bazel.targets'],
bazel_exclude_tags=bazel_exclude_tags,
max_jobs=2 * bazel_cpus), 'type': 'collect_bazel_targets'},
max_jobs=2 * bazel_cpus,
bazel_test_flags=bazel_test_flags,
), 'type': 'collect_bazel_targets'},
],
artifacts=[], # only for collect_target step, which we don't expect artifacts
artifact_suffix=current_app.config['BAZEL_ARTIFACT_SUFFIX'],
Expand Down
5 changes: 3 additions & 2 deletions changes/utils/bazel_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(sudo apt-get -y update || sudo apt-get -y update) >/dev/null 2>&1
sudo apt-get install -y --force-yes {bazel_apt_pkgs} python >/dev/null 2>&1
"{collect_targets_executable}" --output-user-root="{bazel_root}" {bazel_targets} {bazel_exclude_tags} --jobs="{max_jobs}" 2> /dev/null
"{collect_targets_executable}" --output-user-root="{bazel_root}" {bazel_targets} {bazel_exclude_tags} {bazel_test_flags} --jobs="{max_jobs}" 2> /dev/null
""".strip()


Expand All @@ -45,7 +45,7 @@ def get_bazel_setup():
)


def collect_bazel_targets(collect_targets_executable, bazel_targets, bazel_exclude_tags, max_jobs):
def collect_bazel_targets(collect_targets_executable, bazel_targets, bazel_exclude_tags, bazel_test_flags, max_jobs):
"""Construct a command to query the Bazel dependency graph to expand bazel project
config into a set of individual test targets.
Expand All @@ -65,6 +65,7 @@ def collect_bazel_targets(collect_targets_executable, bazel_targets, bazel_exclu
bazel_targets=' '.join(['--target-patterns={}'.format(t) for t in bazel_targets]),
collect_targets_executable=collect_targets_executable,
bazel_exclude_tags=' '.join(['--exclude-tags={}'.format(t) for t in bazel_exclude_tags]),
bazel_test_flags=' '.join(['--test-flags={}'.format(tf) for tf in bazel_test_flags]),
max_jobs=max_jobs,
)

Expand Down
4 changes: 2 additions & 2 deletions tests/changes/models/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_autogenerated_commands(self, get_config):
(sudo apt-get -y update || sudo apt-get -y update) >/dev/null 2>&1
sudo apt-get install -y --force-yes bazel python >/dev/null 2>&1
"/var/changes/input/collect-targets" --output-user-root="/bazel/root/path" --target-patterns=//aa/bb/cc/... --target-patterns=//aa/abc/... --jobs="8" 2> /dev/null
"/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 --jobs="8" 2> /dev/null
""".strip()

assert len(implementation.commands) == 3
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_autogenerated_commands_with_exclusions(self, get_config):
(sudo apt-get -y update || sudo apt-get -y update) >/dev/null 2>&1
sudo apt-get install -y --force-yes bazel python >/dev/null 2>&1
"/var/changes/input/collect-targets" --output-user-root="/bazel/root/path" --target-patterns=//foo/bar/baz/... --target-patterns=//bar/bax/... --exclude-tags=flaky --exclude-tags=another_tag --jobs="4" 2> /dev/null
"/var/changes/input/collect-targets" --output-user-root="/bazel/root/path" --target-patterns=//foo/bar/baz/... --target-patterns=//bar/bax/... --exclude-tags=flaky --exclude-tags=another_tag --test-flags=--spawn_strategy=sandboxed --test-flags=--genrule_strategy=sandboxed --jobs="4" 2> /dev/null
""".strip()

_, implementation = JobPlan.get_build_step_for_job(self._create_job_and_jobplan().id)
Expand Down

0 comments on commit eb1d550

Please sign in to comment.