hybrid_platforms_conductor 32.17.1 → 32.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +3 -0
  4. data/bin/last_deploys +4 -1
  5. data/bin/nodes_to_deploy +5 -5
  6. data/docs/config_dsl.md +22 -0
  7. data/docs/gen/mermaid/README.md-0.png +0 -0
  8. data/docs/gen/mermaid/docs/executables/check-node.md-0.png +0 -0
  9. data/docs/gen/mermaid/docs/executables/deploy.md-0.png +0 -0
  10. data/docs/gen/mermaid/docs/executables/free_ips.md-0.png +0 -0
  11. data/docs/gen/mermaid/docs/executables/get_impacted_nodes.md-0.png +0 -0
  12. data/docs/gen/mermaid/docs/executables/last_deploys.md-0.png +0 -0
  13. data/docs/gen/mermaid/docs/executables/nodes_to_deploy.md-0.png +0 -0
  14. data/docs/gen/mermaid/docs/executables/report.md-0.png +0 -0
  15. data/docs/gen/mermaid/docs/executables/run.md-0.png +0 -0
  16. data/docs/gen/mermaid/docs/executables/ssh_config.md-0.png +0 -0
  17. data/docs/gen/mermaid/docs/executables/test.md-0.png +0 -0
  18. data/docs/plugins.md +25 -0
  19. data/docs/plugins/log/remote_fs.md +26 -0
  20. data/lib/hybrid_platforms_conductor/actions_executor.rb +8 -1
  21. data/lib/hybrid_platforms_conductor/deployer.rb +96 -104
  22. data/lib/hybrid_platforms_conductor/hpc_plugins/log/my_log_plugin.rb.sample +100 -0
  23. data/lib/hybrid_platforms_conductor/hpc_plugins/log/remote_fs.rb +179 -0
  24. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb +7 -20
  25. data/lib/hybrid_platforms_conductor/log.rb +31 -0
  26. data/lib/hybrid_platforms_conductor/version.rb +1 -1
  27. data/spec/hybrid_platforms_conductor_test.rb +22 -6
  28. data/spec/hybrid_platforms_conductor_test/api/deployer/config_dsl_spec.rb +24 -4
  29. data/spec/hybrid_platforms_conductor_test/api/deployer/deploy_spec.rb +187 -212
  30. data/spec/hybrid_platforms_conductor_test/api/deployer/log_plugins/remote_fs_spec.rb +223 -0
  31. data/spec/hybrid_platforms_conductor_test/api/tests_runner/global_spec.rb +1 -1
  32. data/spec/hybrid_platforms_conductor_test/executables/last_deploys_spec.rb +146 -98
  33. data/spec/hybrid_platforms_conductor_test/executables/nodes_to_deploy_spec.rb +240 -83
  34. data/spec/hybrid_platforms_conductor_test/executables/options/common_spec.rb +2 -1
  35. data/spec/hybrid_platforms_conductor_test/helpers/deployer_helpers.rb +40 -53
  36. data/spec/hybrid_platforms_conductor_test/helpers/deployer_test_helpers.rb +2 -2
  37. data/spec/hybrid_platforms_conductor_test/test_log_no_read_plugin.rb +82 -0
  38. data/spec/hybrid_platforms_conductor_test/test_log_plugin.rb +103 -0
  39. metadata +10 -2
@@ -8,23 +8,43 @@ describe 'nodes_to_deploy executable' do
8
8
  # * Parameters::
9
9
  # * *repository* (String): Platform's repository
10
10
  def with_test_platform_for_nodes_to_deploy(additional_platforms_content: '')
11
- with_test_platform({ nodes: { 'node1' => {}, 'node2' => {} } }, false, additional_platforms_content) do |repository|
11
+ with_test_platform(
12
+ { nodes: { 'node1' => {}, 'node2' => {} } },
13
+ false,
14
+ additional_platforms_content + "\nsend_logs_to :test_log"
15
+ ) do |repository|
12
16
  yield repository
13
17
  end
14
18
  end
15
19
 
16
20
  it 'returns all nodes by default' do
17
21
  with_test_platform_for_nodes_to_deploy do
18
- expect_actions_executor_runs([proc do |actions|
19
- expect(actions).to eq(
20
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
21
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
22
- )
22
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
23
23
  {
24
- 'node1' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef1", ''],
25
- 'node2' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef2", '']
24
+ 'node1' => {
25
+ services: %w[service1],
26
+ deployment_info: {
27
+ repo_name_0: 'platform',
28
+ commit_id_0: 'abcdef1',
29
+ exit_status: 0
30
+ },
31
+ exit_status: 0,
32
+ stdout: '',
33
+ stderr: ''
34
+ },
35
+ 'node2' => {
36
+ services: %w[service2],
37
+ deployment_info: {
38
+ repo_name_0: 'platform',
39
+ commit_id_0: 'abcdef2',
40
+ exit_status: 0
41
+ },
42
+ exit_status: 0,
43
+ stdout: '',
44
+ stderr: ''
45
+ }
26
46
  }
27
- end])
47
+ end
28
48
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef1', to_commit: 'master') { [%w[node1 node2], [], [], false] }
29
49
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef2', to_commit: 'master') { [%w[node1 node2], [], [], false] }
30
50
  exit_code, stdout, stderr = run 'nodes_to_deploy'
@@ -41,14 +61,21 @@ describe 'nodes_to_deploy executable' do
41
61
 
42
62
  it 'can filter nodes' do
43
63
  with_test_platform_for_nodes_to_deploy do
44
- expect_actions_executor_runs([proc do |actions|
45
- expect(actions).to eq(
46
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
47
- )
64
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node2]) do
48
65
  {
49
- 'node2' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef2", '']
66
+ 'node2' => {
67
+ services: %w[service2],
68
+ deployment_info: {
69
+ repo_name_0: 'platform',
70
+ commit_id_0: 'abcdef2',
71
+ exit_status: 0
72
+ },
73
+ exit_status: 0,
74
+ stdout: '',
75
+ stderr: ''
76
+ }
50
77
  }
51
- end])
78
+ end
52
79
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef2', to_commit: 'master') { [%w[node1 node2], [], [], false] }
53
80
  exit_code, stdout, stderr = run 'nodes_to_deploy', '--node', 'node2'
54
81
  expect(exit_code).to eq 0
@@ -63,16 +90,32 @@ describe 'nodes_to_deploy executable' do
63
90
 
64
91
  it 'does not return nodes that have no impact' do
65
92
  with_test_platform_for_nodes_to_deploy do
66
- expect_actions_executor_runs([proc do |actions|
67
- expect(actions).to eq(
68
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
69
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
70
- )
93
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
71
94
  {
72
- 'node1' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef1", ''],
73
- 'node2' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef2", '']
95
+ 'node1' => {
96
+ services: %w[service1],
97
+ deployment_info: {
98
+ repo_name_0: 'platform',
99
+ commit_id_0: 'abcdef1',
100
+ exit_status: 0
101
+ },
102
+ exit_status: 0,
103
+ stdout: '',
104
+ stderr: ''
105
+ },
106
+ 'node2' => {
107
+ services: %w[service2],
108
+ deployment_info: {
109
+ repo_name_0: 'platform',
110
+ commit_id_0: 'abcdef2',
111
+ exit_status: 0
112
+ },
113
+ exit_status: 0,
114
+ stdout: '',
115
+ stderr: ''
116
+ }
74
117
  }
75
- end])
118
+ end
76
119
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef1', to_commit: 'master') { [%w[node1], [], [], false] }
77
120
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef2', to_commit: 'master') { [%w[], [], [], false] }
78
121
  exit_code, stdout, stderr = run 'nodes_to_deploy'
@@ -86,16 +129,28 @@ describe 'nodes_to_deploy executable' do
86
129
 
87
130
  it 'considers nodes having no repository info in their logs to be deployed' do
88
131
  with_test_platform_for_nodes_to_deploy do
89
- expect_actions_executor_runs([proc do |actions|
90
- expect(actions).to eq(
91
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
92
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
93
- )
132
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
94
133
  {
95
- 'node1' => [0, "exit_status: 0\n", ''],
96
- 'node2' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef2", '']
134
+ 'node1' => {
135
+ services: %w[service1],
136
+ deployment_info: {},
137
+ exit_status: 0,
138
+ stdout: '',
139
+ stderr: ''
140
+ },
141
+ 'node2' => {
142
+ services: %w[service2],
143
+ deployment_info: {
144
+ repo_name_0: 'platform',
145
+ commit_id_0: 'abcdef2',
146
+ exit_status: 0
147
+ },
148
+ exit_status: 0,
149
+ stdout: '',
150
+ stderr: ''
151
+ }
97
152
  }
98
- end])
153
+ end
99
154
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef2', to_commit: 'master') { [%w[], [], [], false] }
100
155
  exit_code, stdout, stderr = run 'nodes_to_deploy'
101
156
  expect(exit_code).to eq 0
@@ -108,16 +163,32 @@ describe 'nodes_to_deploy executable' do
108
163
 
109
164
  it 'considers nodes having invalid commit ids in their logs to be deployed' do
110
165
  with_test_platform_for_nodes_to_deploy do
111
- expect_actions_executor_runs([proc do |actions|
112
- expect(actions).to eq(
113
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
114
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
115
- )
166
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
116
167
  {
117
- 'node1' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef1", ''],
118
- 'node2' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef2", '']
168
+ 'node1' => {
169
+ services: %w[service1],
170
+ deployment_info: {
171
+ repo_name_0: 'platform',
172
+ commit_id_0: 'abcdef1',
173
+ exit_status: 0
174
+ },
175
+ exit_status: 0,
176
+ stdout: '',
177
+ stderr: ''
178
+ },
179
+ 'node2' => {
180
+ services: %w[service2],
181
+ deployment_info: {
182
+ repo_name_0: 'platform',
183
+ commit_id_0: 'abcdef2',
184
+ exit_status: 0
185
+ },
186
+ exit_status: 0,
187
+ stdout: '',
188
+ stderr: ''
189
+ }
119
190
  }
120
- end])
191
+ end
121
192
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef1', to_commit: 'master') do
122
193
  raise HybridPlatformsConductor::NodesHandler::GitError, 'Mocked git error due to an invalid commit id'
123
194
  end
@@ -148,14 +219,21 @@ describe 'nodes_to_deploy executable' do
148
219
  for_nodes(\'node1\') { deployment_schedule(IceCube::Schedule.new(Time.now.utc - 120, duration: 60)) }
149
220
  for_nodes(\'node2\') { deployment_schedule(IceCube::Schedule.new(Time.now.utc - 60, duration: 120)) }
150
221
  ') do
151
- expect_actions_executor_runs([proc do |actions|
152
- expect(actions).to eq(
153
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
154
- )
222
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node2]) do
155
223
  {
156
- 'node2' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef2", '']
224
+ 'node2' => {
225
+ services: %w[service2],
226
+ deployment_info: {
227
+ repo_name_0: 'platform',
228
+ commit_id_0: 'abcdef2',
229
+ exit_status: 0
230
+ },
231
+ exit_status: 0,
232
+ stdout: '',
233
+ stderr: ''
234
+ }
157
235
  }
158
- end])
236
+ end
159
237
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef2', to_commit: 'master') { [%w[node1 node2], [], [], false] }
160
238
  exit_code, stdout, stderr = run 'nodes_to_deploy'
161
239
  expect(exit_code).to eq 0
@@ -172,14 +250,21 @@ describe 'nodes_to_deploy executable' do
172
250
  for_nodes(\'node1\') { deployment_schedule(IceCube::Schedule.new(Time.now.utc - 120, duration: 60)) }
173
251
  for_nodes(\'node2\') { deployment_schedule(IceCube::Schedule.new(Time.now.utc - 60, duration: 120)) }
174
252
  ') do
175
- expect_actions_executor_runs([proc do |actions|
176
- expect(actions).to eq(
177
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
178
- )
253
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1]) do
179
254
  {
180
- 'node1' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef1", '']
255
+ 'node1' => {
256
+ services: %w[service1],
257
+ deployment_info: {
258
+ repo_name_0: 'platform',
259
+ commit_id_0: 'abcdef1',
260
+ exit_status: 0
261
+ },
262
+ exit_status: 0,
263
+ stdout: '',
264
+ stderr: ''
265
+ }
181
266
  }
182
- end])
267
+ end
183
268
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef1', to_commit: 'master') { [%w[node1 node2], [], [], false] }
184
269
  # 90 seconds before now, the schedule should match only node1
185
270
  exit_code, stdout, stderr = run 'nodes_to_deploy', '--deployment-time', (Time.now.utc - 90).strftime('%F %T')
@@ -197,16 +282,32 @@ describe 'nodes_to_deploy executable' do
197
282
  for_nodes(\'node1\') { deployment_schedule(IceCube::Schedule.new(Time.now.utc - 120, duration: 60)) }
198
283
  for_nodes(\'node2\') { deployment_schedule(IceCube::Schedule.new(Time.now.utc - 60, duration: 120)) }
199
284
  ') do
200
- expect_actions_executor_runs([proc do |actions|
201
- expect(actions).to eq(
202
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
203
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
204
- )
285
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
205
286
  {
206
- 'node1' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef1", ''],
207
- 'node2' => [0, "repo_name_0: platform\nexit_status: 0\ncommit_id_0: abcdef2", '']
287
+ 'node1' => {
288
+ services: %w[service1],
289
+ deployment_info: {
290
+ repo_name_0: 'platform',
291
+ commit_id_0: 'abcdef1',
292
+ exit_status: 0
293
+ },
294
+ exit_status: 0,
295
+ stdout: '',
296
+ stderr: ''
297
+ },
298
+ 'node2' => {
299
+ services: %w[service2],
300
+ deployment_info: {
301
+ repo_name_0: 'platform',
302
+ commit_id_0: 'abcdef2',
303
+ exit_status: 0
304
+ },
305
+ exit_status: 0,
306
+ stdout: '',
307
+ stderr: ''
308
+ }
208
309
  }
209
- end])
310
+ end
210
311
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef1', to_commit: 'master') { [%w[node1 node2], [], [], false] }
211
312
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform', from_commit: 'abcdef2', to_commit: 'master') { [%w[node1 node2], [], [], false] }
212
313
  exit_code, stdout, stderr = run 'nodes_to_deploy', '--ignore-schedule'
@@ -225,16 +326,32 @@ describe 'nodes_to_deploy executable' do
225
326
  'platform1' => { nodes: { 'node1' => {}, 'node2' => {} } },
226
327
  'platform2' => { nodes: {} }
227
328
  ) do
228
- expect_actions_executor_runs([proc do |actions|
229
- expect(actions).to eq(
230
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
231
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
232
- )
329
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
233
330
  {
234
- 'node1' => [0, "repo_name_0: platform1\nexit_status: 0\ncommit_id_0: abcdef1", ''],
235
- 'node2' => [0, "repo_name_0: platform2\nexit_status: 0\ncommit_id_0: abcdef2", '']
331
+ 'node1' => {
332
+ services: %w[service1],
333
+ deployment_info: {
334
+ repo_name_0: 'platform1',
335
+ commit_id_0: 'abcdef1',
336
+ exit_status: 0
337
+ },
338
+ exit_status: 0,
339
+ stdout: '',
340
+ stderr: ''
341
+ },
342
+ 'node2' => {
343
+ services: %w[service2],
344
+ deployment_info: {
345
+ repo_name_0: 'platform2',
346
+ commit_id_0: 'abcdef2',
347
+ exit_status: 0
348
+ },
349
+ exit_status: 0,
350
+ stdout: '',
351
+ stderr: ''
352
+ }
236
353
  }
237
- end])
354
+ end
238
355
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform1', from_commit: 'abcdef1', to_commit: 'master') { [%w[node1], [], [], false] }
239
356
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform2', from_commit: 'abcdef2', to_commit: 'master') { [%w[node2], [], [], false] }
240
357
  exit_code, stdout, stderr = run 'nodes_to_deploy'
@@ -253,16 +370,36 @@ describe 'nodes_to_deploy executable' do
253
370
  'platform2' => { nodes: {} },
254
371
  'platform3' => { nodes: {} }
255
372
  ) do
256
- expect_actions_executor_runs([proc do |actions|
257
- expect(actions).to eq(
258
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
259
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
260
- )
373
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
261
374
  {
262
- 'node1' => [0, "exit_status: 0\nrepo_name_0: platform1\ncommit_id_0: abcdef1\nrepo_name_1: platform2\ncommit_id_1: 1234567", ''],
263
- 'node2' => [0, "exit_status: 0\nrepo_name_0: platform2\ncommit_id_0: abcdef2\nrepo_name_1: platform3\ncommit_id_1: 2345678", '']
375
+ 'node1' => {
376
+ services: %w[service1],
377
+ deployment_info: {
378
+ repo_name_0: 'platform1',
379
+ commit_id_0: 'abcdef1',
380
+ repo_name_1: 'platform2',
381
+ commit_id_1: '1234567',
382
+ exit_status: 0
383
+ },
384
+ exit_status: 0,
385
+ stdout: '',
386
+ stderr: ''
387
+ },
388
+ 'node2' => {
389
+ services: %w[service2],
390
+ deployment_info: {
391
+ repo_name_0: 'platform2',
392
+ commit_id_0: 'abcdef2',
393
+ repo_name_1: 'platform3',
394
+ commit_id_1: '2345678',
395
+ exit_status: 0
396
+ },
397
+ exit_status: 0,
398
+ stdout: '',
399
+ stderr: ''
400
+ }
264
401
  }
265
- end])
402
+ end
266
403
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform1', from_commit: 'abcdef1', to_commit: 'master') { [%w[], [], [], false] }
267
404
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform2', from_commit: '1234567', to_commit: 'master') { [%w[node1], [], [], false] }
268
405
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform2', from_commit: 'abcdef2', to_commit: 'master') { [%w[], [], [], false] }
@@ -283,16 +420,36 @@ describe 'nodes_to_deploy executable' do
283
420
  'platform2' => { nodes: {} },
284
421
  'platform3' => { nodes: {} }
285
422
  ) do
286
- expect_actions_executor_runs([proc do |actions|
287
- expect(actions).to eq(
288
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
289
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
290
- )
423
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
291
424
  {
292
- 'node1' => [0, "exit_status: 0\nrepo_name_0: platform1\ncommit_id_0: abcdef1\nrepo_name_1: platform2\ncommit_id_1: 1234567", ''],
293
- 'node2' => [0, "exit_status: 0\nrepo_name_0: platform2\ncommit_id_0: abcdef2\nrepo_name_1: platform3\ncommit_id_1: 2345678", '']
425
+ 'node1' => {
426
+ services: %w[service1],
427
+ deployment_info: {
428
+ repo_name_0: 'platform1',
429
+ commit_id_0: 'abcdef1',
430
+ repo_name_1: 'platform2',
431
+ commit_id_1: '1234567',
432
+ exit_status: 0
433
+ },
434
+ exit_status: 0,
435
+ stdout: '',
436
+ stderr: ''
437
+ },
438
+ 'node2' => {
439
+ services: %w[service2],
440
+ deployment_info: {
441
+ repo_name_0: 'platform2',
442
+ commit_id_0: 'abcdef2',
443
+ repo_name_1: 'platform3',
444
+ commit_id_1: '2345678',
445
+ exit_status: 0
446
+ },
447
+ exit_status: 0,
448
+ stdout: '',
449
+ stderr: ''
450
+ }
294
451
  }
295
- end])
452
+ end
296
453
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform1', from_commit: 'abcdef1', to_commit: 'master') { [%w[node1], [], [], false] }
297
454
  expect(test_nodes_handler).to receive(:impacted_nodes_from_git_diff).with('platform2', from_commit: 'abcdef2', to_commit: 'master') { [%w[node2], [], [], false] }
298
455
  exit_code, stdout, stderr = run 'nodes_to_deploy'
@@ -12,7 +12,8 @@ describe 'executables\' common options' do
12
12
  nodes: { 'node1' => { meta: { host_ip: '192.168.42.42' }, services: ['node1_service'] } },
13
13
  deployable_services: %w[node1_service]
14
14
  },
15
- true
15
+ true,
16
+ 'send_logs_to :test_log'
16
17
  ) do |repository|
17
18
  yield repository
18
19
  end
@@ -68,71 +68,21 @@ module HybridPlatformsConductorTest
68
68
  Hash[nodes.map { |node| [node, [0, 'Release mutex successful', '']] }]
69
69
  end
70
70
 
71
- # Expect a given set of actions to upload log files on a list of nodes
71
+ # Expect a given set of actions to upload log files on a list of nodes (using the test_log log plugin)
72
72
  #
73
73
  # Parameters::
74
74
  # * *actions* (Object): Actions
75
75
  # * *nodes* (String or Array<String>): Node (or list of nodes) that should be checked
76
- # * *sudo* (String or nil): sudo supposed to be used, or nil if none [default: 'sudo -u root']
77
- def expect_actions_to_upload_logs(actions, nodes, sudo: 'sudo -u root')
76
+ def expect_actions_to_upload_logs(actions, nodes)
78
77
  nodes = [nodes] if nodes.is_a?(String)
79
78
  expect(actions.size).to eq nodes.size
80
79
  nodes.each do |node|
81
80
  expect(actions.key?(node)).to eq true
82
- expect(actions[node][:remote_bash]).to eq "#{sudo ? "#{sudo} " : ''}mkdir -p /var/log/deployments"
83
- expect(actions[node][:scp].first[1]).to eq '/var/log/deployments'
84
- expect(actions[node][:scp][:group]).to eq 'root'
85
- expect(actions[node][:scp][:owner]).to eq 'root'
86
- expect(actions[node][:scp][:sudo]).to eq (!sudo.nil?)
81
+ expect(actions[node]).to eq [{ bash: "echo Save test logs to #{node}" }]
87
82
  end
88
83
  Hash[nodes.map { |node| [node, [0, 'Logs uploaded', '']] }]
89
84
  end
90
85
 
91
- # Expect some logs to have the following information.
92
- # Expected logs format:
93
- #
94
- # date: 2019-08-14 17:02:57
95
- # user: muriel
96
- # debug: Yes
97
- # repo_name: my_remote_platform
98
- # commit_id: c0d16b1b7ae286ae4a059185957e08f0ddc95517
99
- # commit_message: Test commit
100
- # diff_files:
101
- # ===== STDOUT =====
102
- # Deploy successful
103
- # ===== STDERR =====
104
- #
105
- # Parameters::
106
- # * *logs* (String): The logs content
107
- # * *stdout* (String): Expected STDOUT
108
- # * *stderr* (String): Expected STDERR
109
- # * *properties* (Hash<Symbol, String or Regexp>): Expected properties values, per name. Values can be exact strings or regexps.
110
- def expect_logs_to_be(logs, stdout, stderr, properties)
111
- lines = logs.split("\n")
112
- idx_stdout = lines.index('===== STDOUT =====')
113
- expect(idx_stdout).not_to eq nil
114
- idx_stderr = lines.index('===== STDERR =====')
115
- expect(idx_stderr).not_to eq nil
116
- logs_properties = Hash[lines[0..idx_stdout - 1].map do |property_line|
117
- property_fields = property_line.split(': ')
118
- [
119
- property_fields.first.to_sym,
120
- property_fields[1..-1].join(': ')
121
- ]
122
- end]
123
- expect(logs_properties.size).to eq properties.size
124
- properties.each do |expected_property, expected_property_value|
125
- expect(logs_properties.key?(expected_property)).to eq true
126
- if expected_property_value.is_a?(String)
127
- expect(logs_properties[expected_property]).to eq expected_property_value
128
- else
129
- expect(logs_properties[expected_property]).to match expected_property_value
130
- end
131
- end
132
- expect(lines[idx_stdout + 1..idx_stderr - 1].join("\n")).to eq stdout
133
- expect(lines[idx_stderr + 1..-1].join("\n")).to eq stderr
134
- end
135
-
136
86
  # Get a test Deployer
137
87
  #
138
88
  # Result::
@@ -142,6 +92,43 @@ module HybridPlatformsConductorTest
142
92
  @deployer
143
93
  end
144
94
 
95
+ # Expect the test services handler to be called to deploy a given list of services
96
+ #
97
+ # Parameters::
98
+ # * *services* (Hash<String, Array<String> >): List of services to be expected, per node name
99
+ def expect_services_handler_to_deploy(services)
100
+ expect(test_services_handler).to receive(:deploy_allowed?).with(
101
+ services: services,
102
+ secrets: {},
103
+ local_environment: false
104
+ ) do
105
+ nil
106
+ end
107
+ expect(test_services_handler).to receive(:package).with(
108
+ services: services,
109
+ secrets: {},
110
+ local_environment: false
111
+ )
112
+ expect(test_services_handler).to receive(:prepare_for_deploy).with(
113
+ services: services,
114
+ secrets: {},
115
+ local_environment: false,
116
+ why_run: false
117
+ )
118
+ services.each do |node, services|
119
+ expect(test_services_handler).to receive(:actions_to_deploy_on).with(node, services, false) do
120
+ [{ bash: "echo \"Deploying on #{node}\"" }]
121
+ end
122
+ expect(test_services_handler).to receive(:log_info_for).with(node, services) do
123
+ {
124
+ repo_name_0: 'platform',
125
+ commit_id_0: '123456',
126
+ commit_message_0: "Test commit for #{node}: #{services.join(', ')}"
127
+ }
128
+ end
129
+ end
130
+ end
131
+
145
132
  end
146
133
 
147
134
  end