upload/koji: support refunding reserved build ids
Add support for both cancelling and failing a build. This is tested, but not hooked up, as we need some more architecture work before that makes sense. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
f446613d4a
commit
3457038688
2 changed files with 80 additions and 0 deletions
|
|
@ -238,6 +238,33 @@ func (k *Koji) CGInitBuild(taskID *int, name, version, release string) (*CGInitB
|
|||
return &result, nil
|
||||
}
|
||||
|
||||
/* from `koji/__init__.py`
|
||||
BUILD_STATES = Enum((
|
||||
'BUILDING',
|
||||
'COMPLETE',
|
||||
'DELETED',
|
||||
'FAILED',
|
||||
'CANCELED',
|
||||
))
|
||||
*/
|
||||
const (
|
||||
_ = iota /* BUILDING */
|
||||
_ /* COMPLETED */
|
||||
_ /* DELETED */
|
||||
buildStateFailed
|
||||
buildStateCanceled
|
||||
)
|
||||
|
||||
// CGFailBuild marks an in-progress build as failed
|
||||
func (k *Koji) CGFailBuild(buildID int, token string) error {
|
||||
return k.xmlrpc.Call("CGRefundBuild", []interface{}{"osbuild", buildID, token, buildStateFailed}, nil)
|
||||
}
|
||||
|
||||
// CGCancelBuild marks an in-progress build as cancelled, and
|
||||
func (k *Koji) CGCancelBuild(buildID int, token string) error {
|
||||
return k.xmlrpc.Call("CGRefundBuild", []interface{}{"osbuild", buildID, token, buildStateCanceled}, nil)
|
||||
}
|
||||
|
||||
// CGImport imports previously uploaded content, by specifying its metadata, and the temporary
|
||||
// directory where it is located.
|
||||
func (k *Koji) CGImport(build ImageBuild, buildRoots []BuildRoot, images []Image, directory, token string) (*CGImportResult, error) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,59 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/upload/koji"
|
||||
)
|
||||
|
||||
func TestKojiRefund(t *testing.T) {
|
||||
shareDir := "/tmp/osbuild-composer-koji-test"
|
||||
server := "https://localhost/kojihub"
|
||||
|
||||
// base our transport on the default one
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
|
||||
// use the self-signed certificate generated by run-koji-container
|
||||
certPool := x509.NewCertPool()
|
||||
cert, err := ioutil.ReadFile(shareDir + "/ca-crt.pem")
|
||||
require.NoError(t, err)
|
||||
|
||||
ok := certPool.AppendCertsFromPEM(cert)
|
||||
require.True(t, ok)
|
||||
|
||||
transport.TLSClientConfig = &tls.Config{
|
||||
RootCAs: certPool,
|
||||
}
|
||||
|
||||
// login
|
||||
credentials := &koji.GSSAPICredentials{
|
||||
Principal: "osbuild-krb@LOCAL",
|
||||
KeyTab: shareDir + "/client.keytab",
|
||||
}
|
||||
k, err := koji.NewFromGSSAPI(server, credentials, transport)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer func() {
|
||||
err := k.Logout()
|
||||
if err != nil {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}()
|
||||
|
||||
initResult, err := k.CGInitBuild(nil, "name", "verison", "release")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = k.CGCancelBuild(initResult.BuildID, initResult.Token)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = k.CGCancelBuild(initResult.BuildID, initResult.Token)
|
||||
require.Error(t, err)
|
||||
|
||||
initResult, err = k.CGInitBuild(nil, "name", "verison", "release")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = k.CGFailBuild(initResult.BuildID, initResult.Token)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = k.CGFailBuild(initResult.BuildID, initResult.Token)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestKojiImport(t *testing.T) {
|
||||
// define constants
|
||||
server := "https://localhost/kojihub"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue