liboct

package
v0.0.0-...-8e4191d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

README

start to write test case.

Documentation

Overview

This file is used for the 'Schedular'

This file is used for the 'Schedular'

NOTE: this file is used for the 'Schedular' TODO: all 'sync' mode now

Index

Constants

View Source
const (
	TestCaseConfigFile = "case.json"
	TestCaseSourceDir  = "source"
	TestCaseCollectDir = "collect"
	TestCaseReportFile = "report.md"
)
View Source
const (
	DBCase     DBCollectName = "case"
	DBRepo                   = "repo"
	DBResource               = "resource"
	//testing task: for frontend users
	DBTask = "task"
	//scheduler: for backend servers
	DBScheduler = "scheduler"
	//scheduler unit
	DBUnit = "unit"
)
View Source
const (
	TestStatusInit           TestStatus = "init"
	TestStatusAllocating                = "allocating"
	TestStatusAllocated                 = "allocated"
	TestStatusAllocateFailed            = "allocate failed"
	TestStatusDeploying                 = "deploying"
	TestStatusDeployed                  = "deployed"
	TestStatusDeployFailed              = "deploy failed"
	TestStatusRunning                   = "running"
	TestStatusRun                       = "run"
	TestStatusRunFailed                 = "run failed"
	TestStatusCollecting                = "collecting"
	TestStatusCollected                 = "collect"
	TestStatusCollectFailed             = "collect failed"
	TestStatusDestroying                = "destroying"
	TestStatusFinish                    = "finish"
	TestStatusDestroyFailed             = "destroy failed"
)

Warning: this is not the test case status, this is the test status, which is runtime

View Source
const (
	TestActionAction  TestAction = "action"
	TestActionID                 = "id"
	TestActionApply              = "apply"
	TestActionDeploy             = "deploy"
	TestActionRun                = "run"
	TestActionCollect            = "collect"
	TestActionDestroy            = "destroy"
)
View Source
const SchedulerCacheDir = "/tmp/.test_schedular_cache"
View Source
const SchedulerDefaultPrio = 100
View Source
const SchedulerPriority = "Priority"
View Source
const TestCaseCache string = "/tmp/.testcase_cache/"

Variables

This section is empty.

Functions

func ExecSH

func ExecSH(scripts string, dir string) ([]byte, error)

func GetDirFiles

func GetDirFiles(base_dir string, dir string) (files []string)

func MD5

func MD5(data string) (val string)

func PreparePath

func PreparePath(cachename string, filename string) (dir string)

When filename is null, we just want to prepare a pure directory

func ReadCaseFromTar

func ReadCaseFromTar(tarURL string) (content string)

func ReadTar

func ReadTar(tarURL string, fileURL string, suffix string) (content string)

fileURL is the default file, suffix is the potential file

func ReceiveFile

func ReceiveFile(w http.ResponseWriter, r *http.Request, cacheURL string) (realURL string, params map[string]string)

func Render

func Render(w http.ResponseWriter, httpStatus int, ret HttpRet)

func RenderError

func RenderError(w http.ResponseWriter, err error)

func RenderErrorf

func RenderErrorf(w http.ResponseWriter, msg string)

func RenderOK

func RenderOK(w http.ResponseWriter, msg string, data interface{})

func TarDir

func TarDir(caseDir string) (tarURL string)

func TarFileList

func TarFileList(filelist []string, caseDir string, objectName string) (tarURL string, found bool)

file name filelist is like this: './source/file'

func UntarFile

func UntarFile(filename string, cacheURL string)

Types

type DB

type DB struct {
	OCTDB map[DBCollectName](map[string]DBInterface)
}

func DBNew

func DBNew() (db DB)

func GetDefaultDB

func GetDefaultDB() DB

func (*DB) Add

func (db *DB) Add(collect DBCollectName, val DBInterface) (string, error)

func (*DB) CollectExist

func (db *DB) CollectExist(collect DBCollectName) error

func (*DB) GenerateID

func (db *DB) GenerateID(collect DBCollectName, val string) string

The case, repo, resource should be consistent The task could always be different

func (*DB) Get

func (db *DB) Get(collect DBCollectName, id string) (DBInterface, error)

func (*DB) Lookup

func (db *DB) Lookup(collect DBCollectName, query DBQuery) (ids []string)

func (*DB) RegistCollect

func (db *DB) RegistCollect(collect DBCollectName) error

func (*DB) Remove

func (db *DB) Remove(collect DBCollectName, id string) error

func (*DB) Update

func (db *DB) Update(collect DBCollectName, id string, val DBInterface) error

If id exist,s modify it; if id does not exist, add it.

type DBCollectName

type DBCollectName string

type DBInterface

type DBInterface interface {
	String() string
}

type DBQuery

type DBQuery struct {
	Page     int
	PageSize int
	Params   map[string]string
}

type HttpRet

type HttpRet struct {
	Status  RetStatus
	Message string
	Data    interface{}
}

func SendCommand

func SendCommand(apiurl string, b []byte) (ret HttpRet)

func SendFile

func SendFile(postURL string, fileURL string, params map[string]string) (ret HttpRet)

type Resource

type Resource struct {
	ResourceCommon
	ID  string
	URL string

	//0 means no limit
	MaxJobs     int
	TestUnitIDs []string
	Status      ResourceStatus
}

This is record in the testing cluster

func ResourceFromString

func ResourceFromString(val string) (res Resource, err error)

func (*Resource) Allocate

func (res *Resource) Allocate(unit TestUnit) bool

func (*Resource) GetID

func (res *Resource) GetID() string

func (*Resource) IsQualify

func (res *Resource) IsQualify(req ResourceCommon) bool

func (*Resource) IsValid

func (res *Resource) IsValid() error

func (*Resource) SetID

func (res *Resource) SetID(id string)

func (Resource) String

func (res Resource) String() string

type ResourceClass

type ResourceClass string
const (
	ResourceOS        ResourceClass = "os"
	ResourceContainer               = "container"
)

type ResourceCommon

type ResourceCommon struct {
	Class        ResourceClass
	Distribution string
	//ResName is used in 'container', for example: ubuntu/busybox
	ResName string
	Version string
	Arch    string
	CPU     int64
	Memory  int64
}

Common is the request from the user

type ResourceStatus

type ResourceStatus string
const (
	ResourceStatusFree   ResourceStatus = "free"
	ResourceStatusLocked                = "locked"
)

type RetStatus

type RetStatus string
const (
	RetStatusOK     RetStatus = "ok"
	RetStatusFailed RetStatus = "failed"
)

type Scheduler

type Scheduler struct {
	ID      string
	Case    TestCase
	UnitIDs []string
}

func SchedulerFromString

func SchedulerFromString(val string) (s Scheduler, err error)

func SchedulerNew

func SchedulerNew(tc TestCase) (s Scheduler, err error)

func (*Scheduler) Command

func (s *Scheduler) Command(action TestAction) (err error)

func (*Scheduler) GetID

func (s *Scheduler) GetID() string

func (*Scheduler) GetStatus

func (s *Scheduler) GetStatus() TestStatus

func (*Scheduler) SetID

func (s *Scheduler) SetID(id string)

func (Scheduler) String

func (s Scheduler) String() string

type TestAction

type TestAction string

func TestActionFromString

func TestActionFromString(val string) (TestAction, error)

type TestActionCommand

type TestActionCommand struct {
	Action  string
	Command string
	//Used for container
	ResName string
}

Used for tranfer between scheduler and octd/containerpool

func ActionCommandFromString

func ActionCommandFromString(val string) (t TestActionCommand, err error)

func (TestActionCommand) String

func (t TestActionCommand) String() string

type TestCase

type TestCase struct {
	TestCasePub
	//This is not necessary, but since the developer names the bundle,
	//just don't want to miss it
	BundleName string
	/* the dir */
	BundleURL string
}

func CaseFromBundle

func CaseFromBundle(BundleURL string) (tc TestCase, err error)

func CaseFromString

func CaseFromString(val string) (tc TestCase, err error)

func CaseFromTar

func CaseFromTar(tarURL string, bundleURL string) (TestCase, error)

If bundleURL is nil, untar the bundle in the same dir

func (*TestCase) GetBundleContent

func (tc *TestCase) GetBundleContent() string

func (*TestCase) GetBundleName

func (tc *TestCase) GetBundleName() string

func (*TestCase) GetBundleTarURL

func (tc *TestCase) GetBundleTarURL() string

If cacheURL is nil, tar the bundle in the same dir

func (*TestCase) GetBundleURL

func (tc *TestCase) GetBundleURL() string

func (*TestCase) GetID

func (tc *TestCase) GetID() string

func (*TestCase) GetRepoID

func (tc *TestCase) GetRepoID() string

func (*TestCase) GetReportContent

func (tc *TestCase) GetReportContent() string

func (*TestCase) GetReportStatus

func (tc *TestCase) GetReportStatus() (hasReport bool, caseUpdated bool, err error)

func (*TestCase) IsValid

func (tc *TestCase) IsValid() error

func (*TestCase) MatchStatus

func (tc *TestCase) MatchStatus(status string) bool

func (*TestCase) SetBundleName

func (tc *TestCase) SetBundleName(bundle string)

func (*TestCase) SetBundleURL

func (tc *TestCase) SetBundleURL(bundle string)

func (*TestCase) SetID

func (tc *TestCase) SetID(id string)

func (*TestCase) SetRepoID

func (tc *TestCase) SetRepoID(id string)

func (TestCase) String

func (tc TestCase) String() string

type TestCasePub

type TestCasePub struct {
	//set in runtime implementation
	ID          string
	RepoID      string
	Name        string
	Summary     string
	Version     string
	License     string
	Group       string
	Owner       string
	Description string
	Units       []TestUnit
}

type TestCaseRepo

type TestCaseRepo struct {
	TestCaseRepoPub
	//used to get the repo data, default to : /tmp/tcserver_cache/
	CacheDir string
	Cases    []TestCase
	//The id is not public since it should be set in the implementation
	Timestamp int64
}

func RepoFromString

func RepoFromString(val string) (tcr TestCaseRepo, err error)

func (*TestCaseRepo) GetCase

func (repo *TestCaseRepo) GetCase(groupAndName string) (tc TestCase, err error)

func (*TestCaseRepo) GetCases

func (repo *TestCaseRepo) GetCases() []TestCase

func (*TestCaseRepo) GetID

func (repo *TestCaseRepo) GetID() string

func (*TestCaseRepo) IsValid

func (repo *TestCaseRepo) IsValid() error

func (*TestCaseRepo) Modify

func (repo *TestCaseRepo) Modify(newRepo TestCaseRepo)

func (*TestCaseRepo) Purge

func (repo *TestCaseRepo) Purge() error

func (*TestCaseRepo) Refresh

func (repo *TestCaseRepo) Refresh() bool

func (*TestCaseRepo) SetCacheDir

func (repo *TestCaseRepo) SetCacheDir(CacheDir string)

func (*TestCaseRepo) SetID

func (repo *TestCaseRepo) SetID(id string)

func (TestCaseRepo) String

func (repo TestCaseRepo) String() string

type TestCaseRepoPub

type TestCaseRepoPub struct {
	//set in runtime implementation
	ID string
	//Name is the short name of URL, make the repo management easier
	Name       string
	URL        string
	CaseFolder string
	//Type is the method to discover and get the repos. 'git' as a default
	Type string
	//We can disable a repo
	Enable bool
	Groups []string
}

type TestCommand

type TestCommand struct {
	Deploy string
	Run    string
}

type TestStatus

type TestStatus string

type TestTask

type TestTask struct {
	ID      string
	PostURL string

	//a tar.gz file
	BundleURL string
	Status    TestStatus
	Priority  int

	//Return from the scheduler
	SchedulerID string

	//Used in octd, keep track of the unit name
	Name string
}

func TaskFromString

func TaskFromString(val string) (task TestTask, err error)

func TestTaskNew

func TestTaskNew(postURL string, bundleURL string, prio int) (task TestTask, err error)

func (*TestTask) Apply

func (task *TestTask) Apply() error

func (*TestTask) Collect

func (task *TestTask) Collect() error

func (*TestTask) Command

func (task *TestTask) Command(action TestAction) (err error)

func (*TestTask) Deploy

func (task *TestTask) Deploy() error

Donnot need to send files now, since it will be done by the Apply function

func (*TestTask) Destroy

func (task *TestTask) Destroy() error

func (*TestTask) GetID

func (task *TestTask) GetID() string

func (*TestTask) GetSchedulerID

func (task *TestTask) GetSchedulerID() string

func (*TestTask) Loop

func (task *TestTask) Loop() (needContinue error)

func (*TestTask) Run

func (task *TestTask) Run() error

func (*TestTask) SetID

func (task *TestTask) SetID(id string)

func (*TestTask) SetSchedulerID

func (task *TestTask) SetSchedulerID(id string)

func (TestTask) String

func (task TestTask) String() string

type TestUnit

type TestUnit struct {
	ResourceCommon
	//Suggest to name the unit, easier to write/maintain, must be different
	Name string

	//deploy files: script/data
	Commands TestCommand
	//FIXME: I don't want to use Children..
	//	Children []TestUnit
	ReportURL string

	Status TestStatus

	//the id of the scheduler
	SchedulerID string
	//runtime ID, used to keep track of the relevant hostTest/container
	ResourceID string
	//TODO: use the test bundle URL, but should put files into a smaller piece
	BundleURL string
	// contains filtered or unexported fields
}

func UnitFromString

func UnitFromString(val string) (t TestUnit, err error)

func (*TestUnit) Apply

func (t *TestUnit) Apply() error

func (*TestUnit) Collect

func (t *TestUnit) Collect() error

func (*TestUnit) Deploy

func (t *TestUnit) Deploy() error

func (*TestUnit) Destroy

func (t *TestUnit) Destroy() error

func (*TestUnit) GetBundleURL

func (t *TestUnit) GetBundleURL() string

func (*TestUnit) GetID

func (t *TestUnit) GetID() string

func (*TestUnit) GetResourceID

func (t *TestUnit) GetResourceID() string

func (*TestUnit) GetSchedulerID

func (t *TestUnit) GetSchedulerID() string

func (*TestUnit) GetStatus

func (t *TestUnit) GetStatus() TestStatus

func (*TestUnit) Run

func (t *TestUnit) Run() error

func (*TestUnit) SetBundleURL

func (t *TestUnit) SetBundleURL(url string)

func (*TestUnit) SetID

func (t *TestUnit) SetID(id string)

func (*TestUnit) SetResourceID

func (t *TestUnit) SetResourceID(id string)

func (*TestUnit) SetSchedulerID

func (t *TestUnit) SetSchedulerID(id string)

func (*TestUnit) SetStatus

func (t *TestUnit) SetStatus(s TestStatus)

func (TestUnit) String

func (t TestUnit) String() string

func (*TestUnit) UnmarshalJSON

func (t *TestUnit) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL