Implement Deploy with test 73/162373/1
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Wed, 29 Nov 2017 17:22:56 +0000 (18:22 +0100)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 30 Nov 2017 13:25:57 +0000 (14:25 +0100)
Change-Id: Ibc55e994878f639af1f0190c1debd332e35fd1c9
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
manager/dryad_job_runner.go
manager/dryad_job_runner_test.go

index 94e2770..f44bf12 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([]string{"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 8e4a810..5525b6b 100644 (file)
@@ -18,7 +18,6 @@ package manager
 
 import (
        "context"
-       "errors"
 
        "git.tizen.org/tools/weles"
 
@@ -46,63 +45,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([]string{"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())
        })
 })