Skip to content

Commit

Permalink
create volume will not fail with existing volume for spectrum scale
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mohamed <mmohamed@us.ibm.com>
  • Loading branch information
midoblgsm committed Oct 25, 2017
1 parent 7b79335 commit 8606fc4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion local/spectrumscale/spectrumscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *spectrumLocalClient) CreateVolume(createVolumeRequest resources.CreateV
}

if volExists {
return fmt.Errorf("Volume already exists")
return nil
}

s.logger.Printf("Opts for create: %#v\n", createVolumeRequest.Opts)
Expand Down
16 changes: 8 additions & 8 deletions local/spectrumscale/spectrumscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ var _ = Describe("local-client", func() {
Expect(fakeSpectrumScaleConnector.CreateFilesetCallCount()).To(Equal(0))
})

It("should fail when dbClient volumeExists returns true", func() {
fakeSpectrumDataModel.GetVolumeReturns(spectrumscale.SpectrumScaleVolume{}, true, nil)
err = client.CreateVolume(createVolumeRequest)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Volume already exists"))
Expect(fakeSpectrumDataModel.GetVolumeCallCount()).To(Equal(1))
Expect(fakeSpectrumScaleConnector.CreateFilesetCallCount()).To(Equal(0))
})
//It("should fail when dbClient volumeExists returns true", func() {
// fakeSpectrumDataModel.GetVolumeReturns(spectrumscale.SpectrumScaleVolume{}, true, nil)
// err = client.CreateVolume(createVolumeRequest)
// Expect(err).To(HaveOccurred())
// Expect(err.Error()).To(Equal("Volume already exists"))
// Expect(fakeSpectrumDataModel.GetVolumeCallCount()).To(Equal(1))
// Expect(fakeSpectrumScaleConnector.CreateFilesetCallCount()).To(Equal(0))
//})

Context(".FilesetVolume", func() {
BeforeEach(func() {
Expand Down
14 changes: 7 additions & 7 deletions web_server/storage_api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func (h *StorageApiHandler) CreateVolume() http.HandlerFunc {
return
}

h.locker.ReadLock(createVolumeRequest.Name) // will block if another caller is already in process of creating volume with same name
if exists := h.getVolumeExists(createVolumeRequest.Name); exists == true {
utils.WriteResponse(w, 409, &resources.GenericResponse{Err: fmt.Sprintf("Volume `%s` already exists", createVolumeRequest.Name)})
h.locker.ReadUnlock(createVolumeRequest.Name)
return
}
h.locker.ReadUnlock(createVolumeRequest.Name)
//h.locker.ReadLock(createVolumeRequest.Name) // will block if another caller is already in process of creating volume with same name
//if exists := h.getVolumeExists(createVolumeRequest.Name); exists == true {
// utils.WriteResponse(w, 409, &resources.GenericResponse{Err: fmt.Sprintf("Volume `%s` already exists", createVolumeRequest.Name)})
// h.locker.ReadUnlock(createVolumeRequest.Name)
// return
//}
//h.locker.ReadUnlock(createVolumeRequest.Name)

h.locker.WriteLock(createVolumeRequest.Name) // will ensure no other caller can create volume with same name concurrently
defer h.locker.WriteUnlock(createVolumeRequest.Name)
Expand Down

0 comments on commit 8606fc4

Please sign in to comment.