This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
volumecreate_test.go
197 lines (163 loc) · 5.63 KB
/
volumecreate_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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright 2017 VMware, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This test is going to cover various volume creation test cases
// +build runonce runoncewin
package e2e
import (
"strings"
"sync"
dockerclicon "github.com/vmware/vsphere-storage-for-docker/tests/constants/dockercli"
"github.com/vmware/vsphere-storage-for-docker/tests/utils/dockercli"
"github.com/vmware/vsphere-storage-for-docker/tests/utils/inputparams"
"github.com/vmware/vsphere-storage-for-docker/tests/utils/misc"
"github.com/vmware/vsphere-storage-for-docker/tests/utils/verification"
. "gopkg.in/check.v1"
)
type VolumeCreateTestSuite struct {
config *inputparams.TestConfig
volumeList []string
}
func (s *VolumeCreateTestSuite) SetUpSuite(c *C) {
s.config = inputparams.GetTestConfig()
if s.config == nil {
c.Skip("Unable to retrieve test config, skipping volume create tests")
}
}
func (s *VolumeCreateTestSuite) TearDownTest(c *C) {
volList := strings.Join(s.volumeList, " ")
if volList != "" {
out, err := dockercli.DeleteVolume(s.config.DockerHosts[0], volList)
c.Assert(err, IsNil, Commentf(out))
}
// clean the list of volumes created
s.volumeList = s.volumeList[:0]
}
var _ = Suite(&VolumeCreateTestSuite{})
// create volume and do valid/invalid assertion
func (s *VolumeCreateTestSuite) createVolCheck(name, option string, valid bool, c *C) {
var out string
var err error
if option == "" {
out, err = dockercli.CreateVolume(s.config.DockerHosts[0], name)
} else {
out, err = dockercli.CreateVolumeWithOptions(s.config.DockerHosts[0], name, option)
}
// if creation is successful, add it to the list so that it gets cleaned later
if err == nil {
s.volumeList = append(s.volumeList, name)
}
if valid {
// positive test case
c.Assert(err, IsNil, Commentf(out))
} else {
// negative test case
c.Assert(err, Not(IsNil), Commentf(out))
c.Assert(strings.HasPrefix(out, dockerclicon.ErrorVolumeCreate), Equals, true, Commentf(out))
}
}
// loop over volume names to parallely create volumes
func (s *VolumeCreateTestSuite) parallelCreateByName(names []string, valid bool, c *C) {
var wg sync.WaitGroup
for _, volName := range names {
wg.Add(1)
go func(name string) {
defer wg.Done()
s.createVolCheck(name, "", valid, c)
}(volName)
}
wg.Wait()
}
// loop over volume options to parallely create volumes
func (s *VolumeCreateTestSuite) parallelCreateByOption(options []string, valid bool, c *C) {
var wg sync.WaitGroup
for _, volOption := range options {
wg.Add(1)
go func(option string) {
defer wg.Done()
volName := inputparams.GetUniqueVolumeName("option")
s.createVolCheck(volName, option, valid, c)
}(volOption)
}
wg.Wait()
}
func (s *VolumeCreateTestSuite) accessCheck(hostIP string, volList []string, c *C) {
isAvailable := verification.CheckVolumeListAvailability(hostIP, volList)
c.Assert(isAvailable, Equals, true, Commentf("Volume %s is not available after creation", volList))
}
// Valid volume names test
func (s *VolumeCreateTestSuite) TestValidName(c *C) {
misc.LogTestStart(c.TestName())
s.parallelCreateByName(s.validVolNames(), true, c)
s.accessCheck(s.config.DockerHosts[0], s.volumeList, c)
misc.LogTestEnd(c.TestName())
}
// Invalid volume names test
func (s *VolumeCreateTestSuite) TestInvalidName(c *C) {
misc.LogTestStart(c.TestName())
s.parallelCreateByName(invalidVolNameList, false, c)
misc.LogTestEnd(c.TestName())
}
// Valid volume creation options
// 1. size 10gb
// 2. disk format (thin, zeroedthick, eagerzeroedthick)
// 3. attach-as (persistent, independent_persistent)
// 4. fstype ext4 for linux / ntfs for windows
// 5. access (read-write, read-only)
// 6. clone-from valid volume
func (s *VolumeCreateTestSuite) TestValidOptions(c *C) {
misc.LogTestStart(c.TestName())
// Need a valid volume source to test clone-from option
cloneSrcVol := inputparams.GetUniqueVolumeName("clone_src")
s.volumeList = append(s.volumeList, cloneSrcVol)
out, err := dockercli.CreateVolume(s.config.DockerHosts[0], cloneSrcVol)
c.Assert(err, IsNil, Commentf(out))
validVolOpts := []string{
" -o size=10gb",
" -o diskformat=zeroedthick",
" -o diskformat=thin",
" -o diskformat=eagerzeroedthick",
" -o attach-as=independent_persistent",
" -o attach-as=persistent",
" -o fstype=" + validFstype,
" -o access=read-only",
" -o access=read-write",
" -o clone-from=" + cloneSrcVol,
}
s.parallelCreateByOption(validVolOpts, true, c)
s.accessCheck(s.config.DockerHosts[0], s.volumeList, c)
misc.LogTestEnd(c.TestName())
}
// Invalid volume create operations
// 1. Wrong disk formats
// 2. Wrong volume sizes
// 3. Wrong fs types
// 4. Wrong access types
// 5. Unavailable clone source
func (s *VolumeCreateTestSuite) TestInvalidOptions(c *C) {
misc.LogTestStart(c.TestName())
invalidVolOpts := []string{
" -o diskformat=zeroedthickk",
" -o diskformat=zeroedthick,thin",
" -o size=100mbb",
" -o size=100gbEE",
" -o sizes=100mb",
" -o fstype=xfs_ext",
" -o access=read-write-both",
" -o access=write-only",
" -o access=read-write-both",
" -o clone-from=IDontExist",
}
s.parallelCreateByOption(invalidVolOpts, false, c)
misc.LogTestEnd(c.TestName())
}