@@ -10,12 +10,14 @@ import (
10
10
"io/ioutil"
11
11
"math/rand"
12
12
"os"
13
+ "syscall"
13
14
"testing"
14
15
15
16
pmdmanager "github.com/intel/pmem-csi/pkg/pmem-device-manager"
16
17
pmemexec "github.com/intel/pmem-csi/pkg/pmem-exec"
17
18
. "github.com/onsi/ginkgo"
18
19
. "github.com/onsi/gomega"
20
+ "github.com/pkg/errors"
19
21
losetup "gopkg.in/freddierice/go-losetup.v1"
20
22
)
21
23
@@ -58,7 +60,7 @@ var _ = Describe("DeviceManage LVM", func() {
58
60
59
61
dev , err := dm .GetDevice (name )
60
62
Expect (err ).Should (BeNil (), "Failed to retrieve device info" )
61
- Expect (dev .Name ).Should (Equal (name ), "Name mismatch" )
63
+ Expect (dev .VolumeId ).Should (Equal (name ), "Name mismatch" )
62
64
Expect (dev .Size >= size ).Should (BeTrue (), "Size mismatch" )
63
65
Expect (dev .Path ).ShouldNot (BeNil (), "Null device path" )
64
66
})
@@ -89,8 +91,8 @@ var _ = Describe("DeviceManage LVM", func() {
89
91
Expect (err ).Should (BeNil (), "Failed to list devices" )
90
92
Expect (len (list )).Should (BeEquivalentTo (max_devices ), "count mismatch" )
91
93
for _ , dev := range list {
92
- size , ok := sizes [dev .Name ]
93
- Expect (ok ).Should (BeTrue (), "Unexpected device name:" + dev .Name )
94
+ size , ok := sizes [dev .VolumeId ]
95
+ Expect (ok ).Should (BeTrue (), "Unexpected device name:" + dev .VolumeId )
94
96
Expect (dev .Size >= size ).Should (BeTrue (), "Device size mismatch" )
95
97
}
96
98
@@ -106,8 +108,8 @@ var _ = Describe("DeviceManage LVM", func() {
106
108
Expect (err ).Should (BeNil (), "Failed to list devices" )
107
109
Expect (len (list )).Should (BeEquivalentTo (max_devices - max_deletes ), "count mismatch" )
108
110
for _ , dev := range list {
109
- size , ok := sizes [dev .Name ]
110
- Expect (ok ).Should (BeTrue (), "Unexpected device name:" + dev .Name )
111
+ size , ok := sizes [dev .VolumeId ]
112
+ Expect (ok ).Should (BeTrue (), "Unexpected device name:" + dev .VolumeId )
111
113
Expect (dev .Size >= size ).Should (BeTrue (), "Device size mismatch" )
112
114
}
113
115
})
@@ -120,10 +122,27 @@ var _ = Describe("DeviceManage LVM", func() {
120
122
121
123
dev , err := dm .GetDevice (name )
122
124
Expect (err ).Should (BeNil (), "Failed to retrieve device info" )
123
- Expect (dev .Name ).Should (Equal (name ), "Name mismatch" )
125
+ Expect (dev .VolumeId ).Should (Equal (name ), "Name mismatch" )
124
126
Expect (dev .Size >= size ).Should (BeTrue (), "Size mismatch" )
125
127
Expect (dev .Path ).ShouldNot (BeNil (), "Null device path" )
126
128
129
+ mountPath , err := mountDevice (& dev )
130
+ Expect (err ).Should (BeNil (), "Failed to create mount path: %s" , mountPath )
131
+
132
+ defer unmount (mountPath )
133
+
134
+ out , _ := pmemexec .RunCommand ("df" )
135
+ fmt .Println (out )
136
+
137
+ // Delete should fail as the device is in use
138
+ err = dm .DeleteDevice (name , true )
139
+ Expect (err ).ShouldNot (BeNil (), "Error expected when deleting device in use: %s" , dev .VolumeId )
140
+ Expect (errors .Cause (err )).Should (BeEquivalentTo (syscall .EBUSY ), "Expected device busy error: %s" , dev .VolumeId )
141
+
142
+ err = unmount (mountPath )
143
+ Expect (err ).Should (BeNil (), "Failed to unmount the device: %s" , dev .VolumeId )
144
+
145
+ // Delete should succeed
127
146
err = dm .DeleteDevice (name , true )
128
147
Expect (err ).Should (BeNil (), "Failed to delete device" )
129
148
@@ -132,9 +151,12 @@ var _ = Describe("DeviceManage LVM", func() {
132
151
//Expect(os.IsNotExist(errors.Cause())).Should(BeTrue(), "expected error is os.ErrNotExist")
133
152
//Expect(dev).Should(BeNil(), "returned device should be nil")
134
153
154
+ // Delete call should not return any error on non-existing device
135
155
err = dm .DeleteDevice (name , true )
136
156
Expect (err ).Should (BeNil (), "DeleteDevice() is not idempotent" )
157
+
137
158
})
159
+
138
160
})
139
161
})
140
162
@@ -227,3 +249,36 @@ func (vg *testVGS) Clean() error {
227
249
228
250
return nil
229
251
}
252
+
253
+ func mountDevice (device * pmdmanager.PmemDeviceInfo ) (string , error ) {
254
+ targetPath , err := ioutil .TempDir ("/tmp" , "lmv-mnt-path-" )
255
+ if err != nil {
256
+ return "" , err
257
+ }
258
+
259
+ cmd := "mkfs.ext4"
260
+ args := []string {"-b 4096" , "-F" , device .Path }
261
+
262
+ if _ , err := pmemexec .RunCommand (cmd , args ... ); err != nil {
263
+ os .Remove (targetPath )
264
+ return "" , err
265
+ }
266
+
267
+ cmd = "mount"
268
+ args = []string {"-c" , device .Path , targetPath }
269
+
270
+ if _ , err := pmemexec .RunCommand (cmd , args ... ); err != nil {
271
+ os .Remove (targetPath )
272
+ return "" , err
273
+ }
274
+
275
+ return targetPath , nil
276
+ }
277
+
278
+ func unmount (path string ) error {
279
+ args := []string {path }
280
+ if _ , err := pmemexec .RunCommand ("umount" , args ... ); err != nil {
281
+ return err
282
+ }
283
+ return os .Remove (path )
284
+ }
0 commit comments