-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
remote_clusters.js
201 lines (170 loc) · 5.82 KB
/
remote_clusters.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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { API_BASE_PATH } from './constants';
export default function ({ getService }) {
const supertest = getService('supertest');
const retry = getService('retry');
const esTransportPort = process.env.TEST_ES_TRANSPORT_PORT
? process.env.TEST_ES_TRANSPORT_PORT.split('-')[0]
: '9300';
const NODE_SEED = `localhost:${esTransportPort}`;
describe('Remote Clusters', function () {
this.tags(['skipCloud']);
describe('Empty List', () => {
it('should return an empty array when there are no remote clusters', async () => {
const uri = `${API_BASE_PATH}`;
const { body } = await supertest.get(uri).expect(200);
expect(body).to.eql([]);
});
});
describe('Add', () => {
it('should allow us to add a remote cluster', async () => {
const uri = `${API_BASE_PATH}`;
const { body } = await supertest
.post(uri)
.set('kbn-xsrf', 'xxx')
.send({
name: 'test_cluster',
seeds: [NODE_SEED],
skipUnavailable: true,
mode: 'sniff',
})
.expect(200);
expect(body).to.eql({
acknowledged: true,
});
});
it('should not allow us to re-add an existing remote cluster', async () => {
const uri = `${API_BASE_PATH}`;
const { body } = await supertest
.post(uri)
.set('kbn-xsrf', 'xxx')
.send({
name: 'test_cluster',
seeds: [NODE_SEED],
skipUnavailable: false,
mode: 'sniff',
})
.expect(409);
expect(body).to.eql({
statusCode: 409,
error: 'Conflict',
message: 'There is already a remote cluster with that name.',
});
});
});
describe('Update', () => {
it('should allow us to update an existing remote cluster', async () => {
const uri = `${API_BASE_PATH}/test_cluster`;
const { body } = await supertest
.put(uri)
.set('kbn-xsrf', 'xxx')
.send({
skipUnavailable: false,
seeds: [NODE_SEED],
mode: 'sniff',
})
.expect(200);
expect(body).to.eql({
name: 'test_cluster',
skipUnavailable: 'false', // ES issue #35671
seeds: [NODE_SEED],
isConfiguredByNode: false,
mode: 'sniff',
securityModel: 'certificate',
});
});
});
describe('List', () => {
it('should return an array of remote clusters', async () => {
const uri = `${API_BASE_PATH}`;
await retry.try(async () => {
// The API to connect a remote clusters is not synchronous so we need to retry several times to avoid any flakiness.
const { body } = await supertest.get(uri);
expect(body).to.eql([
{
name: 'test_cluster',
seeds: [NODE_SEED],
isConnected: true,
connectedNodesCount: 1,
maxConnectionsPerCluster: 3,
initialConnectTimeout: '30s',
skipUnavailable: false,
isConfiguredByNode: false,
mode: 'sniff',
securityModel: 'certificate',
},
]);
});
});
});
describe('Delete', () => {
it('should allow us to delete a remote cluster', async () => {
const uri = `${API_BASE_PATH}/test_cluster`;
const { body } = await supertest.delete(uri).set('kbn-xsrf', 'xxx').expect(200);
expect(body).to.eql({
itemsDeleted: ['test_cluster'],
errors: [],
});
});
it('should allow us to delete multiple remote clusters', async () => {
// Create clusters to delete.
await supertest
.post(API_BASE_PATH)
.set('kbn-xsrf', 'xxx')
.send({
name: 'test_cluster1',
seeds: [NODE_SEED],
skipUnavailable: true,
mode: 'sniff',
})
.expect(200);
await supertest
.post(API_BASE_PATH)
.set('kbn-xsrf', 'xxx')
.send({
name: 'test_cluster2',
seeds: [NODE_SEED],
skipUnavailable: true,
mode: 'sniff',
})
.expect(200);
const uri = `${API_BASE_PATH}/test_cluster1,test_cluster2`;
const {
body: { itemsDeleted, errors },
} = await supertest.delete(uri).set('kbn-xsrf', 'xxx').expect(200);
expect(errors).to.eql([]);
// The order isn't guaranteed, so we assert against individual names instead of asserting
// against the value of the array itself.
['test_cluster1', 'test_cluster2'].forEach((clusterName) => {
expect(itemsDeleted.includes(clusterName)).to.be(true);
});
});
it(`should tell us which remote clusters couldn't be deleted`, async () => {
const uri = `${API_BASE_PATH}/test_cluster_doesnt_exist`;
const { body } = await supertest.delete(uri).set('kbn-xsrf', 'xxx').expect(200);
expect(body).to.eql({
itemsDeleted: [],
errors: [
{
name: 'test_cluster_doesnt_exist',
error: {
status: 404,
payload: { message: 'There is no remote cluster with that name.' },
options: {
statusCode: 404,
body: { message: 'There is no remote cluster with that name.' },
},
},
},
],
});
});
});
});
}