github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/cmd/jujud/reboot/reboot_nix_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Copyright 2014 Cloudbase Solutions SRL
     3  // Licensed under the AGPLv3, see LICENCE file for details.
     4  
     5  // +build !windows
     6  
     7  package reboot_test
     8  
     9  import (
    10  	"github.com/juju/testing"
    11  	jc "github.com/juju/testing/checkers"
    12  	ft "github.com/juju/testing/filetesting"
    13  	gc "gopkg.in/check.v1"
    14  
    15  	"github.com/juju/juju/apiserver/params"
    16  	"github.com/juju/juju/cmd/jujud/reboot"
    17  )
    18  
    19  // on linux we use the "at" command to schedule a reboot
    20  var rebootBin = "at"
    21  
    22  var expectedRebootScript = `#!/bin/bash
    23  sleep 15
    24  shutdown -r now`
    25  
    26  var expectedShutdownScript = `#!/bin/bash
    27  sleep 15
    28  shutdown -h now`
    29  
    30  func (s *RebootSuite) rebootCommandParams(c *gc.C) []string {
    31  	return []string{
    32  		"-f",
    33  		s.rebootScript(c),
    34  		"now",
    35  	}
    36  }
    37  
    38  func (s *RebootSuite) shutdownCommandParams(c *gc.C) []string {
    39  	return []string{
    40  		"-f",
    41  		s.rebootScript(c),
    42  		"now",
    43  	}
    44  }
    45  
    46  func (s *RebootSuite) TestRebootNoContainers(c *gc.C) {
    47  	w, err := reboot.NewRebootWaiter(s.st, s.acfg)
    48  	c.Assert(err, jc.ErrorIsNil)
    49  	expectedRebootParams := s.rebootCommandParams(c)
    50  
    51  	err = w.ExecuteReboot(params.ShouldReboot)
    52  	c.Assert(err, jc.ErrorIsNil)
    53  	testing.AssertEchoArgs(c, rebootBin, expectedRebootParams...)
    54  	ft.File{s.rebootScriptName, expectedRebootScript, 0755}.Check(c, s.tmpDir)
    55  }
    56  
    57  func (s *RebootSuite) TestShutdownNoContainers(c *gc.C) {
    58  	w, err := reboot.NewRebootWaiter(s.st, s.acfg)
    59  	c.Assert(err, jc.ErrorIsNil)
    60  	expectedShutdownParams := s.shutdownCommandParams(c)
    61  
    62  	err = w.ExecuteReboot(params.ShouldShutdown)
    63  	c.Assert(err, jc.ErrorIsNil)
    64  	testing.AssertEchoArgs(c, rebootBin, expectedShutdownParams...)
    65  	ft.File{s.rebootScriptName, expectedShutdownScript, 0755}.Check(c, s.tmpDir)
    66  }