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
/
volume_access_test.go
174 lines (135 loc) · 7.29 KB
/
volume_access_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
// 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.
// The goal of this test suite is to verify read/write consistency on volumes
// in accordance with the access updates on the volume
// +build runalways
package e2e
import (
"strings"
. "gopkg.in/check.v1"
adminconst "github.com/vmware/vsphere-storage-for-docker/tests/constants/admincli"
"github.com/vmware/vsphere-storage-for-docker/tests/utils/admincli"
"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"
)
const (
errorWriteVolume = "Read-only file system"
)
type VolumeAccessTestSuite struct {
config *inputparams.TestConfig
volumeName string
}
func (s *VolumeAccessTestSuite) SetUpSuite(c *C) {
s.config = inputparams.GetTestConfig()
if s.config == nil {
c.Skip("Unable to retrieve test config, skipping volume access tests")
}
}
func (s *VolumeAccessTestSuite) SetUpTest(c *C) {
dsName := s.config.Datastores[0]
s.volumeName = inputparams.GetUniqueVolumeName("vol_access") + "@" + dsName
}
func (s *VolumeAccessTestSuite) TearDownTest(c *C) {
out, err := dockercli.DeleteVolume(s.config.DockerHosts[0], s.volumeName)
c.Assert(err, IsNil, Commentf(out))
}
var _ = Suite(&VolumeAccessTestSuite{})
// Verify read, write is possible after volume access update
// 1. Write a message from host1 to a file on the volume
// 2. Read the content from host2 from same file on the volume
// Verify the content is same.
// 3. Write another message from host2 to the same file on that volume
// 4. Read from host1 and verify the content is same
// 5. Update the volume access to read-only
// 6. Write from host1 to the file on volume should fail
// 7. Write from host2 should also fail
// 8. Update the volume access to read-write
// 9. Write from host1 should succeed
// 10. Read from host2 to verify the content is same
// 11. Write from host2 should succeed
// 12. Read from host1 to verify the content is same
func (s *VolumeAccessTestSuite) TestAccessUpdate(c *C) {
misc.LogTestStart(c.TestName())
data1 := "message_by_host1"
data2 := "message_by_host2"
testFile := "test.txt"
// Create a volume
out, err := dockercli.CreateVolume(s.config.DockerHosts[0], s.volumeName)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.WriteToVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data1)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.ReadFromVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile)
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data1)
out, err = dockercli.WriteToVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data2)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.ReadFromVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile)
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data2)
out, err = admincli.UpdateVolumeAccess(s.config.EsxHost, s.volumeName, adminconst.DefaultVMgroup, adminconst.ReadOnlyAccess)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.WriteToVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data1)
c.Assert(strings.Contains(out, errorWriteVolume), Equals, true, Commentf(out))
out, err = dockercli.WriteToVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data2)
c.Assert(strings.Contains(out, errorWriteVolume), Equals, true, Commentf(out))
out, err = admincli.UpdateVolumeAccess(s.config.EsxHost, s.volumeName, adminconst.DefaultVMgroup, adminconst.ReadWriteAccess)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.WriteToVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data1)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.ReadFromVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile)
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data1)
out, err = dockercli.WriteToVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data2)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.ReadFromVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile)
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data2)
misc.LogTestEnd(c.TestName())
}
// Verify read, write is possible after volume access update
// 1. Create a volume with read-only access
// 2. Write from host1 to the file on volume should fail
// 3. Write from host2 should also fail
// 4. Update the volume access to read-write
// 5. Write from host1 should succeed
// 6. Read from host2 to verify the content is same
// 7. Write from host2 should succeed
// 8. Read from host1 to verify the content is same
func (s *VolumeAccessTestSuite) TestAccessUpdate_R_RW(c *C) {
misc.LogTestStart(c.TestName())
data1 := "message_by_host1"
data2 := "message_by_host2"
testFile := "test.txt"
// Create a volume
out, err := dockercli.CreateVolumeWithOptions(s.config.DockerHosts[0], s.volumeName, " -o access="+adminconst.ReadOnlyAccess)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.WriteToVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data1)
c.Assert(strings.Contains(out, errorWriteVolume), Equals, true, Commentf(out))
out, err = dockercli.WriteToVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data2)
c.Assert(strings.Contains(out, errorWriteVolume), Equals, true, Commentf(out))
out, err = admincli.UpdateVolumeAccess(s.config.EsxHost, s.volumeName, adminconst.DefaultVMgroup, adminconst.ReadWriteAccess)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.WriteToVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data1)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.ReadFromVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile)
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data1)
out, err = dockercli.WriteToVolume(s.config.DockerHosts[1], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile, data2)
c.Assert(err, IsNil, Commentf(out))
out, err = dockercli.ReadFromVolume(s.config.DockerHosts[0], s.volumeName, inputparams.GetUniqueContainerName("vol_access"), testFile)
c.Assert(err, IsNil, Commentf(out))
c.Assert(out, Equals, data2)
misc.LogTestEnd(c.TestName())
}