Beispiel #1
0
func (s *S) TestNewShouldNotStoreRepoInDbWhenBareCreationFails(c *C) {
	dir, err := commandmocker.Error("git", "", 1)
	c.Check(err, IsNil)
	defer commandmocker.Remove(dir)
	r, err := New("myRepo", []string{"pumpkin"}, true)
	c.Check(err, NotNil)
	err = db.Session.Repository().Find(bson.M{"_id": r.Name}).One(&r)
	c.Assert(err, ErrorMatches, "^not found$")
}
Beispiel #2
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)
}
Beispiel #3
0
func (s *S) TestExecuteCommandFailure(c *C) {
	var buf bytes.Buffer
	tmpdir, err := commandmocker.Error("juju", "failed", 2)
	c.Assert(err, IsNil)
	defer commandmocker.Remove(tmpdir)
	app := NewFakeApp("frases", "static", 1)
	p := JujuProvisioner{}
	err = p.ExecuteCommand(&buf, &buf, app, "ls", "-l")
	c.Assert(err, NotNil)
	c.Assert(err.Error(), Equals, "exit status 2")
	c.Assert(buf.String(), Equals, "failed\n")
}
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)
}
Beispiel #5
0
func (s *S) TestDestroyFailure(c *C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed to destroy the machine", 25)
	c.Assert(err, IsNil)
	defer commandmocker.Remove(tmpdir)
	app := NewFakeApp("idioglossia", "static", 1)
	p := JujuProvisioner{}
	err = p.Destroy(app)
	c.Assert(err, NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, Equals, true)
	c.Assert(pErr.Reason, Equals, "juju failed to destroy the machine")
	c.Assert(pErr.Err.Error(), Equals, "exit status 25")
}
Beispiel #6
0
func (s *S) TestProvisionFailure(c *C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed", 1)
	c.Assert(err, IsNil)
	defer commandmocker.Remove(tmpdir)
	app := NewFakeApp("trace", "python", 0)
	p := JujuProvisioner{}
	err = p.Provision(app)
	c.Assert(err, NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, Equals, true)
	c.Assert(pErr.Reason, Equals, "juju failed")
	c.Assert(pErr.Err.Error(), Equals, "exit status 1")
}
Beispiel #7
0
func (s *S) TestRemoveUnitFailure(c *C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed", 66)
	c.Assert(err, IsNil)
	defer commandmocker.Remove(tmpdir)
	app := NewFakeApp("something", "rush", 1)
	p := JujuProvisioner{}
	err = p.RemoveUnit(app, "something/0")
	c.Assert(err, NotNil)
	e, ok := err.(*provision.Error)
	c.Assert(ok, Equals, true)
	c.Assert(e.Reason, Equals, "juju failed")
	c.Assert(e.Err.Error(), Equals, "exit status 66")
}
Beispiel #8
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)
}
Beispiel #9
0
func (s *S) TestRestartFailure(c *gocheck.C) {
	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.Restart(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")
}
Beispiel #10
0
func (s *S) TestProvisionerRestartFailure(c *gocheck.C) {
	tmpdir, err := commandmocker.Error("ssh", "fatal unexpected failure", 25)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("cribcaged", "python", 1)
	p := LocalProvisioner{}
	err = p.Restart(app)
	c.Assert(err, gocheck.NotNil)
	pErr, ok := err.(*provision.Error)
	c.Assert(ok, gocheck.Equals, true)
	c.Assert(pErr.Reason, gocheck.Equals, "fatal unexpected failure")
	c.Assert(pErr.Err.Error(), gocheck.Equals, "exit status 25")
}
Beispiel #11
0
func (s *S) TestNewContainerReturnsContainerWithoutIdAndLogsOnError(c *gocheck.C) {
	w := new(bytes.Buffer)
	l := stdlog.New(w, "", stdlog.LstdFlags)
	log.SetLogger(l)
	tmpdir, err := commandmocker.Error("docker", "cool error", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("myapp", "python", 1)
	container, err := newContainer(app, deployContainerCmd)
	c.Assert(err, gocheck.NotNil)
	c.Assert(container.id, gocheck.Equals, "")
	c.Assert(w.String(), gocheck.Matches, "(?s).*Error creating container myapp.*")
}
Beispiel #12
0
func (s *S) TestAddUnitsFailure(c *C) {
	tmpdir, err := commandmocker.Error("juju", "juju failed", 1)
	c.Assert(err, IsNil)
	defer commandmocker.Remove(tmpdir)
	app := NewFakeApp("headlong", "rush", 1)
	p := JujuProvisioner{}
	units, err := p.AddUnits(app, 1)
	c.Assert(units, IsNil)
	c.Assert(err, NotNil)
	e, ok := err.(*provision.Error)
	c.Assert(ok, Equals, true)
	c.Assert(e.Reason, Equals, "juju failed")
	c.Assert(e.Err.Error(), Equals, "exit status 1")
}
Beispiel #13
0
func (s *S) TestNewContainerReturnsNilAndLogsOnError(c *gocheck.C) {
	w := new(bytes.Buffer)
	l := stdlog.New(w, "", stdlog.LstdFlags)
	log.SetLogger(l)
	tmpdir, err := commandmocker.Error("docker", "cool error", 1)
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	app := testing.NewFakeApp("myapp", "python", 1)
	container, err := newContainer(app)
	c.Assert(err, gocheck.NotNil)
	defer s.conn.Collection(s.collName).Remove(bson.M{"appname": app.GetName()})
	c.Assert(container, gocheck.IsNil)
	c.Assert(w.String(), gocheck.Matches, `(?s).*Error creating container for the app "myapp".*`)
}
Beispiel #14
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")
}
Beispiel #15
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)
	conn, collection := p.bootstrapCollection()
	defer conn.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",
		"",
		"/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=\":2181\"/g'",
		"/etc/init/juju-machine-agent.conf",
		"-o",
		"StrictHostKeyChecking no",
		"-q",
		"-l",
		"ubuntu",
		"server-1081.novalocal",
		"grep",
		"",
		"/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=\":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)
}