Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1955)

Delta Between Two Patch Sets: environs/manual/bootstrap_test.go

Issue 14433058: Providers are responsible for selecting tools
Left Patch Set: Providers are responsible for selecting tools Created 11 years, 5 months ago
Right Patch Set: Providers are responsible for selecting tools Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « environs/manual/bootstrap.go ('k') | environs/manual/detection.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package manual 4 package manual
5 5
6 import ( 6 import (
7 "os" 7 "os"
8 8
9 gc "launchpad.net/gocheck" 9 gc "launchpad.net/gocheck"
10 10
11 "launchpad.net/juju-core/environs" 11 "launchpad.net/juju-core/environs"
12 "launchpad.net/juju-core/environs/bootstrap"
12 "launchpad.net/juju-core/environs/filestorage" 13 "launchpad.net/juju-core/environs/filestorage"
13 "launchpad.net/juju-core/environs/storage" 14 "launchpad.net/juju-core/environs/storage"
14 "launchpad.net/juju-core/environs/tools" 15 "launchpad.net/juju-core/environs/tools"
15 "launchpad.net/juju-core/instance" 16 "launchpad.net/juju-core/instance"
16 "launchpad.net/juju-core/juju/testing" 17 "launchpad.net/juju-core/juju/testing"
17 "launchpad.net/juju-core/provider/common"
18 ) 18 )
19 19
20 type bootstrapSuite struct { 20 type bootstrapSuite struct {
21 testing.JujuConnSuite 21 testing.JujuConnSuite
22 env *localStorageEnviron 22 env *localStorageEnviron
23 } 23 }
24 24
25 var _ = gc.Suite(&bootstrapSuite{}) 25 var _ = gc.Suite(&bootstrapSuite{})
26 26
27 type localStorageEnviron struct { 27 type localStorageEnviron struct {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 DataDir: "/var/lib/juju", 74 DataDir: "/var/lib/juju",
75 Environ: s.env, 75 Environ: s.env,
76 PossibleTools: toolsList, 76 PossibleTools: toolsList,
77 } 77 }
78 } 78 }
79 79
80 func (s *bootstrapSuite) TestBootstrap(c *gc.C) { 80 func (s *bootstrapSuite) TestBootstrap(c *gc.C) {
81 args := s.getArgs(c) 81 args := s.getArgs(c)
82 args.Host = "ubuntu@" + args.Host 82 args.Host = "ubuntu@" + args.Host
83 83
84 » defer FakeSSH{Series: s.Conn.Environ.Config().DefaultSeries()}.Install(c ).Restore() 84 » defer fakeSSH{Series: s.Conn.Environ.Config().DefaultSeries()}.install(c ).Restore()
85 err := Bootstrap(args) 85 err := Bootstrap(args)
86 c.Assert(err, gc.IsNil) 86 c.Assert(err, gc.IsNil)
87 87
88 » bootstrapState, err := common.LoadState(s.env.Storage()) 88 » bootstrapState, err := bootstrap.LoadState(s.env.Storage())
89 c.Assert(err, gc.IsNil) 89 c.Assert(err, gc.IsNil)
90 c.Assert( 90 c.Assert(
91 bootstrapState.StateInstances, 91 bootstrapState.StateInstances,
92 gc.DeepEquals, 92 gc.DeepEquals,
93 []instance.Id{BootstrapInstanceId}, 93 []instance.Id{BootstrapInstanceId},
94 ) 94 )
95 95
96 // Do it all again; this should work, despite the fact that 96 // Do it all again; this should work, despite the fact that
97 // there's a bootstrap state file. Existence for that is 97 // there's a bootstrap state file. Existence for that is
98 // checked in general bootstrap code (environs/bootstrap). 98 // checked in general bootstrap code (environs/bootstrap).
99 » defer FakeSSH{Series: s.Conn.Environ.Config().DefaultSeries()}.Install(c ).Restore() 99 » defer fakeSSH{Series: s.Conn.Environ.Config().DefaultSeries()}.install(c ).Restore()
100 err = Bootstrap(args) 100 err = Bootstrap(args)
101 c.Assert(err, gc.IsNil) 101 c.Assert(err, gc.IsNil)
102 102
103 // We *do* check that the machine has no juju* upstart jobs, though. 103 // We *do* check that the machine has no juju* upstart jobs, though.
104 » defer InstallFakeSSH(c, "", "/etc/init/jujud-machine-0.conf", 0).Restore () 104 » defer installFakeSSH(c, "", "/etc/init/jujud-machine-0.conf", 0).Restore ()
105 err = Bootstrap(args) 105 err = Bootstrap(args)
106 c.Assert(err, gc.Equals, ErrProvisioned) 106 c.Assert(err, gc.Equals, ErrProvisioned)
107 } 107 }
108 108
109 func (s *bootstrapSuite) TestBootstrapSkipDetection(c *gc.C) { 109 func (s *bootstrapSuite) TestBootstrapSkipDetection(c *gc.C) {
110 args := s.getArgs(c) 110 args := s.getArgs(c)
111 hc, err := instance.ParseHardware("arch=amd64") 111 hc, err := instance.ParseHardware("arch=amd64")
112 c.Assert(err, gc.IsNil) 112 c.Assert(err, gc.IsNil)
113 113
114 type test struct { 114 type test struct {
(...skipping 11 matching lines...) Expand all
126 hc: &hc, 126 hc: &hc,
127 }, { 127 }, {
128 series: "precise", 128 series: "precise",
129 hc: &hc, 129 hc: &hc,
130 }} 130 }}
131 131
132 for i, test := range tests { 132 for i, test := range tests {
133 c.Logf("test %d: %+v", i, test) 133 c.Logf("test %d: %+v", i, test)
134 args.Series = test.series 134 args.Series = test.series
135 args.HardwareCharacteristics = test.hc 135 args.HardwareCharacteristics = test.hc
136 » » var ssh FakeSSH 136 » » var ssh fakeSSH
137 if args.Series != "" && args.HardwareCharacteristics != nil { 137 if args.Series != "" && args.HardwareCharacteristics != nil {
138 // If neither series nor hardware-characteristics 138 // If neither series nor hardware-characteristics
139 // is missing, detection is skipped. 139 // is missing, detection is skipped.
140 ssh.SkipDetection = true 140 ssh.SkipDetection = true
141 } 141 }
142 » » defer ssh.Install(c).Restore() 142 » » defer ssh.install(c).Restore()
143 err = Bootstrap(args) 143 err = Bootstrap(args)
144 c.Assert(err, gc.IsNil) 144 c.Assert(err, gc.IsNil)
145 } 145 }
146 } 146 }
147 147
148 func (s *bootstrapSuite) TestBootstrapScriptFailure(c *gc.C) { 148 func (s *bootstrapSuite) TestBootstrapScriptFailure(c *gc.C) {
149 args := s.getArgs(c) 149 args := s.getArgs(c)
150 args.Host = "ubuntu@" + args.Host 150 args.Host = "ubuntu@" + args.Host
151 series := s.Conn.Environ.Config().DefaultSeries() 151 series := s.Conn.Environ.Config().DefaultSeries()
152 » defer FakeSSH{Series: series, ProvisionAgentExitCode: 1}.Install(c).Rest ore() 152 » defer fakeSSH{Series: series, ProvisionAgentExitCode: 1}.install(c).Rest ore()
153 err := Bootstrap(args) 153 err := Bootstrap(args)
154 c.Assert(err, gc.NotNil) 154 c.Assert(err, gc.NotNil)
155 155
156 // Since the script failed, the state file should have been 156 // Since the script failed, the state file should have been
157 // removed from storage. 157 // removed from storage.
158 » _, err = common.LoadState(s.env.Storage()) 158 » _, err = bootstrap.LoadState(s.env.Storage())
159 c.Check(err, gc.Equals, environs.ErrNotBootstrapped) 159 c.Check(err, gc.Equals, environs.ErrNotBootstrapped)
160 } 160 }
161 161
162 func (s *bootstrapSuite) TestBootstrapEmptyDataDir(c *gc.C) { 162 func (s *bootstrapSuite) TestBootstrapEmptyDataDir(c *gc.C) {
163 args := s.getArgs(c) 163 args := s.getArgs(c)
164 args.DataDir = "" 164 args.DataDir = ""
165 c.Assert(Bootstrap(args), gc.ErrorMatches, "data-dir argument is empty") 165 c.Assert(Bootstrap(args), gc.ErrorMatches, "data-dir argument is empty")
166 } 166 }
167 167
168 func (s *bootstrapSuite) TestBootstrapEmptyHost(c *gc.C) { 168 func (s *bootstrapSuite) TestBootstrapEmptyHost(c *gc.C) {
169 args := s.getArgs(c) 169 args := s.getArgs(c)
170 args.Host = "" 170 args.Host = ""
171 c.Assert(Bootstrap(args), gc.ErrorMatches, "host argument is empty") 171 c.Assert(Bootstrap(args), gc.ErrorMatches, "host argument is empty")
172 } 172 }
173 173
174 func (s *bootstrapSuite) TestBootstrapNilEnviron(c *gc.C) { 174 func (s *bootstrapSuite) TestBootstrapNilEnviron(c *gc.C) {
175 args := s.getArgs(c) 175 args := s.getArgs(c)
176 args.Environ = nil 176 args.Environ = nil
177 c.Assert(Bootstrap(args), gc.ErrorMatches, "environ argument is nil") 177 c.Assert(Bootstrap(args), gc.ErrorMatches, "environ argument is nil")
178 } 178 }
179 179
180 func (s *bootstrapSuite) TestBootstrapNoMatchingTools(c *gc.C) { 180 func (s *bootstrapSuite) TestBootstrapNoMatchingTools(c *gc.C) {
181 // Empty tools list. 181 // Empty tools list.
182 args := s.getArgs(c) 182 args := s.getArgs(c)
183 args.PossibleTools = nil 183 args.PossibleTools = nil
184 series := s.Conn.Environ.Config().DefaultSeries() 184 series := s.Conn.Environ.Config().DefaultSeries()
185 » defer FakeSSH{Series: series, SkipProvisionAgent: true}.Install(c).Resto re() 185 » defer fakeSSH{Series: series, SkipProvisionAgent: true}.install(c).Resto re()
186 c.Assert(Bootstrap(args), gc.ErrorMatches, "no matching tools available" ) 186 c.Assert(Bootstrap(args), gc.ErrorMatches, "no matching tools available" )
187 187
188 // Non-empty list, but none that match the series/arch. 188 // Non-empty list, but none that match the series/arch.
189 » defer FakeSSH{Series: "edgy", SkipProvisionAgent: true}.Install(c).Resto re() 189 » defer fakeSSH{Series: "edgy", SkipProvisionAgent: true}.install(c).Resto re()
190 args = s.getArgs(c) 190 args = s.getArgs(c)
191 c.Assert(Bootstrap(args), gc.ErrorMatches, "no matching tools available" ) 191 c.Assert(Bootstrap(args), gc.ErrorMatches, "no matching tools available" )
192 } 192 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b