Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
dacec687
Commit
dacec687
authored
Nov 12, 2016
by
Lucas Käldström
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a reporter to the system verification check
parent
35094195
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
96 additions
and
51 deletions
+96
-51
e2e_node_suite_test.go
test/e2e_node/e2e_node_suite_test.go
+1
-1
BUILD
test/e2e_node/system/BUILD
+1
-1
cgroup_validator.go
test/e2e_node/system/cgroup_validator.go
+5
-3
cgroup_validator_test.go
test/e2e_node/system/cgroup_validator_test.go
+3
-1
docker_validator.go
test/e2e_node/system/docker_validator.go
+9
-7
docker_validator_test.go
test/e2e_node/system/docker_validator_test.go
+3
-1
kernel_validator.go
test/e2e_node/system/kernel_validator.go
+8
-7
kernel_validator_test.go
test/e2e_node/system/kernel_validator_test.go
+9
-3
os_validator.go
test/e2e_node/system/os_validator.go
+10
-8
os_validator_test.go
test/e2e_node/system/os_validator_test.go
+3
-1
report.go
test/e2e_node/system/report.go
+26
-10
validators.go
test/e2e_node/system/validators.go
+18
-8
No files found.
test/e2e_node/e2e_node_suite_test.go
View file @
dacec687
...
...
@@ -93,7 +93,7 @@ func TestE2eNode(t *testing.T) {
glog
.
Exitf
(
"chroot %q failed: %v"
,
rootfs
,
err
)
}
}
if
err
:=
system
.
Validate
();
err
!=
nil
{
if
err
:=
system
.
Validate
Default
();
err
!=
nil
{
glog
.
Exitf
(
"system validation failed: %v"
,
err
)
}
return
...
...
test/e2e_node/system/BUILD
View file @
dacec687
...
...
@@ -17,8 +17,8 @@ go_library(
"docker_validator.go",
"kernel_validator.go",
"os_validator.go",
"report.go",
"types.go",
"util.go",
"validators.go",
],
tags = ["automanaged"],
...
...
test/e2e_node/system/cgroup_validator.go
View file @
dacec687
...
...
@@ -25,7 +25,9 @@ import (
var
_
Validator
=
&
CgroupsValidator
{}
type
CgroupsValidator
struct
{}
type
CgroupsValidator
struct
{
Reporter
Reporter
}
func
(
c
*
CgroupsValidator
)
Name
()
string
{
return
"cgroups"
...
...
@@ -55,9 +57,9 @@ func (c *CgroupsValidator) validateCgroupSubsystems(cgroupSpec, subsystems []str
}
item
:=
cgroupsConfigPrefix
+
strings
.
ToUpper
(
cgroup
)
if
found
{
r
eport
(
item
,
"enabled"
,
good
)
c
.
Reporter
.
R
eport
(
item
,
"enabled"
,
good
)
}
else
{
r
eport
(
item
,
"missing"
,
bad
)
c
.
Reporter
.
R
eport
(
item
,
"missing"
,
bad
)
missing
=
append
(
missing
,
cgroup
)
}
}
...
...
test/e2e_node/system/cgroup_validator_test.go
View file @
dacec687
...
...
@@ -23,7 +23,9 @@ import (
)
func
TestValidateCgroupSubsystem
(
t
*
testing
.
T
)
{
v
:=
&
CgroupsValidator
{}
v
:=
&
CgroupsValidator
{
Reporter
:
DefaultReporter
,
}
cgroupSpec
:=
[]
string
{
"system1"
,
"system2"
}
for
desc
,
test
:=
range
map
[
string
]
struct
{
cgroupSpec
[]
string
...
...
test/e2e_node/system/docker_validator.go
View file @
dacec687
...
...
@@ -28,7 +28,9 @@ import (
var
_
Validator
=
&
DockerValidator
{}
// DockerValidator validates docker configuration.
type
DockerValidator
struct
{}
type
DockerValidator
struct
{
Reporter
Reporter
}
func
(
d
*
DockerValidator
)
Name
()
string
{
return
"docker"
...
...
@@ -63,22 +65,22 @@ func (d *DockerValidator) validateDockerInfo(spec *DockerSpec, info types.Info)
for
_
,
v
:=
range
spec
.
Version
{
r
:=
regexp
.
MustCompile
(
v
)
if
r
.
MatchString
(
info
.
ServerVersion
)
{
r
eport
(
dockerConfigPrefix
+
"VERSION"
,
info
.
ServerVersion
,
good
)
d
.
Reporter
.
R
eport
(
dockerConfigPrefix
+
"VERSION"
,
info
.
ServerVersion
,
good
)
matched
=
true
}
}
if
!
matched
{
r
eport
(
dockerConfigPrefix
+
"VERSION"
,
info
.
ServerVersion
,
bad
)
d
.
Reporter
.
R
eport
(
dockerConfigPrefix
+
"VERSION"
,
info
.
ServerVersion
,
bad
)
return
fmt
.
Errorf
(
"unsupported docker version: %s"
,
info
.
ServerVersion
)
}
// Validate graph driver.
item
:=
dockerConfigPrefix
+
"GRAPH_DRIVER"
for
_
,
d
:=
range
spec
.
GraphDriver
{
if
info
.
Driver
==
d
{
r
eport
(
item
,
info
.
Driver
,
good
)
for
_
,
g
d
:=
range
spec
.
GraphDriver
{
if
info
.
Driver
==
g
d
{
d
.
Reporter
.
R
eport
(
item
,
info
.
Driver
,
good
)
return
nil
}
}
r
eport
(
item
,
info
.
Driver
,
bad
)
d
.
Reporter
.
R
eport
(
item
,
info
.
Driver
,
bad
)
return
fmt
.
Errorf
(
"unsupported graph driver: %s"
,
info
.
Driver
)
}
test/e2e_node/system/docker_validator_test.go
View file @
dacec687
...
...
@@ -24,7 +24,9 @@ import (
)
func
TestValidateDockerInfo
(
t
*
testing
.
T
)
{
v
:=
&
DockerValidator
{}
v
:=
&
DockerValidator
{
Reporter
:
DefaultReporter
,
}
spec
:=
&
DockerSpec
{
Version
:
[]
string
{
`1\.(9|\d{2,})\..*`
},
GraphDriver
:
[]
string
{
"driver_1"
,
"driver_2"
},
...
...
test/e2e_node/system/kernel_validator.go
View file @
dacec687
...
...
@@ -39,6 +39,7 @@ var _ Validator = &KernelValidator{}
// and kernel configuration.
type
KernelValidator
struct
{
kernelRelease
string
Reporter
Reporter
}
func
(
k
*
KernelValidator
)
Name
()
string
{
...
...
@@ -60,11 +61,11 @@ const (
)
func
(
k
*
KernelValidator
)
Validate
(
spec
SysSpec
)
error
{
out
,
err
:=
exec
.
Command
(
"uname"
,
"-r"
)
.
CombinedOutput
()
release
,
err
:=
exec
.
Command
(
"uname"
,
"-r"
)
.
CombinedOutput
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get kernel release: %v"
,
err
)
}
k
.
kernelRelease
=
strings
.
TrimSpace
(
string
(
out
))
k
.
kernelRelease
=
strings
.
TrimSpace
(
string
(
release
))
var
errs
[]
error
errs
=
append
(
errs
,
k
.
validateKernelVersion
(
spec
.
KernelSpec
))
errs
=
append
(
errs
,
k
.
validateKernelConfig
(
spec
.
KernelSpec
))
...
...
@@ -78,11 +79,11 @@ func (k *KernelValidator) validateKernelVersion(kSpec KernelSpec) error {
for
_
,
versionRegexp
:=
range
versionRegexps
{
r
:=
regexp
.
MustCompile
(
versionRegexp
)
if
r
.
MatchString
(
k
.
kernelRelease
)
{
r
eport
(
"KERNEL_VERSION"
,
k
.
kernelRelease
,
good
)
k
.
Reporter
.
R
eport
(
"KERNEL_VERSION"
,
k
.
kernelRelease
,
good
)
return
nil
}
}
r
eport
(
"KERNEL_VERSION"
,
k
.
kernelRelease
,
bad
)
k
.
Reporter
.
R
eport
(
"KERNEL_VERSION"
,
k
.
kernelRelease
,
bad
)
return
fmt
.
Errorf
(
"unsupported kernel release: %s"
,
k
.
kernelRelease
)
}
...
...
@@ -101,7 +102,7 @@ func (k *KernelValidator) validateCachedKernelConfig(allConfig map[string]kConfi
badConfigs
:=
[]
string
{}
// reportAndRecord is a helper function to record bad config when
// report.
reportAndRecord
:=
func
(
name
,
msg
,
desc
string
,
result
r
esultType
)
{
reportAndRecord
:=
func
(
name
,
msg
,
desc
string
,
result
ValidationR
esultType
)
{
if
result
==
bad
{
badConfigs
=
append
(
badConfigs
,
name
)
}
...
...
@@ -109,7 +110,7 @@ func (k *KernelValidator) validateCachedKernelConfig(allConfig map[string]kConfi
if
result
!=
good
&&
desc
!=
""
{
msg
=
msg
+
" - "
+
desc
}
r
eport
(
name
,
msg
,
result
)
k
.
Reporter
.
R
eport
(
name
,
msg
,
result
)
}
const
(
required
=
iota
...
...
@@ -117,7 +118,7 @@ func (k *KernelValidator) validateCachedKernelConfig(allConfig map[string]kConfi
forbidden
)
validateOpt
:=
func
(
config
KernelConfig
,
expect
int
)
{
var
found
,
missing
r
esultType
var
found
,
missing
ValidationR
esultType
switch
expect
{
case
required
:
found
,
missing
=
good
,
bad
...
...
test/e2e_node/system/kernel_validator_test.go
View file @
dacec687
...
...
@@ -24,7 +24,9 @@ import (
)
func
TestValidateKernelVersion
(
t
*
testing
.
T
)
{
v
:=
&
KernelValidator
{}
v
:=
&
KernelValidator
{
Reporter
:
DefaultReporter
,
}
// Currently, testRegex is align with DefaultSysSpec.KernelVersion, but in the future
// they may be different.
// This is fine, because the test mainly tests the kernel version validation logic,
...
...
@@ -69,7 +71,9 @@ func TestValidateKernelVersion(t *testing.T) {
}
func
TestValidateCachedKernelConfig
(
t
*
testing
.
T
)
{
v
:=
&
KernelValidator
{}
v
:=
&
KernelValidator
{
Reporter
:
DefaultReporter
,
}
testKernelSpec
:=
KernelSpec
{
Required
:
[]
KernelConfig
{{
Name
:
"REQUIRED_1"
},
{
Name
:
"REQUIRED_2"
,
Aliases
:
[]
string
{
"ALIASE_REQUIRED_2"
}}},
Optional
:
[]
KernelConfig
{{
Name
:
"OPTIONAL_1"
},
{
Name
:
"OPTIONAL_2"
}},
...
...
@@ -184,7 +188,9 @@ CONFIG_3=n`
"CONFIG_2"
:
asModule
,
"CONFIG_3"
:
leftOut
,
}
v
:=
&
KernelValidator
{}
v
:=
&
KernelValidator
{
Reporter
:
DefaultReporter
,
}
got
,
err
:=
v
.
parseKernelConfig
(
bytes
.
NewReader
([]
byte
(
config
)))
assert
.
Nil
(
t
,
err
,
"Expect error not to occur when parse kernel configuration %q"
,
config
)
assert
.
Equal
(
t
,
expected
,
got
)
...
...
test/e2e_node/system/os_validator.go
View file @
dacec687
...
...
@@ -24,25 +24,27 @@ import (
var
_
Validator
=
&
OSValidator
{}
type
OSValidator
struct
{}
type
OSValidator
struct
{
Reporter
Reporter
}
func
(
c
*
OSValidator
)
Name
()
string
{
func
(
o
*
OSValidator
)
Name
()
string
{
return
"os"
}
func
(
c
*
OSValidator
)
Validate
(
spec
SysSpec
)
error
{
o
ut
,
err
:=
exec
.
Command
(
"uname"
)
.
CombinedOutput
()
func
(
o
*
OSValidator
)
Validate
(
spec
SysSpec
)
error
{
o
s
,
err
:=
exec
.
Command
(
"uname"
)
.
CombinedOutput
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get os name: %v"
,
err
)
}
return
c
.
validateOS
(
strings
.
TrimSpace
(
string
(
out
)),
spec
.
OS
)
return
o
.
validateOS
(
strings
.
TrimSpace
(
string
(
os
)),
spec
.
OS
)
}
func
(
c
*
OSValidator
)
validateOS
(
os
,
specOS
string
)
error
{
func
(
o
*
OSValidator
)
validateOS
(
os
,
specOS
string
)
error
{
if
os
!=
specOS
{
r
eport
(
"OS"
,
os
,
bad
)
o
.
Reporter
.
R
eport
(
"OS"
,
os
,
bad
)
return
fmt
.
Errorf
(
"unsupported operating system: %s"
,
os
)
}
r
eport
(
"OS"
,
os
,
good
)
o
.
Reporter
.
R
eport
(
"OS"
,
os
,
good
)
return
nil
}
test/e2e_node/system/os_validator_test.go
View file @
dacec687
...
...
@@ -23,7 +23,9 @@ import (
)
func
TestValidateOS
(
t
*
testing
.
T
)
{
v
:=
&
OSValidator
{}
v
:=
&
OSValidator
{
Reporter
:
DefaultReporter
,
}
specOS
:=
"Linux"
for
_
,
test
:=
range
[]
struct
{
os
string
...
...
test/e2e_node/system/
util
.go
→
test/e2e_node/system/
report
.go
View file @
dacec687
...
...
@@ -18,20 +18,22 @@ package system
import
(
"fmt"
"io"
"os"
)
//
r
esultType is type of the validation result. Different validation results
//
ValidationR
esultType is type of the validation result. Different validation results
// corresponds to different colors.
type
resultType
int
type
ValidationResultType
int32
const
(
good
r
esultType
=
iota
good
ValidationR
esultType
=
iota
bad
warn
)
// color is the color of the message.
type
color
int
type
color
int
32
const
(
red
color
=
31
...
...
@@ -40,15 +42,19 @@ const (
white
=
37
)
func
wrap
(
s
string
,
c
color
)
string
{
func
colorize
(
s
string
,
c
color
)
string
{
return
fmt
.
Sprintf
(
"
\0
33[0;%dm%s
\0
33[0m"
,
c
,
s
)
}
// report reports "item: r". item is white, and the color of r depends on the
// result type.
func
report
(
item
,
r
string
,
t
resultType
)
{
// The default reporter for the system verification test
type
StreamReporter
struct
{
// The stream that this reporter is writing to
WriteStream
io
.
Writer
}
func
(
dr
*
StreamReporter
)
Report
(
key
,
value
string
,
resultType
ValidationResultType
)
error
{
var
c
color
switch
t
{
switch
resultType
{
case
good
:
c
=
green
case
bad
:
...
...
@@ -58,5 +64,15 @@ func report(item, r string, t resultType) {
default
:
c
=
white
}
fmt
.
Printf
(
"%s: %s
\n
"
,
wrap
(
item
,
white
),
wrap
(
r
,
c
))
if
dr
.
WriteStream
==
nil
{
return
fmt
.
Errorf
(
"WriteStream has to be defined for this reporter"
)
}
fmt
.
Fprintf
(
dr
.
WriteStream
,
"%s: %s
\n
"
,
colorize
(
key
,
white
),
colorize
(
value
,
c
))
return
nil
}
// DefaultReporter is the default Reporter
var
DefaultReporter
=
&
StreamReporter
{
WriteStream
:
os
.
Stdout
,
}
test/e2e_node/system/validators.go
View file @
dacec687
...
...
@@ -29,21 +29,31 @@ type Validator interface {
Validate
(
SysSpec
)
error
}
// validators are all the validators.
var
validators
=
[]
Validator
{
&
OSValidator
{},
&
KernelValidator
{},
&
CgroupsValidator
{},
&
DockerValidator
{},
// Reporter is the interface for the reporters for the validators.
type
Reporter
interface
{
// Report reports the results of the system verification
Report
(
string
,
string
,
ValidationResultType
)
error
}
// Validate uses all validators to validate the system.
func
Validate
()
error
{
func
Validate
(
spec
SysSpec
,
report
Reporter
)
error
{
var
errs
[]
error
spec
:=
DefaultSysSpec
// validators are all the validators.
var
validators
=
[]
Validator
{
&
OSValidator
{
Reporter
:
report
},
&
KernelValidator
{
Reporter
:
report
},
&
CgroupsValidator
{
Reporter
:
report
},
&
DockerValidator
{
Reporter
:
report
},
}
for
_
,
v
:=
range
validators
{
glog
.
Infof
(
"Validating %s..."
,
v
.
Name
())
errs
=
append
(
errs
,
v
.
Validate
(
spec
))
}
return
errors
.
NewAggregate
(
errs
)
}
// ValidateDefault uses all default validators to validate the system and writes to stdout.
func
ValidateDefault
()
error
{
return
Validate
(
DefaultSysSpec
,
DefaultReporter
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment