Skip to content

Commit f6ab3fb

Browse files
committed
Add e2e and integration tests for image snapshot
1 parent 6c31130 commit f6ab3fb

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

test/e2e/tests/single_zone_e2e_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,65 @@ var _ = Describe("GCE PD CSI Driver", func() {
946946
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected snapshot to not be found")
947947
}()
948948
})
949+
950+
// Use the region of the test location.
951+
It("Should successfully create snapshot backed by disk image", func() {
952+
testContext := getRandomTestContext()
953+
954+
p, z, _ := testContext.Instance.GetIdentity()
955+
client := testContext.Client
956+
957+
// Create Disk
958+
volName, volID := createAndValidateUniqueZonalDisk(client, p, z)
959+
960+
// Create Snapshot
961+
snapshotName := testNamePrefix + string(uuid.NewUUID())
962+
testImageFamily := "test-family"
963+
964+
snapshotParams := map[string]string{common.ParameterKeySnapshotType: common.DiskImageType, common.ParameterKeyImageFamily: testImageFamily}
965+
snapshotID, err := client.CreateSnapshot(snapshotName, volID, snapshotParams)
966+
Expect(err).To(BeNil(), "CreateSnapshot failed with error: %v", err)
967+
968+
// Validate Snapshot Created
969+
snapshot, err := computeService.Images.Get(p, snapshotName).Do()
970+
Expect(err).To(BeNil(), "Could not get snapshot from cloud directly")
971+
Expect(snapshot.Name).To(Equal(snapshotName))
972+
973+
err = wait.Poll(10*time.Second, 5*time.Minute, func() (bool, error) {
974+
snapshot, err := computeService.Images.Get(p, snapshotName).Do()
975+
Expect(err).To(BeNil(), "Could not get snapshot from cloud directly")
976+
if snapshot.Status == "READY" {
977+
return true, nil
978+
}
979+
return false, nil
980+
})
981+
Expect(err).To(BeNil(), "Could not wait for snapshot be ready")
982+
983+
// Check Snapshot Type
984+
snapshot, err = computeService.Images.Get(p, snapshotName).Do()
985+
Expect(err).To(BeNil(), "Could not get snapshot from cloud directly")
986+
_, snapshotType, _, err := common.SnapshotIDToProjectKey(cleanSelfLink(snapshot.SelfLink))
987+
Expect(err).To(BeNil(), "Failed to parse snapshot ID")
988+
Expect(snapshotType).To(Equal(common.DiskImageType), "Expected images type in snapshot ID")
989+
990+
defer func() {
991+
// Delete Disk
992+
err := client.DeleteVolume(volID)
993+
Expect(err).To(BeNil(), "DeleteVolume failed")
994+
995+
// Validate Disk Deleted
996+
_, err = computeService.Disks.Get(p, z, volName).Do()
997+
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
998+
999+
// Delete Snapshot
1000+
err = client.DeleteSnapshot(snapshotID)
1001+
Expect(err).To(BeNil(), "DeleteSnapshot failed")
1002+
1003+
// Validate Snapshot Deleted
1004+
_, err = computeService.Images.Get(p, snapshotName).Do()
1005+
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected snapshot to not be found")
1006+
}()
1007+
})
9491008
})
9501009

9511010
func equalWithinEpsilon(a, b, epsiolon int64) bool {
@@ -1025,3 +1084,9 @@ func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, proje
10251084

10261085
return volName, volID
10271086
}
1087+
1088+
func cleanSelfLink(selfLink string) string {
1089+
temp := strings.TrimPrefix(selfLink, gce.GCEComputeAPIEndpoint)
1090+
temp = strings.TrimPrefix(temp, gce.GCEComputeBetaAPIEndpoint)
1091+
return strings.TrimPrefix(temp, gce.GCEComputeAlphaAPIEndpoint)
1092+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: snapshot.storage.k8s.io/v1beta1
2+
kind: VolumeSnapshotClass
3+
metadata:
4+
name: csi-gce-image-snapshot-class
5+
driver: pd.csi.storage.gke.io
6+
deletionPolicy: Delete
7+
parameters:
8+
snapshot-type: images
9+
image-family: integration-test

test/k8s-integration/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ func handle() error {
203203
testParams := &testParameters{
204204
platform: *platform,
205205
testFocus: *testFocus,
206-
snapshotClassFile: *snapshotClassFile,
207206
stagingVersion: string(uuid.NewUUID()),
208207
deploymentStrategy: *deploymentStrat,
209208
useGKEManagedDriver: *useGKEManagedDriver,

test/run-k8s-integration-ci.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ readonly run_intree_plugin_tests=${RUN_INTREE_PLUGIN_TESTS:-false}
2929
readonly use_kubetest2=${USE_KUBETEST2:-true}
3030
readonly test_pd_labels=${TEST_PD_LABELS:-true}
3131
readonly migration_test=${MIGRATION_TEST:-false}
32+
readonly test_disk_image_snapshot=${TEST_DISK_IMAGE_SNAPSHOT:-true}
3233

3334
readonly GCE_PD_TEST_FOCUS="PersistentVolumes\sGCEPD|[V|v]olume\sexpand|\[sig-storage\]\sIn-tree\sVolumes\s\[Driver:\sgcepd\]|allowedTopologies|Pod\sDisks|PersistentVolumes\sDefault"
3435

@@ -62,7 +63,7 @@ fi
6263
base_cmd="${PKGDIR}/bin/k8s-integration-test \
6364
--run-in-prow=true --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
6465
--do-driver-build=${do_driver_build} --teardown-driver=${teardown_driver} --boskos-resource-type=${boskos_resource_type} \
65-
--storageclass-files="${storage_classes}" --snapshotclass-file=pd-volumesnapshotclass.yaml \
66+
--storageclass-files="${storage_classes}" \
6667
--deployment-strategy=${deployment_strategy} --test-version=${test_version} \
6768
--num-nodes=3 --image-type=${image_type} --use-kubetest2=${use_kubetest2}"
6869

@@ -100,4 +101,10 @@ if [ -n "$gke_node_version" ]; then
100101
base_cmd="${base_cmd} --gke-node-version=${gke_node_version}"
101102
fi
102103

104+
if [ "$test_disk_image_snapshot" = true ]; then
105+
base_cmd="${base_cmd} --snapshotclass-file=image-volumesnapshotclass.yaml"
106+
else
107+
base_cmd="${base_cmd} --snapshotclass-file=pd-volumesnapshotclass.yaml"
108+
fi
109+
103110
eval "$base_cmd"

test/run-k8s-integration-local.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ make -C "${PKGDIR}" test-k8s-integration
5353
#--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml --do-driver-build=true \
5454
#--gce-zone="us-central1-b" --num-nodes=${NUM_NODES:-3}
5555

56+
# This version of the command builds and deploys the GCE PD CSI driver.
57+
# Points to a local K8s repository to get the e2e test binary, does not bring up
58+
# or tear down the kubernetes cluster. In addition, it runs External Storage
59+
# snapshot tests for the PD CSI driver using disk image snapshots.
60+
#${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \
61+
#--staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
62+
#--deploy-overlay-name=prow-canary-sidecar --bringup-cluster=false --teardown-cluster=false --test-focus="External.*Storage.*snapshot" --local-k8s-dir=$KTOP \
63+
#--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --snapshotclass-file=image-volumesnapshotclass.yaml --do-driver-build=true \
64+
#--gce-zone="us-central1-b" --num-nodes=${NUM_NODES:-3}
65+
5666
# This version of the command brings up (and subsequently tears down) a GKE
5767
# cluster with managed GCE PersistentDisk CSI driver add-on enabled, and points to
5868
# the local K8s repository to get the e2e test binary.
@@ -96,4 +106,4 @@ make -C "${PKGDIR}" test-k8s-integration
96106
# --staging-image="${GCE_PD_CSI_STAGING_IMAGE}" --service-account-file="${GCE_PD_SA_DIR}/cloud-sa.json" \
97107
# --deploy-overlay-name=dev --bringup-cluster=false --teardown-cluster=false --local-k8s-dir="$KTOP" \
98108
# --storageclass-files=sc-standard.yaml --do-driver-build=false --test-focus='External.Storage' \
99-
# --gce-zone="us-central1-b" --num-nodes="${NUM_NODES:-3}"
109+
# --gce-zone="us-central1-b" --num-nodes="${NUM_NODES:-3}"

0 commit comments

Comments
 (0)