Implement Deploy with test 99/177399/2
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Wed, 29 Nov 2017 17:22:56 +0000 (18:22 +0100)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 28 Jun 2018 14:50:17 +0000 (16:50 +0200)
Change-Id: Ibc55e994878f639af1f0190c1debd332e35fd1c9
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
manager/dryad_job_runner.go
manager/dryad_job_runner_test.go

index 79fc4d7..36c50e1 100644 (file)
@@ -47,9 +47,35 @@ func newDryadJobRunner(ctx context.Context, rusalka dryad.SessionProvider,
 }
 
 // Deploy is part of DryadJobRunner interface.
-func (d *dryadJobRunner) Deploy() error {
-       // TODO(amistewicz): implement.
-       return d.rusalka.TS()
+func (d *dryadJobRunner) Deploy() (err error) {
+       err = d.rusalka.TS()
+       if err != nil {
+               return
+       }
+
+       // Generate partition mapping for FOTA and store it on Dryad.
+       urls := make([]string, 0, len(d.conf.Action.Deploy.Images))
+       for _, image := range d.conf.Action.Deploy.Images {
+               if p := image.Path; p != "" {
+                       urls = append(urls, p)
+               }
+       }
+       partLayout := make([]fotaMap, 0, len(d.conf.Action.Deploy.PartitionLayout))
+       for _, layout := range d.conf.Action.Deploy.PartitionLayout {
+               if name, part := layout.ImageName, layout.ID; name != "" && part != 0 {
+                       partLayout = append(partLayout, fotaMap{name, part})
+               }
+
+       }
+       mapping := newMapping(partLayout)
+       _, _, err = d.rusalka.Exec("echo", "'"+string(mapping)+"'", ">", fotaFilePath)
+       if err != nil {
+               return
+       }
+
+       // Run FOTA.
+       _, _, err = d.rusalka.Exec(newFotaCmd(fotaSDCardPath, fotaFilePath, urls).GetCmd()...)
+       return err
 }
 
 // Boot is part of DryadJobRunner interface.
index 88980bb..f984ae7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ package manager
 
 import (
        "context"
-       "errors"
 
        "git.tizen.org/tools/weles"
 
@@ -48,63 +47,16 @@ var _ = Describe("DryadJobRunner", func() {
                ctrl.Finish()
        })
 
-       Describe("Deploy", func() {
-               var tsCall *gomock.Call
-
-               BeforeEach(func() {
-                       tsCall = mockSession.EXPECT().TS().Times(1)
-               })
-
-               It("should switch to TS", func() {
-                       err := djr.Deploy()
-                       Expect(err).ToNot(HaveOccurred())
-               })
-
-               It("should fail if TS fails", func() {
-                       tsCall.Return(errors.New("TS failed"))
-
-                       err := djr.Deploy()
-                       Expect(err).To(HaveOccurred())
-               })
-       })
-
-       Describe("Boot", func() {
-               var dutCall *gomock.Call
-
-               BeforeEach(func() {
-                       dutCall = mockSession.EXPECT().DUT().Times(1)
-               })
-
-               It("should switch to DUT", func() {
-                       err := djr.Boot()
-                       Expect(err).ToNot(HaveOccurred())
-               })
-
-               It("should fail if DUT fails", func() {
-                       dutCall.Return(errors.New("DUT failed"))
-
-                       err := djr.Boot()
-                       Expect(err).To(HaveOccurred())
-               })
-       })
-
-       Describe("Test", func() {
-               var execCall *gomock.Call
-
-               BeforeEach(func() {
-                       execCall = mockSession.EXPECT().Exec([]string{"echo", "healthcheck"})
-               })
-
-               It("should exec echo healthcheck", func() {
-                       err := djr.Test()
-                       Expect(err).ToNot(HaveOccurred())
-               })
-
-               It("should fail if Exec fails", func() {
-                       execCall.Return(nil, nil, errors.New("exec failed"))
-
-                       err := djr.Test()
-                       Expect(err).To(HaveOccurred())
-               })
+       It("should execute the basic weles job definition", func() {
+               djr = newDryadJobRunner(context.Background(), mockSession, mockDevice, basicConfig)
+               By("Deploy")
+               gomock.InOrder(
+                       mockSession.EXPECT().TS(),
+                       mockSession.EXPECT().Exec("echo", "'{\"image name_1\":\"1\",\"image_name 2\":\"2\"}'", ">", fotaFilePath),
+                       mockSession.EXPECT().Exec(newFotaCmd(fotaSDCardPath, fotaFilePath,
+                               []string{basicConfig.Action.Deploy.Images[0].Path, basicConfig.Action.Deploy.Images[1].Path}).GetCmd()),
+               )
+
+               Expect(djr.Deploy()).To(Succeed())
        })
 })