Skip to content

Commit 0629d73

Browse files
committed
Add e2e and integration tests for image snapshot
1 parent 25be424 commit 0629d73

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

test/e2e/tests/single_zone_e2e_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,65 @@ var _ = Describe("GCE PD CSI Driver", func() {
876876
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected snapshot to not be found")
877877
}()
878878
})
879+
880+
// Use the region of the test location.
881+
It("Should successfully create snapshot backed by disk image", func() {
882+
testContext := getRandomTestContext()
883+
884+
p, z, _ := testContext.Instance.GetIdentity()
885+
client := testContext.Client
886+
887+
// Create Disk
888+
volName, volID := createAndValidateUniqueZonalDisk(client, p, z)
889+
890+
// Create Snapshot
891+
snapshotName := testNamePrefix + string(uuid.NewUUID())
892+
testImageFamily := "test-family"
893+
894+
snapshotParams := map[string]string{common.ParameterKeySnapshotType: common.DiskImageType, common.ParameterKeyImageFamily: testImageFamily}
895+
snapshotID, err := client.CreateSnapshot(snapshotName, volID, snapshotParams)
896+
Expect(err).To(BeNil(), "CreateSnapshot failed with error: %v", err)
897+
898+
// Validate Snapshot Created
899+
snapshot, err := computeService.Images.Get(p, snapshotName).Do()
900+
Expect(err).To(BeNil(), "Could not get snapshot from cloud directly")
901+
Expect(snapshot.Name).To(Equal(snapshotName))
902+
903+
err = wait.Poll(10*time.Second, 3*time.Minute, func() (bool, error) {
904+
snapshot, err := computeService.Images.Get(p, snapshotName).Do()
905+
Expect(err).To(BeNil(), "Could not get snapshot from cloud directly")
906+
if snapshot.Status == "READY" {
907+
return true, nil
908+
}
909+
return false, nil
910+
})
911+
Expect(err).To(BeNil(), "Could not wait for snapshot be ready")
912+
913+
// Check Snapshot Type
914+
snapshot, err = computeService.Images.Get(p, snapshotName).Do()
915+
Expect(err).To(BeNil(), "Could not get snapshot from cloud directly")
916+
_, snapshotType, _, err := common.SnapshotIDToProjectKey(cleanSelfLink(snapshot.SelfLink))
917+
Expect(err).To(BeNil(), "Failed to parse snapshot ID")
918+
Expect(snapshotType).To(Equal(common.DiskImageType), "Expected images type in snapshot ID")
919+
920+
defer func() {
921+
// Delete Disk
922+
err := client.DeleteVolume(volID)
923+
Expect(err).To(BeNil(), "DeleteVolume failed")
924+
925+
// Validate Disk Deleted
926+
_, err = computeService.Disks.Get(p, z, volName).Do()
927+
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
928+
929+
// Delete Snapshot
930+
err = client.DeleteSnapshot(snapshotID)
931+
Expect(err).To(BeNil(), "DeleteSnapshot failed")
932+
933+
// Validate Snapshot Deleted
934+
_, err = computeService.Images.Get(p, snapshotName).Do()
935+
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected snapshot to not be found")
936+
}()
937+
})
879938
})
880939

881940
func equalWithinEpsilon(a, b, epsiolon int64) bool {
@@ -955,3 +1014,9 @@ func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, proje
9551014

9561015
return volName, volID
9571016
}
1017+
1018+
func cleanSelfLink(selfLink string) string {
1019+
temp := strings.TrimPrefix(selfLink, gce.GCEComputeAPIEndpoint)
1020+
temp = strings.TrimPrefix(temp, gce.GCEComputeBetaAPIEndpoint)
1021+
return strings.TrimPrefix(temp, gce.GCEComputeAlphaAPIEndpoint)
1022+
}
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/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:-false}
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=pd-volumesnapshotclass.yaml"
106+
else
107+
base_cmd="${base_cmd} --snapshotclass-file=image-volumesnapshotclass.yaml"
108+
fi
109+
103110
eval "$base_cmd"

test/run-k8s-integration-local.sh

+10
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-gke-release-staging-head --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.

0 commit comments

Comments
 (0)