feat: add release to debian kernel
This commit is contained in:
parent
4fca6b07e1
commit
b6bc9b36c5
@ -13,6 +13,7 @@ import (
|
||||
"code.dumpstack.io/tools/out-of-tree/cache"
|
||||
"code.dumpstack.io/tools/out-of-tree/config"
|
||||
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot"
|
||||
"code.dumpstack.io/tools/out-of-tree/distro/debian/snapshot/metasnap"
|
||||
"code.dumpstack.io/tools/out-of-tree/fs"
|
||||
)
|
||||
|
||||
@ -38,6 +39,8 @@ type DebianKernel struct {
|
||||
Invalid bool
|
||||
LastFetch time.Time
|
||||
}
|
||||
|
||||
Release Release
|
||||
}
|
||||
|
||||
func (dk DebianKernel) HasDependency(pkgname string) bool {
|
||||
@ -70,6 +73,10 @@ var (
|
||||
)
|
||||
|
||||
func getDebianKernel(version string) (dk DebianKernel, err error) {
|
||||
flog := log.With().
|
||||
Str("version", version).
|
||||
Logger()
|
||||
|
||||
dk.Version.Package = version
|
||||
|
||||
regex := `^(linux-(image|headers)-[a-z+~0-9\.\-]*-(common|amd64|amd64-unsigned)|linux-kbuild-.*|linux-compiler-.*-x86)$`
|
||||
@ -118,6 +125,30 @@ func getDebianKernel(version string) (dk DebianKernel, err error) {
|
||||
s := strings.Replace(dk.Image.Name, "linux-image-", "", -1)
|
||||
dk.Version.ABI = strings.Replace(s, "-amd64", "", -1)
|
||||
|
||||
p := dk.Image
|
||||
repos, err := metasnap.GetRepos(p.Repo.Archive, p.Name, p.Arch, version)
|
||||
if err != nil {
|
||||
err = nil
|
||||
flog.Debug().Err(err).Msg("ignore metasnap")
|
||||
}
|
||||
for _, repo := range repos {
|
||||
for _, release := range ReleaseStrings[1:] {
|
||||
if strings.Contains(repo.Suite, release) {
|
||||
dk.Release = ReleaseFromString(release)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if dk.Release != None {
|
||||
break
|
||||
}
|
||||
}
|
||||
if dk.Release == None {
|
||||
flog.Warn().Msg("release not found")
|
||||
} else {
|
||||
flog.Debug().Msgf("release is %s", dk.Release.Name())
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,9 @@ import (
|
||||
const apiURL = "http://metasnap.debian.net/cgi-bin/api?"
|
||||
|
||||
var (
|
||||
limiterTimeout time.Duration = time.Second
|
||||
limiterBurst int = 3
|
||||
limiterTimeout time.Duration = time.Second / 20
|
||||
limiterBurst int = 3
|
||||
limiterUpdateDelay time.Duration = time.Second * 10
|
||||
|
||||
Limiter = rate.NewLimiter(rate.Every(limiterTimeout), limiterBurst)
|
||||
)
|
||||
@ -28,7 +29,11 @@ var (
|
||||
func lowerLimit() {
|
||||
limiterTimeout = limiterTimeout * 2
|
||||
log.Info().Msgf("limiter timeout set to %v", limiterTimeout)
|
||||
Limiter.SetLimit(rate.Every(limiterTimeout))
|
||||
Limiter.SetLimitAt(
|
||||
time.Now().Add(limiterUpdateDelay),
|
||||
rate.Every(limiterTimeout),
|
||||
)
|
||||
time.Sleep(limiterUpdateDelay)
|
||||
}
|
||||
|
||||
// Retries in case of 5xx errors
|
||||
@ -100,9 +105,9 @@ type Repo struct {
|
||||
Snapshot Snapshot
|
||||
}
|
||||
|
||||
func GetRepo(archive, pkg, arch, ver string) (repos []Repo, err error) {
|
||||
result, err := queryAPIf("archive=%s&pkg=%s&arch=%s&ver=%s",
|
||||
archive, pkg, arch, ver)
|
||||
func GetRepos(archive, pkg, arch, ver string) (repos []Repo, err error) {
|
||||
result, err := queryAPIf("archive=%s&pkg=%s&arch=%s",
|
||||
archive, pkg, arch)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
@ -119,22 +124,24 @@ func GetRepo(archive, pkg, arch, ver string) (repos []Repo, err error) {
|
||||
}
|
||||
|
||||
fields := strings.Split(line, " ")
|
||||
if len(fields) != 4 {
|
||||
if len(fields) != 5 {
|
||||
err = fmt.Errorf("metasnap api returned %s", result)
|
||||
return
|
||||
}
|
||||
|
||||
repo := Repo{
|
||||
Archive: archive,
|
||||
Suite: fields[0],
|
||||
Component: fields[1],
|
||||
Suite: fields[1],
|
||||
Component: fields[2],
|
||||
Snapshot: Snapshot{
|
||||
First: fields[2],
|
||||
Last: fields[3],
|
||||
First: fields[3],
|
||||
Last: fields[4],
|
||||
},
|
||||
}
|
||||
|
||||
repos = append(repos, repo)
|
||||
if fields[0] == ver {
|
||||
repos = append(repos, repo)
|
||||
}
|
||||
}
|
||||
|
||||
if len(repos) == 0 {
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func TestGetRepo(t *testing.T) {
|
||||
func TestGetRepos(t *testing.T) {
|
||||
// existing
|
||||
infos, err := GetRepo("debian", "linux-image-3.8-trunk-amd64",
|
||||
infos, err := GetRepos("debian", "linux-image-3.8-trunk-amd64",
|
||||
"amd64", "3.8.2-1~experimental.1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -17,7 +17,7 @@ func TestGetRepo(t *testing.T) {
|
||||
t.Log(spew.Sdump(infos))
|
||||
|
||||
// non-existing
|
||||
infos, err = GetRepo("debian", "meh", "amd64", "meh")
|
||||
infos, err = GetRepos("debian", "meh", "amd64", "meh")
|
||||
if err == nil {
|
||||
t.Fatalf("should not be ok, result: %s", spew.Sdump(infos))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user