debian-forge-composer/internal/mocks/rpmmd/fixtures.go
Brian C. Lane aca748bc14 Don't Panic in getComposeStatus and skip invalid jobs in fsjobqueue New
This handles corrupt job json files by skipping them. They still exist,
and errors are logged, but the system keeps working.

If one or more of the json files in /var/lib/osbuild-composer/jobs/
becomes corrupt they can stop the osbuild-composer service from
starting, or stop commands like 'composer-cli compose status' from
working because they quit on the first error and miss any job that
aren't broken.
2023-11-20 13:34:40 +01:00

86 lines
1.8 KiB
Go

package rpmmd_mock
import (
"os"
"path"
"github.com/osbuild/osbuild-composer/internal/jobqueue/fsjobqueue"
dnfjson_mock "github.com/osbuild/osbuild-composer/internal/mocks/dnfjson"
"github.com/osbuild/osbuild-composer/internal/store"
"github.com/osbuild/osbuild-composer/internal/worker"
)
type FixtureGenerator func(tmpdir string) Fixture
func createBaseWorkersFixture(tmpdir string) *worker.Server {
q, err := fsjobqueue.New(tmpdir)
if err != nil {
panic(err)
}
return worker.NewServer(nil, q, worker.Config{BasePath: "/api/worker/v1"})
}
func BaseFixture(tmpdir string) Fixture {
return Fixture{
store.FixtureBase(),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.Base,
}
}
func NoComposesFixture(tmpdir string) Fixture {
return Fixture{
store.FixtureEmpty(),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.Base,
}
}
func NonExistingPackage(tmpdir string) Fixture {
return Fixture{
store.FixtureBase(),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.NonExistingPackage,
}
}
func BadDepsolve(tmpdir string) Fixture {
return Fixture{
store.FixtureBase(),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.BadDepsolve,
}
}
func BadFetch(tmpdir string) Fixture {
return Fixture{
store.FixtureBase(),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.BadFetch,
}
}
func OldChangesFixture(tmpdir string) Fixture {
return Fixture{
store.FixtureOldChanges(),
createBaseWorkersFixture(tmpdir),
dnfjson_mock.Base,
}
}
func BadJobJSONFixture(tmpdir string) Fixture {
err := os.Mkdir(path.Join(tmpdir, "/jobs"), 0755)
if err != nil {
panic(err)
}
err = os.WriteFile(path.Join(tmpdir, "/jobs/30000000-0000-0000-0000-000000000005.json"), []byte("{invalid json content"), 0600)
if err != nil {
panic(err)
}
return Fixture{
store.FixtureJobs(),
createBaseWorkersFixture(path.Join(tmpdir, "/jobs")),
dnfjson_mock.Base,
}
}