Пример #1
0
func ReceiveTask(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	realURL, params := liboct.ReceiveFile(w, r, OCTDCacheDir)

	logrus.Debugf("ReceiveTask %v", realURL)

	if id, ok := params["id"]; ok {
		if strings.HasSuffix(realURL, ".tar.gz") {
			liboct.UntarFile(realURL, strings.TrimSuffix(realURL, ".tar.gz"))
		}
		var task liboct.TestTask
		task.ID = id
		task.BundleURL = realURL
		if name, ok := params["name"]; ok {
			task.Name = name
		} else {
			task.Name = id
			logrus.Warnf("Cannot find the name of the task.")
		}
		db.Update(liboct.DBTask, id, task)

		liboct.RenderOK(w, "", nil)
	} else {
		liboct.RenderErrorf(w, fmt.Sprintf("Cannot find the task id: %d", id))
	}
}
Пример #2
0
func ReceiveTask(w http.ResponseWriter, r *http.Request) {
	logrus.Debugf("ReceiveTask begin")
	var tc liboct.TestCase
	db := liboct.GetDefaultDB()
	realURL, _ := liboct.ReceiveFile(w, r, liboct.SchedulerCacheDir)
	tc, err := liboct.CaseFromTar(realURL, "")
	if err != nil {
		liboct.RenderError(w, err)
		return
	}

	s, _ := liboct.SchedulerNew(tc)

	err = s.Command(liboct.TestActionApply)
	if err == nil {
		if id, e := db.Add(liboct.DBScheduler, s); e == nil {
			updateSchedulerBundle(id, realURL)
			liboct.RenderOK(w, id, nil)
		} else {
			liboct.RenderError(w, e)
		}
	} else {
		liboct.RenderError(w, err)
	}
}