Update osrelease and redhatrelease detectors to detect Oracle Linux as well.

This commit is contained in:
Avi Miller 2016-12-20 10:53:30 +11:00
parent 8e1fe0d01f
commit 5eb57fee37
3 changed files with 23 additions and 3 deletions

View File

@ -85,5 +85,5 @@ func (detector *OsReleaseNamespaceDetector) GetRequiredFiles() []string {
// getExcludeFiles returns the list of files that are ought to exclude this detector from Detect()
func (detector *OsReleaseNamespaceDetector) getExcludeFiles() []string {
return []string{"etc/redhat-release", "usr/lib/centos-release"}
return []string{"etc/oracle-release", "etc/redhat-release", "usr/lib/centos-release"}
}

View File

@ -26,17 +26,19 @@ import (
var (
log = capnslog.NewPackageLogger("github.com/coreos/clair", "worker/detectors/namespace/redhatrelease")
oracleReleaseRegexp = regexp.MustCompile(`(?P<os>[^\s]*) (Linux Server release) (?P<version>[\d]+)`)
centosReleaseRegexp = regexp.MustCompile(`(?P<os>[^\s]*) (Linux release|release) (?P<version>[\d]+)`)
redhatReleaseRegexp = regexp.MustCompile(`(?P<os>Red Hat Enterprise Linux) (Client release|Server release|Workstation release) (?P<version>[\d]+)`)
)
// RedhatReleaseNamespaceDetector implements NamespaceDetector and detects the OS from the
// /etc/centos-release, /etc/redhat-release and /etc/system-release files.
// /etc/oracle-release, /etc/centos-release, /etc/redhat-release and /etc/system-release files.
//
// Typically for CentOS and Red-Hat like systems
// eg. CentOS release 5.11 (Final)
// eg. CentOS release 6.6 (Final)
// eg. CentOS Linux release 7.1.1503 (Core)
// eg. Oracle Linux Server release 7.3
// eg. Red Hat Enterprise Linux Server release 7.2 (Maipo)
type RedhatReleaseNamespaceDetector struct{}
@ -53,6 +55,12 @@ func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *
var r []string
// try for Oracle Linux
r = oracleReleaseRegexp.FindStringSubmatch(string(f))
if len(r) == 4 {
return &database.Namespace{Name: strings.ToLower(r[1]) + ":" + r[3]}
}
// try for RHEL
r = redhatReleaseRegexp.FindStringSubmatch(string(f))
if len(r) == 4 {
@ -73,5 +81,5 @@ func (detector *RedhatReleaseNamespaceDetector) Detect(data map[string][]byte) *
// GetRequiredFiles returns the list of files that are required for Detect()
func (detector *RedhatReleaseNamespaceDetector) GetRequiredFiles() []string {
return []string{"etc/centos-release", "etc/redhat-release", "etc/system-release"}
return []string{"etc/oracle-release", "etc/centos-release", "etc/redhat-release", "etc/system-release"}
}

View File

@ -23,6 +23,18 @@ import (
func TestRedhatReleaseNamespaceDetector(t *testing.T) {
testData := []namespace.TestData{
{
ExpectedNamespace: &database.Namespace{Name: "oracle:6"},
Data: map[string][]byte{
"etc/oracle-release": []byte(`Oracle Linux Server release 6.8`),
},
},
{
ExpectedNamespace: &database.Namespace{Name: "oracle:7"},
Data: map[string][]byte{
"etc/oracle-release": []byte(`Oracle Linux Server release 7.2`),
},
},
{
ExpectedNamespace: &database.Namespace{Name: "centos:6"},
Data: map[string][]byte{