Skip to content

Commit 737acf4

Browse files
Set internalName on GCNV SAN import and add test
1 parent 1780201 commit 737acf4

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

storage_drivers/gcp/gcp_gcnv_san.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,10 @@ func (d *SANStorageDriver) Import(ctx context.Context, volConfig *storage.Volume
14331433
}
14341434

14351435
volConfig.Size = strconv.FormatUint(uint64(volume.SizeBytes), 10)
1436+
1437+
// The GCNV creation token cannot be changed, so use it as the internal name
1438+
volConfig.InternalName = originalName
1439+
14361440
// Always save the full GCP ID
14371441
volConfig.InternalID = volume.FullName
14381442

storage_drivers/gcp/gcp_gcnv_san_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,3 +4531,48 @@ func TestSANStorageDriver_Create_PoolNotFound(t *testing.T) {
45314531
assert.Error(t, err)
45324532
assert.Contains(t, err.Error(), "pool unknown_pool does not exist")
45334533
}
4534+
4535+
func TestSANStorageDriver_Import_PreservesInternalName(t *testing.T) {
4536+
mockCtrl := gomock.NewController(t)
4537+
defer mockCtrl.Finish()
4538+
4539+
mockAPI := mockapi.NewMockGCNV(mockCtrl)
4540+
4541+
driver := &SANStorageDriver{
4542+
initialized: true,
4543+
Config: drivers.GCNVStorageDriverConfig{
4544+
CommonStorageDriverConfig: &drivers.CommonStorageDriverConfig{
4545+
StorageDriverName: "google-cloud-netapp-volumes-san",
4546+
},
4547+
},
4548+
API: mockAPI,
4549+
}
4550+
4551+
originalName := "existing-volume"
4552+
volume := &api.Volume{
4553+
Name: originalName,
4554+
FullName: "projects/test-project/locations/us-central1/volumes/existing-volume",
4555+
CreationToken: originalName,
4556+
SizeBytes: testVolumeSize,
4557+
CapacityPool: "test-pool",
4558+
State: api.VolumeStateReady,
4559+
ProtocolTypes: []string{api.ProtocolTypeISCSI},
4560+
}
4561+
4562+
volConfig := &storage.VolumeConfig{
4563+
Name: "new-volume",
4564+
InternalName: "new_volume",
4565+
ImportNotManaged: true,
4566+
}
4567+
4568+
mockAPI.EXPECT().RefreshGCNVResources(gomock.Any()).Return(nil)
4569+
mockAPI.EXPECT().VolumeByName(gomock.Any(), originalName).Return(volume, nil)
4570+
mockAPI.EXPECT().EnsureVolumeInValidCapacityPool(gomock.Any(), volume).Return(nil)
4571+
4572+
err := driver.Import(context.Background(), volConfig, originalName)
4573+
4574+
assert.NoError(t, err)
4575+
assert.Equal(t, originalName, volConfig.InternalName, "internal name should match original volume name")
4576+
assert.Equal(t, volume.FullName, volConfig.InternalID, "internal ID should be set to full volume name")
4577+
assert.Equal(t, strconv.FormatUint(uint64(volume.SizeBytes), 10), volConfig.Size)
4578+
}

0 commit comments

Comments
 (0)