-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path0_s3mgrt_migrate_test.go
249 lines (207 loc) · 10.5 KB
/
0_s3mgrt_migrate_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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package cli_tests
import (
"fmt"
"strings"
"testing"
"time"
"github.com/0chain/system_test/internal/api/util/test"
cliutils "github.com/0chain/system_test/internal/cli/util"
"github.com/stretchr/testify/require"
)
func Test0S3Migration(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
if s3SecretKey == "" || s3AccessKey == "" {
t.Skip("s3SecretKey or s3AccessKey was missing")
}
t.SetSmokeTests("Should migrate existing bucket successfully")
t.RunSequentially("Should migrate existing bucket successfully", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"secret-key": s3SecretKey,
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.Nil(t, err, "Unexpected migration failure", strings.Join(output, "\n"))
require.Equal(t, len(output), 1, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, "Migration completed successfully", output[0], "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should migrate empty bucket successfully", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"secret-key": s3SecretKey,
"bucket": "system-tests-empty",
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.Nil(t, err, "Unexpected migration failure", strings.Join(output, "\n"))
require.Equal(t, len(output), 1, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, "Migration completed successfully", output[0], "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when bucket too large for allocation", func(t *test.SystemTest) {
allocSize := int64(64 * KB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"secret-key": s3SecretKey,
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, output[0], "max_allocation_size", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when bucket does not exist", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"secret-key": s3SecretKey,
"bucket": "invalid",
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, output[0], "Error: operation error S3: GetBucketLocation, https response error StatusCode: 403", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when bucket flag missing", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"secret-key": s3SecretKey,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, output[0], "Error: open : no such file or directory", "Output was not as expected", strings.Join(output, "\n")) // FIXME error message could be better here
})
t.RunSequentially("Should fail when allocation flag missing", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
_ = setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"secret-key": s3SecretKey,
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, output[0], "Error: allocation id is missing", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when access key invalid", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": "invalid",
"secret-key": s3SecretKey,
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, output[0], "Error: operation error S3: GetBucketLocation, https response error StatusCode: 403", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when access key missing", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"secret-key": s3SecretKey,
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Equal(t, output[0], "Error: aws credentials missing", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when secret key invalid", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"secret-key": "invalid",
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, output[0], "Error: operation error S3: GetBucketLocation, https response error StatusCode: 403", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when secret key missing", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": s3AccessKey,
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Equal(t, output[0], "Error: aws credentials missing", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when access and secret key invalid", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"access-key": "invalid",
"secret-key": "invalid",
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Contains(t, output[0], "Error: operation error S3: GetBucketLocation, https response error StatusCode: 403", "Output was not as expected", strings.Join(output, "\n"))
})
t.RunSequentially("Should fail when access and secret key missing", func(t *test.SystemTest) {
allocSize := int64(50 * MB)
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
})
output, err := migrateFromS3(t, configPath, createParams(map[string]interface{}{
"bucket": s3bucketName,
"wallet": escapedTestName(t) + "_wallet.json",
"allocation": allocationID,
}))
require.NotNil(t, err, "Expected a migration failure but got no error", strings.Join(output, "\n"))
require.Greater(t, len(output), 0, "More/Less output was returned than expected", strings.Join(output, "\n"))
require.Equal(t, output[0], "Error: aws credentials missing", "Output was not as expected", strings.Join(output, "\n"))
})
}
func migrateFromS3(t *test.SystemTest, cliConfigFilename, params string) ([]string, error) {
t.Logf("Migrating S3 bucket to Zus...")
return cliutils.RunCommand(t, fmt.Sprintf("./s3mgrt migrate --silent --configDir ./config --config %s --network %s %s", cliConfigFilename, cliConfigFilename, params), 1, time.Second*2)
}