gopenqa

package module
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 14 Imported by: 2

README

gopenqa

gopenqa is a (intentional bad name for a) openQA module written in go. The aim of the project is to create an easy-to-use go library for interacting with openQA.

The project is not feature-complete regarding the openQA API. PR extending the internal API to include your needs are welcome.

What works

  • Job query
  • Job group query
  • Job comment query
  • RabbitMQ

Installation

go get github.com/grisu48/gopenqa

Getting started

Checkout the examples provided within the project.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyParams

func EmptyParams() map[string]string

func ExtractJobIDS added in v0.7.0

func ExtractJobIDS(jobs []Job) []int64

Types

type Children

type Children struct {
	Chained         []int64 `json:"Chained"`
	DirectlyChained []int64 `json:"Directly chained"`
	Parallel        []int64 `json:"Parallel"`
}

Children struct is for chained, directly chained and parallel children/parents

type Comment

type Comment struct {
	ID       int      `json:"id"`
	Text     string   `json:"text"`             // Comment text
	Markdown string   `json:"renderedMarkdown"` // HTML of the rendered markdown
	BugRefs  []string `json:"bugrefs"`          // Referenced bugs
	Created  string   `json:"created"`          // bug creation date
	Updated  string   `json:"updated"`          // timestamp for update
	User     string   `json:"userName"`         // Creator
}

type CommentMQ added in v0.4.0

type CommentMQ struct {
	ID      int    `json:"id"`
	Created string `json:"created"`
	Updates string `json:"updated"`
	Text    string `json:"text"`
	User    string `json:"user"`
}

RabbitMQ comment

type Instance

type Instance struct {
	URL string
	// contains filtered or unexported fields
}

Instance defines a openQA instance

func CreateInstance

func CreateInstance(url string) Instance

Create a openQA instance module

func CreateO3Instance

func CreateO3Instance() Instance

Create a openQA instance module for openqa.opensuse.org

func (*Instance) DeleteJob

func (i *Instance) DeleteJob(id int64) error

func (*Instance) DeleteJobGroup

func (i *Instance) DeleteJobGroup(id int) error

func (*Instance) DeleteJobGroupJobs

func (i *Instance) DeleteJobGroupJobs(id int) error

func (*Instance) DeleteJobTemplate

func (i *Instance) DeleteJobTemplate(id int) error

func (*Instance) DeleteMachine

func (i *Instance) DeleteMachine(id int) error

func (*Instance) GetComments

func (i *Instance) GetComments(job int64) ([]Comment, error)

Fetch comments for a given job

func (*Instance) GetJob

func (i *Instance) GetJob(id int64) (Job, error)

GetJob fetches detailled job information

func (*Instance) GetJobFollow

func (inst *Instance) GetJobFollow(id int64) (Job, error)

GetJob fetches detailled job information and follows the job, if it contains a CloneID

func (*Instance) GetJobGroup

func (i *Instance) GetJobGroup(id int) (JobGroup, error)

func (*Instance) GetJobGroupJobs

func (instance *Instance) GetJobGroupJobs(id int) ([]int64, error)

func (*Instance) GetJobGroups

func (i *Instance) GetJobGroups() ([]JobGroup, error)

func (*Instance) GetJobState added in v0.7.0

func (i *Instance) GetJobState(id int64) (JobState, error)

GetJobState uses the (currently experimental) API call to quickly fetch a job state

func (*Instance) GetJobTemplate

func (i *Instance) GetJobTemplate(id int) (JobTemplate, error)

func (*Instance) GetJobTemplateYAML

func (i *Instance) GetJobTemplateYAML(id int) (string, error)

func (*Instance) GetJobTemplates

func (i *Instance) GetJobTemplates() ([]JobTemplate, error)

func (*Instance) GetJobs added in v0.6.0

func (i *Instance) GetJobs(ids []int64) ([]Job, error)

GetJob fetches detailled information about a list of jobs

func (*Instance) GetJobsFollow added in v0.7.2

func (inst *Instance) GetJobsFollow(ids []int64) ([]Job, error)

GetJob fetches detailled information about a list of jobs. Follows cloned jobs, if applicable

func (*Instance) GetLatestJobs

func (i *Instance) GetLatestJobs(testsuite string, params map[string]string) ([]Job, error)

Get only the latest jobs of a certain testsuite. Testsuite must be given here. * Additional parameters can be supplied via the params map (See GetOverview for more info about usage of those parameters)

func (*Instance) GetMachine

func (i *Instance) GetMachine(id int) (Machine, error)

func (*Instance) GetMachines

func (i *Instance) GetMachines() ([]Machine, error)

func (*Instance) GetOverview

func (i *Instance) GetOverview(testsuite string, params map[string]string) ([]Job, error)

Query the job overview. params is a map for optional parameters, which will be added to the query. * Suitable parameters are `arch`, `distri`, `flavor`, `machine` or `arch`, but everything in this dict will be added to the url * Overview returns only the job id and name

func (*Instance) GetParentJobGroup

func (i *Instance) GetParentJobGroup(id int) (JobGroup, error)

func (*Instance) GetParentJobGroups

func (i *Instance) GetParentJobGroups() ([]JobGroup, error)

func (*Instance) GetProduct

func (i *Instance) GetProduct(id int) (Product, error)

func (*Instance) GetProducts

func (i *Instance) GetProducts() ([]Product, error)

func (*Instance) GetWorkers

func (i *Instance) GetWorkers() ([]Worker, error)

func (*Instance) PostJobGroup

func (i *Instance) PostJobGroup(jobgroup JobGroup) (JobGroup, error)

func (*Instance) PostJobTemplateYAML

func (i *Instance) PostJobTemplateYAML(id int, yaml string) error

func (*Instance) PostMachine

func (i *Instance) PostMachine(machine Machine) (Machine, error)

func (*Instance) PostParentJobGroup

func (i *Instance) PostParentJobGroup(jobgroup JobGroup) (JobGroup, error)

func (*Instance) PostProduct

func (i *Instance) PostProduct(product Product) (Product, error)

func (*Instance) SetAllowParallel added in v0.6.0

func (i *Instance) SetAllowParallel(allow bool)

Set to allow or disallow parallel requests to the instance

func (*Instance) SetApiKey

func (i *Instance) SetApiKey(key string, secret string)

Set the API key and secret

func (*Instance) SetMaxRecursionDepth

func (i *Instance) SetMaxRecursionDepth(depth int)

Set the maximum allowed number of recursions before failing

func (*Instance) SetUserAgent added in v0.4.1

func (i *Instance) SetUserAgent(userAgent string)

Set the UserAgent for HTTP requests

func (*Instance) SetVerbose

func (i *Instance) SetVerbose(verbose bool)

Enable verbosity

type Job

type Job struct {
	AssignedWorkerID int      `json:"assigned_worker_id"`
	BlockedByID      int      `json:"blocked_by_id"`
	Children         Children `json:"children"`
	Parents          Children `json:"parents"`
	CloneID          int64    `json:"clone_id"`
	GroupID          int      `json:"group_id"`
	ID               int64    `json:"id"`
	// Modules
	Name string `json:"name"`
	// Parents
	Priority  int      `json:"priority"`
	Result    string   `json:"result"`
	Settings  Settings `json:"settings"`
	State     string   `json:"state"`
	Tfinished string   `json:"t_finished"`
	Tstarted  string   `json:"t_started"`
	Test      string   `json:"test"`
	/* this is added by the program and not part of the fetched json */
	Link   string
	Prefix string
	Remote string // openQA remote host
	// contains filtered or unexported fields
}

Job instance

func (*Job) Equals

func (j1 *Job) Equals(j2 Job) bool

Compares two jobs according to their unique parameters (ID, GroupID, Test)

func (*Job) FetchAllChildren

func (j *Job) FetchAllChildren(follow bool) ([]Job, error)

Fetch all child jobs * follow determines if we should follow the given children, i.e. get their cloned jobs instead of the original ones if present

func (*Job) FetchChildren

func (j *Job) FetchChildren(ids []int64, follow bool) ([]Job, error)

* Fetch the given child jobs. Use with j.Children.Chained, j.Children.DirectlyChained and j.Children.Parallel * if follow is set to true, the method will return the cloned job instead of the original one, if present

func (*Job) IsCloned added in v0.7.0

func (j *Job) IsCloned() bool

IsCloned returns true, if the job has been cloned/restarted

func (*Job) JobState

func (j *Job) JobState() string

JobState returns or the job state or the result, if the job is done

func (*Job) String

func (j *Job) String() string

Format job as a string

type JobGroup

type JobGroup struct {
	ID               int    `json:"id"`
	Name             string `json:"name"`
	ParentID         int    `json:"parent_id"`
	Description      string `json:"description"`
	BuildVersionSort int    `json:"build_version_sort"`
	CarryOverBugrefs int    `json:"carry_over_bugrefs"`
	DefaultPriority  int    `json:"default_priority`
	// Disabled because of type mismatch in json
	// Sometimes it's returned as int, sometimes as string and we cannot deal with that atm
	//KeepImportantLogsInDays    int    `json:"keep_important_logs_in_days"`
	//KeepImportantResultsInDays int    `json:"keep_important_results_in_days"`
	//KeepLogsInDays             int    `json:"keep_logs_in_days"`
	//KeepResultsInDays          int    `json:"keep_results_in_days"`
	//SizeLimit                  int    `json:"size_limit_gb"` // Size limit in GB
	SortOrder int    `json:"sort_order"`
	Template  string `json:"template"`
}

Job Group

type JobState added in v0.7.0

type JobState struct {
	BlockedBy int64  `json:"blocked_by_id"`
	Result    string `json:"result"`
	State     string `json:"state"`
}

Special struct for getting quick job status

type JobStatus

type JobStatus struct {
	Type      string      // Type of the update. Currently "job.done" and "job.restarted" are set
	Arch      string      `json:"ARCH"`
	Build     string      `json:"BUILD"`
	Flavor    string      `json:"FLAVOR"`
	Machine   string      `json:"MACHINE"`
	Test      string      `json:"TEST"`
	BugRef    string      `json:"bugref"`
	GroupID   int         `json:"group_id"`
	ID        int64       `json:"id"`
	NewBuild  string      `json:"newbuild"`
	Reason    string      `json:"reason"`
	Remaining int         `json:"remaining"`
	Result    interface{} `json:"result"`
}

JobStatus is the returns struct for job status updates from RabbitMQ

type JobTemplate

type JobTemplate struct {
	GroupName string    `json:"group_name"`
	ID        int       `json:"id"`
	Machine   Machine   `json:"machine"`
	Priority  int       `json:"prio"`
	Product   Product   `json:"product"`
	TestSuite TestSuite `json:"test_suite"`
}

Job Template

type Machine

type Machine struct {
	ID       int               `json:"id"`
	Backend  string            `json:"backend"`
	Name     string            `json:"name"`
	Settings map[string]string `json:"settings"`
}

Machine type

func (*Machine) Equals added in v0.3.2

func (m *Machine) Equals(m2 Machine) bool

type Product

type Product struct {
	Arch     string            `json:"arch"`
	Distri   string            `json:"distri"`
	Flavor   string            `json:"flavor"`
	Group    string            `json:"group"`
	ID       int               `json:"id"`
	Version  string            `json:"version"`
	Settings map[string]string `json:"settings"`
}

Product

type RabbitMQ

type RabbitMQ struct {
	// contains filtered or unexported fields
}

RabbitMQ struct is the object which handles the connection to a RabbitMQ instance

func ConnectRabbitMQ

func ConnectRabbitMQ(remote string) (RabbitMQ, error)

ConnectRabbitMQ connects to a RabbitMQ instance and returns the RabbitMQ object

func (*RabbitMQ) Close

func (mq *RabbitMQ) Close()

Close connection

func (*RabbitMQ) Closed added in v0.5.3

func (mq *RabbitMQ) Closed() bool

Connected returns true if RabbitMQ is closing or if it is closed.

func (*RabbitMQ) Connected added in v0.5.3

func (mq *RabbitMQ) Connected() bool

Connected returns true if RabbitMQ is connected

func (*RabbitMQ) NotifyClose added in v0.5.3

func (mq *RabbitMQ) NotifyClose(callback RabbitMQCloseCallback)

NotifyClose registeres a defined callback function for when the RabbitMQ connection is closed

func (*RabbitMQ) Reconnect added in v0.5.3

func (mq *RabbitMQ) Reconnect() error

Reconnect to the RabbitMQ server. This will close any previous connections and channels

func (*RabbitMQ) Subscribe

func (mq *RabbitMQ) Subscribe(key string) (RabbitMQSubscription, error)

Subscribe to a given key and get the messages via the callback function. This method will return after establishing the channel and call the callback function when a new message arrives This message returns a RabbitMQSubscription object, which in turn can be used to receive the incoming messages

type RabbitMQCloseCallback added in v0.5.3

type RabbitMQCloseCallback func(error)

Callback when the connection was closed

type RabbitMQSubscription

type RabbitMQSubscription struct {
	// contains filtered or unexported fields
}

RabbitMQSubscription handles a single subscription

func (*RabbitMQSubscription) Close

func (sub *RabbitMQSubscription) Close()

Close subscription channel

func (*RabbitMQSubscription) Connected added in v0.5.3

func (sub *RabbitMQSubscription) Connected() bool

Connected returns true if RabbitMQ is connected

func (*RabbitMQSubscription) Receive

func (sub *RabbitMQSubscription) Receive() (amqp.Delivery, error)

Receive receives a raw non-empty RabbitMQ messages

func (*RabbitMQSubscription) ReceiveComment added in v0.4.0

func (sub *RabbitMQSubscription) ReceiveComment() (CommentMQ, error)

ReceiveJobStatus receives the next message and try to parse it as Comment. Use this for job status updates

func (*RabbitMQSubscription) ReceiveJob

func (sub *RabbitMQSubscription) ReceiveJob() (Job, error)

ReceiveJob receives the next message and try to parse it as job

func (*RabbitMQSubscription) ReceiveJobStatus

func (sub *RabbitMQSubscription) ReceiveJobStatus() (JobStatus, error)

ReceiveJobStatus receives the next message and try to parse it as JobStatus. Use this for job status updates

type Settings

type Settings struct {
	Arch    string `json:"ARCH"`
	Backend string `json:"BACKEND"`
	Machine string `json:"MACHINE"`
}

Job Setting struct

type TestSuite

type TestSuite struct {
	ID          int               `json:"id"`
	Name        string            `json:"name"`
	Description string            `json:"description"`
	Settings    map[string]string `json:"settings"`
}

Test Suite

type Worker

type Worker struct {
	Alive      int               `json:"alive"`
	Connected  int               `json:"connected"`
	Error      string            `json:"error"` // Error string if present
	Host       string            `json:"host"`
	ID         int               `json:"id"`
	Instance   int               `json:"instance"`
	Status     string            `json:"status"`
	Websocket  int               `json:"websocket"`
	Properties map[string]string `json:"properties"` // Worker properties as returned by openQA
}

Worker instance

Directories

Path Synopsis
cmd
gopenqa command
* This is a example CLI tool for demonstrating the usage of gopenqa.
* This is a example CLI tool for demonstrating the usage of gopenqa.
examples
list_jobgroups command
rabbitmq command

Jump to

Keyboard shortcuts

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