func (s *UserDataSuite) TestShutdownInitCommandsUpstart(c *gc.C) {
	s.SetFeatureFlags(feature.AddressAllocation)
	cmds, err := containerinit.ShutdownInitCommands(service.InitSystemUpstart, "trusty")
	c.Assert(err, jc.ErrorIsNil)

	filename := "/etc/init/juju-template-restart.conf"
	script := `
description "juju shutdown job"
author "Juju Team <*****@*****.**>"
start on stopped cloud-final

script
  /bin/cat > /etc/network/interfaces << EOC
# loopback interface
auto lo
iface lo inet loopback

# primary interface
auto eth0
iface eth0 inet dhcp
EOC
  /bin/rm -fr /var/lib/dhcp/dhclient* /var/log/cloud-init*.log
  /sbin/shutdown -h now
end script

post-stop script
  rm /etc/init/juju-template-restart.conf
end script
`[1:]
	c.Check(cmds, gc.HasLen, 1)
	testing.CheckWriteFileCommand(c, cmds[0], filename, script, nil)
}
Beispiel #2
0
func (wct WriteConfTest) checkWriteExecScript(c *gc.C, commands []string) {
	script := "#!/usr/bin/env bash\n\n" + wct.Script
	testing.CheckWriteFileCommand(c, commands[0], wct.scriptname(), script, nil)

	// Check the remaining commands.
	c.Check(commands[1:], jc.DeepEquals, []string{
		"chmod 0755 " + wct.scriptname(),
	})
}
Beispiel #3
0
func (wct WriteConfTest) checkWriteConf(c *gc.C, commands []string) {
	// This check must be done without regard to map order.
	parse := func(lines []string) interface{} {
		return parseConfSections(lines)
	}
	testing.CheckWriteFileCommand(c, commands[0], wct.filename(), wct.Expected, parse)

	// Check the remaining commands.
	c.Check(commands[1:], jc.DeepEquals, []string{
		"/bin/systemctl link " + wct.filename(),
		"/bin/systemctl daemon-reload",
		"/bin/systemctl enable " + wct.filename(),
	})
}