~rogpeppe/juju-core/438-local-instance-Addresses

« back to all changes in this revision

Viewing changes to environs/configstore/disk_test.go

[r=thumper],[bug=1231724] Make local provider work.

lp:1231724 shows that if a local provider is bootstrapped,
the created directory $(JUJU_HOME)/environments is not readable
by the user that started the provider as the bootstrap is done
by root, and the files and directories created are owned by
root with 0600 permission, which means you can't even run
juju status on a bootstrapped local provider.

https://codereview.appspot.com/14258043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package configstore_test
5
5
 
6
6
import (
 
7
        "fmt"
7
8
        "io/ioutil"
8
9
        "os"
 
10
        "os/user"
9
11
        "path/filepath"
10
12
        "strings"
 
13
        "syscall"
11
14
 
12
15
        gc "launchpad.net/gocheck"
13
16
 
14
17
        "launchpad.net/juju-core/environs/configstore"
15
18
        "launchpad.net/juju-core/errors"
16
19
        jc "launchpad.net/juju-core/testing/checkers"
 
20
        "launchpad.net/juju-core/testing/testbase"
17
21
)
18
22
 
19
23
var _ = gc.Suite(&diskInterfaceSuite{})
58
62
 
59
63
var _ = gc.Suite(&diskStoreSuite{})
60
64
 
61
 
type diskStoreSuite struct{}
 
65
type diskStoreSuite struct {
 
66
        testbase.LoggingSuite
 
67
}
62
68
 
63
69
func (*diskStoreSuite) TestNewDisk(c *gc.C) {
64
70
        dir := c.MkDir()
145
151
        c.Assert(info.Initialized(), jc.IsFalse)
146
152
}
147
153
 
 
154
func (s *diskStoreSuite) TestCreatePermissions(c *gc.C) {
 
155
        // Even though it doesn't test the actual chown, it does test the code path.
 
156
        user, err := user.Current()
 
157
        c.Assert(err, gc.IsNil)
 
158
        s.PatchEnvironment("SUDO_UID", user.Uid)
 
159
        s.PatchEnvironment("SUDO_GID", user.Gid)
 
160
 
 
161
        dir := c.MkDir()
 
162
        store, err := configstore.NewDisk(dir)
 
163
        c.Assert(err, gc.IsNil)
 
164
 
 
165
        // Create some new environment info.
 
166
        _, err = store.CreateInfo("someenv")
 
167
        c.Assert(err, gc.IsNil)
 
168
 
 
169
        checkPath := func(path string) {
 
170
                stat, err := os.Stat(path)
 
171
                c.Assert(err, gc.IsNil)
 
172
                c.Assert(fmt.Sprint(stat.Sys().(*syscall.Stat_t).Uid), gc.Equals, user.Uid)
 
173
                c.Assert(fmt.Sprint(stat.Sys().(*syscall.Stat_t).Gid), gc.Equals, user.Gid)
 
174
        }
 
175
        checkPath(storePath(dir, ""))
 
176
        checkPath(storePath(dir, "someenv"))
 
177
}
 
178
 
148
179
func (*diskStoreSuite) TestWriteTempFileFails(c *gc.C) {
149
180
        dir := c.MkDir()
150
181
        store, err := configstore.NewDisk(dir)