Skip to content

Commit 5d2acdb

Browse files
author
Horacio Duran
committed
Made Juju client XDG compatible
location for juju files is now (in order of choice): * $JUJU_DATA we might want to change the var name, but this particular one is shorter than $JUJU_XDG_DATA_HOME which would be impractical. * XDG_DATA_HOME or * .local/share/juju
1 parent c655490 commit 5d2acdb

File tree

122 files changed

+520
-446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+520
-446
lines changed

agent/format-1.18_whitebox_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (*format_1_18Suite) TestReadConfWithExisting1_18ConfigFileContents(c *gc.C)
5353
var agentConfig1_18Contents = `
5454
# format 1.18
5555
tag: machine-0
56-
datadir: /home/user/.juju/local
56+
datadir: /home/user/.local/share/juju/local
5757
logdir: /var/log/juju-user-local
5858
nonce: user-admin:bootstrap
5959
jobs:
@@ -103,7 +103,7 @@ values:
103103
NAMESPACE: user-local
104104
PROVIDER_TYPE: local
105105
STORAGE_ADDR: 10.0.3.1:8040
106-
STORAGE_DIR: /home/user/.juju/local/storage
106+
STORAGE_DIR: /home/user/.local/share/juju/local/storage
107107
controllercert: '-----BEGIN CERTIFICATE-----
108108
109109
MIICNzCCAaKgAwIBAgIBADALBgkqhkiG9w0BAQUwQzENMAsGA1UEChMEanVqdTEy
@@ -202,7 +202,7 @@ prefer-ipv6: true
202202
var agentConfig1_18NotStateMachine = `
203203
# format 1.18
204204
tag: machine-1
205-
datadir: /home/user/.juju/local
205+
datadir: /home/user/.local/share/juju/local
206206
logdir: /var/log/juju-user-local
207207
nonce: user-admin:bootstrap
208208
jobs:
@@ -253,7 +253,7 @@ values:
253253
NAMESPACE: user-local
254254
PROVIDER_TYPE: local
255255
STORAGE_ADDR: 10.0.3.1:8040
256-
STORAGE_DIR: /home/user/.juju/local/storage
256+
STORAGE_DIR: /home/user/.local/share/juju/local/storage
257257
apiport: 17070
258258
prefer-ipv6: true
259259
`[1:]

apiserver/common/block_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (m mockBlock) Message() string { return m.m }
3232
func (m mockBlock) ModelUUID() string { return "" }
3333

3434
type blockCheckerSuite struct {
35-
testing.FakeJujuHomeSuite
35+
testing.FakeJujuXDGDataHomeSuite
3636
aBlock state.Block
3737
destroy, remove, change state.Block
3838

@@ -42,7 +42,7 @@ type blockCheckerSuite struct {
4242
var _ = gc.Suite(&blockCheckerSuite{})
4343

4444
func (s *blockCheckerSuite) SetUpTest(c *gc.C) {
45-
s.FakeJujuHomeSuite.SetUpTest(c)
45+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
4646
s.destroy = mockBlock{t: state.DestroyBlock, m: "Mock BLOCK testing: DESTROY"}
4747
s.remove = mockBlock{t: state.RemoveBlock, m: "Mock BLOCK testing: REMOVE"}
4848
s.change = mockBlock{t: state.ChangeBlock, m: "Mock BLOCK testing: CHANGE"}

cloudconfig/providerinit/providerinit_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ func (s *CloudInitSuite) TestControllerUserDataPrecise(c *gc.C) {
193193
}
194194

195195
func (*CloudInitSuite) testUserData(c *gc.C, series string, bootstrap bool) {
196-
testJujuHome := c.MkDir()
197-
defer osenv.SetJujuHome(osenv.SetJujuHome(testJujuHome))
196+
testJujuXDGDataHome := c.MkDir()
197+
defer osenv.SetJujuXDGDataHome(osenv.SetJujuXDGDataHome(testJujuXDGDataHome))
198198
// Use actual series paths instead of local defaults
199199
logDir := must(paths.LogDir(series))
200200
metricsSpoolDir := must(paths.MetricsSpoolDir(series))

cmd/juju/backups/package_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestPackage(t *testing.T) {
4444
}
4545

4646
type BaseBackupsSuite struct {
47-
jujutesting.FakeJujuHomeSuite
47+
jujutesting.FakeJujuXDGDataHomeSuite
4848

4949
command cmd.Command
5050
metaresult *params.BackupsMetadataResult
@@ -54,7 +54,7 @@ type BaseBackupsSuite struct {
5454
}
5555

5656
func (s *BaseBackupsSuite) SetUpTest(c *gc.C) {
57-
s.FakeJujuHomeSuite.SetUpTest(c)
57+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
5858

5959
s.command = backups.NewSuperCommand()
6060
s.metaresult = &params.BackupsMetadataResult{
@@ -71,7 +71,7 @@ func (s *BaseBackupsSuite) TearDownTest(c *gc.C) {
7171
}
7272
}
7373

74-
s.FakeJujuHomeSuite.TearDownTest(c)
74+
s.FakeJujuXDGDataHomeSuite.TearDownTest(c)
7575
}
7676

7777
func (s *BaseBackupsSuite) checkHelp(c *gc.C, subcmd cmd.Command) {

cmd/juju/block/block_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type BlockCommandSuite struct {
2222
}
2323

2424
func (s *BlockCommandSuite) SetUpTest(c *gc.C) {
25-
s.FakeJujuHomeSuite.SetUpTest(c)
25+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
2626
s.mockClient = &block.MockBlockClient{}
2727
s.PatchValue(block.BlockClient, func(p *block.BaseBlockCommand) (block.BlockClientAPI, error) {
2828
return s.mockClient, nil

cmd/juju/block/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type listCommandSuite struct {
1919
}
2020

2121
func (s *listCommandSuite) SetUpTest(c *gc.C) {
22-
s.FakeJujuHomeSuite.SetUpTest(c)
22+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
2323
s.mockClient = &block.MockBlockClient{}
2424
s.PatchValue(block.ListClient, func(_ *modelcmd.ModelCommandBase) (block.BlockListAPI, error) {
2525
return s.mockClient, nil

cmd/juju/block/package_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestAll(t *stdtesting.T) {
1616
}
1717

1818
type ProtectionCommandSuite struct {
19-
testing.FakeJujuHomeSuite
19+
testing.FakeJujuXDGDataHomeSuite
2020
}
2121

2222
func (s *ProtectionCommandSuite) assertErrorMatches(c *gc.C, err error, expected string) {

cmd/juju/block/unblock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type UnblockCommandSuite struct {
1919
}
2020

2121
func (s *UnblockCommandSuite) SetUpTest(c *gc.C) {
22-
s.FakeJujuHomeSuite.SetUpTest(c)
22+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
2323
s.mockClient = &block.MockBlockClient{}
2424
}
2525

cmd/juju/cachedimages/delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
type deleteImageCommandSuite struct {
16-
testing.FakeJujuHomeSuite
16+
testing.FakeJujuXDGDataHomeSuite
1717
mockAPI *fakeImageDeleteAPI
1818
}
1919

@@ -37,7 +37,7 @@ func (f *fakeImageDeleteAPI) DeleteImage(kind, series, arch string) error {
3737
}
3838

3939
func (s *deleteImageCommandSuite) SetUpTest(c *gc.C) {
40-
s.FakeJujuHomeSuite.SetUpTest(c)
40+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
4141
s.mockAPI = &fakeImageDeleteAPI{}
4242
s.PatchValue(cachedimages.GetDeleteImageAPI, func(_ *cachedimages.CachedImagesCommandBase) (cachedimages.DeleteImageAPI, error) {
4343
return s.mockAPI, nil

cmd/juju/cachedimages/list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
type listImagesCommandSuite struct {
19-
testing.FakeJujuHomeSuite
19+
testing.FakeJujuXDGDataHomeSuite
2020
mockAPI *fakeImagesListAPI
2121
}
2222

@@ -45,7 +45,7 @@ func (f *fakeImagesListAPI) ListImages(kind, series, arch string) ([]params.Imag
4545
}
4646

4747
func (s *listImagesCommandSuite) SetUpTest(c *gc.C) {
48-
s.FakeJujuHomeSuite.SetUpTest(c)
48+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
4949
s.mockAPI = &fakeImagesListAPI{}
5050
s.PatchValue(cachedimages.GetListImagesAPI, func(_ *cachedimages.CachedImagesCommandBase) (cachedimages.ListImagesAPI, error) {
5151
return s.mockAPI, nil

cmd/juju/commands/apiinfo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
type APIInfoSuite struct {
18-
testing.FakeJujuHomeSuite
18+
testing.FakeJujuXDGDataHomeSuite
1919
}
2020

2121
var _ = gc.Suite(&APIInfoSuite{})

cmd/juju/commands/bootstrap_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848
)
4949

5050
type BootstrapSuite struct {
51-
coretesting.FakeJujuHomeSuite
51+
coretesting.FakeJujuXDGDataHomeSuite
5252
testing.MgoSuite
5353
envtesting.ToolsFixture
5454
mockBlockClient *mockBlockClient
@@ -59,13 +59,13 @@ type BootstrapSuite struct {
5959
var _ = gc.Suite(&BootstrapSuite{})
6060

6161
func (s *BootstrapSuite) SetUpSuite(c *gc.C) {
62-
s.FakeJujuHomeSuite.SetUpSuite(c)
62+
s.FakeJujuXDGDataHomeSuite.SetUpSuite(c)
6363
s.MgoSuite.SetUpSuite(c)
6464
s.PatchValue(&simplestreams.SimplestreamsJujuPublicKey, sstesting.SignedMetadataPublicKey)
6565
}
6666

6767
func (s *BootstrapSuite) SetUpTest(c *gc.C) {
68-
s.FakeJujuHomeSuite.SetUpTest(c)
68+
s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
6969
s.MgoSuite.SetUpTest(c)
7070
s.ToolsFixture.SetUpTest(c)
7171

@@ -93,13 +93,13 @@ func (s *BootstrapSuite) SetUpTest(c *gc.C) {
9393

9494
func (s *BootstrapSuite) TearDownSuite(c *gc.C) {
9595
s.MgoSuite.TearDownSuite(c)
96-
s.FakeJujuHomeSuite.TearDownSuite(c)
96+
s.FakeJujuXDGDataHomeSuite.TearDownSuite(c)
9797
}
9898

9999
func (s *BootstrapSuite) TearDownTest(c *gc.C) {
100100
s.ToolsFixture.TearDownTest(c)
101101
s.MgoSuite.TearDownTest(c)
102-
s.FakeJujuHomeSuite.TearDownTest(c)
102+
s.FakeJujuXDGDataHomeSuite.TearDownTest(c)
103103
dummy.Reset()
104104
}
105105

@@ -146,7 +146,7 @@ func (s *BootstrapSuite) TestBootstrapAPIReadyRetries(c *gc.C) {
146146
} {
147147
for _, modelFlag := range s.modelFlags {
148148

149-
resetJujuHome(c, "devenv")
149+
resetJujuXDGDataHome(c, "devenv")
150150

151151
s.mockBlockClient.num_retries = t.num_retries
152152
s.mockBlockClient.retry_count = 0
@@ -195,7 +195,7 @@ type bootstrapTest struct {
195195
}
196196

197197
func (s *BootstrapSuite) patchVersionAndSeries(c *gc.C, envName string) {
198-
env := resetJujuHome(c, envName)
198+
env := resetJujuXDGDataHome(c, envName)
199199
s.PatchValue(&series.HostSeries, func() string { return config.PreferredSeries(env.Config()) })
200200
s.patchVersion(c)
201201
}
@@ -212,7 +212,7 @@ func (s *BootstrapSuite) patchVersion(c *gc.C) {
212212
func (s *BootstrapSuite) run(c *gc.C, test bootstrapTest) testing.Restorer {
213213
// Create home with dummy provider and remove all
214214
// of its envtools.
215-
env := resetJujuHome(c, "peckham")
215+
env := resetJujuXDGDataHome(c, "peckham")
216216

217217
// Although we're testing PrepareEndpointsForCaching interactions
218218
// separately in the juju package, here we just ensure it gets
@@ -461,7 +461,7 @@ func (s *BootstrapSuite) TestBootstrapPropagatesEnvErrors(c *gc.C) {
461461

462462
// Change permissions on the jenv file to simulate some kind of
463463
// unexpected error when trying to read info from the environment
464-
jenvFile := testing.HomePath(".juju", "models", "cache.yaml")
464+
jenvFile := testing.JujuXDGDataHomePath("models", "cache.yaml")
465465
err = os.Chmod(jenvFile, os.FileMode(0200))
466466
c.Assert(err, jc.ErrorIsNil)
467467

@@ -575,7 +575,7 @@ func (s *BootstrapSuite) TestBootstrapJenvWarning(c *gc.C) {
575575

576576
func (s *BootstrapSuite) TestInvalidLocalSource(c *gc.C) {
577577
s.PatchValue(&version.Current, version.MustParse("1.2.0"))
578-
env := resetJujuHome(c, "devenv")
578+
env := resetJujuXDGDataHome(c, "devenv")
579579

580580
// Bootstrap the environment with an invalid source.
581581
// The command returns with an error.
@@ -614,7 +614,7 @@ func createImageMetadata(c *gc.C) (string, []*imagemetadata.ImageMetadata) {
614614

615615
func (s *BootstrapSuite) TestBootstrapCalledWithMetadataDir(c *gc.C) {
616616
sourceDir, _ := createImageMetadata(c)
617-
resetJujuHome(c, "devenv")
617+
resetJujuXDGDataHome(c, "devenv")
618618

619619
var bootstrap fakeBootstrapFuncs
620620
s.PatchValue(&getBootstrapFuncs, func() BootstrapInterface {
@@ -629,7 +629,7 @@ func (s *BootstrapSuite) TestBootstrapCalledWithMetadataDir(c *gc.C) {
629629
}
630630

631631
func (s *BootstrapSuite) checkBootstrapWithVersion(c *gc.C, vers, expect string) {
632-
resetJujuHome(c, "devenv")
632+
resetJujuXDGDataHome(c, "devenv")
633633

634634
var bootstrap fakeBootstrapFuncs
635635
s.PatchValue(&getBootstrapFuncs, func() BootstrapInterface {
@@ -657,7 +657,7 @@ func (s *BootstrapSuite) TestBootstrapWithBinaryVersionNumber(c *gc.C) {
657657
}
658658

659659
func (s *BootstrapSuite) TestBootstrapWithAutoUpgrade(c *gc.C) {
660-
resetJujuHome(c, "devenv")
660+
resetJujuXDGDataHome(c, "devenv")
661661

662662
var bootstrap fakeBootstrapFuncs
663663
s.PatchValue(&getBootstrapFuncs, func() BootstrapInterface {
@@ -673,7 +673,7 @@ func (s *BootstrapSuite) TestBootstrapWithAutoUpgrade(c *gc.C) {
673673
func (s *BootstrapSuite) TestAutoSyncLocalSource(c *gc.C) {
674674
sourceDir := createToolsSource(c, vAll)
675675
s.PatchValue(&version.Current, version.MustParse("1.2.0"))
676-
env := resetJujuHome(c, "peckham")
676+
env := resetJujuXDGDataHome(c, "peckham")
677677

678678
// Bootstrap the environment with the valid source.
679679
// The bootstrapping has to show no error, because the tools
@@ -699,7 +699,7 @@ func (s *BootstrapSuite) setupAutoUploadTest(c *gc.C, vers, ser string) environs
699699

700700
// Create home with dummy provider and remove all
701701
// of its envtools.
702-
return resetJujuHome(c, "devenv")
702+
return resetJujuXDGDataHome(c, "devenv")
703703
}
704704

705705
func (s *BootstrapSuite) TestAutoUploadAfterFailedSync(c *gc.C) {
@@ -751,7 +751,7 @@ Building tools to upload (1.7.3.1-raring-%s)
751751

752752
func (s *BootstrapSuite) TestBootstrapDestroy(c *gc.C) {
753753
for _, modelFlag := range s.modelFlags {
754-
resetJujuHome(c, "devenv")
754+
resetJujuXDGDataHome(c, "devenv")
755755
s.patchVersion(c)
756756

757757
opc, errc := cmdtesting.RunCommand(cmdtesting.NullContext(c), newBootstrapCommand(), modelFlag, "brokenenv", "--auto-upgrade")
@@ -776,7 +776,7 @@ func (s *BootstrapSuite) TestBootstrapDestroy(c *gc.C) {
776776

777777
func (s *BootstrapSuite) TestBootstrapKeepBroken(c *gc.C) {
778778
for _, modelFlag := range s.modelFlags {
779-
resetJujuHome(c, "devenv")
779+
resetJujuXDGDataHome(c, "devenv")
780780
s.patchVersion(c)
781781

782782
opc, errc := cmdtesting.RunCommand(cmdtesting.NullContext(c), newBootstrapCommand(), modelFlag, "brokenenv", "--keep-broken", "--auto-upgrade")
@@ -814,9 +814,9 @@ func createToolsSource(c *gc.C, versions []version.Binary) string {
814814
return source
815815
}
816816

817-
// resetJujuHome restores an new, clean Juju home environment without tools.
818-
func resetJujuHome(c *gc.C, envName string) environs.Environ {
819-
jenvDir := testing.HomePath(".juju", "models")
817+
// resetJujuXDGDataHome restores an new, clean Juju home environment without tools.
818+
func resetJujuXDGDataHome(c *gc.C, envName string) environs.Environ {
819+
jenvDir := testing.JujuXDGDataHomePath("models")
820820
err := os.RemoveAll(jenvDir)
821821
c.Assert(err, jc.ErrorIsNil)
822822
coretesting.WriteEnvironments(c, modelConfig)

cmd/juju/commands/debuglog_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
type DebugLogSuite struct {
21-
testing.FakeJujuHomeSuite
21+
testing.FakeJujuXDGDataHomeSuite
2222
}
2323

2424
var _ = gc.Suite(&DebugLogSuite{})

cmd/juju/commands/enableha_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
)
2727

2828
type EnableHASuite struct {
29-
// TODO (cherylj) change this back to a FakeJujuHomeSuite to
30-
// remove the mongo dependency once enable-ha is
29+
// TODO (cherylj) change this back to a FakeJujuXDGDataHomeSuite to
30+
// remove the mongo dependency once ensure-availability is
3131
// moved under a supercommand again.
3232
testing.JujuConnSuite
3333
fake *fakeHAClient

cmd/juju/commands/helptool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
type HelpToolSuite struct {
17-
testing.FakeJujuHomeSuite
17+
testing.FakeJujuXDGDataHomeSuite
1818
}
1919

2020
var _ = gc.Suite(&HelpToolSuite{})

0 commit comments

Comments
 (0)