Exemplo n.º 1
0
func (s *S) TestNewBareShouldReturnMeaningfullErrorWhenBareCreationFails(c *gocheck.C) {
	dir, err := commandmocker.Error("git", "cmd output", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(dir)
	err = newBare("foo")
	c.Check(err, gocheck.NotNil)
	got := err.Error()
	expected := "Could not create git bare repository: exit status 1. cmd output"
	c.Assert(got, gocheck.Equals, expected)
}
Exemplo n.º 2
0
func (s *S) TestExecutedCmdFailure(c *gocheck.C) {
	var buf bytes.Buffer
	tmpdir, err := commandmocker.Error("juju", "failed", 2)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("frases", "static", 1)
	p := JujuProvisioner{}
	err = p.ExecuteCommand(&buf, &buf, app, "ls", "-l")
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, "exit status 2")
	c.Assert(buf.String(), gocheck.Equals, "failed\n")
}
Exemplo n.º 3
0
func (s *S) TestNewShouldNotStoreRepoInDbWhenBareCreationFails(c *gocheck.C) {
	dir, err := commandmocker.Error("git", "", 1)
	c.Check(err, gocheck.IsNil)
	defer commandmocker.Remove(dir)
	r, err := New("myRepo", []string{"pumpkin"}, true)
	c.Check(err, gocheck.NotNil)
	conn, err := db.Conn()
	c.Assert(err, gocheck.IsNil)
	defer conn.Close()
	err = conn.Repository().Find(bson.M{"_id": r.Name}).One(&r)
	c.Assert(err, gocheck.ErrorMatches, "^not found$")
}
Exemplo n.º 4
0
func (s *S) TestRemoveUnitFailure(c *gocheck.C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed", 66)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("something", "rush", 1)
	p := JujuProvisioner{}
	err = p.RemoveUnit(app, "something/0")
	c.Assert(err, gocheck.NotNil)
	e, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(e.Reason, gocheck.Equals, "juju failed")
	c.Assert(e.Err.Error(), gocheck.Equals, "exit status 66")
}
Exemplo n.º 5
0
func (s *S) TestRemoveUnitUnknownByJuju(c *gocheck.C) {
	output := `013-01-11 20:02:07,883 INFO Connecting to environment...
2013-01-11 20:02:10,147 INFO Connected to environment.
2013-01-11 20:02:10,160 ERROR Service unit 'two/2' was not found`
	tmpdir, err := commandmocker.Error("juju", output, 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("two", "rush", 3)
	p := JujuProvisioner{}
	err = p.RemoveUnit(app, "two/2")
	c.Assert(err, gocheck.IsNil)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
}
Exemplo n.º 6
0
func (s *S) TestDestroyFailure(c *gocheck.C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed to destroy the machine", 25)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("idioglossia", "static", 1)
	p := JujuProvisioner{}
	err = p.Destroy(app)
	c.Assert(err, gocheck.NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(pErr.Reason, gocheck.Equals, "juju failed to destroy the machine")
	c.Assert(pErr.Err.Error(), gocheck.Equals, "exit status 25")
}
Exemplo n.º 7
0
func (s *S) TestCollectStatusFailure(c *gocheck.C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	p := JujuProvisioner{}
	_, err = p.CollectStatus()
	c.Assert(err, gocheck.NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(pErr.Reason, gocheck.Equals, "juju failed")
	c.Assert(pErr.Err.Error(), gocheck.Equals, "exit status 1")
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
}
Exemplo n.º 8
0
func (s *S) TestAddUnitsFailure(c *gocheck.C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("headlong", "rush", 1)
	p := JujuProvisioner{}
	units, err := p.AddUnits(app, 1)
	c.Assert(units, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
	e, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(e.Reason, gocheck.Equals, "juju failed")
	c.Assert(e.Err.Error(), gocheck.Equals, "exit status 1")
}
Exemplo n.º 9
0
func (s *S) TestProvisionFailure(c *gocheck.C) {
	config.Set("juju:charms-path", "/home/charms")
	defer config.Unset("juju:charms-path")
	tmpdir, err := commandmocker.Error("juju", "juju failed", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("trace", "python", 0)
	p := JujuProvisioner{}
	err = p.Provision(app)
	c.Assert(err, gocheck.NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(pErr.Reason, gocheck.Equals, "juju failed")
	c.Assert(pErr.Err.Error(), gocheck.Equals, "exit status 1")
}
Exemplo n.º 10
0
func (s *S) TestStartFailure(c *gocheck.C) {
	// h := &testing.TestHandler{}
	// gandalfServer := testing.StartGandalfTestServer(h)
	// defer gandalfServer.Close()
	tmpdir, err := commandmocker.Error("juju", "juju failed to run command", 25)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("cribcaged", "python", 1)
	p := JujuProvisioner{}
	err = p.Start(app)
	c.Assert(err, gocheck.NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(pErr.Reason, gocheck.Equals, "juju failed to run command\n")
	c.Assert(pErr.Err.Error(), gocheck.Equals, "exit status 25")
}
Exemplo n.º 11
0
// This example demonstrates the mocking of the SSH command.
func ExampleAdd() {
	msg := "HELP!"
	path, err := commandmocker.Error("ssh", msg, 1)
	if err != nil {
		panic(err)
	}
	defer commandmocker.Remove(path)
	cmd := exec.Command("ssh", "-l", "root", "127.0.0.1")
	out, err := cmd.CombinedOutput()
	fmt.Println(err)
	fmt.Printf("%s\n", out)
	fmt.Println(commandmocker.Parameters(path))
	fmt.Println(commandmocker.Ran(path))
	// Output:
	// exit status 1
	// HELP!
	// [-l root 127.0.0.1]
	// true
}
Exemplo n.º 12
0
func (s *S) TestInstanceAgenstConfigHealerHeal(c *gocheck.C) {
	server, err := ec2test.NewServer()
	c.Assert(err, gocheck.IsNil)
	defer server.Quit()
	id := server.NewInstances(1, "small", "ami-123", ec2.InstanceState{Code: 16, Name: "running"}, nil)[0]
	p := JujuProvisioner{}
	m := machine{
		AgentState:    "not-started",
		IPAddress:     "localhost",
		InstanceID:    id,
		InstanceState: "running",
	}
	p.saveBootstrapMachine(m)
	collection := p.bootstrapCollection()
	defer collection.Close()
	defer collection.Remove(m)
	a := app.App{
		Name:  "as_i_rise",
		Units: []app.Unit{{Name: "as_i_rise/0", State: "down", Ip: "server-1081.novalocal"}},
	}
	err = s.conn.Apps().Insert(&a)
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Apps().Remove(bson.M{"name": "as_i_rise"})
	sshTmpdir, err := commandmocker.Error("ssh", "", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(sshTmpdir)
	h := instanceAgentsConfigHealer{}
	auth := aws.Auth{AccessKey: "access", SecretKey: "secret"}
	region := aws.SAEast
	region.EC2Endpoint = server.URL()
	h.e = ec2.New(auth, region)
	err = h.Heal()
	c.Assert(err, gocheck.IsNil)
	sshOutput := []string{
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"grep",
		"i-0.internal.invalid",
		"/etc/init/juju-machine-agent.conf",
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"sudo",
		"sed",
		"-i",
		"'s/env JUJU_ZOOKEEPER=.*/env JUJU_ZOOKEEPER=\"i-0.internal.invalid:2181\"/g'",
		"/etc/init/juju-machine-agent.conf",
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"grep",
		"i-0.internal.invalid",
		"/etc/init/juju-as_i_rise-0.conf",
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"sudo",
		"sed",
		"-i",
		"'s/env JUJU_ZOOKEEPER=.*/env JUJU_ZOOKEEPER=\"i-0.internal.invalid:2181\"/g'",
		"/etc/init/juju-as_i_rise-0.conf",
	}
	c.Assert(commandmocker.Ran(sshTmpdir), gocheck.Equals, true)
	c.Assert(commandmocker.Parameters(sshTmpdir), gocheck.DeepEquals, sshOutput)
}