Esempio n. 1
0
func RunBuildPlan(config *client.Config) (Result, error) {
	var err error

	currentAdapter, err := adapter.Get(selectedAdapter)
	if err != nil {
		return RESULT_INFRA_FAILED, err
	}

	currentReporter, err := reporter.Get(selectedReporter)
	if err != nil {
		log.Printf("[engine] failed to initialize reporter: %s", selectedReporter)
		return RESULT_INFRA_FAILED, err
	}
	log.Printf("[engine] started with reporter %s, adapter %s", selectedReporter, selectedAdapter)

	engine := &Engine{
		config:    config,
		clientLog: client.NewLog(),
		adapter:   currentAdapter,
		reporter:  currentReporter,
	}

	return engine.Run()
}
Esempio n. 2
0
func (s *AdapterSuite) TestCompleteFlow(c *C) {
	var cmd *client.Command
	var err error
	var result *client.CommandResult

	if os.Getenv("CHANGES") == "1" {
		c.ExpectFailure("For as yet unknown reasons, container initialization fails on Changes.")
	}

	clientLog := client.NewLog()
	adapter, err := adapter.Get("lxc")
	c.Assert(err, IsNil)

	wg := sync.WaitGroup{}

	wg.Add(1)
	go func() {
		defer wg.Done()
		s.reportLogChunks(clientLog)
	}()

	config := &client.Config{}
	config.JobstepID = containerName

	err = adapter.Init(config)
	c.Assert(err, IsNil)

	err = adapter.Prepare(clientLog)
	c.Assert(err, IsNil)
	defer adapter.Shutdown(clientLog)

	cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho hello > foo.txt\nexit 0")
	c.Assert(err, IsNil)

	result, err = adapter.Run(cmd, clientLog)
	c.Assert(err, IsNil)
	c.Assert(string(result.Output), Equals, "")
	c.Assert(result.Success, Equals, true)

	cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho $HOME\nexit 0")
	cmd.CaptureOutput = true
	c.Assert(err, IsNil)

	result, err = adapter.Run(cmd, clientLog)
	c.Assert(err, IsNil)
	c.Assert(string(result.Output), Equals, "/home/ubuntu\n")
	c.Assert(result.Success, Equals, true)

	cmd, err = client.NewCommand("test", "#!/bin/bash -e\ndd if=/dev/zero of=test.img bs=1M count=10 && mkfs.ext4 -b 1024 -j -F test.img && sudo mount -v -o loop test.img /mnt")
	cmd.CaptureOutput = true
	c.Assert(err, IsNil)

	result, err = adapter.Run(cmd, clientLog)
	c.Assert(err, IsNil)
	c.Assert(result.Success, Equals, true)

	// test with a command that expects stdin
	cmd, err = client.NewCommand("test", "#!/bin/bash -e\nread foo\nexit 1")
	c.Assert(err, IsNil)

	result, err = adapter.Run(cmd, clientLog)
	c.Assert(err, IsNil)
	c.Assert(string(result.Output), Equals, "")
	c.Assert(result.Success, Equals, false)

	artifacts, err := adapter.CollectArtifacts([]string{"foo.txt"}, clientLog)
	c.Assert(err, IsNil)
	c.Assert(len(artifacts), Equals, 1)
	c.Assert(artifacts[0], Matches, ".*/home/ubuntu/foo.txt")

	clientLog.Close()

	wg.Wait()
}
Esempio n. 3
0
func (s *AdapterSuite) TestCompleteFlow(c *C) {
	var cmd *client.Command
	var err error
	var result *client.CommandResult

	clientLog := client.NewLog()
	adapter, err := adapter.Get("lxc")
	c.Assert(err, IsNil)

	wg := sync.WaitGroup{}

	wg.Add(1)
	go func() {
		defer wg.Done()
		s.reportLogChunks(clientLog)
	}()

	config := &client.Config{}
	config.JobstepID = containerName

	err = adapter.Init(config)
	c.Assert(err, IsNil)

	err = adapter.Prepare(clientLog)
	c.Assert(err, IsNil)
	defer adapter.Shutdown(clientLog)

	cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho hello > foo.txt\nexit 0")
	c.Assert(err, IsNil)

	result, err = adapter.Run(cmd, clientLog)
	c.Assert(err, IsNil)
	c.Assert(string(result.Output), Equals, "")
	c.Assert(result.Success, Equals, true)

	cmd, err = client.NewCommand("test", "#!/bin/bash -e\necho $HOME\nexit 0")
	cmd.CaptureOutput = true
	c.Assert(err, IsNil)

	result, err = adapter.Run(cmd, clientLog)
	c.Assert(err, IsNil)
	c.Assert(string(result.Output), Equals, "/home/ubuntu\n")
	c.Assert(result.Success, Equals, true)

	// test with a command that expects stdin
	cmd, err = client.NewCommand("test", "#!/bin/bash -e\nread foo\nexit 1")
	c.Assert(err, IsNil)

	result, err = adapter.Run(cmd, clientLog)
	c.Assert(err, IsNil)
	c.Assert(string(result.Output), Equals, "")
	c.Assert(result.Success, Equals, false)

	artifacts, err := adapter.CollectArtifacts([]string{"foo.txt"}, clientLog)
	c.Assert(err, IsNil)
	c.Assert(len(artifacts), Equals, 1)
	c.Assert(artifacts[0], Matches, ".*/home/ubuntu/foo.txt")

	clientLog.Close()

	wg.Wait()
}