17
def ensure_tarmac_log_dir():
18
"""Hack-around tarmac not creating its own log directory."""
20
os.makedirs(os.path.expanduser("~/logs/"))
22
# Could be already exists, or cannot create, either way, just continue
26
def create_tarmac_repository():
27
"""Try to ensure a shared repository for the code."""
38
sys.stderr.write('Could not import bzrlib to ensure a repository\n')
41
b, _ = branch.Branch.open_containing('.')
43
sys.stderr.write('Could not open local branch\n')
45
# By the time we get here, we've already branched everything from
46
# launchpad. So if we aren't in a shared repository, we create one, and
47
# fetch all the data into it, so it doesn't have to be fetched again.
48
if b.repository.is_shared():
51
expected_dir = 'src/launchpad.net/'
52
offset = pwd.rfind(expected_dir)
54
sys.stderr.write('Could not find %r to create a shared repo\n')
56
path = pwd[:offset+len(expected_dir)]
58
repository.Repository.open(path)
59
except (errors.NoRepositoryPresent, errors.NotBranchError):
60
pass # Good, the repo didn't exist
62
# We must have already created the repo.
64
repo_fmt = controldir.format_registry.make_bzrdir('default')
65
trans = transport.get_transport(path)
66
info = repo_fmt.initialize_on_transport_ex(trans, create_prefix=False,
67
make_working_trees=True, shared_repo=True, force_new_repo=True,
68
use_existing_dir=True,
69
repo_format_name=repo_fmt.repository_format.get_format_string())
71
sys.stderr.write('Reconfiguring to use a shared repository\n')
72
reconfiguration = reconfigure.Reconfigure.to_use_shared(b.bzrdir)
74
reconfiguration.apply(False)
75
except errors.NoRepositoryPresent:
76
sys.stderr.write('tarmac did a lightweight checkout,'
77
' not fetching into the repo.\n')
80
def ensure_juju_core_dependencies():
81
"""Ensure that juju-core and all dependencies have been installed."""
82
# Note: This potentially overwrites goose while it is updating the world.
83
# However, if we are targetting the trunk branch of goose, that should have
84
# already been updated to the latest version by tarmac.
85
# I don't quite see a way to reconcile that we want the latest juju-core
86
# and all of the other dependencies, but we don't want to touch goose
87
# itself. One option would be to have a split GOPATH. One installs the
88
# latest juju-core and everything else. The other is where the
89
# goose-under-test resides. So we don't add the goose-under-test to GOPATH,
90
# call "go get", then add it to the GOPATH for the rest of the testing.
91
cmd = ['go', 'get', '-u', '-x', 'launchpad.net/juju-core/...']
92
sys.stderr.write('Running: %s\n' % (' '.join(cmd),))
93
retcode = subprocess.call(cmd)
95
sys.stderr.write('WARN: Failed to update launchpad.net/juju-core\n')
98
def tarmac_setup(opts):
99
"""Do all the bits of setup that need to happen for the tarmac bot."""
100
ensure_tarmac_log_dir()
101
create_tarmac_repository()
102
ensure_juju_core_dependencies()
107
if sys.platform == 'win32':
108
pwd = pwd.replace('\\', '/')
109
offset = pwd.rfind('src/launchpad.net/goose')
111
sys.stderr.write('Could not find "src/launchpad.net/goose" in cwd: %s\n'
113
sys.stderr.write('Unable to automatically set GOPATH\n')
115
add_gopath = pwd[:offset].rstrip('/')
116
gopath = os.environ.get("GOPATH")
118
if add_gopath in gopath:
120
# Put this path first, so we know we are running these tests
121
gopath = add_gopath + os.pathsep + gopath
124
sys.stderr.write('Setting GOPATH to: %s\n' % (gopath,))
125
os.environ['GOPATH'] = gopath
129
cmd_str = ' '.join(cmd)
130
sys.stderr.write('Running: %s\n' % (cmd_str,))
131
retcode = subprocess.call(cmd)
133
sys.stderr.write('FAIL: failed running: %s\n' % (cmd_str,))
137
def run_go_fmt(opts):
138
return run_cmd(['go', 'fmt', './...'])
141
def run_go_build(opts):
142
return run_cmd(['go', 'build', './...'])
145
def run_go_test(opts):
146
# Note: I wish we could run this with '-gocheck.v'
147
return run_cmd(['go', 'test', './...'])
150
def run_juju_core_tests(opts):
151
"""Run the juju-core test suite"""
152
orig_wd = os.getcwd()
154
sys.stderr.write('Switching to juju-core')
155
os.chdir('../juju-core')
156
retval = run_cmd(['go', 'build', './...'])
159
return run_cmd(['go', 'test', './...'])
164
def run_live_tests(opts):
165
"""Run all of the live tests."""
166
orig_wd = os.getcwd()
168
for d in KNOWN_LIVE_SUITES:
170
cmd = ['go', 'test', '-live', '-gocheck.v']
171
sys.stderr.write('Running: %s in %s\n' % (' '.join(cmd), d))
173
retcode = subprocess.call(cmd)
175
sys.stderr.write('FAIL: Running live tests in %s\n' % (d,))
176
final_retcode = retcode
183
p = argparse.ArgumentParser(description='Run the goose test suite')
184
p.add_argument('--verbose', action='store_true', help='Be chatty')
185
p.add_argument('--version', action='version', version='%(prog)s 0.1')
186
p.add_argument('--tarmac', action='store_true',
187
help="Pass this if the script is running as the tarmac bot."
188
" This is used for stuff like ensuring repositories and"
189
" logging directories are initialized.")
190
p.add_argument('--juju-core', action='store_true',
191
help="Run the juju-core trunk tests as well as the goose tests.")
192
p.add_argument('--live', action='store_true',
193
help="Run tests against a live service.")
195
opts = p.parse_args(args)
199
to_run = [run_go_fmt, run_go_build, run_go_test]
201
to_run.append(run_juju_core_tests)
203
to_run.append(run_live_tests)
210
if __name__ == '__main__':