Log job output to special artifact
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 14 Dec 2017 16:40:21 +0000 (17:40 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Fri, 5 Jan 2018 14:25:35 +0000 (15:25 +0100)
Change-Id: Ie7450b292c05af57b18e79d693cb6b82d69379f6

controller/downloaderimpl.go
manager/dryad_job.go
manager/dryad_job_runner.go
parser.go

index 3b115e9..5efb796 100644 (file)
@@ -273,6 +273,12 @@ func (h *DownloaderImpl) Download(j JobID) {
                return
        }
 
+       config.Path, err = h.pullCreate(j, "results")
+       if err != nil {
+               h.fail(j, fmt.Sprintf("Internal Weles error while creating a new path in ArtifactManager : %s", err.Error()))
+               return
+       }
+
        for i, image := range config.Action.Deploy.Images {
                if image.URI != "" {
                        path, err := h.push(j, AM_IMAGEFILE, fmt.Sprintf("Image_%d", i), image.URI)
index fdc317d..dd6d3e5 100644 (file)
@@ -20,6 +20,7 @@ import (
        "context"
        "fmt"
        "log"
+       "os"
        "sync"
 
        . "git.tizen.org/tools/weles"
@@ -33,13 +34,13 @@ type dryadJob struct {
        notify     chan<- DryadJobStatusChange
        cancel     context.CancelFunc
        failReason string
+       f          *os.File
 }
 
 // newDryadJobWithCancel creates an instance of dryadJob without a goroutine.
 // It is intended to be used by tests and newDryadJob only.
 func newDryadJobWithCancel(job JobID, changes chan<- DryadJobStatusChange,
        runner DryadJobRunner, cancel context.CancelFunc) *dryadJob {
-
        dJob := &dryadJob{
                mutex:  new(sync.Mutex),
                runner: runner,
@@ -59,10 +60,16 @@ func newDryadJob(job JobID, rusalka Dryad, conf Config, changes chan<- DryadJobS
        session, _ := dryad.NewSessionProvider(rusalka) // FIXME: Make use of returned error.
        device := dryad.NewDeviceCommunicationProvider(session)
 
+       f, err := os.Create(conf.Path)
+       if err != nil {
+               panic(err)
+       }
+
        ctx, cancel := context.WithCancel(context.Background())
-       runner := newDryadJobRunner(ctx, session, device, conf)
+       runner := newDryadJobRunner(ctx, session, device, conf, f)
 
        dJob := newDryadJobWithCancel(job, changes, runner, cancel)
+       dJob.f = f
 
        go dJob.run(ctx)
        return dJob
@@ -109,6 +116,7 @@ func (d *dryadJob) run(ctx context.Context) {
                }
                d.changeStatus(DJ_OK)
        }()
+       defer d.f.Close()
        d.executePhase(DJ_DEPLOY, d.runner.Deploy)
        d.executePhase(DJ_BOOT, d.runner.Boot)
        d.executePhase(DJ_TEST, d.runner.Test)
index 353e087..9013711 100644 (file)
@@ -20,6 +20,8 @@ package manager
 
 import (
        "context"
+       "io"
+       "log"
        "strings"
        "time"
 
@@ -38,22 +40,25 @@ type dryadJobRunner struct {
        rusalka dryad.SessionProvider
        device  dryad.DeviceCommunicationProvider
        conf    weles.Config
+       log     *log.Logger
 }
 
 // newDryadJobRunner prepares a new instance of dryadJobRunner
 // and returns DryadJobRunner interface to it.
 func newDryadJobRunner(ctx context.Context, rusalka dryad.SessionProvider,
-       device dryad.DeviceCommunicationProvider, conf weles.Config) DryadJobRunner {
+       device dryad.DeviceCommunicationProvider, conf weles.Config, w io.Writer) DryadJobRunner {
        return &dryadJobRunner{
                ctx:     ctx,
                rusalka: rusalka,
                device:  device,
                conf:    conf,
+               log:     log.New(w, "", log.LstdFlags),
        }
 }
 
 // Deploy is part of DryadJobRunner interface.
 func (d *dryadJobRunner) Deploy() (err error) {
+       d.log.Println("DEPLOY")
        err = d.rusalka.TS()
        if err != nil {
                return
@@ -86,6 +91,7 @@ func (d *dryadJobRunner) Deploy() (err error) {
 
 // Boot is part of DryadJobRunner interface.
 func (d *dryadJobRunner) Boot() (err error) {
+       d.log.Println("BOOT")
        // Attempt to start a device boot.
        err = d.rusalka.DUT()
        if err != nil {
@@ -109,16 +115,28 @@ func (d *dryadJobRunner) Boot() (err error) {
 
 // Test is part of DryadJobRunner interface.
 func (d *dryadJobRunner) Test() error {
+       d.log.Println("TEST")
        for _, testcase := range d.conf.Action.Test.TestCases {
+               d.log.Println("current testcase:", testcase)
                for _, testaction := range testcase.TestActions {
+                       d.log.Println("current testaction:", testaction)
                        switch action := testaction.(type) {
                        case weles.Push:
-                               d.device.CopyFilesTo([]string{action.Path}, action.Dest)
+                               err := d.device.CopyFilesTo([]string{action.Path}, action.Dest)
+                               if err != nil {
+                                       return err
+                               }
                        case weles.Run:
                                // TODO: action.Name splot should smarter (shell-like) or avoided at all.
-                               d.device.Exec(strings.Split(action.Name, " "), defaultDeviceExecTimeout)
+                               stdout, stderr, err := d.device.Exec(strings.Split(action.Name, " "), defaultDeviceExecTimeout)
+                               d.log.Println("stdout:", string(stdout))
+                               d.log.Println("stderr:", string(stderr))
+                               d.log.Println("error", err.Error())
                        case weles.Pull:
-                               d.device.CopyFilesFrom([]string{action.Src}, action.Path)
+                               err := d.device.CopyFilesFrom([]string{action.Src}, action.Path)
+                               if err != nil {
+                                       return err
+                               }
                        default:
                                panic("unknown test action type")
                        }
index e250d3a..f425672 100644 (file)
--- a/parser.go
+++ b/parser.go
@@ -147,6 +147,9 @@ type Config struct {
        Timeouts   Timeouts `yaml:"timeouts"`
        Priority   Priority `yaml:"priority"`
        Action     Action   `yaml:"actions"`
+
+       // Path defines ArtifactDB path. It's added for Controller purposes.
+       Path string `yaml:"-"`
 }
 
 // Parser defines methods of YAML parser.