~dave-cheney/juju-core/167-simplestreams-add-trusty

« back to all changes in this revision

Viewing changes to provider/manual/environ_test.go

[r=axwalk] provider/manual: set storage in SetConfig

We currently rely on EnableBootstrapStorage to
specify the storage mechanism to use for bootstrap
and sync-tools. This is insufficient in practice,
causing panics such as those in lp:1262764.

Instead, we inject a boolean attribute into the
environment config that is stored in state; this
attribute is false in the .jenv file, and true
in state. We use its value to decide whether to
use sshstorage (external) or httpstorage (internal).

A followup will eliminate BootstrapStorager.

Fixes lp:1262764

https://codereview.appspot.com/61480043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
        env *manualEnviron
27
27
}
28
28
 
 
29
type dummyStorage struct {
 
30
        storage.Storage
 
31
}
 
32
 
29
33
var _ = gc.Suite(&environSuite{})
30
34
 
31
35
func (s *environSuite) SetUpTest(c *gc.C) {
32
 
        envConfig := getEnvironConfig(c, MinimalConfigValues())
33
 
        s.env = &manualEnviron{cfg: envConfig}
 
36
        env, err := manualProvider{}.Open(MinimalConfig(c))
 
37
        c.Assert(err, gc.IsNil)
 
38
        s.env = env.(*manualEnviron)
34
39
}
35
40
 
36
41
func (s *environSuite) TestSetConfig(c *gc.C) {
128
133
        c.Assert(strings.Contains(url, "/tools"), jc.IsTrue)
129
134
}
130
135
 
131
 
type dummyStorage struct {
132
 
        storage.Storage
133
 
}
134
 
 
135
136
func (s *environSuite) TestEnvironBootstrapStorager(c *gc.C) {
136
 
        var newSSHStorageResult = struct {
137
 
                stor storage.Storage
138
 
                err  error
139
 
        }{dummyStorage{}, errors.New("failed to get SSH storage")}
140
 
        s.PatchValue(&newSSHStorage, func(sshHost, storageDir, storageTmpdir string) (storage.Storage, error) {
141
 
                return newSSHStorageResult.stor, newSSHStorageResult.err
142
 
        })
143
 
 
144
137
        var initUbuntuResult error
145
138
        s.PatchValue(&initUbuntuUser, func(host, user, authorizedKeys string, stdin io.Reader, stdout io.Writer) error {
146
139
                return initUbuntuResult
150
143
        initUbuntuResult = errors.New("failed to initialise ubuntu user")
151
144
        c.Assert(s.env.EnableBootstrapStorage(ctx), gc.Equals, initUbuntuResult)
152
145
        initUbuntuResult = nil
153
 
        c.Assert(s.env.EnableBootstrapStorage(ctx), gc.Equals, newSSHStorageResult.err)
 
146
        c.Assert(s.env.EnableBootstrapStorage(ctx), gc.IsNil)
154
147
        // after the user is initialised once successfully,
155
148
        // another attempt will not be made.
156
149
        initUbuntuResult = errors.New("failed to initialise ubuntu user")
157
 
        c.Assert(s.env.EnableBootstrapStorage(ctx), gc.Equals, newSSHStorageResult.err)
158
 
 
159
 
        // after the bootstrap storage is initialised once successfully,
160
 
        // another attempt will not be made.
161
 
        backup := newSSHStorageResult.err
162
 
        newSSHStorageResult.err = nil
163
 
        c.Assert(s.env.EnableBootstrapStorage(ctx), gc.IsNil)
164
 
        newSSHStorageResult.err = backup
165
150
        c.Assert(s.env.EnableBootstrapStorage(ctx), gc.IsNil)
166
151
}