/
manilavolume.go
114 lines (89 loc) · 2.38 KB
/
manilavolume.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package test
import (
"bytes"
"context"
"os/exec"
"strconv"
"strings"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"k8s.io/kubernetes/test/e2e/framework"
storageframework "k8s.io/kubernetes/test/e2e/storage/framework"
)
func runCmd(name string, args ...string) ([]byte, error) {
var stdout, stderr bytes.Buffer
cmd := exec.Command(name, args...)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
framework.Logf("Running %s %v", cmd.Path, cmd.Args)
err := cmd.Run()
framework.Logf("Stdout output %s %v: `%s`", cmd.Path, cmd.Args, stdout.String())
framework.Logf("Stderr output %s %v: `%s`", cmd.Path, cmd.Args, stderr.String())
return stdout.Bytes(), err
}
// It is assumed that the `openstack` and other related programs
// are accessible from $PATH on the node.
type manilaVolume struct {
shareID string
accessID string
}
func manilaCreateVolume(
shareProto,
accessType,
accessTo string,
sizeInGiB int,
config *storageframework.PerTestConfig,
) storageframework.TestVolume {
ginkgo.By("Creating a test Manila volume externally")
// Create share.
out, err := runCmd(
"openstack",
"share",
"create",
shareProto,
strconv.Itoa(sizeInGiB),
"--property=provisioned-by=manila.csi.openstack.org/e2e.test",
"--format=value",
"--column=id",
"--wait",
)
shareID := strings.TrimSpace(string(out))
framework.ExpectNoError(err)
gomega.Expect(shareID).ToNot(gomega.BeEmpty())
framework.Logf("Created test Manila volume %s", shareID)
// Grant access to the share.
out, err = runCmd(
"openstack",
"share",
"access",
"create",
shareID,
accessType,
accessTo,
"--format=value",
"--column=id",
)
// XXX: In case of cephx access rights, the access_key field might
// not be generated in time for when the volume is mounted.
// Tests may fail. A workaround would be to wait until it is ready.
accessID := strings.TrimSpace(string(out))
framework.ExpectNoError(err)
gomega.Expect(accessID).ToNot(gomega.Equal(""))
framework.Logf("Created access right %s for Manila volume %s", accessID, shareID)
return &manilaVolume{
shareID: shareID,
accessID: accessID,
}
}
func (v *manilaVolume) DeleteVolume(ctx context.Context) {
ginkgo.By("Deleting test Manila volume externally")
_, err := runCmd(
"openstack",
"share",
"delete",
v.shareID,
)
if err != nil {
framework.Failf("Failed to remove Manila volume %s: %v", v.shareID, err)
}
}