Skip to content

Commit 73b4f33

Browse files
various fixes for windows tests
1 parent bb6c733 commit 73b4f33

File tree

14 files changed

+71
-17
lines changed

14 files changed

+71
-17
lines changed

cloudconfig/containerinit/container_userdata_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/juju/juju/service"
2222
systemdtesting "github.com/juju/juju/service/systemd/testing"
2323
"github.com/juju/juju/testing"
24+
"github.com/juju/juju/version"
2425
)
2526

2627
func Test(t *stdtesting.T) {
@@ -184,6 +185,7 @@ end script
184185
}
185186

186187
func (s *UserDataSuite) TestShutdownInitCommandsSystemd(c *gc.C) {
188+
s.PatchValue(&version.Current.Series, "vivid")
187189
commands, err := containerinit.ShutdownInitCommands(service.InitSystemSystemd)
188190
c.Assert(err, jc.ErrorIsNil)
189191

cloudconfig/userdatacfg.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,15 @@ func (c *baseConfigure) addMachineAgentToBoot() error {
119119
cmds = append(cmds, startCmds...)
120120

121121
svcName := c.icfg.MachineAgentServiceName
122-
c.conf.AddRunCmd(cloudinit.LogProgressCmd("Starting Juju machine agent (%s)", svcName))
122+
// TODO (gsamfira): This is temporary until we find a cleaner way to fix
123+
// cloudinit.LogProgressCmd to not add >&9 on Windows.
124+
targetOS, err := version.GetOSFromSeries(c.icfg.Series)
125+
if err != nil {
126+
return err
127+
}
128+
if targetOS != version.Windows {
129+
c.conf.AddRunCmd(cloudinit.LogProgressCmd("Starting Juju machine agent (%s)", svcName))
130+
}
123131
c.conf.AddScripts(cmds...)
124132
return nil
125133
}

cloudconfig/userdatacfg_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func minimalInstanceConfig(tweakers ...func(instancecfg.InstanceConfig)) instanc
104104
EnvironTag: testing.EnvironmentTag,
105105
},
106106
Constraints: envConstraints,
107-
DataDir: instancecfg.DataDir,
108-
LogDir: agent.DefaultLogDir,
107+
DataDir: dataDir,
108+
LogDir: logDir,
109109
Jobs: allMachineJobs,
110110
CloudInitOutputLog: cloudInitOutputLog,
111111
InstanceId: "i-bootstrap",
@@ -994,8 +994,8 @@ func (*cloudinitSuite) TestCloudInitVerify(c *gc.C) {
994994
EnvironTag: testing.EnvironmentTag,
995995
},
996996
Config: minimalConfig(c),
997-
DataDir: instancecfg.DataDir,
998-
LogDir: agent.DefaultLogDir,
997+
DataDir: dataDir,
998+
LogDir: logDir,
999999
Jobs: normalMachineJobs,
10001000
CloudInitOutputLog: cloudInitOutputLog,
10011001
InstanceId: "i-bootstrap",

cloudconfig/userdatacfg_unix.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Copyright 2014, 2015 Cloudbase Solutions
33
// Licensed under the AGPLv3, see LICENCE file for details.
44

5-
// +build !windows
6-
75
package cloudconfig
86

97
import (

cloudconfig/windows_userdata_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,6 @@ values:
873873
874874
"@
875875
cmd.exe /C mklink /D C:\Juju\lib\juju\tools\machine-10 1.2.3-win8-amd64
876-
echo 'Starting Juju machine agent (jujud-machine-10)' >&9
877876
New-Service -Credential $jujuCreds -Name 'jujud-machine-10' -DisplayName 'juju agent for machine-10' '''C:\Juju\lib\juju\tools\machine-10\jujud.exe'' machine --data-dir ''C:\Juju\lib\juju'' --machine-id 10 --debug'
878877
cmd.exe /C sc config 'jujud-machine-10' start=delayed-auto
879878
Start-Service 'jujud-machine-10'`

cmd/juju/environment/create_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/juju/cmd"
1010
"github.com/juju/errors"
1111
jc "github.com/juju/testing/checkers"
12+
"github.com/juju/utils"
1213
gc "gopkg.in/check.v1"
1314
"gopkg.in/yaml.v1"
1415

@@ -164,7 +165,8 @@ func (s *createSuite) TestConfigFileFormatError(c *gc.C) {
164165

165166
func (s *createSuite) TestConfigFileDoesntExist(c *gc.C) {
166167
_, err := s.run(c, "test", "--config", "missing-file")
167-
c.Assert(err, gc.ErrorMatches, `open .* no such file or directory`)
168+
errMsg := ".*" + utils.NoSuchFileErrRegexp
169+
c.Assert(err, gc.ErrorMatches, errMsg)
168170
}
169171

170172
func (s *createSuite) TestConfigValuePrecedence(c *gc.C) {

cmd/plugins/local/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package local_test
66
import (
77
"fmt"
88
"os/exec"
9+
"runtime"
910
"strings"
1011

1112
"github.com/juju/cmd"
@@ -60,6 +61,9 @@ func (s *mainSuite) TestRunAsRootCallsFuncIfRoot(c *gc.C) {
6061
}
6162

6263
func (s *mainSuite) TestRunAsRootCallsSudoIfNotRoot(c *gc.C) {
64+
if runtime.GOOS == "windows" {
65+
c.Skip("No root on windows")
66+
}
6367
s.PatchValue(local.CheckIfRoot, func() bool { return false })
6468
testing.PatchExecutableAsEchoArgs(c, s, "sudo")
6569
// the command needs to be in the path...

dependencies.tsv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ google.golang.org/cloud git f20d6dcccb44ed49de45ae3703312cb46e627db1 2015-03-19T
3737
gopkg.in/amz.v3 git f5c958d2b012da23a4600bad441f20b13ec262c4 2015-04-03T18:23:57Z
3838
gopkg.in/check.v1 git 64131543e7896d5bcc6bd5a76287eb75ea96c673 2014-10-24T13:38:53Z
3939
gopkg.in/errgo.v1 git 81357a83344ddd9f7772884874e5622c2a3da21c 2014-10-13T17:33:38Z
40-
gopkg.in/juju/charm.v5 git 4ce6225dae243c82f8a342749accaefbadad38e0 2015-04-10T08:52:37Z
40+
gopkg.in/juju/charm.v5 git 6b74a2771545912f8a91a544b0f28405b9938624 2015-04-14T14:33:47Z
4141
gopkg.in/juju/charmstore.v4 git ab64d50370f9c167a7cd55be8ea22c3842aae46d 2015-04-10T09:44:12Z
4242
gopkg.in/macaroon-bakery.v0 git 9593b80b01ba04b519769d045dffd6abd827d2fd 2015-04-10T07:46:55Z
4343
gopkg.in/macaroon.v1 git ab3940c6c16510a850e1c2dd628b919f0f3f1464 2015-01-21T11:42:31Z

provider/azure/customdata_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
jc "github.com/juju/testing/checkers"
1212
gc "gopkg.in/check.v1"
1313

14-
"github.com/juju/juju/agent"
1514
"github.com/juju/juju/api"
1615
"github.com/juju/juju/cloudconfig/instancecfg"
1716
"github.com/juju/juju/cloudconfig/providerinit"
@@ -37,6 +36,7 @@ func must(s string, err error) string {
3736
}
3837

3938
var logDir = must(paths.LogDir("precise"))
39+
var dataDir = must(paths.DataDir("precise"))
4040
var cloudInitOutputLog = path.Join(logDir, "cloud-init-output.log")
4141

4242
// makeInstanceConfig produces a valid cloudinit machine config.
@@ -46,8 +46,8 @@ func makeInstanceConfig(c *gc.C) *instancecfg.InstanceConfig {
4646
return &instancecfg.InstanceConfig{
4747
MachineId: machineId,
4848
MachineNonce: "gxshasqlnng",
49-
DataDir: instancecfg.DataDir,
50-
LogDir: agent.DefaultLogDir,
49+
DataDir: dataDir,
50+
LogDir: logDir,
5151
Jobs: []multiwatcher.MachineJob{
5252
multiwatcher.JobManageEnviron,
5353
multiwatcher.JobHostUnits,

service/upstart/upstart.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io/ioutil"
1010
"os"
1111
"os/exec"
12+
"runtime"
1213
"path"
1314
"regexp"
1415
"text/template"
@@ -31,6 +32,12 @@ var (
3132

3233
// IsRunning returns whether or not upstart is the local init system.
3334
func IsRunning() (bool, error) {
35+
// On windows casting the error to exec.Error does not yield a os.PathError type
36+
// Its easyer to just return nil before even trying to execute an external command
37+
// on windows at least
38+
if runtime.GOOS == "windows" {
39+
return false, nil
40+
}
3441
cmd := exec.Command(initctlPath, "--system", "list")
3542
_, err := cmd.CombinedOutput()
3643
if err == nil {

service/windows/service.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ func (s *Service) Status() (string, error) {
107107

108108
// Running returns true if the Service appears to be running.
109109
func (s *Service) Running() (bool, error) {
110+
installed, err := s.Installed()
111+
if err != nil {
112+
return false, err
113+
}
114+
if !installed {
115+
return false, nil
116+
}
110117
status, err := s.Status()
111118
logger.Infof("Service %q Status %q", s.Service.Name, status)
112119
if err != nil {
@@ -120,11 +127,16 @@ func (s *Service) Running() (bool, error) {
120127

121128
// Installed returns whether the service is installed
122129
func (s *Service) Installed() (bool, error) {
123-
_, err := s.Status()
130+
services, err := ListServices()
124131
if err != nil {
125-
return false, errors.Trace(err)
132+
return false, err
126133
}
127-
return true, nil
134+
for _, val := range services {
135+
if val == s.Name() {
136+
return true, nil
137+
}
138+
}
139+
return false, nil
128140
}
129141

130142
// Exists returns whether the service configuration exists in the
@@ -168,7 +180,14 @@ func (s *Service) Stop() error {
168180

169181
// Remove deletes the service.
170182
func (s *Service) Remove() error {
171-
_, err := s.Status()
183+
installed, err := s.Installed()
184+
if err != nil {
185+
return err
186+
}
187+
if !installed {
188+
return nil
189+
}
190+
err = s.Stop()
172191
if err != nil {
173192
return err
174193
}

storage/provider/rootfs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package provider_test
66
import (
77
"errors"
88
"path/filepath"
9+
"runtime"
910

1011
"github.com/juju/names"
1112
jc "github.com/juju/testing/checkers"
@@ -26,6 +27,9 @@ type rootfsSuite struct {
2627
}
2728

2829
func (s *rootfsSuite) SetUpTest(c *gc.C) {
30+
if runtime.GOOS == "windows" {
31+
c.Skip("Tests relevant only on *nix systems")
32+
}
2933
s.BaseSuite.SetUpTest(c)
3034
s.storageDir = c.MkDir()
3135
}

storage/provider/tmpfs_test.go

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

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

910
"github.com/juju/names"
1011
jc "github.com/juju/testing/checkers"
@@ -24,6 +25,9 @@ type tmpfsSuite struct {
2425
}
2526

2627
func (s *tmpfsSuite) SetUpTest(c *gc.C) {
28+
if runtime.GOOS == "windows" {
29+
c.Skip("Tests relevant only on *nix systems")
30+
}
2731
s.BaseSuite.SetUpTest(c)
2832
s.storageDir = c.MkDir()
2933
}

worker/provisioner/container_initialisation_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,13 @@ type SetIPAndARPForwardingSuite struct {
403403
coretesting.BaseSuite
404404
}
405405

406+
func (s *SetIPAndARPForwardingSuite) SetUpSuite(c *gc.C) {
407+
if runtime.GOOS == "windows" {
408+
c.Skip("bug 1403084: Skipping for now")
409+
}
410+
s.BaseSuite.SetUpSuite(c)
411+
}
412+
406413
var _ = gc.Suite(&SetIPAndARPForwardingSuite{})
407414

408415
func (s *SetIPAndARPForwardingSuite) TestSuccess(c *gc.C) {

0 commit comments

Comments
 (0)