예제 #1
0
파일: put.go 프로젝트: shtlee/qa
// upload the file and get the download url
func (self *PutFile) doTestPutFile() (url, msg string, err error) {
	entry := self.BucketName + ":" + self.Key
	authPolicy := &uptoken.AuthPolicy{
		Scope:    entry,
		Deadline: 3600,
	}
	authPolicy.Deadline += uint32(time.Now().Unix())
	token := uptoken.MakeAuthTokenString(self.Env.AccessKey, self.Env.SecretKey, authPolicy)

	// in fact, upload should be a part of Up not Rs
	begin := time.Now()
	_, code, err := self.Conn.Upload(entry, self.DataFile, "", "", "", token)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("UP    "+self.Env.Id+"_"+self.Name+"_doTestPutFile", begin, end, duration)
	if err != nil || code != 200 {
		return
	}

	getRet, code, err := self.Conn.Get(entry, "", "", 3600)
	if err != nil || code != 200 {
		return
	}
	url = getRet.URL
	// check shal
	return
}
예제 #2
0
파일: resumable_put.go 프로젝트: shtlee/qa
func (self *UpResuPut) doTestDownload() (msg string, err error) {
	h := sha1.New()
	begin := time.Now()
	var req *http.Request
	if req, err = http.NewRequest("GET", self.Url, nil); err != nil {
		return
	}
	var resp *http.Response
	if resp, err = http.DefaultClient.Do(req); err != nil {
		return
	}
	defer resp.Body.Close()
	if _, err = io.Copy(h, resp.Body); err != nil {
		return
	}
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("UP    "+self.Env.Id+"_"+self.Name+"_doTestDownload", begin, end, duration)

	hash := hex.EncodeToString(h.Sum(nil))
	if hash != self.DataSha1 {
		err = errors.New("check shal failed!")
		return
	}
	return
}
예제 #3
0
파일: publish.go 프로젝트: shtlee/qa
func (p *Pub) doTestUnpublish() (msg string, err error) {
	begin := time.Now()
	if _, err = p.rsCli.Unpublish(p.Domain); err != nil {
		err = errors.Info(err, "unpublish domain failed", p.Domain)
		return
	}
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("Pb    "+p.Env.Id+"_"+p.Name+"_doTestUnpublish", begin, end, duration)
	return
}
예제 #4
0
파일: publish.go 프로젝트: shtlee/qa
func (p *Pub) doTestDownload() (msg string, err error) {

	var (
		url string
	)
	if p.isNormalDomain {
		url = "http://" + p.Domain + "/" + p.Key
	} else {
		url = "http://" + p.DomainIp + "/" + p.Key
	}
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		err = errors.Info(err, "Download failed:", url)
		return
	}
	if !p.isNormalDomain {
		req.Host = p.Domain
	}
	begin := time.Now()
	resp, err := http.DefaultClient.Do(req)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("Fp    "+p.Env.Id+"_"+p.Name+"_doTestDownload", begin, end, duration)
	if err != nil {
		err = errors.Info(err, "Download failed:", url)
		return
	}
	defer resp.Body.Close()
	if resp.StatusCode/100 != 2 {
		err = errors.New("download status code is not 20x!")
		err = errors.Info(err, url, resp.StatusCode)
		return
	}
	if ct, ok := resp.Header["Content-Type"]; !ok || len(ct) != 1 || ct[0] != p.dataType {
		err = errors.New("Invalid content type")
		return
	}

	h := sha1.New()
	if _, err = io.Copy(h, resp.Body); err != nil {
		err = errors.Info(err, "check sha1 failed")
		return
	}
	if p.DataSha1 != hex.EncodeToString(h.Sum(nil)) {
		err = errors.New("Invalid data sha1")
		err = errors.Info(err, p.DataSha1, hex.EncodeToString(h.Sum(nil)))
		return
	}

	return
}
예제 #5
0
파일: publish.go 프로젝트: shtlee/qa
func (p *Pub) doTestPublish() (msg string, err error) {

	if p.isNormalDomain {
		p.Domain = p.Domain + "/" + strconv.FormatInt(rand.Int63(), 10)
	} else {
		p.Domain = strconv.FormatInt(rand.Int63(), 10) + "." + p.Domain
	}
	begin := time.Now()
	if _, err = p.rsCli.Publish(p.Domain, p.Bucket); err != nil {
		err = errors.Info(err, "Publish failed: ", p.Bucket, p.Domain)
		return
	}
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("Pb    "+p.Env.Id+"_"+p.Name+"_doTestPublish", begin, end, duration)
	return
}
예제 #6
0
파일: fop_imgexif.go 프로젝트: shtlee/qa
func (self *FopImgExif) doTestImgExif(downloadUrl string) (msg string, err error) {
	begin := time.Now()
	url := downloadUrl + "exif"
	netBuf, err := util.DoHttpGet(url)
	var TargetExif ImgExif
	json.Unmarshal(netBuf.Bytes(), &TargetExif)
	if self.SrcExif != TargetExif {
		err = errors.New("Umatched Exif!")
	}
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("Fp    "+self.Env.Id+"_"+self.Name+"_doTestImgOp", begin, end, duration)
	if err != nil {
		return
	}
	return
}
예제 #7
0
파일: fop_imginfo.go 프로젝트: shtlee/qa
func (self *FopImgInfo) doTestGetImgInfo(downloadUrl string) (msg string, err error) {
	begin := time.Now()
	url := downloadUrl + "imageInfo"
	netBuf, err := util.DoHttpGet(url)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("Fp    "+self.Env.Id+"_"+self.Name+"_doTestGetImgInfo", begin, end, duration)
	if err != nil {
		return
	}

	var serImgInfo ImageInfo
	json.Unmarshal(netBuf.Bytes(), &serImgInfo)
	locImgInfo := self.TargetImgInfo

	if err = CheckImgInfo(serImgInfo, locImgInfo); err != nil {
		return
	}
	return
}
예제 #8
0
파일: resumable_put.go 프로젝트: shtlee/qa
func (self *UpResuPut) doTestRSGet() (msg string, err error) {
	var ret rs.GetRet

	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	rsservice, err := rs.New(self.Env.Hosts, self.Env.Ips, dt)
	if err != nil {
		return
	}
	begin := time.Now()
	ret, code, err := rsservice.Get(self.EntryURI, "", "", 3600)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("UP    "+self.Env.Id+"_"+self.Name+"_doTestRsGet", begin, end, duration)

	if err != nil || code != 200 {
		return
	}
	self.Url = ret.URL
	return
}
예제 #9
0
파일: publish.go 프로젝트: shtlee/qa
func (p *Pub) doTestUpload() (msg string, err error) {

	p.dataType = "application/qbox-mon"
	entryName := p.Bucket + ":" + p.Key
	f, err := os.Open(p.DataFile)
	if err != nil {
		err = errors.Info(err, "Upload failed: ", p.DataFile)
		return
	}
	defer f.Close()
	fi, _ := f.Stat()
	begin := time.Now()
	_, _, err = p.rsCli.Put(entryName, p.dataType, f, fi.Size())
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("Pb    "+p.Env.Id+"_"+p.Name+"_doTestUpload", begin, end, duration)
	if err != nil {
		err = errors.Info(err, "upload failed:", entryName)
	}
	return
}
예제 #10
0
파일: fop_imgop.go 프로젝트: shtlee/qa
func (self *FopImgOp) doTestImgOp(downloadUrl string) (msg string, err error) {
	begin := time.Now()
	url := downloadUrl + self.Op
	netBuf, err := util.DoHttpGet(url)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("Fp    "+self.Env.Id+"_"+self.Name+"_doTestImgOp", begin, end, duration)
	if err != nil {
		return
	}
	targetFile, err := os.Open(self.TargetImg)
	if err != nil {
		return
	}
	_, err = util.CheckImg(netBuf, targetFile)
	if err != nil {
		return
	}

	return
}
예제 #11
0
파일: put.go 프로젝트: shtlee/qa
func (self *PutFile) doTestCheckSha1(url string) (msg string, err error) {
	begin := time.Now()
	netBuf, err := util.DoHttpGet(url)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("RS    "+self.Env.Id+"_"+self.Name+"_doTestIoDownload", begin, end, duration)
	if err != nil {
		return
	}

	h := sha1.New()
	_, err = io.Copy(h, netBuf)
	if err != nil {
		return
	}
	sha1Code := hex.EncodeToString(h.Sum(nil))
	if self.Sha1 != sha1Code {
		err = errors.New("check sha1 failed!")
	}
	return
}
예제 #12
0
파일: resumable_put.go 프로젝트: shtlee/qa
func (self *UpResuPut) doTestPut() (msg string, err error) {

	DataFile := self.DataFile
	entry := self.Bucket + ":" + self.Key
	self.EntryURI = entry
	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	host := self.Env.Hosts["up"]
	ip := self.Env.Ips["up"]
	upservice, _ := up.NewService(host, ip, self.BlockBits, self.ChunkSize, self.PutRetryTimes, dt, 1, 1)
	log.Info(upservice)

	f, err := os.Open(DataFile)
	if err != nil {
		return
	}
	defer f.Close()
	fi, err := f.Stat()
	blockCnt := upservice.BlockCount(fi.Size())

	var (
		checksums []string           = make([]string, blockCnt)
		progs     []up.BlockProgress = make([]up.BlockProgress, blockCnt)
		ret       up.PutRet
		code      int
	)
	begin := time.Now()
	code, err = upservice.Put(f, fi.Size(), checksums, progs, func(int, string) {}, func(int, *up.BlockProgress) {})

	if err != nil || code != 200 {
		return
	}
	code, err = upservice.Mkfile(&ret, "/rs-mkfile/", entry, fi.Size(), "", "", checksums)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("UP    "+self.Env.Id+"_"+self.Name+"_doTestPut", begin, end, duration)
	if err != nil || code != 200 {
		return
	}
	return
}