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
78eeb763
Commit
78eeb763
authored
Oct 24, 2016
by
Ryan Hitchman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make hack/update_owners.py get list from local repo, add --check option.
parent
85207190
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
60 deletions
+88
-60
update_owners.py
hack/update_owners.py
+45
-9
empty.go
test/e2e/empty.go
+2
-2
apparmor_test.go
test/e2e_node/apparmor_test.go
+41
-49
test_owners.csv
test/test_owners.csv
+0
-0
No files found.
hack/update_owners.py
View file @
78eeb763
...
...
@@ -14,12 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import
argparse
import
collections
import
csv
import
re
import
json
import
os
import
random
import
subprocess
import
sys
import
time
import
urllib2
...
...
@@ -33,6 +35,13 @@ SKIP_MAINTAINERS = {
'a-robinson'
,
'aronchick'
,
'bgrant0607-nocc'
,
'david-mcmahon'
,
'goltermann'
,
'sarahnovotny'
}
def
normalize
(
name
):
name
=
re
.
sub
(
r'\[.*?\]|\{.*?\}'
,
''
,
name
)
name
=
re
.
sub
(
r'\s+'
,
' '
,
name
)
return
name
.
strip
()
def
get_test_history
(
days_ago
):
url
=
time
.
strftime
(
GCS_URL_BASE
+
'logs/
%
Y-
%
m-
%
d.json'
,
time
.
gmtime
(
time
.
time
()
-
days_ago
*
24
*
60
*
60
))
...
...
@@ -43,10 +52,19 @@ def get_test_history(days_ago):
return
json
.
loads
(
content
)
def
normalize
(
name
):
name
=
re
.
sub
(
r'\[.*?\]|\{.*?\}'
,
''
,
name
)
name
=
re
.
sub
(
r'\s+'
,
' '
,
name
)
return
name
.
strip
()
def
get_test_names_from_test_history
():
test_names
=
set
()
for
days_ago
in
range
(
4
):
test_history
=
get_test_history
(
days_ago
)
test_names
.
update
(
normalize
(
name
)
for
name
in
test_history
[
'test_names'
])
return
test_names
def
get_test_names_from_local_files
():
tests_json
=
subprocess
.
check_output
([
'go'
,
'run'
,
'test/list/main.go'
,
'-json'
])
tests
=
json
.
loads
(
tests_json
)
return
{
normalize
(
t
[
'Name'
]
+
(
' '
+
t
[
'TestName'
]
if
'k8s.io/'
not
in
t
[
'Name'
]
else
''
))
for
t
in
tests
}
def
load_owners
(
fname
):
...
...
@@ -98,10 +116,16 @@ def get_maintainers():
def
main
():
test_names
=
set
()
for
days_ago
in
range
(
4
):
test_history
=
get_test_history
(
days_ago
)
test_names
.
update
(
normalize
(
name
)
for
name
in
test_history
[
'test_names'
])
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--history'
,
action
=
'store_true'
,
help
=
'Generate test list from result history.'
)
parser
.
add_argument
(
'--user'
,
help
=
'User to assign new tests to (RANDOM for random assignment).'
)
parser
.
add_argument
(
'--check'
,
action
=
'store_true'
,
help
=
'Exit with a nonzero status if the test list has changed.'
)
options
=
parser
.
parse_args
()
if
options
.
history
:
test_names
=
get_test_names_from_test_history
()
else
:
test_names
=
get_test_names_from_local_files
()
test_names
.
add
(
'DEFAULT'
)
test_names
=
sorted
(
test_names
)
owners
=
load_owners
(
OWNERS_PATH
)
...
...
@@ -115,6 +139,13 @@ def main():
print
'# NEW TESTS (
%
d):'
%
len
(
new_tests
)
print
'
\n
'
.
join
(
new_tests
)
if
options
.
check
:
if
new_tests
or
outdated_tests
:
print
print
'ERROR: the test list has changed'
sys
.
exit
(
1
)
sys
.
exit
(
0
)
for
name
in
outdated_tests
:
owners
.
pop
(
name
)
...
...
@@ -130,7 +161,12 @@ def main():
owner
for
name
,
(
owner
,
random
)
in
owners
.
iteritems
()
if
owner
in
maintainers
)
for
test_name
in
set
(
test_names
)
-
set
(
owners
):
new_owner
,
_count
=
random
.
choice
(
owner_counts
.
most_common
()[
-
4
:])
if
options
.
user
==
'RANDOM'
:
new_owner
,
_count
=
random
.
choice
(
owner_counts
.
most_common
()[
-
4
:])
elif
options
.
user
:
new_owner
=
options
.
user
else
:
raise
AssertionError
(
'--user must be specified for new tests'
)
owner_counts
[
new_owner
]
+=
1
owners
[
test_name
]
=
(
new_owner
,
True
)
...
...
test/e2e/empty.go
View file @
78eeb763
...
...
@@ -24,7 +24,7 @@ import (
.
"github.com/onsi/ginkgo"
)
var
_
=
framework
.
KubeDescribe
(
"[Feature:Empty]"
,
func
()
{
var
_
=
framework
.
KubeDescribe
(
"
Empty
[Feature:Empty]"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"empty"
)
BeforeEach
(
func
()
{
...
...
@@ -39,5 +39,5 @@ var _ = framework.KubeDescribe("[Feature:Empty]", func() {
framework
.
ExpectNoError
(
err
)
})
It
(
"
D
oes nothing"
,
func
()
{})
It
(
"
d
oes nothing"
,
func
()
{})
})
test/e2e_node/apparmor_test.go
View file @
78eeb763
...
...
@@ -38,58 +38,50 @@ import (
var
_
=
framework
.
KubeDescribe
(
"AppArmor [Feature:AppArmor]"
,
func
()
{
if
isAppArmorEnabled
()
{
testAppArmorNode
()
}
else
{
testNonAppArmorNode
()
}
})
func
testAppArmorNode
()
{
BeforeEach
(
func
()
{
By
(
"Loading AppArmor profiles for testing"
)
framework
.
ExpectNoError
(
loadTestProfiles
(),
"Could not load AppArmor test profiles"
)
})
Context
(
"when running with AppArmor"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"apparmor-test"
)
It
(
"should reject an unloaded profile"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileNamePrefix
+
"non-existant-profile"
)
Expect
(
status
.
Phase
)
.
To
(
Equal
(
api
.
PodFailed
),
"PodStatus: %+v"
,
status
)
Expect
(
status
.
Reason
)
.
To
(
Equal
(
"AppArmor"
),
"PodStatus: %+v"
,
status
)
BeforeEach
(
func
()
{
By
(
"Loading AppArmor profiles for testing"
)
framework
.
ExpectNoError
(
loadTestProfiles
(),
"Could not load AppArmor test profiles"
)
})
It
(
"should enforce a profile blocking writes"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileNamePrefix
+
apparmorProfilePrefix
+
"deny-write"
)
if
len
(
status
.
ContainerStatuses
)
==
0
{
framework
.
Failf
(
"Unexpected pod status: %s"
,
spew
.
Sdump
(
status
))
return
}
state
:=
status
.
ContainerStatuses
[
0
]
.
State
.
Terminated
Expect
(
state
.
ExitCode
)
.
To
(
Not
(
BeZero
()),
"ContainerStateTerminated: %+v"
,
state
)
})
It
(
"should enforce a permissive profile"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileNamePrefix
+
apparmorProfilePrefix
+
"audit-write"
)
if
len
(
status
.
ContainerStatuses
)
==
0
{
framework
.
Failf
(
"Unexpected pod status: %s"
,
spew
.
Sdump
(
status
))
return
}
state
:=
status
.
ContainerStatuses
[
0
]
.
State
.
Terminated
Expect
(
state
.
ExitCode
)
.
To
(
BeZero
(),
"ContainerStateTerminated: %+v"
,
state
)
Context
(
"when running with AppArmor"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"apparmor-test"
)
It
(
"should reject an unloaded profile"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileNamePrefix
+
"non-existant-profile"
)
Expect
(
status
.
Phase
)
.
To
(
Equal
(
api
.
PodFailed
),
"PodStatus: %+v"
,
status
)
Expect
(
status
.
Reason
)
.
To
(
Equal
(
"AppArmor"
),
"PodStatus: %+v"
,
status
)
})
It
(
"should enforce a profile blocking writes"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileNamePrefix
+
apparmorProfilePrefix
+
"deny-write"
)
if
len
(
status
.
ContainerStatuses
)
==
0
{
framework
.
Failf
(
"Unexpected pod status: %s"
,
spew
.
Sdump
(
status
))
return
}
state
:=
status
.
ContainerStatuses
[
0
]
.
State
.
Terminated
Expect
(
state
.
ExitCode
)
.
To
(
Not
(
BeZero
()),
"ContainerStateTerminated: %+v"
,
state
)
})
It
(
"should enforce a permissive profile"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileNamePrefix
+
apparmorProfilePrefix
+
"audit-write"
)
if
len
(
status
.
ContainerStatuses
)
==
0
{
framework
.
Failf
(
"Unexpected pod status: %s"
,
spew
.
Sdump
(
status
))
return
}
state
:=
status
.
ContainerStatuses
[
0
]
.
State
.
Terminated
Expect
(
state
.
ExitCode
)
.
To
(
BeZero
(),
"ContainerStateTerminated: %+v"
,
state
)
})
})
})
}
func
testNonAppArmorNode
()
{
Context
(
"when running without AppArmor"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"apparmor-test"
)
It
(
"should reject a pod with an AppArmor profile"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileRuntimeDefault
)
Expect
(
status
.
Phase
)
.
To
(
Equal
(
api
.
PodFailed
),
"PodStatus: %+v"
,
status
)
Expect
(
status
.
Reason
)
.
To
(
Equal
(
"AppArmor"
),
"PodStatus: %+v"
,
status
)
}
else
{
Context
(
"when running without AppArmor"
,
func
()
{
f
:=
framework
.
NewDefaultFramework
(
"apparmor-test"
)
It
(
"should reject a pod with an AppArmor profile"
,
func
()
{
status
:=
runAppArmorTest
(
f
,
apparmor
.
ProfileRuntimeDefault
)
Expect
(
status
.
Phase
)
.
To
(
Equal
(
api
.
PodFailed
),
"PodStatus: %+v"
,
status
)
Expect
(
status
.
Reason
)
.
To
(
Equal
(
"AppArmor"
),
"PodStatus: %+v"
,
status
)
})
})
}
)
}
}
}
)
const
apparmorProfilePrefix
=
"e2e-node-apparmor-test-"
const
testProfiles
=
`
...
...
test/test_owners.csv
View file @
78eeb763
This diff is collapsed.
Click to expand it.
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