upload/koji: use CGInitBuild and clarify metadata structs
Move to requiring CGInitBuild to be called before CGImport. In the future we could make the former optional again, but for now we want to allow the caller to have done CGInitBuild and for composer only to do the CGImport using the passed in build_id and token. Also rename and document some struct fields in the metadata struct to make them more specific to our use-case and hopefully easier to read. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
e4b839b31f
commit
f446613d4a
6 changed files with 149 additions and 65 deletions
|
|
@ -23,18 +23,19 @@ type Koji struct {
|
|||
transport http.RoundTripper
|
||||
}
|
||||
|
||||
type BuildExtra struct {
|
||||
type ImageBuildExtra struct {
|
||||
Image interface{} `json:"image"` // No extra info tracked at build level.
|
||||
}
|
||||
|
||||
type Build struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Release string `json:"release"`
|
||||
Source string `json:"source"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
Extra BuildExtra `json:"extra"`
|
||||
type ImageBuild struct {
|
||||
BuildID uint64 `json:"build_id"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Release string `json:"release"`
|
||||
Source string `json:"source"`
|
||||
StartTime int64 `json:"start_time"`
|
||||
EndTime int64 `json:"end_time"`
|
||||
Extra ImageBuildExtra `json:"extra"`
|
||||
}
|
||||
|
||||
type Host struct {
|
||||
|
|
@ -43,7 +44,7 @@ type Host struct {
|
|||
}
|
||||
|
||||
type ContentGenerator struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name"` // Must be 'osbuild'.
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
|
|
@ -57,12 +58,12 @@ type Tool struct {
|
|||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type Component struct {
|
||||
type RPM struct {
|
||||
Type string `json:"type"` // must be 'rpm'
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Release string `json:"release"`
|
||||
Epoch *uint64 `json:"epoch"`
|
||||
Epoch *string `json:"epoch,omitempty"`
|
||||
Arch string `json:"arch"`
|
||||
Sigmd5 string `json:"sigmd5"`
|
||||
Signature *string `json:"signature"`
|
||||
|
|
@ -74,35 +75,40 @@ type BuildRoot struct {
|
|||
ContentGenerator ContentGenerator `json:"content_generator"`
|
||||
Container Container `json:"container"`
|
||||
Tools []Tool `json:"tools"`
|
||||
Components []Component `json:"components"`
|
||||
RPMs []RPM `json:"components"`
|
||||
}
|
||||
|
||||
type OutputExtraImageInfo struct {
|
||||
type ImageExtraInfo struct {
|
||||
// TODO: Ideally this is where the pipeline would be passed.
|
||||
Arch string `json:"arch"` // TODO: why?
|
||||
}
|
||||
|
||||
type OutputExtra struct {
|
||||
Image OutputExtraImageInfo `json:"image"`
|
||||
type ImageExtra struct {
|
||||
Info ImageExtraInfo `json:"image"`
|
||||
}
|
||||
|
||||
type Output struct {
|
||||
BuildRootID uint64 `json:"buildroot_id"`
|
||||
Filename string `json:"filename"`
|
||||
FileSize uint64 `json:"filesize"`
|
||||
Arch string `json:"arch"`
|
||||
ChecksumType string `json:"checksum_type"` // must be 'md5'
|
||||
MD5 string `json:"checksum"`
|
||||
Type string `json:"type"`
|
||||
Components []Component `json:"component"`
|
||||
Extra OutputExtra `json:"extra"`
|
||||
type Image struct {
|
||||
BuildRootID uint64 `json:"buildroot_id"`
|
||||
Filename string `json:"filename"`
|
||||
FileSize uint64 `json:"filesize"`
|
||||
Arch string `json:"arch"`
|
||||
ChecksumType string `json:"checksum_type"` // must be 'md5'
|
||||
MD5 string `json:"checksum"`
|
||||
Type string `json:"type"`
|
||||
RPMs []RPM `json:"component"`
|
||||
Extra ImageExtra `json:"extra"`
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
MetadataVersion int `json:"metadata_version"` // must be '0'
|
||||
Build Build `json:"build"`
|
||||
ImageBuild ImageBuild `json:"build"`
|
||||
BuildRoots []BuildRoot `json:"buildroots"`
|
||||
Output []Output `json:"output"`
|
||||
Images []Image `json:"output"`
|
||||
}
|
||||
|
||||
type CGInitBuildResult struct {
|
||||
BuildID int `xmlrpc:"build_id"`
|
||||
Token string `xmlrpc:"token"`
|
||||
}
|
||||
|
||||
type CGImportResult struct {
|
||||
|
|
@ -209,13 +215,36 @@ func (k *Koji) Logout() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CGInitBuild reserves a build ID and initializes a build
|
||||
func (k *Koji) CGInitBuild(taskID *int, name, version, release string) (*CGInitBuildResult, error) {
|
||||
var buildInfo struct {
|
||||
TaskID *int `xmlrpc:"task_id,omitempty"`
|
||||
Name string `xmlrpc:"name"`
|
||||
Version string `xmlrpc:"version"`
|
||||
Release string `xmlrpc:"release"`
|
||||
}
|
||||
|
||||
buildInfo.TaskID = taskID
|
||||
buildInfo.Name = name
|
||||
buildInfo.Version = version
|
||||
buildInfo.Release = release
|
||||
|
||||
var result CGInitBuildResult
|
||||
err := k.xmlrpc.Call("CGInitBuild", []interface{}{"osbuild", buildInfo}, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// CGImport imports previously uploaded content, by specifying its metadata, and the temporary
|
||||
// directory where it is located.
|
||||
func (k *Koji) CGImport(build Build, buildRoots []BuildRoot, output []Output, directory string) (*CGImportResult, error) {
|
||||
func (k *Koji) CGImport(build ImageBuild, buildRoots []BuildRoot, images []Image, directory, token string) (*CGImportResult, error) {
|
||||
m := &Metadata{
|
||||
Build: build,
|
||||
ImageBuild: build,
|
||||
BuildRoots: buildRoots,
|
||||
Output: output,
|
||||
Images: images,
|
||||
}
|
||||
metadata, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
|
|
@ -223,7 +252,7 @@ func (k *Koji) CGImport(build Build, buildRoots []BuildRoot, output []Output, di
|
|||
}
|
||||
|
||||
var result CGImportResult
|
||||
err = k.xmlrpc.Call("CGImport", []interface{}{string(metadata), directory}, &result)
|
||||
err = k.xmlrpc.Call("CGImport", []interface{}{string(metadata), directory, token}, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func TestKojiImport(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Import the build
|
||||
build := koji.Build{
|
||||
build := koji.ImageBuild{
|
||||
Name: buildName,
|
||||
Version: "1",
|
||||
Release: "1",
|
||||
|
|
@ -103,11 +103,11 @@ func TestKojiImport(t *testing.T) {
|
|||
Type: "nspawn",
|
||||
Arch: "noarch",
|
||||
},
|
||||
Tools: []koji.Tool{},
|
||||
Components: []koji.Component{},
|
||||
Tools: []koji.Tool{},
|
||||
RPMs: []koji.RPM{},
|
||||
},
|
||||
}
|
||||
output := []koji.Output{
|
||||
output := []koji.Image{
|
||||
{
|
||||
BuildRootID: 1,
|
||||
Filename: filename,
|
||||
|
|
@ -116,16 +116,21 @@ func TestKojiImport(t *testing.T) {
|
|||
ChecksumType: "md5",
|
||||
MD5: hash,
|
||||
Type: "image",
|
||||
Components: []koji.Component{},
|
||||
Extra: koji.OutputExtra{
|
||||
Image: koji.OutputExtraImageInfo{
|
||||
RPMs: []koji.RPM{},
|
||||
Extra: koji.ImageExtra{
|
||||
Info: koji.ImageExtraInfo{
|
||||
Arch: "noarch",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
result, err := k.CGImport(build, buildRoots, output, uploadDirectory)
|
||||
initResult, err := k.CGInitBuild(nil, build.Name, build.Version, build.Release)
|
||||
require.NoError(t, err)
|
||||
|
||||
build.BuildID = uint64(initResult.BuildID)
|
||||
|
||||
importResult, err := k.CGImport(build, buildRoots, output, uploadDirectory, initResult.Token)
|
||||
require.NoError(t, err)
|
||||
|
||||
// check if the build is really there:
|
||||
|
|
@ -136,7 +141,7 @@ func TestKojiImport(t *testing.T) {
|
|||
"--keytab", credentials.KeyTab,
|
||||
"--principal", credentials.Principal,
|
||||
"list-builds",
|
||||
"--buildid", strconv.Itoa(result.BuildID),
|
||||
"--buildid", strconv.Itoa(importResult.BuildID),
|
||||
)
|
||||
|
||||
// sample output:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue