forked from yp-engineering/rbd-docker-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unlock_test.go
52 lines (44 loc) · 1.23 KB
/
unlock_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2015 YP LLC.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package main
// trying to write a small test to reproduce (un)locking issues
import (
"bytes"
"fmt"
"log"
"os/exec"
"strings"
"testing"
//"github.com/stretchr/testify/assert"
assert "github.com/stretchr/testify/require"
)
//"github.com/ceph/go-ceph/rbd"
//"github.com/ceph/go-ceph/rados"
var (
//testDriver cephRBDVolumeDriver
testPool = "rbd"
testImage = "rbd-test"
)
func TestShUnlockImage(t *testing.T) {
// lock it first ... ?
locker, err := testDriver.lockImage(testPool, testImage)
if err != nil {
log.Printf("WARN: Unable to lock image in preparation for test: %s", err)
locker = testDriver.localLockerCookie()
}
// now unlock it
err = testDriver.unlockImage(testPool, testImage, locker)
assert.Nil(t, err, fmt.Sprintf("Unable to unlock image using sh rbd: %s", err))
}
func test_sh(name string, args ...string) (string, error) {
cmd := exec.Command(name, args...)
log.Printf("DEBUG: sh CMD: %q", cmd)
var stderr bytes.Buffer
cmd.Stderr = &stderr
out, err := cmd.Output()
if err != nil {
log.Printf("ERROR: %q: %s", err, stderr)
}
return strings.Trim(string(out), " \n"), err
}