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