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

Commit

Permalink
Use a consistent bazel root directory (--output_user_root)
Browse files Browse the repository at this point in the history
Summary:
Required to make fetching artifacts from bazel simpler.
Please see https://bazel.io/versions/master/docs/output_directories.html for details on bazel output directories.

Test Plan: Will fix tests shortly

Reviewers: kylec, naphat

Reviewed By: naphat

Subscribers: changesbot

Differential Revision: https://tails.corp.dropbox.com/D224250
  • Loading branch information
Anup Chenthamarakshan committed Aug 29, 2016
1 parent 6bd51d8 commit 52e3716
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
7 changes: 3 additions & 4 deletions changes/buildsteps/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ def __init__(self, commands=None, repo_path=None, path=None, env=None,
can be specified with "backend": "hg". Default revision is
"origin/master" or "default" (for hg), but an explicit revision
can be specified with "revision".
artifact_search_path: The path in which test artifacts can be
found in, relative to the `repo_path`. This defaults to the
value for `path`.
artifact_search_path: Absolute path in which test artifacts can be
found in. This defaults to the value for `path`.
"""
if commands is None:
raise ValueError("Missing required config: need commands")
Expand All @@ -148,7 +147,7 @@ def __init__(self, commands=None, repo_path=None, path=None, env=None,
# default repo_path to path if none specified
self.repo_path = path or DEFAULT_PATH
self.path = self.repo_path
self.artifact_search_path = os.path.join(self.repo_path, artifact_search_path) if artifact_search_path else self.path
self.artifact_search_path = artifact_search_path if artifact_search_path else self.path
self.release = release
self.max_executors = max_executors
self.resources = {
Expand Down
9 changes: 9 additions & 0 deletions changes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,16 @@ def create_app(_read_config=True, **config):
# Maximum memory allowed per executor (in MB)
app.config['MAX_MEM_MB_PER_EXECUTOR'] = 16384

# Absolute path to Bazel root (passed via --output_root to Bazel)
# Storing bazel cache in tmpfs could be a bad idea because:
# - tmpfs means any files stored here will be stored purely in RAM and will eat into container limits
# - these containers are not persisted from the snapshot
#
# Bazel will create parent directories (if the user has appropriate permissions), if missing.
app.config['BAZEL_ROOT_PATH'] = '/tmp/bazel_changes'

app.config.update(config)

if _read_config:
if os.environ.get('CHANGES_CONF'):
# CHANGES_CONF=/etc/changes.conf.py
Expand Down
3 changes: 2 additions & 1 deletion changes/models/jobplan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import logging
import os
import uuid

from collections import defaultdict
Expand Down Expand Up @@ -227,7 +228,7 @@ def get_build_step_for_job(cls, job_id):
max_jobs=2 * bazel_cpus), 'type': 'collect_tests'},
],
artifacts=['*.xml'],
artifact_search_path=current_app.config['BAZEL_TEST_OUTPUT_RELATIVE_PATH'],
artifact_search_path=os.path.join(current_app.config['BAZEL_ROOT_PATH'], current_app.config['BAZEL_TEST_OUTPUT_RELATIVE_PATH']),
cpus=bazel_cpus,
memory=bazel_memory,
)
Expand Down
8 changes: 5 additions & 3 deletions changes/utils/bazel_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sudo apt-get -y update || sudo apt-get -y update
sudo apt-get install -y --force-yes %(bazel_apt_pkgs)s
/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --batch version
/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --output_user_root=%(bazel_root)s --batch version
""".strip()

# We run setup again because changes does not run setup before collecting tests, but we need bazel
Expand All @@ -30,7 +30,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)s python >/dev/null 2>&1
(/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --batch query \
(/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --output_user_root=%(bazel_root)s --batch query \
'let t = tests(%(bazel_targets)s) in ($t %(exclusion_subquery)s)' | \
python -c "%(jsonify_script)s") 2> /dev/null
""".strip()
Expand All @@ -45,6 +45,7 @@ def get_bazel_setup():
return BASH_BAZEL_SETUP % dict(
apt_spec=current_app.config['APT_SPEC'],
bazel_apt_pkgs=' '.join(current_app.config['BAZEL_APT_PKGS']),
bazel_root=current_app.config['BAZEL_ROOT_PATH'],
)


Expand Down Expand Up @@ -90,8 +91,9 @@ def collect_bazel_targets(bazel_targets, bazel_exclude_tags, max_jobs):
return COLLECT_BAZEL_TARGETS % dict(
apt_spec=current_app.config['APT_SPEC'],
bazel_apt_pkgs=' '.join(current_app.config['BAZEL_APT_PKGS']),
bazel_root=current_app.config['BAZEL_ROOT_PATH'],
bazel_targets=' + '.join(bazel_targets),
jsonify_script=jsonify_script.read() % dict(max_jobs=max_jobs),
jsonify_script=jsonify_script.read() % dict(max_jobs=max_jobs, bazel_root=current_app.config['BAZEL_ROOT_PATH']),
exclusion_subquery=exclusion_subquery,
)

Expand Down
2 changes: 1 addition & 1 deletion changes/utils/collect_bazel_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

targets = sys.stdin.read().splitlines()
out = {
'cmd': '/usr/bin/bazel test --jobs=%(max_jobs)s {test_names}',
'cmd': '/usr/bin/bazel --output_user_root=%(bazel_root)s test --jobs=%(max_jobs)s {test_names}',
'tests': targets,
}
json.dump(out, sys.stdout)
4 changes: 2 additions & 2 deletions tests/changes/buildsteps/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def test_get_allocation_params_with_artifact_search_path(self):
jobphase = self.create_jobphase(job)
jobstep = self.create_jobstep(jobphase)

buildstep = self.get_buildstep(repo_path='source', path='tests', artifact_search_path='out')
buildstep = self.get_buildstep(repo_path='source', path='tests', artifact_search_path='/out')
result = buildstep.get_allocation_params(jobstep)
assert result == {
'adapter': 'basic',
Expand All @@ -583,7 +583,7 @@ def test_get_allocation_params_with_artifact_search_path(self):
'pre-launch': 'echo pre',
'post-launch': 'echo post',
'artifacts-server': 'http://localhost:1234',
'artifact-search-path': 'source/out',
'artifact-search-path': '/out',
'use-external-env': 'false',
'dist': 'ubuntu',
}
Expand Down
15 changes: 7 additions & 8 deletions tests/changes/models/test_job.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import absolute_import

import mock
import os

from flask import current_app

from changes.buildsteps.default import DEFAULT_PATH
from changes.models.command import CommandType
from changes.models.jobplan import JobPlan
from changes.testutils import TestCase
Expand All @@ -16,6 +14,7 @@ def _create_job_and_jobplan(self):
current_app.config['APT_SPEC'] = 'deb http://example.com/debian distribution component1'
current_app.config['ENCAP_RSYNC_URL'] = 'rsync://example.com/encap/'
current_app.config['BAZEL_APT_PKGS'] = ['bazel']
current_app.config['BAZEL_ROOT_PATH'] = '/bazel/root/path'

project = self.create_project()
plan = self.create_plan(project)
Expand Down Expand Up @@ -59,7 +58,7 @@ def test_autogenerated_commands(self, get_config):
sudo apt-get -y update || sudo apt-get -y update
sudo apt-get install -y --force-yes bazel
/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --batch version
/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --output_user_root=/bazel/root/path --batch version
""".strip()

sync_encap_expected = """
Expand All @@ -78,15 +77,15 @@ 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
(/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --batch query \
(/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --output_user_root=/bazel/root/path --batch query \
'let t = tests(//aa/bb/cc/... + //aa/abc/...) in ($t )' | \
python -c "import sys
import json
targets = sys.stdin.read().splitlines()
out = {
'cmd': '/usr/bin/bazel test --jobs=8 {test_names}',
'cmd': '/usr/bin/bazel --output_user_root=/bazel/root/path test --jobs=8 {test_names}',
'tests': targets,
}
json.dump(out, sys.stdout)
Expand All @@ -104,7 +103,7 @@ def test_autogenerated_commands(self, get_config):
assert implementation.commands[2].type == CommandType.collect_tests
assert implementation.commands[2].script == collect_tests_expected

assert implementation.artifact_search_path == os.path.join(DEFAULT_PATH, current_app.config['BAZEL_TEST_OUTPUT_RELATIVE_PATH'])
assert implementation.artifact_search_path == '/bazel/root/path/bazel-testlogs/'
assert implementation.artifacts == ['*.xml']

@mock.patch('changes.models.project.Project.get_config')
Expand Down Expand Up @@ -137,15 +136,15 @@ 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
(/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --batch query \
(/usr/bin/bazel --nomaster_blazerc --blazerc=/dev/null --output_user_root=/bazel/root/path --batch query \
'let t = tests(//foo/bar/baz/... + //bar/bax/...) in ($t except (attr("tags", "(\[| )flaky(\]|,)", $t)) except (attr("tags", "(\[| )another_tag(\]|,)", $t)))' | \
python -c "import sys
import json
targets = sys.stdin.read().splitlines()
out = {
'cmd': '/usr/bin/bazel test --jobs=4 {test_names}',
'cmd': '/usr/bin/bazel --output_user_root=/bazel/root/path test --jobs=4 {test_names}',
'tests': targets,
}
json.dump(out, sys.stdout)
Expand Down

0 comments on commit 52e3716

Please sign in to comment.