Skip to content

Commit f4e2307

Browse files
committed
Merge pull request juju#1545 from bogdanteleaga/ci-various-windows-fixes
Ci various windows fixes Various fixes for windows tests (Review request: http://reviews.vapour.ws/r/874/)
2 parents c97cb7c + 75f8248 commit f4e2307

File tree

11 files changed

+109
-28
lines changed

11 files changed

+109
-28
lines changed

cmd/juju/environment/jenv_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ func (*jenvSuite) TestJenvFileNotFound(c *gc.C) {
6464
func (*jenvSuite) TestJenvFileDirectory(c *gc.C) {
6565
jenvCmd := &environment.JenvCommand{}
6666
ctx, err := testing.RunCommand(c, jenvCmd, c.MkDir())
67-
c.Assert(err, gc.ErrorMatches, "cannot read the provided jenv file .*: is a directory")
67+
68+
// The error is different on some platforms
69+
c.Assert(err, gc.ErrorMatches, "cannot read the provided jenv file .*: (is a directory|The handle is invalid.)")
6870
c.Assert(testing.Stdout(ctx), gc.Equals, "")
6971
}
7072

cmd/jujud/agent/machine.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ var (
109109
getMetricAPI = metricAPI
110110
)
111111

112+
// Variable to override in tests, default is true
113+
var EnableJournaling = true
114+
112115
func init() {
113116
stateWorkerDialOpts = mongo.DefaultDialOpts()
114117
stateWorkerDialOpts.PostDial = func(session *mgo.Session) error {
115118
safe := mgo.Safe{
116119
// Wait for group commit if journaling is enabled,
117120
// which is always true in production.
118-
J: true,
121+
J: EnableJournaling,
119122
}
120123
_, err := replicaset.CurrentConfig(session)
121124
if err == nil {

featuretests/leadership_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package featuretests
66
import (
77
"fmt"
88
"io/ioutil"
9+
"os"
10+
"path/filepath"
11+
"runtime"
912
"time"
1013

1114
"github.com/juju/names"
@@ -46,6 +49,10 @@ func (s *leadershipSuite) SetUpTest(c *gc.C) {
4649
defer file.Close()
4750
s.AgentSuite.PatchValue(&agentcmd.JujuRun, file.Name())
4851

52+
if runtime.GOOS == "windows" {
53+
s.AgentSuite.PatchValue(&agentcmd.EnableJournaling, false)
54+
}
55+
4956
fakeEnsureMongo := agenttesting.FakeEnsure{}
5057
s.AgentSuite.PatchValue(&cmdutil.EnsureMongoServer, fakeEnsureMongo.FakeEnsureMongo)
5158

@@ -96,6 +103,12 @@ func (s *leadershipSuite) SetUpTest(c *gc.C) {
96103
machineAgentFactory := agentcmd.MachineAgentFactoryFn(&agentConf, &agentConf)
97104
s.machineAgent = machineAgentFactory(stateServer.Id())
98105

106+
// See comment in createMockJujudExecutable
107+
if runtime.GOOS == "windows" {
108+
dirToRemove := createMockJujudExecutable(c, s.DataDir(), s.machineAgent.Tag().String())
109+
s.AddCleanup(func(*gc.C) { os.RemoveAll(dirToRemove) })
110+
}
111+
99112
c.Log("Starting machine agent...")
100113
go func() {
101114
err := s.machineAgent.Run(coretesting.Context(c))
@@ -107,6 +120,7 @@ func (s *leadershipSuite) TearDownTest(c *gc.C) {
107120
c.Log("Stopping machine agent...")
108121
err := s.machineAgent.Stop()
109122
c.Assert(err, gc.IsNil)
123+
os.RemoveAll(filepath.Join(s.DataDir(), "tools"))
110124

111125
s.AgentSuite.TearDownTest(c)
112126
}
@@ -258,6 +272,10 @@ func (s *uniterLeadershipSuite) SetUpTest(c *gc.C) {
258272
defer file.Close()
259273
s.AgentSuite.PatchValue(&agentcmd.JujuRun, file.Name())
260274

275+
if runtime.GOOS == "windows" {
276+
s.AgentSuite.PatchValue(&agentcmd.EnableJournaling, false)
277+
}
278+
261279
fakeEnsureMongo := agenttesting.FakeEnsure{}
262280
s.AgentSuite.PatchValue(&cmdutil.EnsureMongoServer, fakeEnsureMongo.FakeEnsureMongo)
263281

@@ -311,13 +329,32 @@ func (s *uniterLeadershipSuite) SetUpTest(c *gc.C) {
311329
machineAgentFactory := agentcmd.MachineAgentFactoryFn(&agentConf, &agentConf)
312330
s.machineAgent = machineAgentFactory(stateServer.Id())
313331

332+
// See comment in createMockJujudExecutable
333+
if runtime.GOOS == "windows" {
334+
dirToRemove := createMockJujudExecutable(c, s.DataDir(), s.machineAgent.Tag().String())
335+
s.AddCleanup(func(*gc.C) { os.RemoveAll(dirToRemove) })
336+
}
337+
314338
c.Log("Starting machine agent...")
315339
go func() {
316340
err := s.machineAgent.Run(coretesting.Context(c))
317341
c.Assert(err, gc.IsNil)
318342
}()
319343
}
320344

345+
// When a machine agent is ran it creates a symlink to the jujud executable.
346+
// Since we cannot create symlinks to a non-existent file on windows,
347+
// we place a dummy executable in the expected location.
348+
func createMockJujudExecutable(c *gc.C, dir, tag string) string {
349+
toolsDir := filepath.Join(dir, "tools")
350+
err := os.MkdirAll(filepath.Join(toolsDir, tag), 0755)
351+
c.Assert(err, gc.IsNil)
352+
err = ioutil.WriteFile(filepath.Join(toolsDir, tag, "jujud.exe"),
353+
[]byte("echo 1"), 0777)
354+
c.Assert(err, gc.IsNil)
355+
return toolsDir
356+
}
357+
321358
func (s *uniterLeadershipSuite) TearDownTest(c *gc.C) {
322359
c.Log("Stopping machine agent...")
323360
err := s.machineAgent.Stop()

state/backups/archive_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package backups_test
55

66
import (
7+
jc "github.com/juju/testing/checkers"
78
gc "gopkg.in/check.v1"
89

910
"github.com/juju/juju/state/backups"
@@ -28,8 +29,8 @@ func (s *archiveSuite) TestNewCanonoicalArchivePaths(c *gc.C) {
2829
func (s *archiveSuite) TestNewNonCanonicalArchivePaths(c *gc.C) {
2930
ap := backups.NewNonCanonicalArchivePaths("/tmp")
3031

31-
c.Check(ap.ContentDir, gc.Equals, "/tmp/juju-backup")
32-
c.Check(ap.FilesBundle, gc.Equals, "/tmp/juju-backup/root.tar")
33-
c.Check(ap.DBDumpDir, gc.Equals, "/tmp/juju-backup/dump")
34-
c.Check(ap.MetadataFile, gc.Equals, "/tmp/juju-backup/metadata.json")
32+
c.Check(ap.ContentDir, jc.SamePath, "/tmp/juju-backup")
33+
c.Check(ap.FilesBundle, jc.SamePath, "/tmp/juju-backup/root.tar")
34+
c.Check(ap.DBDumpDir, jc.SamePath, "/tmp/juju-backup/dump")
35+
c.Check(ap.MetadataFile, jc.SamePath, "/tmp/juju-backup/metadata.json")
3536
}

state/backups/create_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package backups_test
55

66
import (
77
"os"
8+
"runtime"
89

910
jc "github.com/juju/testing/checkers"
1011
gc "gopkg.in/check.v1"
@@ -29,6 +30,9 @@ func (d *TestDBDumper) Dump(dumpDir string) error {
2930
}
3031

3132
func (s *createSuite) TestLegacy(c *gc.C) {
33+
if runtime.GOOS == "windows" {
34+
c.Skip("bug 1403084: Currently does not work on windows, see comments inside backups.create function")
35+
}
3236
meta := backupstesting.NewMetadataStarted()
3337
metadataFile, err := meta.AsJSONBuffer()
3438
c.Assert(err, jc.ErrorIsNil)

state/backups/db_restore_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
package backups_test
55

66
import (
7+
"path/filepath"
8+
79
jc "github.com/juju/testing/checkers"
810
gc "gopkg.in/check.v1"
911

12+
"github.com/juju/juju/agent"
1013
"github.com/juju/juju/state/backups"
1114
"github.com/juju/juju/testing"
1215
"github.com/juju/juju/version"
@@ -19,18 +22,28 @@ type mongoRestoreSuite struct {
1922
}
2023

2124
func (s *mongoRestoreSuite) TestMongoRestoreArgsForVersion(c *gc.C) {
25+
dir := filepath.Join(agent.DefaultDataDir, "db")
2226
versionNumber := version.Number{}
2327
versionNumber.Major = 1
2428
versionNumber.Minor = 21
2529
args, err := backups.MongoRestoreArgsForVersion(versionNumber, "/some/fake/path")
2630
c.Assert(err, jc.ErrorIsNil)
27-
c.Assert(args, gc.DeepEquals, []string{"--drop", "--dbpath", "/var/lib/juju/db", "/some/fake/path"})
31+
c.Assert(args, gc.HasLen, 4)
32+
c.Assert(args[0], gc.Equals, "--drop")
33+
c.Assert(args[1], gc.Equals, "--dbpath")
34+
c.Assert(args[2], jc.SamePath, dir)
35+
c.Assert(args[3], gc.Equals, "/some/fake/path")
2836

2937
versionNumber.Major = 1
3038
versionNumber.Minor = 22
3139
args, err = backups.MongoRestoreArgsForVersion(versionNumber, "/some/fake/path")
3240
c.Assert(err, jc.ErrorIsNil)
33-
c.Assert(args, gc.DeepEquals, []string{"--drop", "--oplogReplay", "--dbpath", "/var/lib/juju/db", "/some/fake/path"})
41+
c.Assert(args, gc.HasLen, 5)
42+
c.Assert(args[0], gc.Equals, "--drop")
43+
c.Assert(args[1], gc.Equals, "--oplogReplay")
44+
c.Assert(args[2], gc.Equals, "--dbpath")
45+
c.Assert(args[3], jc.SamePath, dir)
46+
c.Assert(args[4], gc.Equals, "/some/fake/path")
3447

3548
versionNumber.Major = 0
3649
versionNumber.Minor = 0

upgrades/customimagemetadata_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ type migrateCustomImageMetadataStorageSuite struct {
2525

2626
var _ = gc.Suite(&migrateCustomImageMetadataStorageSuite{})
2727

28-
var customImageMetadata = map[string][]byte{
29-
"images/abc": []byte("abc"),
30-
"images/def/ghi": []byte("xyz"),
31-
}
32-
3328
func (s *migrateCustomImageMetadataStorageSuite) TestMigrateCustomImageMetadata(c *gc.C) {
3429
stor := s.Environ.(environs.EnvironStorage).Storage()
3530
for path, content := range customImageMetadata {

upgrades/toolstorage_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
jujutesting "github.com/juju/juju/juju/testing"
1919
"github.com/juju/juju/state"
2020
"github.com/juju/juju/state/toolstorage"
21+
coretools "github.com/juju/juju/tools"
2122
"github.com/juju/juju/upgrades"
2223
"github.com/juju/juju/version"
2324
)
@@ -56,22 +57,23 @@ func (s *migrateToolsStorageSuite) TestMigrateToolsStorageNoTools(c *gc.C) {
5657
func (s *migrateToolsStorageSuite) TestMigrateToolsStorage(c *gc.C) {
5758
stor := s.Environ.(environs.EnvironStorage).Storage()
5859
envtesting.RemoveFakeTools(c, stor, "releases")
59-
envtesting.AssertUploadFakeToolsVersions(c, stor, "releases", "released", migrateToolsVersions...)
60-
s.testMigrateToolsStorage(c, &mockAgentConfig{})
60+
tools := envtesting.AssertUploadFakeToolsVersions(c, stor, "releases", "released", migrateToolsVersions...)
61+
s.testMigrateToolsStorage(c, &mockAgentConfig{}, tools)
6162
}
6263

6364
func (s *migrateToolsStorageSuite) TestMigrateToolsStorageLocalstorage(c *gc.C) {
6465
storageDir := c.MkDir()
6566
stor, err := filestorage.NewFileStorageWriter(storageDir)
6667
c.Assert(err, jc.ErrorIsNil)
67-
envtesting.AssertUploadFakeToolsVersions(c, stor, "releases", "released", migrateToolsVersions...)
68+
tools := envtesting.AssertUploadFakeToolsVersions(c, stor, "releases", "released", migrateToolsVersions...)
6869
for _, providerType := range []string{"local", "manual"} {
69-
s.testMigrateToolsStorage(c, &mockAgentConfig{
70+
config := &mockAgentConfig{
7071
values: map[string]string{
7172
agent.ProviderType: providerType,
7273
agent.StorageDir: storageDir,
7374
},
74-
})
75+
}
76+
s.testMigrateToolsStorage(c, config, tools)
7577
}
7678
}
7779

@@ -89,7 +91,7 @@ func (s *migrateToolsStorageSuite) TestMigrateToolsStorageBadSHA256(c *gc.C) {
8991
c.Assert(err, gc.ErrorMatches, "failed to fetch 1.2.3-precise-amd64 tools: hash mismatch")
9092
}
9193

92-
func (s *migrateToolsStorageSuite) testMigrateToolsStorage(c *gc.C, agentConfig agent.Config) {
94+
func (s *migrateToolsStorageSuite) testMigrateToolsStorage(c *gc.C, agentConfig agent.Config, tools []*coretools.Tools) {
9395
fakeToolsStorage := &fakeToolsStorage{
9496
stored: make(map[version.Binary]toolstorage.Metadata),
9597
}
@@ -99,15 +101,15 @@ func (s *migrateToolsStorageSuite) testMigrateToolsStorage(c *gc.C, agentConfig
99101
err := upgrades.MigrateToolsStorage(s.State, agentConfig)
100102
c.Assert(err, jc.ErrorIsNil)
101103
c.Assert(fakeToolsStorage.stored, gc.DeepEquals, map[version.Binary]toolstorage.Metadata{
102-
migrateToolsVersions[0]: {
103-
Version: migrateToolsVersions[0],
104-
Size: 129,
105-
SHA256: "f26c7a6832cc5fd3a01eaa46c79a7fa7f4714ff3263f7372cedb9470a7b40bae",
104+
tools[0].Version: toolstorage.Metadata{
105+
Version: tools[0].Version,
106+
Size: tools[0].Size,
107+
SHA256: tools[0].SHA256,
106108
},
107-
migrateToolsVersions[1]: {
108-
Version: migrateToolsVersions[1],
109-
Size: 129,
110-
SHA256: "eba00d942f9f69e2c862c23095fdb2a0ff578c7c4e77cc28829fcc98cb152693",
109+
tools[1].Version: toolstorage.Metadata{
110+
Version: tools[1].Version,
111+
Size: tools[1].Size,
112+
SHA256: tools[1].SHA256,
111113
},
112114
})
113115
}

upgrades/util_unix_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2015 Canonical Ltd.
2+
// Copyright 2015 Cloudbase Solutions SRL
3+
// Licensed under the AGPLv3, see LICENCE file for details.
4+
5+
// +build !windows
6+
7+
package upgrades_test
8+
9+
var customImageMetadata = map[string][]byte{
10+
"images/abc": []byte("abc"),
11+
"images/def/ghi": []byte("xyz"),
12+
}

upgrades/util_windows_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2015 Canonical Ltd.
2+
// Copyright 2015 Cloudbase Solutions SRL
3+
// Licensed under the AGPLv3, see LICENCE file for details.
4+
5+
// +build windows
6+
7+
package upgrades_test
8+
9+
var customImageMetadata = map[string][]byte{
10+
"images\\abc": []byte("abc"),
11+
"images\\def\\ghi": []byte("xyz"),
12+
}

worker/uniter/runner/jujuc/tools_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (s *ToolsSuite) testEnsureSymlinks(c *gc.C, dir string) {
5454
assertLink := func(path string) time.Time {
5555
target, err := symlink.Read(path)
5656
c.Assert(err, jc.ErrorIsNil)
57-
c.Assert(target, gc.Equals, jujudPath)
57+
c.Assert(target, jc.SamePath, jujudPath)
5858
fi, err := os.Lstat(path)
5959
c.Assert(err, jc.ErrorIsNil)
6060
return fi.ModTime()

0 commit comments

Comments
 (0)