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
b138e6d1
Commit
b138e6d1
authored
Apr 08, 2019
by
Vladimir Vivien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CSI - Surfaces klog flags; common tests aggregation
parent
9e83e6d1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
112 deletions
+150
-112
BUILD
pkg/volume/csi/BUILD
+1
-0
csi_attacher_test.go
pkg/volume/csi/csi_attacher_test.go
+6
-6
csi_mounter_test.go
pkg/volume/csi/csi_mounter_test.go
+3
-67
csi_plugin_test.go
pkg/volume/csi/csi_plugin_test.go
+2
-39
csi_util_test.go
pkg/volume/csi/csi_util_test.go
+138
-0
No files found.
pkg/volume/csi/BUILD
View file @
b138e6d1
...
...
@@ -50,6 +50,7 @@ go_test(
"csi_drivers_store_test.go",
"csi_mounter_test.go",
"csi_plugin_test.go",
"csi_util_test.go",
"expander_test.go",
],
embed = [":go_default_library"],
...
...
pkg/volume/csi/csi_attacher_test.go
View file @
b138e6d1
...
...
@@ -334,9 +334,9 @@ func TestAttacherWithCSIDriver(t *testing.T) {
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
fakeClient
:=
fakeclient
.
NewSimpleClientset
(
getCSIDriver
(
"not-attachable"
,
nil
,
&
bFalse
),
getCSIDriver
(
"attachable"
,
nil
,
&
bTrue
),
getCSIDriver
(
"nil"
,
nil
,
nil
),
get
Test
CSIDriver
(
"not-attachable"
,
nil
,
&
bFalse
),
get
Test
CSIDriver
(
"attachable"
,
nil
,
&
bTrue
),
get
Test
CSIDriver
(
"nil"
,
nil
,
nil
),
)
plug
,
fakeWatcher
,
tmpDir
,
_
:=
newTestWatchPlugin
(
t
,
fakeClient
)
defer
os
.
RemoveAll
(
tmpDir
)
...
...
@@ -418,9 +418,9 @@ func TestAttacherWaitForVolumeAttachmentWithCSIDriver(t *testing.T) {
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
fakeClient
:=
fakeclient
.
NewSimpleClientset
(
getCSIDriver
(
"not-attachable"
,
nil
,
&
bFalse
),
getCSIDriver
(
"attachable"
,
nil
,
&
bTrue
),
getCSIDriver
(
"nil"
,
nil
,
nil
),
get
Test
CSIDriver
(
"not-attachable"
,
nil
,
&
bFalse
),
get
Test
CSIDriver
(
"attachable"
,
nil
,
&
bTrue
),
get
Test
CSIDriver
(
"nil"
,
nil
,
nil
),
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
fakeClient
)
defer
os
.
RemoveAll
(
tmpDir
)
...
...
pkg/volume/csi/csi_mounter_test.go
View file @
b138e6d1
...
...
@@ -17,10 +17,7 @@ limitations under the License.
package
csi
import
(
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path"
...
...
@@ -30,7 +27,6 @@ import (
api
"k8s.io/api/core/v1"
storage
"k8s.io/api/storage/v1"
storagev1beta1
"k8s.io/api/storage/v1beta1"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
...
...
@@ -147,9 +143,9 @@ func MounterSetUpTests(t *testing.T, podInfoEnabled bool) {
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
klog
.
Infof
(
"Starting test %s"
,
test
.
name
)
fakeClient
:=
fakeclient
.
NewSimpleClientset
(
getCSIDriver
(
"no-info"
,
&
noPodMountInfo
,
nil
),
getCSIDriver
(
"info"
,
&
currentPodInfoMount
,
nil
),
getCSIDriver
(
"nil"
,
nil
,
nil
),
get
Test
CSIDriver
(
"no-info"
,
&
noPodMountInfo
,
nil
),
get
Test
CSIDriver
(
"info"
,
&
currentPodInfoMount
,
nil
),
get
Test
CSIDriver
(
"nil"
,
nil
,
nil
),
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
fakeClient
)
defer
os
.
RemoveAll
(
tmpDir
)
...
...
@@ -695,63 +691,3 @@ func TestUnmounterTeardown(t *testing.T) {
}
}
func
TestSaveVolumeData
(
t
*
testing
.
T
)
{
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
testCases
:=
[]
struct
{
name
string
data
map
[
string
]
string
shouldFail
bool
}{
{
name
:
"test with data ok"
,
data
:
map
[
string
]
string
{
"key0"
:
"val0"
,
"_key1"
:
"val1"
,
"key2"
:
"val2"
}},
{
name
:
"test with data ok 2 "
,
data
:
map
[
string
]
string
{
"_key0_"
:
"val0"
,
"&key1"
:
"val1"
,
"key2"
:
"val2"
}},
}
for
i
,
tc
:=
range
testCases
{
t
.
Logf
(
"test case: %s"
,
tc
.
name
)
specVolID
:=
fmt
.
Sprintf
(
"spec-volid-%d"
,
i
)
mountDir
:=
path
.
Join
(
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
),
"/mount"
)
if
err
:=
os
.
MkdirAll
(
mountDir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
mountDir
,
err
)
}
err
:=
saveVolumeData
(
path
.
Dir
(
mountDir
),
volDataFileName
,
tc
.
data
)
if
!
tc
.
shouldFail
&&
err
!=
nil
{
t
.
Errorf
(
"unexpected failure: %v"
,
err
)
}
// did file get created
dataDir
:=
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
)
file
:=
path
.
Join
(
dataDir
,
volDataFileName
)
if
_
,
err
:=
os
.
Stat
(
file
);
err
!=
nil
{
t
.
Errorf
(
"failed to create data dir: %v"
,
err
)
}
// validate content
data
,
err
:=
ioutil
.
ReadFile
(
file
)
if
!
tc
.
shouldFail
&&
err
!=
nil
{
t
.
Errorf
(
"failed to read data file: %v"
,
err
)
}
jsonData
:=
new
(
bytes
.
Buffer
)
if
err
:=
json
.
NewEncoder
(
jsonData
)
.
Encode
(
tc
.
data
);
err
!=
nil
{
t
.
Errorf
(
"failed to encode json: %v"
,
err
)
}
if
string
(
data
)
!=
jsonData
.
String
()
{
t
.
Errorf
(
"expecting encoded data %v, got %v"
,
string
(
data
),
jsonData
)
}
}
}
func
getCSIDriver
(
name
string
,
podInfoMount
*
bool
,
attachable
*
bool
)
*
storagev1beta1
.
CSIDriver
{
return
&
storagev1beta1
.
CSIDriver
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
storagev1beta1
.
CSIDriverSpec
{
PodInfoOnMount
:
podInfoMount
,
AttachRequired
:
attachable
,
},
}
}
pkg/volume/csi/csi_plugin_test.go
View file @
b138e6d1
...
...
@@ -25,7 +25,6 @@ import (
"testing"
api
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
...
...
@@ -86,42 +85,6 @@ func newTestPlugin(t *testing.T, client *fakeclient.Clientset) (*csiPlugin, stri
return
csiPlug
,
tmpDir
}
func
makeTestPV
(
name
string
,
sizeGig
int
,
driverName
,
volID
string
)
*
api
.
PersistentVolume
{
return
&
api
.
PersistentVolume
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
api
.
PersistentVolumeSpec
{
AccessModes
:
[]
api
.
PersistentVolumeAccessMode
{
api
.
ReadWriteOnce
},
Capacity
:
api
.
ResourceList
{
api
.
ResourceName
(
api
.
ResourceStorage
)
:
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
sizeGig
),
),
},
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
CSI
:
&
api
.
CSIPersistentVolumeSource
{
Driver
:
driverName
,
VolumeHandle
:
volID
,
ReadOnly
:
false
,
},
},
},
}
}
func
makeTestVol
(
name
string
,
driverName
string
)
*
api
.
Volume
{
ro
:=
false
return
&
api
.
Volume
{
Name
:
name
,
VolumeSource
:
api
.
VolumeSource
{
CSI
:
&
api
.
CSIVolumeSource
{
Driver
:
driverName
,
ReadOnly
:
&
ro
,
},
},
}
}
func
registerFakePlugin
(
pluginName
,
endpoint
string
,
versions
[]
string
,
t
*
testing
.
T
)
{
highestSupportedVersions
,
err
:=
highestSupportedVersion
(
versions
)
if
err
!=
nil
{
...
...
@@ -910,7 +873,7 @@ func TestPluginCanAttach(t *testing.T) {
}
for
_
,
test
:=
range
tests
{
csiDriver
:=
getCSIDriver
(
test
.
driverName
,
nil
,
&
test
.
canAttach
)
csiDriver
:=
get
Test
CSIDriver
(
test
.
driverName
,
nil
,
&
test
.
canAttach
)
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
fakeCSIClient
:=
fakeclient
.
NewSimpleClientset
(
csiDriver
)
plug
,
tmpDir
:=
newTestPlugin
(
t
,
fakeCSIClient
)
...
...
@@ -971,7 +934,7 @@ func TestPluginFindAttachablePlugin(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmpDir
)
client
:=
fakeclient
.
NewSimpleClientset
(
getCSIDriver
(
test
.
driverName
,
nil
,
&
test
.
canAttach
))
client
:=
fakeclient
.
NewSimpleClientset
(
get
Test
CSIDriver
(
test
.
driverName
,
nil
,
&
test
.
canAttach
))
factory
:=
informers
.
NewSharedInformerFactory
(
client
,
csiResyncPeriod
)
host
:=
volumetest
.
NewFakeVolumeHostWithCSINodeName
(
tmpDir
,
...
...
pkg/volume/csi/csi_util_test.go
0 → 100644
View file @
b138e6d1
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
csi
import
(
"bytes"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"path"
"testing"
api
"k8s.io/api/core/v1"
storagev1beta1
"k8s.io/api/storage/v1beta1"
"k8s.io/apimachinery/pkg/api/resource"
meta
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog"
)
// TestMain starting point for all tests.
// Surfaces klog flags by default to enable
// go test -v ./ --args <klog flags>
func
TestMain
(
m
*
testing
.
M
)
{
klog
.
InitFlags
(
flag
.
CommandLine
)
os
.
Exit
(
m
.
Run
())
}
func
makeTestPV
(
name
string
,
sizeGig
int
,
driverName
,
volID
string
)
*
api
.
PersistentVolume
{
return
&
api
.
PersistentVolume
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
api
.
PersistentVolumeSpec
{
AccessModes
:
[]
api
.
PersistentVolumeAccessMode
{
api
.
ReadWriteOnce
},
Capacity
:
api
.
ResourceList
{
api
.
ResourceName
(
api
.
ResourceStorage
)
:
resource
.
MustParse
(
fmt
.
Sprintf
(
"%dGi"
,
sizeGig
),
),
},
PersistentVolumeSource
:
api
.
PersistentVolumeSource
{
CSI
:
&
api
.
CSIPersistentVolumeSource
{
Driver
:
driverName
,
VolumeHandle
:
volID
,
ReadOnly
:
false
,
},
},
},
}
}
func
makeTestVol
(
name
string
,
driverName
string
)
*
api
.
Volume
{
ro
:=
false
return
&
api
.
Volume
{
Name
:
name
,
VolumeSource
:
api
.
VolumeSource
{
CSI
:
&
api
.
CSIVolumeSource
{
Driver
:
driverName
,
ReadOnly
:
&
ro
,
},
},
}
}
func
getTestCSIDriver
(
name
string
,
podInfoMount
*
bool
,
attachable
*
bool
)
*
storagev1beta1
.
CSIDriver
{
return
&
storagev1beta1
.
CSIDriver
{
ObjectMeta
:
meta
.
ObjectMeta
{
Name
:
name
,
},
Spec
:
storagev1beta1
.
CSIDriverSpec
{
PodInfoOnMount
:
podInfoMount
,
AttachRequired
:
attachable
,
},
}
}
func
TestSaveVolumeData
(
t
*
testing
.
T
)
{
plug
,
tmpDir
:=
newTestPlugin
(
t
,
nil
)
defer
os
.
RemoveAll
(
tmpDir
)
testCases
:=
[]
struct
{
name
string
data
map
[
string
]
string
shouldFail
bool
}{
{
name
:
"test with data ok"
,
data
:
map
[
string
]
string
{
"key0"
:
"val0"
,
"_key1"
:
"val1"
,
"key2"
:
"val2"
}},
{
name
:
"test with data ok 2 "
,
data
:
map
[
string
]
string
{
"_key0_"
:
"val0"
,
"&key1"
:
"val1"
,
"key2"
:
"val2"
}},
}
for
i
,
tc
:=
range
testCases
{
t
.
Logf
(
"test case: %s"
,
tc
.
name
)
specVolID
:=
fmt
.
Sprintf
(
"spec-volid-%d"
,
i
)
mountDir
:=
path
.
Join
(
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
),
"/mount"
)
if
err
:=
os
.
MkdirAll
(
mountDir
,
0755
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
t
.
Errorf
(
"failed to create dir [%s]: %v"
,
mountDir
,
err
)
}
err
:=
saveVolumeData
(
path
.
Dir
(
mountDir
),
volDataFileName
,
tc
.
data
)
if
!
tc
.
shouldFail
&&
err
!=
nil
{
t
.
Errorf
(
"unexpected failure: %v"
,
err
)
}
// did file get created
dataDir
:=
getTargetPath
(
testPodUID
,
specVolID
,
plug
.
host
)
file
:=
path
.
Join
(
dataDir
,
volDataFileName
)
if
_
,
err
:=
os
.
Stat
(
file
);
err
!=
nil
{
t
.
Errorf
(
"failed to create data dir: %v"
,
err
)
}
// validate content
data
,
err
:=
ioutil
.
ReadFile
(
file
)
if
!
tc
.
shouldFail
&&
err
!=
nil
{
t
.
Errorf
(
"failed to read data file: %v"
,
err
)
}
jsonData
:=
new
(
bytes
.
Buffer
)
if
err
:=
json
.
NewEncoder
(
jsonData
)
.
Encode
(
tc
.
data
);
err
!=
nil
{
t
.
Errorf
(
"failed to encode json: %v"
,
err
)
}
if
string
(
data
)
!=
jsonData
.
String
()
{
t
.
Errorf
(
"expecting encoded data %v, got %v"
,
string
(
data
),
jsonData
)
}
}
}
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