forked from openebs/mayastor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_nexus_grpc.js
341 lines (295 loc) · 8.82 KB
/
test_nexus_grpc.js
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
'use strict';
const assert = require('chai').assert;
const async = require('async');
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const { createClient } = require('grpc-kit');
const grpc = require('grpc');
const common = require('./test_common');
// just some UUID used for nexus ID
const UUID = 'dbe4d7eb-118a-4d15-b789-a18d9af6ff21';
const UUID2 = 'dbe4d7eb-118a-4d15-b789-a18d9af6ff22';
// tunables of the test suite
var endpoint = process.env.MAYASTOR_ENDPOINT;
let config = `
[ISCSI]
NodeBase "iqn.2016-06.io.openebs"
# Socket I/O timeout sec. (0 is infinite)
Timeout 30
DiscoveryAuthMethod None
DefaultTime2Wait 2
DefaultTime2Retain 60
ImmediateData Yes
ErrorRecoveryLevel 0
[Malloc]
NumberOfLuns 2
LunSizeInMB 64
BlockSize 4096
[PortalGroup1]
Portal GR1 0.0.0.0:3261
[InitiatorGroup1]
InitiatorName Any
Netmask 127.0.0.1/24
[TargetNode0]
TargetName "iqn.2016-06.io.openebs:disk0"
TargetAlias "Data Disk0"
Mapping PortalGroup1 InitiatorGroup1
AuthMethod None
UseDigest Auto
LUN0 Malloc0
QueueDepth 128
[TargetNode1]
TargetName "iqn.2016-06.io.openebs:disk1"
TargetAlias "Data Disk1"
Mapping PortalGroup1 InitiatorGroup1
AuthMethod None
LUN0 Malloc1
QueueDepth 128
`;
let nbd_device;
after(common.stopMayastor);
describe('nexus_grpc', function() {
this.timeout(200000); // for network e2e tests we need long timeouts
// start mayastor if needed
before(() => {
// if no explicit gRPC endpoint given then create one by starting
// mayastor and grpc server
if (!endpoint) {
endpoint = common.endpoint;
common.startMayastor(config);
common.startMayastorGrpc();
}
});
// stop mayastor server if it was started by us
after(common.stopMayastor);
describe('nexus', function() {
var client;
before(done => {
client = createClient(
{
protoPath: path.join(
__dirname,
'..',
'rpc',
'proto',
'mayastor_service.proto'
),
packageName: 'mayastor_service',
serviceName: 'Mayastor',
options: {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
},
},
endpoint
);
if (!client) {
return done(new Error('Failed to initialize grpc client'));
}
async.series(
[
next => {
common.waitForMayastor(pingDone => {
// use harmless method to test if the mayastor is up and running
client.listPools({}, pingDone);
}, next);
},
next => {
// We need to read/write the raw device from test suite
let child = common.runAsRoot('sh', ['-c', 'chmod o+rw /dev/nbd*']);
child.stderr.on('data', data => {
console.log(data.toString());
});
child.on('close', (code, signal) => {
if (code != 0) {
next(new Error('Failed to chmod nbd devs'));
} else {
next();
}
});
},
],
done
);
});
after(done => {
async.series(
[
next => {
// Undo change of permissions on /dev/nbd*
let child = common.runAsRoot('sh', ['-c', 'chmod o-rw /dev/nbd*']);
child.on('close', (code, signal) => {
if (code != 0) {
next(new Error('Failed to chmod nbd devs'));
} else {
next();
}
});
},
],
err => {
if (client != null) {
client.close();
}
done(err);
}
);
});
it('Should not list any nexus devices', done => {
client.ListNexus({}, (err, res) => {
assert(res.nexus_list.length === 0);
done();
});
});
it('it should be able to create a Nexus using two iSCSI URI', done => {
let args = {
uuid: UUID,
size: 131072,
children: [
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk0',
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk1',
],
};
client.CreateNexus(args, done);
});
it('should be able to list the created nexus', done => {
client.ListNexus({}, (err, res) => {
assert(res.nexus_list.length !== 0);
let nexus = res.nexus_list[0];
assert(nexus.uuid === UUID);
assert(nexus.state === 'online');
assert(nexus.children.length === 2);
assert(nexus.children[0].state === nexus.children[1].state);
done();
});
});
it('should succeed creating the same nexus again', done => {
let args = {
uuid: UUID,
size: 131072,
children: [
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk0',
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk1',
],
};
client.CreateNexus(args, done);
});
it('should succeed creating the same nexus nexus again but with different URIs', done => {
let args = {
uuid: UUID,
size: 131072,
children: [
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk2',
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk3',
],
};
client.CreateNexus(args, done);
});
it('should fail to create another nexus with in use URIs', done => {
let args = {
uuid: UUID2,
size: 131072,
children: [
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk0',
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk1',
],
};
client.CreateNexus(args, (err, res) => {
assert(err.code === 13);
done();
});
});
it('should fail creating a nexus with non existing URIs', done => {
let args = {
uuid: UUID2,
size: 131072,
children: [
'iscsi://127.0.0.1:3261/iqn.2016-06.io.spdk:disk2',
'iscsi://127.0.0.1:3261/iqn.2016-06.io.spdk:disk3',
],
};
client.CreateNexus(args, (err, res) => {
assert(err.code === 13);
done();
});
});
it('should be able to publish a nexus device using nbd', done => {
client.PublishNexus({ uuid: UUID }, (err, res) => {
assert(res.device_path);
nbd_device = res.device_path;
done();
});
});
it('should be able to write to the nbd device', done => {
fs.open(nbd_device, 'w', 666, (err, fd) => {
if (err) return done(err);
let buffer = Buffer.alloc(512, 'z', 'utf8');
fs.write(fd, buffer, 0, 512, (err, nr, buffer) => {
if (err) return done(err);
assert(nr === 512);
assert(buffer[0] === 122);
assert(buffer[511] === 122);
fs.fsync(fd, err => {
if (err) done(err);
fs.close(fd, () => {
done();
});
});
});
});
});
it('should be able to read the written data back', done => {
fs.open(nbd_device, 'r', 666, (err, fd) => {
if (err) done(err);
let buffer = Buffer.alloc(512, 'a', 'utf8');
fs.read(fd, buffer, 0, 512, 0, (err, nr, buffer) => {
if (err) done(err);
buffer.forEach(function(e){
assert(e === 122);
});
fs.close(fd, () => {
done();
});
});
});
});
it('should be able to unpublish the nexus device', done => {
client.unpublishNexus({ uuid: UUID }, done);
});
it('should be able to destroy the nexus', done => {
client.DestroyNexus({ uuid: UUID }, done);
});
it('it should be able to re-create a Nexus using two iSCSI URI', done => {
let args = {
uuid: UUID,
size: 131072,
children: [
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk0',
'iscsi://127.0.0.1:3261/iqn.2016-06.io.openebs:disk1',
],
};
client.CreateNexus(args, done);
});
it('should be able to publish the new nexus device using NBD and a crypto key', done => {
client.PublishNexus({ uuid: UUID, key: '0123456789123456' }, (err, res) => {
assert(res.device_path);
nbd_device = res.device_path;
done();
});
});
it('should be able to unpublish the encrypted nexus device', done => {
client.unpublishNexus({ uuid: UUID }, done);
});
it('should be able to publish a nexus device using NBD and a crypto key and then immediately destroy it', done => {
client.PublishNexus({ uuid: UUID, key: '0123456789123456' }, (err, res) => {
assert(res.device_path);
nbd_device = res.device_path;
client.DestroyNexus({ uuid: UUID }, done);
});
});
});
});