Skip to content

Commit 184a7ae

Browse files
authored
Merge pull request #190 from mauriciopoppe/integration-tests-k
Scripts to run the integration tests with a real kubernetes VM
2 parents 167159f + 52667b6 commit 184a7ae

11 files changed

+180
-103
lines changed

integrationtests/disk_v1_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/kubernetes-csi/csi-proxy/client/api/disk/v1"
12+
v1 "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1"
1313
diskv1client "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1"
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
@@ -51,19 +51,20 @@ func v1DiskTests(t *testing.T) {
5151
t.Errorf("Expected to get at least one diskIDs, instead got diskIDsResponse.DiskIDs=%+v", diskIDsMap)
5252
}
5353

54+
// some disks may have the field Page83, if it's a GCE Persistent disk
55+
// it'll have a nonempty SerialNumber
5456
// first disk is the VM disk (other disks might be VHD)
55-
diskNumber := 0
56-
diskIDs, found := diskIDsMap[uint32(diskNumber)]
57-
if !found {
58-
t.Errorf("Cannot find Disk %d", diskNumber)
59-
}
60-
page83 := diskIDs.Page83
61-
if page83 == "" {
62-
t.Errorf("page83 field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
63-
}
64-
serialNumber := diskIDs.SerialNumber
65-
if serialNumber == "" {
66-
t.Errorf("serialNumber field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
57+
for diskNumber, diskIDs := range diskIDsMap {
58+
if len(diskIDs.SerialNumber) > 0 {
59+
// the nvme disks don't have a Page83 number
60+
if strings.HasPrefix(diskIDs.SerialNumber, "nvme") {
61+
continue
62+
}
63+
page83 := diskIDs.Page83
64+
if page83 == "" {
65+
t.Errorf("page83 field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
66+
}
67+
}
6768
}
6869

6970
listDiskLocationsRequest := &v1.ListDiskLocationsRequest{}

integrationtests/disk_v1beta1_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,6 @@ func v1beta1DiskTests(t *testing.T) {
4747
t.Errorf("Expected to get at least one diskIDs, instead got diskIDsResponse.DiskIDs=%+v", diskIDsMap)
4848
}
4949

50-
// first disk is the VM disk (other disks might be VHD)
51-
diskNumber := 0
52-
diskIDs, found := diskIDsMap[strconv.FormatUint(uint64(diskNumber), 10)]
53-
if !found {
54-
t.Errorf("Cannot find Disk %d", diskNumber)
55-
}
56-
page83 := diskIDs.Identifiers["page83"]
57-
if page83 == "" {
58-
t.Errorf("page83 field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
59-
}
60-
serialNumber := diskIDs.Identifiers["serialNumber"]
61-
if serialNumber == "" {
62-
t.Errorf("serialNumber field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
63-
}
64-
6550
listDiskLocationsRequest := &v1beta1.ListDiskLocationsRequest{}
6651
listDiskLocationsResponse, err := client.ListDiskLocations(context.TODO(), listDiskLocationsRequest)
6752
require.Nil(t, err)

integrationtests/disk_v1beta2_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,6 @@ func v1beta2DiskTests(t *testing.T) {
4848
t.Errorf("Expected to get at least one diskIDs, instead got diskIDsResponse.DiskIDs=%+v", diskIDsMap)
4949
}
5050

51-
// first disk is the VM disk (other disks might be VHD)
52-
diskNumber := 0
53-
diskIDs, found := diskIDsMap[strconv.FormatUint(uint64(diskNumber), 10)]
54-
if !found {
55-
t.Errorf("Cannot find Disk %d", diskNumber)
56-
}
57-
page83 := diskIDs.Identifiers["page83"]
58-
if page83 == "" {
59-
t.Errorf("page83 field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
60-
}
61-
serialNumber := diskIDs.Identifiers["serialNumber"]
62-
if serialNumber == "" {
63-
t.Errorf("serialNumber field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
64-
}
65-
6651
listDiskLocationsRequest := &v1beta2.ListDiskLocationsRequest{}
6752
listDiskLocationsResponse, err := client.ListDiskLocations(context.TODO(), listDiskLocationsRequest)
6853
require.Nil(t, err)

integrationtests/disk_v1beta3_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,20 @@ func v1beta3DiskTests(t *testing.T) {
5151
t.Errorf("Expected to get at least one diskIDs, instead got diskIDsResponse.DiskIDs=%+v", diskIDsMap)
5252
}
5353

54+
// some disks may have the field Page83, if it's a GCE Persistent disk
55+
// it'll have a nonempty SerialNumber
5456
// first disk is the VM disk (other disks might be VHD)
55-
diskNumber := 0
56-
diskIDs, found := diskIDsMap[uint32(diskNumber)]
57-
if !found {
58-
t.Errorf("Cannot find Disk %d", diskNumber)
59-
}
60-
page83 := diskIDs.Page83
61-
if page83 == "" {
62-
t.Errorf("page83 field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
63-
}
64-
serialNumber := diskIDs.SerialNumber
65-
if serialNumber == "" {
66-
t.Errorf("serialNumber field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
57+
for diskNumber, diskIDs := range diskIDsMap {
58+
if len(diskIDs.SerialNumber) > 0 {
59+
// the nvme disks don't have a Page83 number
60+
if strings.HasPrefix(diskIDs.SerialNumber, "nvme") {
61+
continue
62+
}
63+
page83 := diskIDs.Page83
64+
if page83 == "" {
65+
t.Errorf("page83 field of diskNumber=%d should be defined, instead got diskIDs=%v", diskNumber, diskIDs)
66+
}
67+
}
6768
}
6869

6970
listDiskLocationsRequest := &v1beta3.ListDiskLocationsRequest{}

integrationtests/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func shouldRunIscsiTests() bool {
156156
}
157157

158158
func runPowershellCmd(t *testing.T, command string) (string, error) {
159-
cmd := exec.Command("powershell", "/c", command)
159+
cmd := exec.Command("powershell", "/c", fmt.Sprintf("& { $global:ProgressPreference = 'SilentlyContinue'; %s }", command))
160160
t.Logf("Executing command: %q", cmd.String())
161161
result, err := cmd.CombinedOutput()
162162
return string(result), err
@@ -205,7 +205,7 @@ func diskInit(t *testing.T) (*VirtualHardDisk, func()) {
205205
s1 := rand.NewSource(time.Now().UTC().UnixNano())
206206
r1 := rand.New(s1)
207207

208-
testId := r1.Intn(1000)
208+
testId := r1.Intn(10000000)
209209
testPluginPath := fmt.Sprintf("C:\\var\\lib\\kubelet\\plugins\\testplugin-%d.csi.io\\", testId)
210210
mountPath := fmt.Sprintf("%smount-%d", testPluginPath, testId)
211211
vhdxPath := fmt.Sprintf("%sdisk-%d.vhdx", testPluginPath, testId)

scripts/bump-version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#/bin/bash
1+
#!/bin/bash
22

33
# bump-version.sh
44
# Bumps an API version from an old version to a new one

scripts/run-integration.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
#
4+
# Runs the integration tests
5+
#
6+
# Requirements:
7+
# - a kubernetes cluster with a Windows nodepool
8+
#
9+
# Steps:
10+
# - cross compile the csi-proxy binary and the integration tests
11+
# - copy to the VM using scp
12+
# - restart the CSI Proxy binary process with a helper powershell script
13+
# - run the integration tests
14+
15+
set -euxo pipefail
16+
17+
pkgdir=${GOPATH}/src/github.com/kubernetes-csi/csi-proxy
18+
source $pkgdir/scripts/utils.sh
19+
20+
main() {
21+
compile_csi_proxy
22+
compile_csi_proxy_integration_tests
23+
sync_csi_proxy
24+
sync_csi_proxy_integration_tests
25+
sync_powershell_utils
26+
restart_csi_proxy
27+
run_csi_proxy_integration_tests
28+
}
29+
30+
main

scripts/sync-csi-proxy.ps1

Lines changed: 0 additions & 28 deletions
This file was deleted.

scripts/sync-csi-proxy.sh

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#/bin/bash
1+
#!/bin/bash
2+
23
#
34
# Installs CSI Proxy in a kubernetes node
45
#
@@ -10,25 +11,16 @@
1011
# - copy to the VM using scp
1112
# - restart the CSI Proxy binary process with a helper powershell script
1213

13-
set -ex
14+
set -euxo pipefail
1415

15-
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
16-
csi_proxy_bin_path="$script_dir/../bin/csi-proxy.exe"
17-
sync_script_ps_path="$script_dir/sync-csi-proxy.ps1"
16+
pkgdir=${GOPATH}/src/github.com/kubernetes-csi/csi-proxy
17+
source $pkgdir/scripts/utils.sh
1818

1919
main() {
20-
echo "Compiling CSI Proxy"
21-
make build
22-
23-
local windows_node=$(kubectl get nodes -l kubernetes.io/os=windows -o jsonpath='{.items[*].metadata.name}')
24-
gcloud compute instances describe $windows_node > /dev/null
25-
26-
echo "Sync the csi-proxy.exe binary"
27-
local current_account=$(gcloud config list account --format "value(core.account)" | sed -r 's/@\S+//g')
28-
gcloud compute scp $csi_proxy_bin_path $sync_script_ps_path $windows_node:"C:\\Users\\${current_account}"
29-
30-
echo "Restart csi-proxy service"
31-
gcloud compute ssh $windows_node --command="powershell .\sync-csi-proxy.ps1"
20+
compile_csi_proxy
21+
sync_csi_proxy
22+
sync_powershell_utils
23+
restart_csi_proxy
3224
}
3325

3426
main

scripts/utils.psm1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Restart-CSIProxy {
2+
# stop the csiproxy service
3+
Get-Process csi-proxy | Stop-Process -Force
4+
sc.exe stop csiproxy
5+
Start-Sleep -Seconds 1;
6+
sc.exe delete csiproxy
7+
Start-Sleep -Seconds 1;
8+
9+
# copy the binary from the user directory
10+
Copy-Item -Path "C:\Users\$env:UserName\csi-proxy.exe" -Destination "C:\etc\kubernetes\node\bin\csi-proxy.exe"
11+
12+
# restart the csiproxy service
13+
$flags = "-v=5 -windows-service -log_file=C:\etc\kubernetes\logs\csi-proxy.log -logtostderr=false"
14+
sc.exe create csiproxy start= "auto" binPath= "C:\etc\kubernetes\node\bin\csi-proxy.exe $flags"
15+
sc.exe failure csiproxy reset= 0 actions= restart/10000
16+
sc.exe start csiproxy
17+
18+
Start-Sleep -Seconds 5;
19+
20+
Write-Output "Checking the status of csi-proxy"
21+
sc.exe query csiproxy
22+
[System.IO.Directory]::GetFiles("\\.\\pipe\\")
23+
24+
Write-Output "Get logs"
25+
Get-Content C:\etc\kubernetes\logs\csi-proxy.log -Tail 20
26+
}
27+
28+
function Run-CSIProxyIntegrationTests {
29+
param (
30+
[string]$test_args = ""
31+
)
32+
33+
$ErrorActionPreference = "Stop";
34+
Write-Output "Running integration tests with test_args=$test_args";
35+
$flags = $test_args.Split(" ");
36+
.\integrationtests.test.exe @flags
37+
38+
if (-not $?) {
39+
throw "failed to run with exit code=$?"
40+
}
41+
}

scripts/utils.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
# Importing this library shouldn't have side effects
4+
5+
pkgdir=${GOPATH}/src/github.com/kubernetes-csi/csi-proxy
6+
7+
# current_account is the current user
8+
# in CI, the value is `prow`
9+
current_account=$USER
10+
# windows_node is the id of the GCE Windows instance
11+
windows_node=$(kubectl get nodes -l kubernetes.io/os=windows -o jsonpath='{.items[*].metadata.name}')
12+
13+
# set the default zone for the gcloud sdk
14+
if ! [ -z "${GCP_ZONE:-}" ]; then
15+
export CLOUDSDK_COMPUTE_ZONE="$GCP_ZONE"
16+
fi
17+
18+
sync_file_to_vm() {
19+
gcloud compute scp $@ $windows_node:"C:\\Users\\${current_account}"
20+
}
21+
22+
compile_csi_proxy() {
23+
echo "Compiling CSI Proxy"
24+
make -C $pkgdir build
25+
}
26+
27+
compile_csi_proxy_integration_tests() {
28+
echo "Compiling CSI Proxy integration tests"
29+
GOOS=windows GOARCH=amd64 go test -c $pkgdir/integrationtests -o $pkgdir/bin/integrationtests.test.exe
30+
}
31+
32+
sync_csi_proxy() {
33+
echo "Sync the csi-proxy.exe binary"
34+
local csi_proxy_bin_path="$pkgdir/bin/csi-proxy.exe"
35+
sync_file_to_vm $csi_proxy_bin_path
36+
}
37+
38+
sync_csi_proxy_integration_tests() {
39+
echo "Sync the integrationtests.exe binary"
40+
local integration_bin_path="$pkgdir/bin/integrationtests.test.exe"
41+
sync_file_to_vm $integration_bin_path
42+
}
43+
44+
sync_powershell_utils() {
45+
local utils_psm1="$pkgdir/scripts/utils.psm1"
46+
sync_file_to_vm $utils_psm1
47+
}
48+
49+
restart_csi_proxy() {
50+
echo "Restart csi-proxy service"
51+
gcloud compute ssh $windows_node --command='powershell -c "& { $ErrorActionPreference = \"Stop\"; Import-Module (Resolve-Path(\"utils.psm1\")); Restart-CSIProxy; }"'
52+
}
53+
54+
run_csi_proxy_integration_tests() {
55+
echo "Run integration tests"
56+
local ps1=$(cat << 'EOF'
57+
"& {
58+
$ErrorActionPreference = \"Stop\";
59+
Import-Module (Resolve-Path(\"utils.psm1\"));
60+
Run-CSIProxyIntegrationTests -test_args \"--test.v --test.run TestAPIGroups\";
61+
Run-CSIProxyIntegrationTests -test_args \"--test.v --test.run TestFilesystemAPIGroup\";
62+
Run-CSIProxyIntegrationTests -test_args \"--test.v --test.run TestDiskAPIGroup\";
63+
Run-CSIProxyIntegrationTests -test_args \"--test.v --test.run TestVolumeAPIs\";
64+
Run-CSIProxyIntegrationTests -test_args \"--test.v --test.run TestSmbAPIGroup\";
65+
}"
66+
EOF
67+
);
68+
69+
gcloud compute ssh $windows_node --command="powershell -c $(echo $ps1 | tr '\n' ' ')"
70+
}

0 commit comments

Comments
 (0)