--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+// File manager/dryad_job_runner_fota.go provides wrapper of CLI to fota tool available on Dryad.
+
+package manager
+
+import (
+ "encoding/json"
+ "strconv"
+)
+
+const (
+ fotaSDCardPath = "/dev/sda"
+ fotaFilePath = "/tmp/fota.json"
+)
+
+type fotaCmd struct {
+ sdcard string
+ mapping string
+ md5sums string
+ URLs []string
+}
+
+func newFotaCmd(sdcard, mapping string, urls []string) *fotaCmd {
+ return &fotaCmd{
+ sdcard: sdcard,
+ mapping: mapping,
+ URLs: urls,
+ }
+}
+
+func (f *fotaCmd) SetMD5(url string) {
+ f.md5sums = url
+}
+
+func (f *fotaCmd) GetCmd() (cmd []string) {
+ cmd = []string{"fota",
+ "-map", f.mapping,
+ "-sdcard", f.sdcard}
+ if f.md5sums != "" {
+ cmd = append(cmd, "-md5")
+ cmd = append(cmd, f.md5sums)
+ }
+ cmd = append(cmd, f.URLs...)
+ return
+}
+
+type fotaMap struct {
+ name string
+ part int
+}
+
+func newMapping(fms []fotaMap) []byte {
+ fotaMapping := make(map[string]string)
+ for _, fm := range fms {
+ fotaMapping[fm.name] = strconv.Itoa(fm.part)
+ }
+ ret, err := json.Marshal(fotaMapping)
+ if err != nil {
+ panic(err)
+ }
+ return ret
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package manager
+
+import (
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+)
+
+var _ = Describe("DryadJobRunnerFota", func() {
+ var (
+ sdcard = "/dev/path to sdcard"
+ mapping = "path to mapping"
+ md5 = "url to md5sums"
+ urls = []string{"https://some secure server", "http://some not so secure one"}
+ f *fotaCmd
+ )
+
+ BeforeEach(func() {
+ f = newFotaCmd(sdcard, mapping, urls)
+ })
+
+ checkOrder := func(cmd []string) {
+ for i, part := range cmd {
+ switch part {
+ case "fota":
+ Expect(i).To(Equal(0))
+ case "-map":
+ Expect(cmd[i+1]).To(Equal(mapping))
+ case "-md5":
+ Expect(cmd[i+1]).To(Equal(md5))
+ case "-sdcard":
+ Expect(cmd[i+1]).To(Equal(sdcard))
+ }
+ }
+ }
+
+ It("should work for some arguments", func() {
+ cmd := f.GetCmd()
+ Expect(cmd).To(ConsistOf(
+ "fota",
+ "-sdcard", sdcard,
+ "-map", mapping,
+ urls[0], urls[1],
+ ))
+ checkOrder(cmd)
+ })
+
+ It("should add md5sum argument", func() {
+ f.SetMD5(md5)
+ cmd := f.GetCmd()
+ Expect(cmd).To(ConsistOf(
+ "fota",
+ "-sdcard", sdcard,
+ "-map", mapping,
+ "-md5", md5,
+ urls[0], urls[1],
+ ))
+ checkOrder(cmd)
+ })
+})