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
5979655d
Commit
5979655d
authored
Oct 06, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14949 from brendandburns/flakes10
Auto commit by PR queue bot
parents
1ac70eca
2afddde0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
28 deletions
+101
-28
exec_test.go
pkg/kubelet/network/exec/exec_test.go
+101
-28
No files found.
pkg/kubelet/network/exec/exec_test.go
View file @
5979655d
...
@@ -25,16 +25,44 @@ import (
...
@@ -25,16 +25,44 @@ import (
"math/rand"
"math/rand"
"os"
"os"
"path"
"path"
"sync"
"testing"
"testing"
"text/template"
"text/template"
"k8s.io/kubernetes/pkg/kubelet/network"
"k8s.io/kubernetes/pkg/kubelet/network"
"k8s.io/kubernetes/pkg/util/sets"
)
)
// The temp dir where test plugins will be stored.
func
tmpDirOrDie
()
string
{
const
testPluginPath
=
"/tmp/fake/plugins/net"
dir
,
err
:=
ioutil
.
TempDir
(
os
.
TempDir
(),
"exec-test"
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"error creating tmp dir: %v"
,
err
))
}
return
path
.
Join
(
dir
,
"fake"
,
"plugins"
,
"net"
)
}
var
lock
sync
.
Mutex
var
namesInUse
=
sets
.
NewString
()
func
selectName
()
string
{
lock
.
Lock
()
defer
lock
.
Unlock
()
for
{
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
if
!
namesInUse
.
Has
(
pluginName
)
{
namesInUse
.
Insert
(
pluginName
)
return
pluginName
}
}
}
func
releaseName
(
name
string
)
{
lock
.
Lock
()
defer
lock
.
Unlock
()
namesInUse
.
Delete
(
name
)
}
func
installPluginUnderTest
(
t
*
testing
.
T
,
vendorName
string
,
plugName
string
,
execTemplateData
*
map
[
string
]
interface
{})
{
func
installPluginUnderTest
(
t
*
testing
.
T
,
vendorName
,
testPluginPath
,
plugName
string
,
execTemplateData
*
map
[
string
]
interface
{})
{
vendoredName
:=
plugName
vendoredName
:=
plugName
if
vendorName
!=
""
{
if
vendorName
!=
""
{
vendoredName
=
fmt
.
Sprintf
(
"%s~%s"
,
vendorName
,
plugName
)
vendoredName
=
fmt
.
Sprintf
(
"%s~%s"
,
vendorName
,
plugName
)
...
@@ -85,7 +113,7 @@ echo -n $@ &> {{.OutputFile}}
...
@@ -85,7 +113,7 @@ echo -n $@ &> {{.OutputFile}}
f
.
Close
()
f
.
Close
()
}
}
func
tearDownPlugin
(
plugName
string
)
{
func
tearDownPlugin
(
testPluginPath
string
)
{
err
:=
os
.
RemoveAll
(
testPluginPath
)
err
:=
os
.
RemoveAll
(
testPluginPath
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Printf
(
"Error in cleaning up test: %v"
,
err
)
fmt
.
Printf
(
"Error in cleaning up test: %v"
,
err
)
...
@@ -93,10 +121,15 @@ func tearDownPlugin(plugName string) {
...
@@ -93,10 +121,15 @@ func tearDownPlugin(plugName string) {
}
}
func
TestSelectPlugin
(
t
*
testing
.
T
)
{
func
TestSelectPlugin
(
t
*
testing
.
T
)
{
// The temp dir where test plugins will be stored.
testPluginPath
:=
tmpDirOrDie
()
// install some random plugin under testPluginPath
// install some random plugin under testPluginPath
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
pluginName
:=
selectName
()
defer
tearDownPlugin
(
pluginName
)
defer
tearDownPlugin
(
testPluginPath
)
installPluginUnderTest
(
t
,
""
,
pluginName
,
nil
)
defer
releaseName
(
pluginName
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -108,11 +141,16 @@ func TestSelectPlugin(t *testing.T) {
...
@@ -108,11 +141,16 @@ func TestSelectPlugin(t *testing.T) {
}
}
func
TestSelectVendoredPlugin
(
t
*
testing
.
T
)
{
func
TestSelectVendoredPlugin
(
t
*
testing
.
T
)
{
// The temp dir where test plugins will be stored.
testPluginPath
:=
tmpDirOrDie
()
// install some random plugin under testPluginPath
// install some random plugin under testPluginPath
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
pluginName
:=
selectName
()
defer
tearDownPlugin
(
pluginName
)
defer
tearDownPlugin
(
testPluginPath
)
defer
releaseName
(
pluginName
)
vendor
:=
"mycompany"
vendor
:=
"mycompany"
installPluginUnderTest
(
t
,
vendor
,
pluginName
,
nil
)
installPluginUnderTest
(
t
,
vendor
,
testPluginPath
,
pluginName
,
nil
)
vendoredPluginName
:=
fmt
.
Sprintf
(
"%s/%s"
,
vendor
,
pluginName
)
vendoredPluginName
:=
fmt
.
Sprintf
(
"%s/%s"
,
vendor
,
pluginName
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
vendoredPluginName
,
network
.
NewFakeHost
(
nil
))
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
vendoredPluginName
,
network
.
NewFakeHost
(
nil
))
...
@@ -125,10 +163,15 @@ func TestSelectVendoredPlugin(t *testing.T) {
...
@@ -125,10 +163,15 @@ func TestSelectVendoredPlugin(t *testing.T) {
}
}
func
TestSelectWrongPlugin
(
t
*
testing
.
T
)
{
func
TestSelectWrongPlugin
(
t
*
testing
.
T
)
{
// The temp dir where test plugins will be stored.
testPluginPath
:=
tmpDirOrDie
()
// install some random plugin under testPluginPath
// install some random plugin under testPluginPath
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
pluginName
:=
selectName
()
defer
tearDownPlugin
(
pluginName
)
defer
tearDownPlugin
(
testPluginPath
)
installPluginUnderTest
(
t
,
""
,
pluginName
,
nil
)
defer
releaseName
(
pluginName
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
wrongPlugin
:=
"abcd"
wrongPlugin
:=
"abcd"
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
wrongPlugin
,
network
.
NewFakeHost
(
nil
))
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
wrongPlugin
,
network
.
NewFakeHost
(
nil
))
...
@@ -138,9 +181,15 @@ func TestSelectWrongPlugin(t *testing.T) {
...
@@ -138,9 +181,15 @@ func TestSelectWrongPlugin(t *testing.T) {
}
}
func
TestPluginValidation
(
t
*
testing
.
T
)
{
func
TestPluginValidation
(
t
*
testing
.
T
)
{
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
// The temp dir where test plugins will be stored.
defer
tearDownPlugin
(
pluginName
)
testPluginPath
:=
tmpDirOrDie
()
installPluginUnderTest
(
t
,
""
,
pluginName
,
nil
)
// install some random plugin under testPluginPath
pluginName
:=
selectName
()
defer
tearDownPlugin
(
testPluginPath
)
defer
releaseName
(
pluginName
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
// modify the perms of the pluginExecutable
// modify the perms of the pluginExecutable
f
,
err
:=
os
.
Open
(
path
.
Join
(
testPluginPath
,
pluginName
,
pluginName
))
f
,
err
:=
os
.
Open
(
path
.
Join
(
testPluginPath
,
pluginName
,
pluginName
))
...
@@ -161,9 +210,15 @@ func TestPluginValidation(t *testing.T) {
...
@@ -161,9 +210,15 @@ func TestPluginValidation(t *testing.T) {
}
}
func
TestPluginSetupHook
(
t
*
testing
.
T
)
{
func
TestPluginSetupHook
(
t
*
testing
.
T
)
{
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
// The temp dir where test plugins will be stored.
defer
tearDownPlugin
(
pluginName
)
testPluginPath
:=
tmpDirOrDie
()
installPluginUnderTest
(
t
,
""
,
pluginName
,
nil
)
// install some random plugin under testPluginPath
pluginName
:=
selectName
()
defer
tearDownPlugin
(
testPluginPath
)
defer
releaseName
(
pluginName
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
...
@@ -183,9 +238,15 @@ func TestPluginSetupHook(t *testing.T) {
...
@@ -183,9 +238,15 @@ func TestPluginSetupHook(t *testing.T) {
}
}
func
TestPluginTearDownHook
(
t
*
testing
.
T
)
{
func
TestPluginTearDownHook
(
t
*
testing
.
T
)
{
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
// The temp dir where test plugins will be stored.
defer
tearDownPlugin
(
pluginName
)
testPluginPath
:=
tmpDirOrDie
()
installPluginUnderTest
(
t
,
""
,
pluginName
,
nil
)
// install some random plugin under testPluginPath
pluginName
:=
selectName
()
defer
tearDownPlugin
(
testPluginPath
)
defer
releaseName
(
pluginName
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
...
@@ -205,9 +266,15 @@ func TestPluginTearDownHook(t *testing.T) {
...
@@ -205,9 +266,15 @@ func TestPluginTearDownHook(t *testing.T) {
}
}
func
TestPluginStatusHook
(
t
*
testing
.
T
)
{
func
TestPluginStatusHook
(
t
*
testing
.
T
)
{
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
// The temp dir where test plugins will be stored.
defer
tearDownPlugin
(
pluginName
)
testPluginPath
:=
tmpDirOrDie
()
installPluginUnderTest
(
t
,
""
,
pluginName
,
nil
)
// install some random plugin under testPluginPath
pluginName
:=
selectName
()
defer
tearDownPlugin
(
testPluginPath
)
defer
releaseName
(
pluginName
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
nil
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
...
@@ -230,14 +297,20 @@ func TestPluginStatusHook(t *testing.T) {
...
@@ -230,14 +297,20 @@ func TestPluginStatusHook(t *testing.T) {
}
}
func
TestPluginStatusHookIPv6
(
t
*
testing
.
T
)
{
func
TestPluginStatusHookIPv6
(
t
*
testing
.
T
)
{
pluginName
:=
fmt
.
Sprintf
(
"test%d"
,
rand
.
Intn
(
1000
))
// The temp dir where test plugins will be stored.
defer
tearDownPlugin
(
pluginName
)
testPluginPath
:=
tmpDirOrDie
()
// install some random plugin under testPluginPath
pluginName
:=
selectName
()
defer
tearDownPlugin
(
testPluginPath
)
defer
releaseName
(
pluginName
)
pluginDir
:=
path
.
Join
(
testPluginPath
,
pluginName
)
pluginDir
:=
path
.
Join
(
testPluginPath
,
pluginName
)
execTemplate
:=
&
map
[
string
]
interface
{}{
execTemplate
:=
&
map
[
string
]
interface
{}{
"IPAddress"
:
"fe80::e2cb:4eff:fef9:6710"
,
"IPAddress"
:
"fe80::e2cb:4eff:fef9:6710"
,
"OutputFile"
:
path
.
Join
(
pluginDir
,
pluginName
+
".out"
),
"OutputFile"
:
path
.
Join
(
pluginDir
,
pluginName
+
".out"
),
}
}
installPluginUnderTest
(
t
,
""
,
pluginName
,
execTemplate
)
installPluginUnderTest
(
t
,
""
,
testPluginPath
,
pluginName
,
execTemplate
)
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
plug
,
err
:=
network
.
InitNetworkPlugin
(
ProbeNetworkPlugins
(
testPluginPath
),
pluginName
,
network
.
NewFakeHost
(
nil
))
...
...
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