8
"github.com/juju/testing"
9
jc "github.com/juju/testing/checkers"
10
ft "github.com/juju/testing/filetesting"
11
gc "gopkg.in/check.v1"
13
"github.com/juju/juju/apiserver/params"
14
"github.com/juju/juju/cmd/jujud/reboot"
17
// on linux we use the "at" command to schedule a reboot
20
var expectedRebootScript = `#!/bin/bash
24
var expectedShutdownScript = `#!/bin/bash
28
var lxcLsScript = `#!/bin/bash
29
echo juju-machine-1-lxc-0
32
var lxcInfoScriptMissbehave = `#!/bin/bash
34
Name: juju-machine-1-lxc-0
38
CPU use: 186.37 seconds
40
Memory use: 202.45 MiB
44
Total bytes: 12.82 MiB
48
var lxcInfoScript = `#!/bin/bash
49
LINE_COUNT=$(wc -l "$TEMP/empty-lxc-response" 2>/dev/null | awk '{print $1}')
57
Name: juju-machine-1-lxc-0
61
CPU use: 186.37 seconds
63
Memory use: 202.45 MiB
67
Total bytes: 12.82 MiB
69
echo 1 >> "$TEMP/empty-lxc-response"
73
func (s *RebootSuite) rebootCommandParams(c *gc.C) []string {
81
func (s *RebootSuite) shutdownCommandParams(c *gc.C) []string {
89
func (s *RebootSuite) TestRebootWithContainers(c *gc.C) {
90
testing.PatchExecutable(c, s, "lxc-ls", lxcLsScript)
91
testing.PatchExecutable(c, s, "lxc-info", lxcInfoScript)
92
expectedRebootParams := s.rebootCommandParams(c)
94
// Timeout after 5 seconds
95
s.PatchValue(reboot.Timeout, time.Duration(5*time.Second))
96
w, err := reboot.NewRebootWaiter(s.st, s.acfg)
97
c.Assert(err, jc.ErrorIsNil)
99
err = w.ExecuteReboot(params.ShouldReboot)
100
c.Assert(err, jc.ErrorIsNil)
101
testing.AssertEchoArgs(c, rebootBin, expectedRebootParams...)
102
ft.File{s.rebootScriptName, expectedRebootScript, 0755}.Check(c, s.tmpDir)
105
func (s *RebootSuite) TestRebootWithMissbehavingContainers(c *gc.C) {
106
testing.PatchExecutable(c, s, "lxc-ls", lxcLsScript)
107
testing.PatchExecutable(c, s, "lxc-info", lxcInfoScriptMissbehave)
108
expectedRebootParams := s.rebootCommandParams(c)
110
// Timeout after 5 seconds
111
s.PatchValue(reboot.Timeout, time.Duration(5*time.Second))
112
w, err := reboot.NewRebootWaiter(s.st, s.acfg)
113
c.Assert(err, jc.ErrorIsNil)
115
err = w.ExecuteReboot(params.ShouldReboot)
116
c.Assert(err, jc.ErrorIsNil)
117
testing.AssertEchoArgs(c, rebootBin, expectedRebootParams...)
118
ft.File{s.rebootScriptName, expectedRebootScript, 0755}.Check(c, s.tmpDir)
121
func (s *RebootSuite) TestRebootNoContainers(c *gc.C) {
122
w, err := reboot.NewRebootWaiter(s.st, s.acfg)
123
c.Assert(err, jc.ErrorIsNil)
124
expectedRebootParams := s.rebootCommandParams(c)
126
err = w.ExecuteReboot(params.ShouldReboot)
127
c.Assert(err, jc.ErrorIsNil)
128
testing.AssertEchoArgs(c, rebootBin, expectedRebootParams...)
129
ft.File{s.rebootScriptName, expectedRebootScript, 0755}.Check(c, s.tmpDir)
132
func (s *RebootSuite) TestShutdownNoContainers(c *gc.C) {
133
w, err := reboot.NewRebootWaiter(s.st, s.acfg)
134
c.Assert(err, jc.ErrorIsNil)
135
expectedShutdownParams := s.shutdownCommandParams(c)
137
err = w.ExecuteReboot(params.ShouldShutdown)
138
c.Assert(err, jc.ErrorIsNil)
139
testing.AssertEchoArgs(c, rebootBin, expectedShutdownParams...)
140
ft.File{s.rebootScriptName, expectedShutdownScript, 0755}.Check(c, s.tmpDir)