worker: ns detectors now support VersionFormat

This also filters unknown namespaces from the generic lsb-release and
osrelease detectors.
This commit is contained in:
Jimmy Zelinskie 2017-01-03 13:15:46 -05:00
parent 9e39a26f26
commit 8bedd0a367
6 changed files with 53 additions and 7 deletions

View File

@ -48,7 +48,10 @@ func (d *detector) Detect(data map[string][]byte) *database.Namespace {
match := versionRegexp.FindStringSubmatch(line)
if len(match) > 0 {
versionNumbers := strings.Split(match[0], ".")
return &database.Namespace{Name: osName + ":" + "v" + versionNumbers[0] + "." + versionNumbers[1]}
return &database.Namespace{
Name: osName + ":" + "v" + versionNumbers[0] + "." + versionNumbers[1],
VersionFormat: "dpkg",
}
}
}
}

View File

@ -75,7 +75,10 @@ func (detector *AptSourcesNamespaceDetector) Detect(data map[string][]byte) *dat
}
if OS != "" && version != "" {
return &database.Namespace{Name: OS + ":" + version}
return &database.Namespace{
Name: OS + ":" + version,
VersionFormat: "dpkg",
}
}
return nil
}

View File

@ -69,8 +69,22 @@ func (detector *LsbReleaseNamespaceDetector) Detect(data map[string][]byte) *dat
}
}
// Determine the VersionFormat.
var versionFormat string
switch OS {
case "debian", "ubuntu":
versionFormat = "dpkg"
case "centos", "rhel", "fedora", "amzn", "ol", "oracle":
versionFormat = "rpm"
default:
return nil
}
if OS != "" && version != "" {
return &database.Namespace{Name: OS + ":" + version}
return &database.Namespace{
Name: OS + ":" + version,
VersionFormat: versionFormat,
}
}
return nil
}

View File

@ -72,8 +72,22 @@ func (detector *OsReleaseNamespaceDetector) Detect(data map[string][]byte) *data
}
}
// Determine the VersionFormat.
var versionFormat string
switch OS {
case "debian", "ubuntu":
versionFormat = "dpkg"
case "centos", "rhel", "fedora", "amzn", "ol", "oracle":
versionFormat = "rpm"
default:
return nil
}
if OS != "" && version != "" {
return &database.Namespace{Name: OS + ":" + version}
return &database.Namespace{
Name: OS + ":" + version,
VersionFormat: versionFormat,
}
}
return nil
}

View File

@ -58,20 +58,29 @@ func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *
// try for Oracle Linux
r = oracleReleaseRegexp.FindStringSubmatch(string(f))
if len(r) == 4 {
return &database.Namespace{Name: strings.ToLower(r[1]) + ":" + r[3]}
return &database.Namespace{
Name: strings.ToLower(r[1]) + ":" + r[3],
VersionFormat: "rpm",
}
}
// try for RHEL
r = redhatReleaseRegexp.FindStringSubmatch(string(f))
if len(r) == 4 {
// TODO(vbatts) this is a hack until https://github.com/coreos/clair/pull/193
return &database.Namespace{Name: "centos" + ":" + r[3]}
return &database.Namespace{
Name: "centos" + ":" + r[3],
VersionFormat: "rpm",
}
}
// then try centos first
r = centosReleaseRegexp.FindStringSubmatch(string(f))
if len(r) == 4 {
return &database.Namespace{Name: strings.ToLower(r[1]) + ":" + r[3]}
return &database.Namespace{
Name: strings.ToLower(r[1]) + ":" + r[3],
VersionFormat: "rpm",
}
}
}

View File

@ -89,6 +89,7 @@ func TestProcessWithDistUpgrade(t *testing.T) {
for _, nufv := range nonUpgradedFeatureVersions {
nufv.Feature.Namespace.Name = "debian:7"
nufv.Feature.Namespace.VersionFormat = "dpkg"
assert.Contains(t, wheezy.Features, nufv)
}
}
@ -101,10 +102,12 @@ func TestProcessWithDistUpgrade(t *testing.T) {
for _, nufv := range nonUpgradedFeatureVersions {
nufv.Feature.Namespace.Name = "debian:7"
nufv.Feature.Namespace.VersionFormat = "dpkg"
assert.Contains(t, jessie.Features, nufv)
}
for _, nufv := range nonUpgradedFeatureVersions {
nufv.Feature.Namespace.Name = "debian:8"
nufv.Feature.Namespace.VersionFormat = "dpkg"
assert.NotContains(t, jessie.Features, nufv)
}
}