Merge lp:~waigani/juju-core/1307241-isolate-from-jujud into lp:~go-bot/juju-core/trunk
- 1307241-isolate-from-jujud
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 2763 |
Proposed branch: | lp:~waigani/juju-core/1307241-isolate-from-jujud |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
827 lines (+247/-147) 11 files modified
cmd/juju/bootstrap_test.go (+5/-28) cmd/juju/upgradejuju_test.go (+2/-27) cmd/plugins/juju-metadata/toolsmetadata_test.go (+13/-13) environs/bootstrap/bootstrap_test.go (+4/-30) environs/sync/sync_test.go (+155/-30) environs/tools/build.go (+11/-4) environs/tools/simplestreams_test.go (+6/-6) environs/tools/testing/testing.go (+42/-0) environs/tools/tools_test.go (+4/-4) state/apiserver/client/client_test.go (+2/-2) state/apiserver/tools_test.go (+3/-3) |
To merge this branch: | bzr merge lp:~waigani/juju-core/1307241-isolate-from-jujud |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+215590@code.launchpad.net |
Commit message
Fix 1307241. Isolate jujud.
Add the following mock functions to
environs/
GetMockBundleTools
GetMockBuildTools
Make envtools.
Patch functions in tests where
needed to ensure tests pass without
dependencies on jujud.
https:/
R=fwereade, wallyworld
Description of the change
Fix 1307241. Isolate jujud.
Add the following mock functions to
environs/
GetMockUploadTools
GetMockBundleTools
GetMockBuildTools
Make envtools.
Patch functions in tests where
needed to ensure tests pass without
dependencies on jujud.
Jesse Meek (waigani) wrote : | # |
Dave Cheney (dave-cheney) wrote : | # |
On 2014/04/15 09:15:27, waigani wrote:
> Please take a look.
I'm not sure I understand the rational for this change. If jujud fails
to compile, maybe that is where the test should stop.
Ian Booth (wallyworld) wrote : | # |
On 2014/04/15 10:10:15, dfc wrote:
> On 2014/04/15 09:15:27, waigani wrote:
> > Please take a look.
> I'm not sure I understand the rational for this change. If jujud fails
to
> compile, maybe that is where the test should stop.
We want to mock out the BundleTools because it adds unnecessary
complexity to the tests which depend on it. eg when we test that tools
are synced, we don't care that the real compile is not done; we just
want a stub which runs quickly and is robust against whatever
arch/series/os it is running on. Having said that, there need to be
tests added which confirm that BundleTools itself works properly.
Ian Booth (wallyworld) wrote : | # |
Looking good so far. I like that duped functionality has been
consolidated.
If we are mocking out BundleTools, we need tests for BundleTools itself
to ensure that function does what it is supposed to do. We also need to
ensure (if not done already) that the tests which use the mock assert
that the mock is called correctly.
https:/
File cmd/juju/
https:/
cmd/juju/
Don't do this - make toolsDir an argument to GetMockBuildTools and pass
in s.toolsDir
https:/
File environs/
https:/
environs/
remove this and make it an arg to the functions which need it
John A Meinel (jameinel) wrote : | # |
The tests mentioned fail with juju-mongodb because juju-mongodb doesn't provide a Javascript engine (juju itself doesn't use it, only the store subset does, and there only in tests, IIRC).
You need to have "mongodb-server" installed which provides the full V8 engine.
Though IMO, our test suite shouldn't require you to symlink juju-mongodb to be able to run, it should detect that /usr/bin/
But yes, that is unrelated to your change.
Jesse Meek (waigani) wrote : | # |
Please take a look.
William Reade (fwereade) wrote : | # |
I don't think this is quite there yet. Definitely some good stuff, but
we should chat.
https:/
File environs/
https:/
environs/
"launchpad.
explicit "toolstesting" throughout please
https:/
File environs/
https:/
environs/
do we *have* to mess with the real environment? I accept that *perhaps*
we do, but, eww.
https:/
environs/
This is wrong. You need to capture the result of Getenv at setup time --
sadly, you can't just drop the defer and move the code and actually have
it work the same ;).
https:/
environs/
c.Assert(vers, gc.DeepEquals, version.Binary{}) ?
https:/
File environs/
https:/
environs/
bundles all the current juju tools
s/bundles/bundle/
https:/
File environs/
https:/
environs/
effect of tools.Upload, but skips the time-
GetMockUploadTools returns an UploadFunc that...
https:/
environs/
neatly mocked?
I feel like fixing *this* TODO might have been a step in a slightly
better direction, but I'm not totally sure at this point.
edit: I'm getting surer. I'll be around later tonight, let's chat live
-- it's been a while since I saw this code, and I might be missing
something, but I think there's something funky about the layering here.
https:/
environs/
newVers)
Don't we have a SeriesToUpload func somewhere? Shouldn't we be using
that, rather copy/pasting its functionality? (or, better, mocking a
slightly different layer such that the *only* thing we patch out is the
costly build operation -- ISTM that all the rest of the time we really
just want to patch out the building, because we can cheaply upload to
dummy-provider storage anyway. Right?)
Jesse Meek (waigani) wrote : | # |
https:/
File environs/
https:/
environs/
"launchpad.
On 2014/05/07 12:52:05, fwereade wrote:
> explicit "toolstesting" throughout please
Done.
https:/
File environs/
https:/
environs/
On 2014/05/07 12:52:06, fwereade wrote:
> do we *have* to mess with the real environment? I accept that
*perhaps* we do,
> but, eww.
Done. Using s.PatchEnvPathP
https:/
environs/
On 2014/05/07 12:52:05, fwereade wrote:
> This is wrong. You need to capture the result of Getenv at setup time
-- sadly,
> you can't just drop the defer and move the code and actually have it
work the
> same ;).
Done. I've mocked go cmd directly.
https:/
environs/
On 2014/05/07 12:52:06, fwereade wrote:
> c.Assert(vers, gc.DeepEquals, version.Binary{}) ?
Done.
https:/
File environs/
https:/
environs/
neatly mocked?
On 2014/05/07 12:52:06, fwereade wrote:
> I feel like fixing *this* TODO might have been a step in a slightly
better
> direction, but I'm not totally sure at this point.
> edit: I'm getting surer. I'll be around later tonight, let's chat live
-- it's
> been a while since I saw this code, and I might be missing something,
but I
> think there's something funky about the layering here.
UploadTools was being mocked in several places in the tests before my
cl. Each place reproduced the same functionality, so I created this
function clean things up.
As such, shouldn't removing UploadTools be done in a separate branch? If
so, for now shouldn't we leave this function as it at least cleans up
all the stray mock UploadTools funcs and eases making UploadTools
unmockable?
What are you referring to when you talk about build logic in
agent/tools?
https:/
environs/
filepath.
On 2014/05/07 12:52:06, fwereade wrote:
> This seems strange to me... AFAICS the only client passes in "", and
the
> replacement "jujud" directory is always empty anyway, so can't we
just: drop the
> dir param, skip the Archive call, write nothing, return the hash of
the empty
> file, and be done?
Done.
Jesse Meek (waigani) wrote : | # |
Please take a look.
Jesse Meek (waigani) wrote : | # |
On 2014/05/14 02:49:37, waigani wrote:
> Please take a look.
Please see my comments here:
https:/
William Reade (fwereade) wrote : | # |
ISTM that we don't use GetMockUploadTools all *that* much, and it'd be
worth dropping it (and just patching out the building/bundling, so we
get fake tools put in the right place, in the right way). As it is I
think GMUT is a liability, and it needs to be dropped either in this CL
or a followup (but a followup *soon* -- I really don't want it hanging
around).
Please run this by wallyworld again, as well: he's much more au fait
with the various tricky little details around here, but if he's happy I
will be too (modulo my various comments here).
https:/
File environs/
https:/
environs/
btw, please don't just insert this test suite in between the definition
and the methods of the uploadSuite
https:/
environs/
This isn't accurate any more
https:/
environs/
blank lines before comments in general, please
https:/
environs/
I'm not sure you *really* need this bit, but equally you don't have to
take it out :).
The super-sweet spot would be to pull all the MakeTool-style
functionality out into its own helpers and use all that same (tested)
test-support code elsewhere -- but if you want to do that, it'd deserve
its own CL.
https:/
environs/
improve test speed.
It's not 100% clear what this test is meant to be doing, indeed. Given
what we have elsewhere I think I'd be testing this stuff by mocking the
build/bundle stuff, and directly checking what gets uploaded.
https:/
environs/
command "go" failed: exit status 1; `)
please break all these cases into separate test methods where possible
https:/
environs/
TestMockBundleT
The SUT here is BuildToolsTarball, isn't it? We're testing that it calls
BundleTools in the expected way.
https:/
environs/
writer seems unused -- I'd expect us to write something to it and check
that it was somehow reflected in the result of BuildToolsTarba
https:/
environs/
sync.BuildTools
error/result check?
Jesse Meek (waigani) wrote : | # |
Please take a look.
https:/
File environs/
https:/
environs/
On 2014/05/15 08:57:20, fwereade wrote:
> btw, please don't just insert this test suite in between the
definition and the
> methods of the uploadSuite
Ah right. The suite goes before the methods for the suite. Got it.
https:/
environs/
On 2014/05/15 08:57:20, fwereade wrote:
> This isn't accurate any more
Done.
https:/
environs/
On 2014/05/15 08:57:20, fwereade wrote:
> blank lines before comments in general, please
Done.
https:/
environs/
On 2014/05/15 08:57:19, fwereade wrote:
> I'm not sure you *really* need this bit, but equally you don't have to
take it
> out :).
> The super-sweet spot would be to pull all the MakeTool-style
functionality out
> into its own helpers and use all that same (tested) test-support code
elsewhere
> -- but if you want to do that, it'd deserve its own CL.
Do you mean a helper suite i.e. FakeToolsSuite or a helper package like
utils?
https:/
environs/
improve test speed.
On 2014/05/15 08:57:19, fwereade wrote:
> It's not 100% clear what this test is meant to be doing, indeed. Given
what we
> have elsewhere I think I'd be testing this stuff by mocking the
build/bundle
> stuff, and directly checking what gets uploaded.
Done. Is TestUploadTools
https:/
environs/
command "go" failed: exit status 1; `)
On 2014/05/15 08:57:19, fwereade wrote:
> please break all these cases into separate test methods where possible
Done.
https:/
environs/
TestMockBundleT
On 2014/05/15 08:57:20, fwereade wrote:
> The SUT here is BuildToolsTarball, isn't it? We're testing that it
calls
> BundleTools in the expected way.
I don't follow sorry. I was testing if the mocked BundleTools gets
called. I could have easily used sync.Upload instead. I also don't know
what SUT means sorry.
https:/
environs/
On 2014/05/15 08:57:19, fwereade wrote:
> writer seems unused -- I'd expect us to write something to it and
check that it
> was somehow reflected in the result of BuildToolsTarba
Done.
https:/
Ian Booth (wallyworld) wrote : | # |
William Reade (fwereade) wrote : | # |
Thanks, this is great. LGTM with trivials.
https:/
File environs/
https:/
environs/
On 2014/05/16 03:06:07, waigani wrote:
> On 2014/05/15 08:57:19, fwereade wrote:
> > I'm not sure you *really* need this bit, but equally you don't have
to take it
> > out :).
> >
> > The super-sweet spot would be to pull all the MakeTool-style
functionality out
> > into its own helpers and use all that same (tested) test-support
code
> elsewhere
> > -- but if you want to do that, it'd deserve its own CL.
> Do you mean a helper suite i.e. FakeToolsSuite or a helper package
like utils?
I'd guess a suite would work well for easy integration of
setup/teardown, but not necessarily. Whatever seems to work best :).
https:/
environs/
improve test speed.
On 2014/05/16 03:06:08, waigani wrote:
> On 2014/05/15 08:57:19, fwereade wrote:
> > It's not 100% clear what this test is meant to be doing, indeed.
Given what we
> > have elsewhere I think I'd be testing this stuff by mocking the
build/bundle
> > stuff, and directly checking what gets uploaded.
> Done. Is TestUploadTools
Yeah, as long as we exercise both the happy path and the sad one, I
think we're good.
https:/
environs/
TestMockBundleT
On 2014/05/16 03:06:08, waigani wrote:
> On 2014/05/15 08:57:20, fwereade wrote:
> > The SUT here is BuildToolsTarball, isn't it? We're testing that it
calls
> > BundleTools in the expected way.
> I don't follow sorry. I was testing if the mocked BundleTools gets
called. I
> could have easily used sync.Upload instead. I also don't know what SUT
means
> sorry.
System Under Test. And no need to apologise :).
https:/
File environs/
https:/
environs/
On 2014/05/16 03:06:08, waigani wrote:
> On 2014/05/15 08:57:20, fwereade wrote:
> > I'm still nervous that this is a parallel implementation of logic in
> uploadTools
> > itself that *will* invitably change out of sync with this
implementation. This
> > is basically how mocking ends up going wrong IMO...
> Done. It's GONE GONE GONE!
w00t!
https:/
File environs/
https:/
environs/
improve test speed.
Hey, I think it's clicked. It's downloading the tools (and doing some
basic checks on them) to check that they really got uploaded. I think
I'd be h...
William Reade (fwereade) wrote : | # |
On 2014/05/16 08:29:36, fwereade wrote:
> Thanks, this is great. LGTM with trivials.
https:/
> File environs/
https:/
> environs/
improve
> test speed.
> Hey, I think it's clicked. It's downloading the tools (and doing some
basic
> checks on them) to check that they really got uploaded. I think I'd be
happiest
> to see more direct, explicit tests: I think we actually have pretty
detailed
> ones around bootstrap/
detail in the
> Upload tests and maybe a bit less in the cmd/juju ones.
I don't want that in this CL, though, it's big enough already.
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~waigani/juju-core/1307241-isolate-from-jujud into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
-------
FAIL: bootstrap_
[LOG] 0:00.016 INFO juju.utils hostname SSL verification enabled
[LOG] 0:00.016 DEBUG juju.environs.tools reading v1.* tools
[LOG] 0:00.017 INFO juju.environs.
[LOG] 0:00.017 DEBUG juju.environs.
[LOG] 0:00.018 INFO juju.environs.
[LOG] 0:00.019 DEBUG juju.environs.
[LOG] 0:00.020 DEBUG juju.environs.tools no architecture specified when finding tools, looking for any
[LOG] 0:00.020 DEBUG juju.environs.tools no series specified when finding tools, looking for any
[LOG] 0:00.020 DEBUG juju.environs.
[LOG] 0:00.020 DEBUG juju.environs.
[LOG] 0:00.020 DEBUG juju.environs.
Jesse Meek (waigani) wrote : | # |
Please take a look.
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~waigani/juju-core/1307241-isolate-from-jujud into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
FAIL launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launc...
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~waigani/juju-core/1307241-isolate-from-jujud into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
FAIL launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launch...
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~waigani/juju-core/1307241-isolate-from-jujud into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
-------
PANIC: sync_test.go:420: badBuildSuite.
... Panic: cannot share a state between two dummy environs; old "only"; new "only" (PC=0x414311)
/usr/lib/
in panic
/home/tarmac/
Go Bot (go-bot) wrote : | # |
Attempt to merge into lp:juju-core failed due to conflicts:
text conflict in environs/
John A Meinel (jameinel) wrote : | # |
I'm not sure what changed, but Tarmac really doesn't like this branch:
014-05-20 10:12:04 ERROR An error occurred trying to merge lp:juju-core: Server sent an unexpected error: ('error', 'GhostRevisions
2014-05-20 10:12:04 ERROR Traceback (most recent call last):
File "/home/
merged = self._do_
File "/home/
str(
File "<string>", line 4, in revision_
File "/home/
self.
File "/home/
self.
File "/home/
self.
File "/home/
self.
File "/home/
_translate_
File "/home/
raise errors.
UnknownErrorFro
Preview Diff
1 | === modified file 'cmd/juju/bootstrap_test.go' |
2 | --- cmd/juju/bootstrap_test.go 2014-05-16 01:33:13 +0000 |
3 | +++ cmd/juju/bootstrap_test.go 2014-05-20 00:26:58 +0000 |
4 | @@ -27,7 +27,7 @@ |
5 | "launchpad.net/juju-core/environs/sync" |
6 | envtesting "launchpad.net/juju-core/environs/testing" |
7 | envtools "launchpad.net/juju-core/environs/tools" |
8 | - ttesting "launchpad.net/juju-core/environs/tools/testing" |
9 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
10 | "launchpad.net/juju-core/juju/arch" |
11 | "launchpad.net/juju-core/provider/dummy" |
12 | coretesting "launchpad.net/juju-core/testing" |
13 | @@ -56,6 +56,8 @@ |
14 | // Set up a local source with tools. |
15 | sourceDir := createToolsSource(c, vAll) |
16 | s.PatchValue(&envtools.DefaultBaseURL, sourceDir) |
17 | + |
18 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
19 | } |
20 | |
21 | func (s *BootstrapSuite) TearDownSuite(c *gc.C) { |
22 | @@ -149,32 +151,7 @@ |
23 | c.Check(stripped, gc.Matches, test.err) |
24 | } |
25 | |
26 | -// mockUploadTools simulates the effect of tools.Upload, but skips the time- |
27 | -// consuming build from source. |
28 | -// TODO(fwereade) better factor agent/tools such that build logic is |
29 | -// exposed and can itself be neatly mocked? |
30 | -func mockUploadTools(stor storage.Storage, forceVersion *version.Number, series ...string) (*coretools.Tools, error) { |
31 | - vers := version.Current |
32 | - if forceVersion != nil { |
33 | - vers.Number = *forceVersion |
34 | - } |
35 | - versions := []version.Binary{vers} |
36 | - for _, series := range series { |
37 | - if series != version.Current.Series { |
38 | - newVers := vers |
39 | - newVers.Series = series |
40 | - versions = append(versions, newVers) |
41 | - } |
42 | - } |
43 | - agentTools, err := envtesting.UploadFakeToolsVersions(stor, versions...) |
44 | - if err != nil { |
45 | - return nil, err |
46 | - } |
47 | - return agentTools[0], nil |
48 | -} |
49 | - |
50 | func (s *BootstrapSuite) TestTest(c *gc.C) { |
51 | - s.PatchValue(&sync.Upload, mockUploadTools) |
52 | for i, test := range bootstrapTests { |
53 | c.Logf("\ntest %d: %s", i, test.info) |
54 | test.run(c) |
55 | @@ -542,7 +519,7 @@ |
56 | } |
57 | |
58 | func (s *BootstrapSuite) setupAutoUploadTest(c *gc.C, vers, series string) environs.Environ { |
59 | - s.PatchValue(&sync.Upload, mockUploadTools) |
60 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
61 | sourceDir := createToolsSource(c, vAll) |
62 | s.PatchValue(&envtools.DefaultBaseURL, sourceDir) |
63 | |
64 | @@ -659,7 +636,7 @@ |
65 | versionStrings[i] = vers.String() |
66 | } |
67 | source := c.MkDir() |
68 | - ttesting.MakeTools(c, source, "releases", versionStrings) |
69 | + toolstesting.MakeTools(c, source, "releases", versionStrings) |
70 | return source |
71 | } |
72 | |
73 | |
74 | === modified file 'cmd/juju/upgradejuju_test.go' |
75 | --- cmd/juju/upgradejuju_test.go 2014-05-12 04:28:39 +0000 |
76 | +++ cmd/juju/upgradejuju_test.go 2014-05-20 00:26:58 +0000 |
77 | @@ -21,6 +21,7 @@ |
78 | "launchpad.net/juju-core/environs/sync" |
79 | envtesting "launchpad.net/juju-core/environs/testing" |
80 | envtools "launchpad.net/juju-core/environs/tools" |
81 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
82 | "launchpad.net/juju-core/juju/testing" |
83 | coretesting "launchpad.net/juju-core/testing" |
84 | "launchpad.net/juju-core/version" |
85 | @@ -275,33 +276,7 @@ |
86 | expectUploaded: []string{"2.7.3.2-quantal-amd64", "2.7.3.2-%LTS%-amd64", "2.7.3.2-raring-amd64"}, |
87 | }} |
88 | |
89 | -// getMockBuildTools returns a sync.BuildToolsTarballFunc implementation which generates |
90 | -// a fake tools tarball. |
91 | -func (s *UpgradeJujuSuite) getMockBuildTools(c *gc.C) sync.BuildToolsTarballFunc { |
92 | - return func(forceVersion *version.Number) (*sync.BuiltTools, error) { |
93 | - // UploadFakeToolsVersions requires a storage to write to. |
94 | - stor, err := filestorage.NewFileStorageWriter(s.toolsDir) |
95 | - c.Assert(err, gc.IsNil) |
96 | - vers := version.Current |
97 | - if forceVersion != nil { |
98 | - vers.Number = *forceVersion |
99 | - } |
100 | - versions := []version.Binary{vers} |
101 | - uploadedTools, err := envtesting.UploadFakeToolsVersions(stor, versions...) |
102 | - c.Assert(err, gc.IsNil) |
103 | - agentTools := uploadedTools[0] |
104 | - return &sync.BuiltTools{ |
105 | - Dir: s.toolsDir, |
106 | - StorageName: envtools.StorageName(vers), |
107 | - Version: vers, |
108 | - Size: agentTools.Size, |
109 | - Sha256Hash: agentTools.SHA256, |
110 | - }, nil |
111 | - } |
112 | -} |
113 | - |
114 | func (s *UpgradeJujuSuite) TestUpgradeJuju(c *gc.C) { |
115 | - s.PatchValue(&sync.BuildToolsTarball, s.getMockBuildTools(c)) |
116 | oldVersion := version.Current |
117 | defer func() { |
118 | version.Current = oldVersion |
119 | @@ -415,7 +390,7 @@ |
120 | } |
121 | err := s.State.UpdateEnvironConfig(updateAttrs, nil, nil) |
122 | c.Assert(err, gc.IsNil) |
123 | - s.toolsDir = c.MkDir() |
124 | + s.PatchValue(&sync.BuildToolsTarball, toolstesting.GetMockBuildTools(c)) |
125 | } |
126 | |
127 | func (s *UpgradeJujuSuite) TestUpgradeJujuWithRealUpload(c *gc.C) { |
128 | |
129 | === modified file 'cmd/plugins/juju-metadata/toolsmetadata_test.go' |
130 | --- cmd/plugins/juju-metadata/toolsmetadata_test.go 2014-05-16 01:33:13 +0000 |
131 | +++ cmd/plugins/juju-metadata/toolsmetadata_test.go 2014-05-20 00:26:58 +0000 |
132 | @@ -19,7 +19,7 @@ |
133 | "launchpad.net/juju-core/environs/configstore" |
134 | envtesting "launchpad.net/juju-core/environs/testing" |
135 | "launchpad.net/juju-core/environs/tools" |
136 | - ttesting "launchpad.net/juju-core/environs/tools/testing" |
137 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
138 | "launchpad.net/juju-core/juju/osenv" |
139 | "launchpad.net/juju-core/provider/dummy" |
140 | coretesting "launchpad.net/juju-core/testing" |
141 | @@ -95,13 +95,13 @@ |
142 | |
143 | func (s *ToolsMetadataSuite) TestGenerateDefaultDirectory(c *gc.C) { |
144 | metadataDir := osenv.JujuHome() // default metadata dir |
145 | - ttesting.MakeTools(c, metadataDir, "releases", versionStrings) |
146 | + toolstesting.MakeTools(c, metadataDir, "releases", versionStrings) |
147 | ctx := coretesting.Context(c) |
148 | code := cmd.Main(envcmd.Wrap(&ToolsMetadataCommand{}), ctx, nil) |
149 | c.Assert(code, gc.Equals, 0) |
150 | output := ctx.Stdout.(*bytes.Buffer).String() |
151 | c.Assert(output, gc.Matches, expectedOutputDirectory) |
152 | - metadata := ttesting.ParseMetadataFromDir(c, metadataDir, false) |
153 | + metadata := toolstesting.ParseMetadataFromDir(c, metadataDir, false) |
154 | c.Assert(metadata, gc.HasLen, len(versionStrings)) |
155 | obtainedVersionStrings := make([]string, len(versionStrings)) |
156 | for i, metadata := range metadata { |
157 | @@ -113,13 +113,13 @@ |
158 | |
159 | func (s *ToolsMetadataSuite) TestGenerateDirectory(c *gc.C) { |
160 | metadataDir := c.MkDir() |
161 | - ttesting.MakeTools(c, metadataDir, "releases", versionStrings) |
162 | + toolstesting.MakeTools(c, metadataDir, "releases", versionStrings) |
163 | ctx := coretesting.Context(c) |
164 | code := cmd.Main(envcmd.Wrap(&ToolsMetadataCommand{}), ctx, []string{"-d", metadataDir}) |
165 | c.Assert(code, gc.Equals, 0) |
166 | output := ctx.Stdout.(*bytes.Buffer).String() |
167 | c.Assert(output, gc.Matches, expectedOutputDirectory) |
168 | - metadata := ttesting.ParseMetadataFromDir(c, metadataDir, false) |
169 | + metadata := toolstesting.ParseMetadataFromDir(c, metadataDir, false) |
170 | c.Assert(metadata, gc.HasLen, len(versionStrings)) |
171 | obtainedVersionStrings := make([]string, len(versionStrings)) |
172 | for i, metadata := range metadata { |
173 | @@ -131,14 +131,14 @@ |
174 | |
175 | func (s *ToolsMetadataSuite) TestGenerateWithPublicFallback(c *gc.C) { |
176 | // Write tools and metadata to the public tools location. |
177 | - ttesting.MakeToolsWithCheckSum(c, s.publicStorageDir, "releases", versionStrings) |
178 | + toolstesting.MakeToolsWithCheckSum(c, s.publicStorageDir, "releases", versionStrings) |
179 | |
180 | // Run the command with no local metadata. |
181 | ctx := coretesting.Context(c) |
182 | metadataDir := c.MkDir() |
183 | code := cmd.Main(envcmd.Wrap(&ToolsMetadataCommand{}), ctx, []string{"-d", metadataDir}) |
184 | c.Assert(code, gc.Equals, 0) |
185 | - metadata := ttesting.ParseMetadataFromDir(c, metadataDir, false) |
186 | + metadata := toolstesting.ParseMetadataFromDir(c, metadataDir, false) |
187 | c.Assert(metadata, gc.HasLen, len(versionStrings)) |
188 | obtainedVersionStrings := make([]string, len(versionStrings)) |
189 | for i, metadata := range metadata { |
190 | @@ -150,13 +150,13 @@ |
191 | |
192 | func (s *ToolsMetadataSuite) TestGenerateWithMirrors(c *gc.C) { |
193 | metadataDir := c.MkDir() |
194 | - ttesting.MakeTools(c, metadataDir, "releases", versionStrings) |
195 | + toolstesting.MakeTools(c, metadataDir, "releases", versionStrings) |
196 | ctx := coretesting.Context(c) |
197 | code := cmd.Main(envcmd.Wrap(&ToolsMetadataCommand{}), ctx, []string{"--public", "-d", metadataDir}) |
198 | c.Assert(code, gc.Equals, 0) |
199 | output := ctx.Stdout.(*bytes.Buffer).String() |
200 | c.Assert(output, gc.Matches, expectedOutputMirrors) |
201 | - metadata := ttesting.ParseMetadataFromDir(c, metadataDir, true) |
202 | + metadata := toolstesting.ParseMetadataFromDir(c, metadataDir, true) |
203 | c.Assert(metadata, gc.HasLen, len(versionStrings)) |
204 | obtainedVersionStrings := make([]string, len(versionStrings)) |
205 | for i, metadata := range metadata { |
206 | @@ -184,7 +184,7 @@ |
207 | currentVersion.String() + ".1-precise-amd64", |
208 | } |
209 | metadataDir := osenv.JujuHome() // default metadata dir |
210 | - ttesting.MakeTools(c, metadataDir, "releases", versionStrings) |
211 | + toolstesting.MakeTools(c, metadataDir, "releases", versionStrings) |
212 | ctx := coretesting.Context(c) |
213 | code := cmd.Main(envcmd.Wrap(&ToolsMetadataCommand{}), ctx, nil) |
214 | c.Assert(code, gc.Equals, 0) |
215 | @@ -197,11 +197,11 @@ |
216 | .*Writing tools/streams/v1/com\.ubuntu\.juju:released:tools\.json |
217 | `[1:], regexp.QuoteMeta(versionStrings[0]), regexp.QuoteMeta(versionStrings[1])) |
218 | c.Assert(output, gc.Matches, expectedOutput) |
219 | - metadata := ttesting.ParseMetadataFromDir(c, metadataDir, false) |
220 | + metadata := toolstesting.ParseMetadataFromDir(c, metadataDir, false) |
221 | c.Assert(metadata, gc.HasLen, 2) |
222 | |
223 | filename := fmt.Sprintf("juju-%s-precise-amd64.tgz", currentVersion) |
224 | - size, sha256 := ttesting.SHA256sum(c, filepath.Join(metadataDir, "tools", "releases", filename)) |
225 | + size, sha256 := toolstesting.SHA256sum(c, filepath.Join(metadataDir, "tools", "releases", filename)) |
226 | c.Assert(metadata[0], gc.DeepEquals, &tools.ToolsMetadata{ |
227 | Release: "precise", |
228 | Version: currentVersion.String(), |
229 | @@ -213,7 +213,7 @@ |
230 | }) |
231 | |
232 | filename = fmt.Sprintf("juju-%s.1-precise-amd64.tgz", currentVersion) |
233 | - size, sha256 = ttesting.SHA256sum(c, filepath.Join(metadataDir, "tools", "releases", filename)) |
234 | + size, sha256 = toolstesting.SHA256sum(c, filepath.Join(metadataDir, "tools", "releases", filename)) |
235 | c.Assert(metadata[1], gc.DeepEquals, &tools.ToolsMetadata{ |
236 | Release: "precise", |
237 | Version: currentVersion.String() + ".1", |
238 | |
239 | === modified file 'environs/bootstrap/bootstrap_test.go' |
240 | --- environs/bootstrap/bootstrap_test.go 2014-05-15 05:14:01 +0000 |
241 | +++ environs/bootstrap/bootstrap_test.go 2014-05-20 00:26:58 +0000 |
242 | @@ -16,12 +16,11 @@ |
243 | "launchpad.net/juju-core/environs/bootstrap" |
244 | "launchpad.net/juju-core/environs/config" |
245 | "launchpad.net/juju-core/environs/configstore" |
246 | - "launchpad.net/juju-core/environs/filestorage" |
247 | "launchpad.net/juju-core/environs/simplestreams" |
248 | "launchpad.net/juju-core/environs/storage" |
249 | - "launchpad.net/juju-core/environs/sync" |
250 | envtesting "launchpad.net/juju-core/environs/testing" |
251 | envtools "launchpad.net/juju-core/environs/tools" |
252 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
253 | "launchpad.net/juju-core/juju/arch" |
254 | "launchpad.net/juju-core/provider/dummy" |
255 | coretesting "launchpad.net/juju-core/testing" |
256 | @@ -156,6 +155,7 @@ |
257 | }} |
258 | |
259 | func (s *bootstrapSuite) TestBootstrapTools(c *gc.C) { |
260 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
261 | allTests := append(envtesting.BootstrapToolsTests, bootstrapSetAgentVersionTests...) |
262 | // version.Current is set in the loop so ensure it is restored later. |
263 | s.PatchValue(&version.Current, version.Current) |
264 | @@ -290,32 +290,6 @@ |
265 | "cannot upload bootstrap tools: Juju cannot bootstrap because no tools are available for your environment.*") |
266 | } |
267 | |
268 | -// getMockBuildTools returns a sync.BuildToolsTarballFunc implementation which generates |
269 | -// a fake tools tarball. |
270 | -func (s *bootstrapSuite) getMockBuildTools(c *gc.C) sync.BuildToolsTarballFunc { |
271 | - toolsDir := c.MkDir() |
272 | - return func(forceVersion *version.Number) (*sync.BuiltTools, error) { |
273 | - // UploadFakeToolsVersions requires a storage to write to. |
274 | - stor, err := filestorage.NewFileStorageWriter(toolsDir) |
275 | - c.Assert(err, gc.IsNil) |
276 | - vers := version.Current |
277 | - if forceVersion != nil { |
278 | - vers.Number = *forceVersion |
279 | - } |
280 | - versions := []version.Binary{vers} |
281 | - uploadedTools, err := envtesting.UploadFakeToolsVersions(stor, versions...) |
282 | - c.Assert(err, gc.IsNil) |
283 | - agentTools := uploadedTools[0] |
284 | - return &sync.BuiltTools{ |
285 | - Dir: toolsDir, |
286 | - StorageName: envtools.StorageName(vers), |
287 | - Version: vers, |
288 | - Size: agentTools.Size, |
289 | - Sha256Hash: agentTools.SHA256, |
290 | - }, nil |
291 | - } |
292 | -} |
293 | - |
294 | func (s *bootstrapSuite) TestEnsureToolsAvailability(c *gc.C) { |
295 | existingToolsVersion := version.MustParseBinary("1.19.0-trusty-amd64") |
296 | s.PatchValue(&version.Current, existingToolsVersion) |
297 | @@ -326,7 +300,7 @@ |
298 | cliVersion := version.Current |
299 | cliVersion.Arch = "arm64" |
300 | version.Current = cliVersion |
301 | - s.PatchValue(&sync.BuildToolsTarball, s.getMockBuildTools(c)) |
302 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
303 | // Host runs arm64, environment supports arm64. |
304 | s.PatchValue(&arch.HostArch, func() string { |
305 | return "arm64" |
306 | @@ -378,7 +352,7 @@ |
307 | cliVersion := version.Current |
308 | cliVersion.Arch = "arm64" |
309 | version.Current = cliVersion |
310 | - s.PatchValue(&sync.BuildToolsTarball, s.getMockBuildTools(c)) |
311 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
312 | // Host runs arm64, environment supports arm64. |
313 | s.PatchValue(&arch.HostArch, func() string { |
314 | return "arm64" |
315 | |
316 | === modified file 'environs/sync/sync_test.go' |
317 | --- environs/sync/sync_test.go 2014-05-16 01:33:13 +0000 |
318 | +++ environs/sync/sync_test.go 2014-05-20 00:26:58 +0000 |
319 | @@ -12,7 +12,6 @@ |
320 | "os/exec" |
321 | "path/filepath" |
322 | "sort" |
323 | - "strings" |
324 | "testing" |
325 | |
326 | jc "github.com/juju/testing/checkers" |
327 | @@ -27,9 +26,10 @@ |
328 | "launchpad.net/juju-core/environs/sync" |
329 | envtesting "launchpad.net/juju-core/environs/testing" |
330 | envtools "launchpad.net/juju-core/environs/tools" |
331 | - ttesting "launchpad.net/juju-core/environs/tools/testing" |
332 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
333 | "launchpad.net/juju-core/provider/dummy" |
334 | coretesting "launchpad.net/juju-core/testing" |
335 | + "launchpad.net/juju-core/testing/testbase" |
336 | coretools "launchpad.net/juju-core/tools" |
337 | "launchpad.net/juju-core/utils" |
338 | "launchpad.net/juju-core/version" |
339 | @@ -50,6 +50,7 @@ |
340 | |
341 | var _ = gc.Suite(&syncSuite{}) |
342 | var _ = gc.Suite(&uploadSuite{}) |
343 | +var _ = gc.Suite(&badBuildSuite{}) |
344 | |
345 | func (s *syncSuite) setUpTest(c *gc.C) { |
346 | s.FakeJujuHomeSuite.SetUpTest(c) |
347 | @@ -86,8 +87,8 @@ |
348 | for i, vers := range vAll { |
349 | versionStrings[i] = vers.String() |
350 | } |
351 | - ttesting.MakeTools(c, baseDir, "releases", versionStrings) |
352 | - ttesting.MakeTools(c, s.localStorage, "releases", versionStrings) |
353 | + toolstesting.MakeTools(c, baseDir, "releases", versionStrings) |
354 | + toolstesting.MakeTools(c, s.localStorage, "releases", versionStrings) |
355 | |
356 | // Switch the default tools location. |
357 | baseURL, err := s.storage.URL(storage.BaseToolsPath) |
358 | @@ -279,6 +280,8 @@ |
359 | c.Assert(err, gc.IsNil) |
360 | c.Assert(t.Version, gc.Equals, version.Current) |
361 | c.Assert(t.URL, gc.Not(gc.Equals), "") |
362 | + // TODO(waigani) Does this test need to download tools? If not, |
363 | + // sync.bundleTools can be mocked to improve test speed. |
364 | dir := downloadTools(c, t) |
365 | out, err := exec.Command(filepath.Join(dir, "jujud"), "version").CombinedOutput() |
366 | c.Assert(err, gc.IsNil) |
367 | @@ -307,38 +310,14 @@ |
368 | c.Assert(t.Version, gc.Equals, vers) |
369 | } |
370 | |
371 | -// Test that the upload procedure fails correctly |
372 | -// when the build process fails (because of a bad Go source |
373 | -// file in this case). |
374 | -func (s *uploadSuite) TestUploadBadBuild(c *gc.C) { |
375 | - gopath := c.MkDir() |
376 | - join := append([]string{gopath, "src"}, strings.Split("launchpad.net/juju-core/cmd/broken", "/")...) |
377 | - pkgdir := filepath.Join(join...) |
378 | - err := os.MkdirAll(pkgdir, 0777) |
379 | - c.Assert(err, gc.IsNil) |
380 | - |
381 | - err = ioutil.WriteFile(filepath.Join(pkgdir, "broken.go"), []byte("nope"), 0666) |
382 | - c.Assert(err, gc.IsNil) |
383 | - |
384 | - defer os.Setenv("GOPATH", os.Getenv("GOPATH")) |
385 | - os.Setenv("GOPATH", gopath) |
386 | - |
387 | - t, err := sync.Upload(s.env.Storage(), nil) |
388 | - c.Assert(t, gc.IsNil) |
389 | - c.Assert(err, gc.ErrorMatches, `build command "go" failed: exit status 1; can't load package:(.|\n)*`) |
390 | -} |
391 | - |
392 | func (s *uploadSuite) TestSyncTools(c *gc.C) { |
393 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
394 | builtTools, err := sync.BuildToolsTarball(nil) |
395 | c.Assert(err, gc.IsNil) |
396 | t, err := sync.SyncBuiltTools(s.env.Storage(), builtTools) |
397 | c.Assert(err, gc.IsNil) |
398 | c.Assert(t.Version, gc.Equals, version.Current) |
399 | c.Assert(t.URL, gc.Not(gc.Equals), "") |
400 | - dir := downloadTools(c, t) |
401 | - out, err := exec.Command(filepath.Join(dir, "jujud"), "version").CombinedOutput() |
402 | - c.Assert(err, gc.IsNil) |
403 | - c.Assert(string(out), gc.Equals, version.Current.String()+"\n") |
404 | } |
405 | |
406 | func (s *uploadSuite) TestSyncToolsFakeSeries(c *gc.C) { |
407 | @@ -384,7 +363,7 @@ |
408 | actualRaw := downloadToolsRaw(c, t) |
409 | c.Assert(string(actualRaw), gc.Equals, string(expectRaw)) |
410 | } |
411 | - metadata := ttesting.ParseMetadataFromStorage(c, s.env.Storage(), false) |
412 | + metadata := toolstesting.ParseMetadataFromStorage(c, s.env.Storage(), false) |
413 | c.Assert(metadata, gc.HasLen, 3) |
414 | for i, tm := range metadata { |
415 | c.Assert(tm.Release, gc.Equals, expectSeries[i]) |
416 | @@ -417,3 +396,149 @@ |
417 | c.Assert(err, gc.IsNil) |
418 | return buf.Bytes() |
419 | } |
420 | + |
421 | +func bundleTools(c *gc.C) (version.Binary, string, error) { |
422 | + f, err := ioutil.TempFile("", "juju-tgz") |
423 | + c.Assert(err, gc.IsNil) |
424 | + defer f.Close() |
425 | + defer os.Remove(f.Name()) |
426 | + |
427 | + return envtools.BundleTools(f, &version.Current.Number) |
428 | +} |
429 | + |
430 | +type badBuildSuite struct { |
431 | + env environs.Environ |
432 | + testbase.LoggingSuite |
433 | + envtesting.ToolsFixture |
434 | +} |
435 | + |
436 | +var badGo = ` |
437 | +#!/bin/bash --norc |
438 | +exit 1 |
439 | +`[1:] |
440 | + |
441 | +func (s *badBuildSuite) SetUpTest(c *gc.C) { |
442 | + s.LoggingSuite.SetUpTest(c) |
443 | + s.ToolsFixture.SetUpTest(c) |
444 | + // We only want to use simplestreams to find any synced tools. |
445 | + cfg, err := config.New(config.NoDefaults, dummy.SampleConfig()) |
446 | + c.Assert(err, gc.IsNil) |
447 | + s.env, err = environs.Prepare(cfg, coretesting.Context(c), configstore.NewMem()) |
448 | + c.Assert(err, gc.IsNil) |
449 | + |
450 | + // Mock go cmd |
451 | + testPath := c.MkDir() |
452 | + s.PatchEnvPathPrepend(testPath) |
453 | + path := filepath.Join(testPath, "go") |
454 | + err = ioutil.WriteFile(path, []byte(badGo), 0755) |
455 | + c.Assert(err, gc.IsNil) |
456 | + |
457 | + // Check mocked go cmd errors |
458 | + out, err := exec.Command("go").CombinedOutput() |
459 | + c.Assert(err, gc.ErrorMatches, "exit status 1") |
460 | + c.Assert(string(out), gc.Equals, "") |
461 | +} |
462 | + |
463 | +func (s *badBuildSuite) TearDownTest(c *gc.C) { |
464 | + dummy.Reset() |
465 | + s.ToolsFixture.TearDownTest(c) |
466 | + s.LoggingSuite.TearDownTest(c) |
467 | +} |
468 | + |
469 | +func (s *badBuildSuite) TestBundleToolsBadBuild(c *gc.C) { |
470 | + // Test that original bundleTools Func fails as expected |
471 | + vers, sha256Hash, err := bundleTools(c) |
472 | + c.Assert(vers, gc.DeepEquals, version.Binary{}) |
473 | + c.Assert(sha256Hash, gc.Equals, "") |
474 | + c.Assert(err, gc.ErrorMatches, `build command "go" failed: exit status 1; `) |
475 | + |
476 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
477 | + |
478 | + // Test that BundleTools func passes after it is |
479 | + // mocked out |
480 | + vers, sha256Hash, err = bundleTools(c) |
481 | + c.Assert(err, gc.IsNil) |
482 | + c.Assert(vers.Number, gc.Equals, version.Current.Number) |
483 | + c.Assert(sha256Hash, gc.Equals, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") |
484 | +} |
485 | + |
486 | +func (s *badBuildSuite) TestUploadToolsBadBuild(c *gc.C) { |
487 | + // Test that original Upload Func fails as expected |
488 | + t, err := sync.Upload(s.env.Storage(), nil) |
489 | + c.Assert(t, gc.IsNil) |
490 | + c.Assert(err, gc.ErrorMatches, `build command "go" failed: exit status 1; `) |
491 | + |
492 | + // Test that Upload func passes after BundleTools func is mocked out |
493 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
494 | + t, err = sync.Upload(s.env.Storage(), nil) |
495 | + c.Assert(err, gc.IsNil) |
496 | + c.Assert(t.Version, gc.Equals, version.Current) |
497 | + c.Assert(t.URL, gc.Not(gc.Equals), "") |
498 | +} |
499 | + |
500 | +func (s *badBuildSuite) TestBuildToolsBadBuild(c *gc.C) { |
501 | + // Test that original BuildToolsTarball fails |
502 | + builtTools, err := sync.BuildToolsTarball(nil) |
503 | + c.Assert(err, gc.ErrorMatches, `build command "go" failed: exit status 1; `) |
504 | + c.Assert(builtTools, gc.IsNil) |
505 | + |
506 | + // Test that BuildToolsTarball func passes after BundleTools func is |
507 | + // mocked out |
508 | + s.PatchValue(&envtools.BundleTools, toolstesting.GetMockBundleTools(c)) |
509 | + builtTools, err = sync.BuildToolsTarball(nil) |
510 | + c.Assert(builtTools.Version, gc.Equals, version.Current) |
511 | + c.Assert(err, gc.IsNil) |
512 | +} |
513 | + |
514 | +func (s *uploadSuite) TestMockBundleTools(c *gc.C) { |
515 | + var ( |
516 | + writer io.Writer |
517 | + forceVersion *version.Number |
518 | + n int |
519 | + p bytes.Buffer |
520 | + ) |
521 | + p.WriteString("Hello World") |
522 | + |
523 | + s.PatchValue(&envtools.BundleTools, func(writerArg io.Writer, forceVersionArg *version.Number) (vers version.Binary, sha256Hash string, err error) { |
524 | + writer = writerArg |
525 | + n, err = writer.Write(p.Bytes()) |
526 | + c.Assert(err, gc.IsNil) |
527 | + forceVersion = forceVersionArg |
528 | + return |
529 | + }) |
530 | + |
531 | + _, err := sync.BuildToolsTarball(&version.Current.Number) |
532 | + c.Assert(err, gc.IsNil) |
533 | + c.Assert(*forceVersion, gc.Equals, version.Current.Number) |
534 | + c.Assert(writer, gc.NotNil) |
535 | + c.Assert(n, gc.Equals, len(p.Bytes())) |
536 | +} |
537 | + |
538 | +func (s *uploadSuite) TestMockBuildTools(c *gc.C) { |
539 | + s.PatchValue(&version.Current, version.MustParseBinary("1.9.1-trusty-amd64")) |
540 | + buildToolsFunc := toolstesting.GetMockBuildTools(c) |
541 | + builtTools, err := buildToolsFunc(nil) |
542 | + c.Assert(err, gc.IsNil) |
543 | + |
544 | + builtTools.Dir = "" |
545 | + |
546 | + expectedBuiltTools := &sync.BuiltTools{ |
547 | + StorageName: "name", |
548 | + Version: version.Current, |
549 | + Size: 127, |
550 | + Sha256Hash: "6a19d08ca4913382ca86508aa38eb8ee5b9ae2d74333fe8d862c0f9e29b82c39", |
551 | + } |
552 | + c.Assert(builtTools, gc.DeepEquals, expectedBuiltTools) |
553 | + |
554 | + vers := version.MustParseBinary("1.5.3-trusty-amd64") |
555 | + builtTools, err = buildToolsFunc(&vers.Number) |
556 | + c.Assert(err, gc.IsNil) |
557 | + builtTools.Dir = "" |
558 | + expectedBuiltTools = &sync.BuiltTools{ |
559 | + StorageName: "name", |
560 | + Version: vers, |
561 | + Size: 127, |
562 | + Sha256Hash: "cad8ccedab8f26807ff379ddc2f2f78d9a7cac1276e001154cee5e39b9ddcc38", |
563 | + } |
564 | + c.Assert(builtTools, gc.DeepEquals, expectedBuiltTools) |
565 | +} |
566 | |
567 | === modified file 'environs/tools/build.go' |
568 | --- environs/tools/build.go 2014-04-03 04:17:49 +0000 |
569 | +++ environs/tools/build.go 2014-05-20 00:26:58 +0000 |
570 | @@ -18,10 +18,10 @@ |
571 | "launchpad.net/juju-core/version" |
572 | ) |
573 | |
574 | -// archive writes the executable files found in the given directory in |
575 | +// Archive writes the executable files found in the given directory in |
576 | // gzipped tar format to w, returning the SHA256 hash of the resulting file. |
577 | // An error is returned if an entry inside dir is not a regular executable file. |
578 | -func archive(w io.Writer, dir string) (string, error) { |
579 | +func Archive(w io.Writer, dir string) (string, error) { |
580 | entries, err := ioutil.ReadDir(dir) |
581 | if err != nil { |
582 | return "", err |
583 | @@ -198,11 +198,18 @@ |
584 | return nil |
585 | } |
586 | |
587 | +// BundleToolsFunc is a function which can bundle all the current juju tools |
588 | +// in gzipped tar format to the given writer. |
589 | +type BundleToolsFunc func(w io.Writer, forceVersion *version.Number) (version.Binary, string, error) |
590 | + |
591 | +// Override for testing. |
592 | +var BundleTools BundleToolsFunc = bundleTools |
593 | + |
594 | // BundleTools bundles all the current juju tools in gzipped tar |
595 | // format to the given writer. |
596 | // If forceVersion is not nil, a FORCE-VERSION file is included in |
597 | // the tools bundle so it will lie about its current version number. |
598 | -func BundleTools(w io.Writer, forceVersion *version.Number) (tvers version.Binary, sha256Hash string, err error) { |
599 | +func bundleTools(w io.Writer, forceVersion *version.Number) (tvers version.Binary, sha256Hash string, err error) { |
600 | dir, err := ioutil.TempDir("", "juju-tools") |
601 | if err != nil { |
602 | return version.Binary{}, "", err |
603 | @@ -232,7 +239,7 @@ |
604 | if err != nil { |
605 | return version.Binary{}, "", fmt.Errorf("invalid version %q printed by jujud", tvs) |
606 | } |
607 | - sha256Hash, err = archive(w, dir) |
608 | + sha256Hash, err = Archive(w, dir) |
609 | if err != nil { |
610 | return version.Binary{}, "", err |
611 | } |
612 | |
613 | === modified file 'environs/tools/simplestreams_test.go' |
614 | --- environs/tools/simplestreams_test.go 2014-03-21 03:27:16 +0000 |
615 | +++ environs/tools/simplestreams_test.go 2014-05-20 00:26:58 +0000 |
616 | @@ -22,7 +22,7 @@ |
617 | sstesting "launchpad.net/juju-core/environs/simplestreams/testing" |
618 | "launchpad.net/juju-core/environs/storage" |
619 | "launchpad.net/juju-core/environs/tools" |
620 | - ttesting "launchpad.net/juju-core/environs/tools/testing" |
621 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
622 | "launchpad.net/juju-core/testing/testbase" |
623 | coretools "launchpad.net/juju-core/tools" |
624 | "launchpad.net/juju-core/utils" |
625 | @@ -332,7 +332,7 @@ |
626 | c.Assert(err, gc.IsNil) |
627 | err = tools.MergeAndWriteMetadata(writer, toolsList, tools.DoNotWriteMirrors) |
628 | c.Assert(err, gc.IsNil) |
629 | - metadata := ttesting.ParseMetadataFromDir(c, dir, false) |
630 | + metadata := toolstesting.ParseMetadataFromDir(c, dir, false) |
631 | assertMetadataMatches(c, dir, toolsList, metadata) |
632 | } |
633 | |
634 | @@ -342,7 +342,7 @@ |
635 | "2.0.1-raring-amd64", |
636 | } |
637 | dir := c.MkDir() |
638 | - ttesting.MakeTools(c, dir, "releases", versionStrings) |
639 | + toolstesting.MakeTools(c, dir, "releases", versionStrings) |
640 | |
641 | toolsList := coretools.List{ |
642 | { |
643 | @@ -364,7 +364,7 @@ |
644 | } |
645 | err = tools.MergeAndWriteMetadata(writer, toolsList, writeMirrors) |
646 | c.Assert(err, gc.IsNil) |
647 | - metadata := ttesting.ParseMetadataFromDir(c, dir, withMirrors) |
648 | + metadata := toolstesting.ParseMetadataFromDir(c, dir, withMirrors) |
649 | assertMetadataMatches(c, dir, toolsList, metadata) |
650 | } |
651 | |
652 | @@ -404,7 +404,7 @@ |
653 | err = tools.MergeAndWriteMetadata(writer, newToolsList, tools.DoNotWriteMirrors) |
654 | c.Assert(err, gc.IsNil) |
655 | requiredToolsList := append(existingToolsList, newToolsList[1]) |
656 | - metadata := ttesting.ParseMetadataFromDir(c, dir, false) |
657 | + metadata := toolstesting.ParseMetadataFromDir(c, dir, false) |
658 | assertMetadataMatches(c, dir, requiredToolsList, metadata) |
659 | } |
660 | |
661 | @@ -557,7 +557,7 @@ |
662 | func (*metadataHelperSuite) TestResolveMetadata(c *gc.C) { |
663 | var versionStrings = []string{"1.2.3-precise-amd64"} |
664 | dir := c.MkDir() |
665 | - ttesting.MakeTools(c, dir, "releases", versionStrings) |
666 | + toolstesting.MakeTools(c, dir, "releases", versionStrings) |
667 | toolsList := coretools.List{{ |
668 | Version: version.MustParseBinary(versionStrings[0]), |
669 | Size: 123, |
670 | |
671 | === modified file 'environs/tools/testing/testing.go' |
672 | --- environs/tools/testing/testing.go 2014-05-13 23:18:30 +0000 |
673 | +++ environs/tools/testing/testing.go 2014-05-20 00:26:58 +0000 |
674 | @@ -5,7 +5,9 @@ |
675 | |
676 | import ( |
677 | "bytes" |
678 | + "crypto/sha256" |
679 | "fmt" |
680 | + "io" |
681 | "io/ioutil" |
682 | "os" |
683 | "path" |
684 | @@ -20,7 +22,9 @@ |
685 | "launchpad.net/juju-core/environs/filestorage" |
686 | "launchpad.net/juju-core/environs/simplestreams" |
687 | "launchpad.net/juju-core/environs/storage" |
688 | + "launchpad.net/juju-core/environs/sync" |
689 | "launchpad.net/juju-core/environs/tools" |
690 | + coretesting "launchpad.net/juju-core/testing" |
691 | coretools "launchpad.net/juju-core/tools" |
692 | "launchpad.net/juju-core/utils" |
693 | "launchpad.net/juju-core/utils/set" |
694 | @@ -28,6 +32,44 @@ |
695 | "launchpad.net/juju-core/version/ubuntu" |
696 | ) |
697 | |
698 | +func GetMockBundleTools(c *gc.C) tools.BundleToolsFunc { |
699 | + return func(w io.Writer, forceVersion *version.Number) (vers version.Binary, sha256Hash string, err error) { |
700 | + vers = version.Current |
701 | + if forceVersion != nil { |
702 | + vers.Number = *forceVersion |
703 | + } |
704 | + sha256Hash = fmt.Sprintf("%x", sha256.New().Sum(nil)) |
705 | + return vers, sha256Hash, err |
706 | + } |
707 | +} |
708 | + |
709 | +// GetMockBuildTools returns a sync.BuildToolsTarballFunc implementation which generates |
710 | +// a fake tools tarball. |
711 | +func GetMockBuildTools(c *gc.C) sync.BuildToolsTarballFunc { |
712 | + return func(forceVersion *version.Number) (*sync.BuiltTools, error) { |
713 | + vers := version.Current |
714 | + if forceVersion != nil { |
715 | + vers.Number = *forceVersion |
716 | + } |
717 | + |
718 | + tgz, checksum := coretesting.TarGz( |
719 | + coretesting.NewTarFile("jujud", 0777, "jujud contents "+vers.String())) |
720 | + |
721 | + toolsDir, err := ioutil.TempDir("", "juju-tools") |
722 | + c.Assert(err, gc.IsNil) |
723 | + name := "name" |
724 | + ioutil.WriteFile(filepath.Join(toolsDir, name), tgz, 0777) |
725 | + |
726 | + return &sync.BuiltTools{ |
727 | + Dir: toolsDir, |
728 | + StorageName: name, |
729 | + Version: vers, |
730 | + Size: int64(len(tgz)), |
731 | + Sha256Hash: checksum, |
732 | + }, nil |
733 | + } |
734 | +} |
735 | + |
736 | // MakeTools creates some fake tools with the given version strings. |
737 | func MakeTools(c *gc.C, metadataDir, subdir string, versionStrings []string) coretools.List { |
738 | return makeTools(c, metadataDir, subdir, versionStrings, false) |
739 | |
740 | === modified file 'environs/tools/tools_test.go' |
741 | --- environs/tools/tools_test.go 2014-05-13 04:30:48 +0000 |
742 | +++ environs/tools/tools_test.go 2014-05-20 00:26:58 +0000 |
743 | @@ -18,7 +18,7 @@ |
744 | "launchpad.net/juju-core/environs/configstore" |
745 | envtesting "launchpad.net/juju-core/environs/testing" |
746 | envtools "launchpad.net/juju-core/environs/tools" |
747 | - ttesting "launchpad.net/juju-core/environs/tools/testing" |
748 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
749 | "launchpad.net/juju-core/provider/dummy" |
750 | "launchpad.net/juju-core/testing" |
751 | "launchpad.net/juju-core/testing/testbase" |
752 | @@ -82,11 +82,11 @@ |
753 | } |
754 | |
755 | func (s *SimpleStreamsToolsSuite) uploadCustom(c *gc.C, verses ...version.Binary) map[version.Binary]string { |
756 | - return ttesting.UploadToDirectory(c, s.customToolsDir, verses...) |
757 | + return toolstesting.UploadToDirectory(c, s.customToolsDir, verses...) |
758 | } |
759 | |
760 | func (s *SimpleStreamsToolsSuite) uploadPublic(c *gc.C, verses ...version.Binary) map[version.Binary]string { |
761 | - return ttesting.UploadToDirectory(c, s.publicToolsDir, verses...) |
762 | + return toolstesting.UploadToDirectory(c, s.publicToolsDir, verses...) |
763 | } |
764 | |
765 | func (s *SimpleStreamsToolsSuite) resetEnv(c *gc.C, attrs map[string]interface{}) { |
766 | @@ -180,7 +180,7 @@ |
767 | |
768 | func (s *SimpleStreamsToolsSuite) TestFindToolsInControlBucket(c *gc.C) { |
769 | s.reset(c, nil) |
770 | - custom := ttesting.UploadToStorage(c, s.env.Storage(), envtesting.V110p...) |
771 | + custom := toolstesting.UploadToStorage(c, s.env.Storage(), envtesting.V110p...) |
772 | s.uploadPublic(c, envtesting.VAll...) |
773 | actual, err := envtools.FindTools(s.env, 1, 1, coretools.Filter{}, envtools.DoNotAllowRetry) |
774 | c.Assert(err, gc.IsNil) |
775 | |
776 | === modified file 'state/apiserver/client/client_test.go' |
777 | --- state/apiserver/client/client_test.go 2014-05-13 04:30:48 +0000 |
778 | +++ state/apiserver/client/client_test.go 2014-05-20 00:26:58 +0000 |
779 | @@ -21,7 +21,7 @@ |
780 | "launchpad.net/juju-core/environs/config" |
781 | "launchpad.net/juju-core/environs/manual" |
782 | envstorage "launchpad.net/juju-core/environs/storage" |
783 | - ttesting "launchpad.net/juju-core/environs/tools/testing" |
784 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
785 | "launchpad.net/juju-core/instance" |
786 | "launchpad.net/juju-core/provider/dummy" |
787 | "launchpad.net/juju-core/state" |
788 | @@ -1607,7 +1607,7 @@ |
789 | result, err := s.APIState.Client().FindTools(2, -1, "", "") |
790 | c.Assert(err, gc.IsNil) |
791 | c.Assert(result.Error, jc.Satisfies, params.IsCodeNotFound) |
792 | - ttesting.UploadToStorage(c, s.Conn.Environ.Storage(), version.MustParseBinary("2.12.0-precise-amd64")) |
793 | + toolstesting.UploadToStorage(c, s.Conn.Environ.Storage(), version.MustParseBinary("2.12.0-precise-amd64")) |
794 | result, err = s.APIState.Client().FindTools(2, 12, "precise", "amd64") |
795 | c.Assert(err, gc.IsNil) |
796 | c.Assert(result.Error, gc.IsNil) |
797 | |
798 | === modified file 'state/apiserver/tools_test.go' |
799 | --- state/apiserver/tools_test.go 2014-03-13 05:57:38 +0000 |
800 | +++ state/apiserver/tools_test.go 2014-05-20 00:26:58 +0000 |
801 | @@ -12,7 +12,7 @@ |
802 | gc "launchpad.net/gocheck" |
803 | |
804 | "launchpad.net/juju-core/environs/tools" |
805 | - ttesting "launchpad.net/juju-core/environs/tools/testing" |
806 | + toolstesting "launchpad.net/juju-core/environs/tools/testing" |
807 | "launchpad.net/juju-core/state" |
808 | "launchpad.net/juju-core/state/api/params" |
809 | coretools "launchpad.net/juju-core/tools" |
810 | @@ -106,7 +106,7 @@ |
811 | localStorage := c.MkDir() |
812 | vers := version.MustParseBinary("1.9.0-quantal-amd64") |
813 | versionStrings := []string{vers.String()} |
814 | - expectedTools := ttesting.MakeToolsWithCheckSum(c, localStorage, "releases", versionStrings) |
815 | + expectedTools := toolstesting.MakeToolsWithCheckSum(c, localStorage, "releases", versionStrings) |
816 | |
817 | // Now try uploading them. |
818 | toolsFile := tools.StorageName(vers) |
819 | @@ -136,7 +136,7 @@ |
820 | localStorage := c.MkDir() |
821 | vers := version.MustParseBinary("1.9.0-quantal-amd64") |
822 | versionStrings := []string{vers.String()} |
823 | - expectedTools := ttesting.MakeToolsWithCheckSum(c, localStorage, "releases", versionStrings) |
824 | + expectedTools := toolstesting.MakeToolsWithCheckSum(c, localStorage, "releases", versionStrings) |
825 | |
826 | // Now try uploading them. |
827 | toolsFile := tools.StorageName(vers) |
Reviewers: mp+215590_ code.launchpad. net,
Message:
Please take a look.
Description:
Fix 1307241 isolate tests
Lots of tests fail without the jujud package.
Isolate tests to ensure they can run without
jujud.
So far: patched sync.Upload in cmd/juju and
environs/bootstrap tests, tests now pass.
https:/ /code.launchpad .net/~waigani/ juju-core/ 1307241- isolate- from-jujud/ +merge/ 215590
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/87130045/
Affected files (+107, -86 lines): bootstrap_ test.go upgradejuju_ test.go bootstrap/ bootstrap_ test.go jujutest/ livetests. go sync/sync_ test.go tools/build. go tools/testing/ testing. go
A [revision details]
M cmd/juju/
M cmd/juju/
M environs/
M environs/
M environs/
M environs/
M environs/