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
@@ -0,0 +1,223 @@
1
+ describe HybridPlatformsConductor::Deployer do
2
+
3
+ context 'checking log plugins' do
4
+
5
+ context 'remote_fs' do
6
+
7
+ # Return a test platform ready to test the remote_fs log plugin
8
+ #
9
+ # Parameters::
10
+ # * Proc: Code called with platform prepared
11
+ def with_test_platform_for_remote_fs
12
+ with_test_platform({ nodes: { 'node' => { services: %w[service1 service2] } } }, false, 'send_logs_to :remote_fs') do
13
+ yield
14
+ end
15
+ end
16
+
17
+ it 'returns actions to save logs' do
18
+ with_test_platform_for_remote_fs do
19
+ with_connections_mocked_on ['node'] do
20
+ test_actions_executor.connector(:ssh).ssh_user = 'test_user'
21
+ expect_services_handler_to_deploy('node' => %w[service1 service2])
22
+ expect_actions_executor_runs([
23
+ # First run, we expect the mutex to be setup, and the deployment actions to be run
24
+ proc do |actions_per_nodes|
25
+ expect_actions_to_deploy_on(
26
+ actions_per_nodes,
27
+ 'node',
28
+ mocked_result: { 'node' => [0, 'Deploy successful stdout', 'Deploy successful stderr'] }
29
+ )
30
+ end,
31
+ # Second run, we expect the mutex to be released
32
+ proc { |actions_per_nodes| expect_actions_to_unlock(actions_per_nodes, 'node') },
33
+ # Third run, we expect logs to be uploaded on the node
34
+ proc do |actions_per_nodes|
35
+ expect(actions_per_nodes['node'].size).to eq 3
36
+ expect(actions_per_nodes['node'][0].keys.sort).to eq %i[ruby remote_bash].sort
37
+ expect(actions_per_nodes['node'][0][:remote_bash]).to eq 'sudo -u root mkdir -p /var/log/deployments && sudo -u root chmod 600 /var/log/deployments'
38
+ expect(actions_per_nodes['node'][1].keys.sort).to eq %i[scp].sort
39
+ expect(actions_per_nodes['node'][1][:scp].delete(:sudo)).to eq true
40
+ expect(actions_per_nodes['node'][1][:scp].delete(:owner)).to eq 'root'
41
+ expect(actions_per_nodes['node'][1][:scp].delete(:group)).to eq 'root'
42
+ expect(actions_per_nodes['node'][1][:scp].size).to eq 1
43
+ tmp_log_file = actions_per_nodes['node'][1][:scp].first[0]
44
+ expect(actions_per_nodes['node'][1][:scp].first[1]).to eq '/var/log/deployments'
45
+ expect(actions_per_nodes['node'][2].keys.sort).to eq %i[ruby remote_bash].sort
46
+ expect(actions_per_nodes['node'][2][:remote_bash]).to eq "sudo -u root chmod 600 /var/log/deployments/#{File.basename(tmp_log_file)}"
47
+ # Call the Ruby codes to be tested
48
+ actions_per_nodes['node'][0][:ruby].call
49
+ expect(File.exist?(tmp_log_file)).to eq true
50
+ file_content_regexp = Regexp.new <<~EOREGEXP
51
+ repo_name_0: platform
52
+ commit_id_0: 123456
53
+ commit_message_0: Test commit for node: service1, service2
54
+ date: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
55
+ user: test_user
56
+ debug: No
57
+ services: service1, service2
58
+ exit_status: 0
59
+ ===== STDOUT =====
60
+ Deploy successful stdout
61
+ ===== STDERR =====
62
+ Deploy successful stderr
63
+ EOREGEXP
64
+ actions_per_nodes['node'][2][:ruby].call
65
+ # Check temporary log file gets deleted for security reasons
66
+ expect(File.exist?(tmp_log_file)).to eq false
67
+ end
68
+ ])
69
+ expect(test_deployer.deploy_on('node')).to eq('node' => [0, 'Deploy successful stdout', 'Deploy successful stderr'])
70
+ end
71
+ end
72
+ end
73
+
74
+ it 'returns actions to save logs using root' do
75
+ with_test_platform_for_remote_fs do
76
+ with_connections_mocked_on ['node'] do
77
+ test_actions_executor.connector(:ssh).ssh_user = 'root'
78
+ expect_services_handler_to_deploy('node' => %w[service1 service2])
79
+ expect_actions_executor_runs([
80
+ # First run, we expect the mutex to be setup, and the deployment actions to be run
81
+ proc do |actions_per_nodes|
82
+ expect_actions_to_deploy_on(
83
+ actions_per_nodes,
84
+ 'node',
85
+ sudo: nil,
86
+ mocked_result: { 'node' => [0, 'Deploy successful stdout', 'Deploy successful stderr'] }
87
+ )
88
+ end,
89
+ # Second run, we expect the mutex to be released
90
+ proc { |actions_per_nodes| expect_actions_to_unlock(actions_per_nodes, 'node', sudo: nil) },
91
+ # Third run, we expect logs to be uploaded on the node
92
+ proc do |actions_per_nodes|
93
+ expect(actions_per_nodes['node'].size).to eq 3
94
+ expect(actions_per_nodes['node'][0].keys.sort).to eq %i[ruby remote_bash].sort
95
+ expect(actions_per_nodes['node'][0][:remote_bash]).to eq 'mkdir -p /var/log/deployments && chmod 600 /var/log/deployments'
96
+ expect(actions_per_nodes['node'][1].keys.sort).to eq %i[scp].sort
97
+ expect(actions_per_nodes['node'][1][:scp].delete(:sudo)).to eq false
98
+ expect(actions_per_nodes['node'][1][:scp].delete(:owner)).to eq 'root'
99
+ expect(actions_per_nodes['node'][1][:scp].delete(:group)).to eq 'root'
100
+ expect(actions_per_nodes['node'][1][:scp].size).to eq 1
101
+ tmp_log_file = actions_per_nodes['node'][1][:scp].first[0]
102
+ expect(actions_per_nodes['node'][1][:scp].first[1]).to eq '/var/log/deployments'
103
+ expect(actions_per_nodes['node'][2].keys.sort).to eq %i[ruby remote_bash].sort
104
+ expect(actions_per_nodes['node'][2][:remote_bash]).to eq "chmod 600 /var/log/deployments/#{File.basename(tmp_log_file)}"
105
+ # Call the Ruby codes to be tested
106
+ actions_per_nodes['node'][0][:ruby].call
107
+ expect(File.exist?(tmp_log_file)).to eq true
108
+ file_content_regexp = Regexp.new <<~EOREGEXP
109
+ repo_name_0: platform
110
+ commit_id_0: 123456
111
+ commit_message_0: Test commit for node: service1, service2
112
+ date: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
113
+ user: root
114
+ debug: No
115
+ services: service1, service2
116
+ exit_status: 0
117
+ ===== STDOUT =====
118
+ Deploy successful stdout
119
+ ===== STDERR =====
120
+ Deploy successful stderr
121
+ EOREGEXP
122
+ actions_per_nodes['node'][2][:ruby].call
123
+ # Check temporary log file gets deleted for security reasons
124
+ expect(File.exist?(tmp_log_file)).to eq false
125
+ end
126
+ ])
127
+ expect(test_deployer.deploy_on('node')).to eq('node' => [0, 'Deploy successful stdout', 'Deploy successful stderr'])
128
+ end
129
+ end
130
+ end
131
+
132
+ it 'reads logs' do
133
+ with_test_platform_for_remote_fs do
134
+ expect_actions_executor_runs([
135
+ # Expect the actions to get log files
136
+ proc do |actions_per_nodes|
137
+ expect(actions_per_nodes).to eq('node' => [{ remote_bash: 'sudo -u root cat /var/log/deployments/`sudo -u root ls -t /var/log/deployments/ | head -1`' }])
138
+ { 'node' => [0, <<~EOS, ''] }
139
+ repo_name_0: platform
140
+ commit_id_0: 123456
141
+ commit_message_0: Test commit for node: service1, service2
142
+ diff_files_0: file1, file2, file3
143
+ date: 2017-11-23 18:43:01
144
+ user: test_user
145
+ debug: Yes
146
+ services: service1, service2, service3
147
+ exit_status: 0
148
+ ===== STDOUT =====
149
+ Deploy successful stdout
150
+ ===== STDERR =====
151
+ Deploy successful stderr
152
+ EOS
153
+ end
154
+ ])
155
+ expect(test_deployer.deployment_info_from('node')).to eq(
156
+ 'node' => {
157
+ deployment_info: {
158
+ repo_name_0: 'platform',
159
+ commit_id_0: '123456',
160
+ commit_message_0: 'Test commit for node: service1, service2',
161
+ diff_files_0: %w[file1 file2 file3],
162
+ date: Time.parse('2017-11-23 18:43:01 UTC'),
163
+ debug: true,
164
+ user: 'test_user'
165
+ },
166
+ exit_status: 0,
167
+ services: %w[service1 service2 service3],
168
+ stderr: 'Deploy successful stderr',
169
+ stdout: 'Deploy successful stdout'
170
+ }
171
+ )
172
+ end
173
+ end
174
+
175
+ it 'reads logs using root' do
176
+ with_test_platform_for_remote_fs do
177
+ test_actions_executor.connector(:ssh).ssh_user = 'root'
178
+ expect_actions_executor_runs([
179
+ # Expect the actions to get log files
180
+ proc do |actions_per_nodes|
181
+ expect(actions_per_nodes).to eq('node' => [{ remote_bash: 'cat /var/log/deployments/`ls -t /var/log/deployments/ | head -1`' }])
182
+ { 'node' => [0, <<~EOS, ''] }
183
+ repo_name_0: platform
184
+ commit_id_0: 123456
185
+ commit_message_0: Test commit for node: service1, service2
186
+ diff_files_0: file1, file2, file3
187
+ date: 2017-11-23 18:43:01
188
+ user: test_user
189
+ debug: Yes
190
+ services: service1, service2, service3
191
+ exit_status: 0
192
+ ===== STDOUT =====
193
+ Deploy successful stdout
194
+ ===== STDERR =====
195
+ Deploy successful stderr
196
+ EOS
197
+ end
198
+ ])
199
+ expect(test_deployer.deployment_info_from('node')).to eq(
200
+ 'node' => {
201
+ deployment_info: {
202
+ repo_name_0: 'platform',
203
+ commit_id_0: '123456',
204
+ commit_message_0: 'Test commit for node: service1, service2',
205
+ diff_files_0: %w[file1 file2 file3],
206
+ date: Time.parse('2017-11-23 18:43:01 UTC'),
207
+ debug: true,
208
+ user: 'test_user'
209
+ },
210
+ exit_status: 0,
211
+ services: %w[service1 service2 service3],
212
+ stderr: 'Deploy successful stderr',
213
+ stdout: 'Deploy successful stdout'
214
+ }
215
+ )
216
+ end
217
+ end
218
+
219
+ end
220
+
221
+ end
222
+
223
+ end
@@ -5,7 +5,7 @@ describe HybridPlatformsConductor::TestsRunner do
5
5
  # Prepare the test platform with test plugins
6
6
  #
7
7
  # Parameters::
8
- # * *platforms_info* (Hash): The platofrms info [default: {}]
8
+ # * *platforms_info* (Hash): The platforms info [default: {}]
9
9
  def with_test_platform_for_global_tests(platforms_info: {})
10
10
  with_test_platform(platforms_info) do
11
11
  register_test_plugins(test_tests_runner,
@@ -14,33 +14,45 @@ describe 'last_deploys executable' do
14
14
 
15
15
  it 'checks all nodes by default' do
16
16
  with_test_platform_for_last_deploys do
17
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
18
- expect(actions).to eq(
19
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
20
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
21
- )
17
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
22
18
  {
23
- 'node1' => [0, <<~EOS, ''],
24
- date: 2019-08-21 10:12:15
25
- user: admin_user1
26
- services: service1
27
- EOS
28
- 'node2' => [0, <<~EOS, '']
29
- date: 2019-08-22 10:12:15
30
- user: admin_user2
31
- services: service1, service2
32
- EOS
19
+ 'node1' => {
20
+ services: %w[service1],
21
+ deployment_info: {
22
+ repo_name_0: 'platform',
23
+ commit_id_0: 'abcdef1',
24
+ exit_status: 0,
25
+ date: Time.parse('2019-08-21 10:12:15 UTC'),
26
+ user: 'admin_user1'
27
+ },
28
+ exit_status: 0,
29
+ stdout: '',
30
+ stderr: ''
31
+ },
32
+ 'node2' => {
33
+ services: %w[service1 service2],
34
+ deployment_info: {
35
+ repo_name_0: 'platform',
36
+ commit_id_0: 'abcdef2',
37
+ exit_status: 0,
38
+ date: Time.parse('2019-08-22 10:12:15 UTC'),
39
+ user: 'admin_user2'
40
+ },
41
+ exit_status: 0,
42
+ stdout: '',
43
+ stderr: ''
44
+ }
33
45
  }
34
- end])
46
+ end
35
47
  exit_code, stdout, stderr = run 'last_deploys'
36
48
  expect(exit_code).to eq 0
37
49
  expect(stdout).to eq(<<~EOS)
38
- +-------+---------------------+-------------+--------------------+-------+
39
- | Node | Date | Admin | Services | Error |
40
- +-------+---------------------+-------------+--------------------+-------+
41
- | node1 | 2019-08-21 10:12:15 | admin_user1 | service1 | |
42
- | node2 | 2019-08-22 10:12:15 | admin_user2 | service1, service2 | |
43
- +-------+---------------------+-------------+--------------------+-------+
50
+ +-------+-------------------------+-------------+--------------------+-------+
51
+ | Node | Date | Admin | Services | Error |
52
+ +-------+-------------------------+-------------+--------------------+-------+
53
+ | node1 | 2019-08-21 10:12:15 UTC | admin_user1 | service1 | |
54
+ | node2 | 2019-08-22 10:12:15 UTC | admin_user2 | service1, service2 | |
55
+ +-------+-------------------------+-------------+--------------------+-------+
44
56
  EOS
45
57
  expect(stderr).to eq ''
46
58
  end
@@ -48,33 +60,45 @@ describe 'last_deploys executable' do
48
60
 
49
61
  it 'sorts results by user' do
50
62
  with_test_platform_for_last_deploys do
51
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
52
- expect(actions).to eq(
53
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
54
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
55
- )
63
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
56
64
  {
57
- 'node1' => [0, <<~EOS, ''],
58
- date: 2019-08-21 10:12:15
59
- user: admin_user2
60
- services: service1
61
- EOS
62
- 'node2' => [0, <<~EOS, '']
63
- date: 2019-08-22 10:12:15
64
- user: admin_user1
65
- services: service1, service2
66
- EOS
65
+ 'node1' => {
66
+ services: %w[service1],
67
+ deployment_info: {
68
+ repo_name_0: 'platform',
69
+ commit_id_0: 'abcdef1',
70
+ exit_status: 0,
71
+ date: Time.parse('2019-08-21 10:12:15 UTC'),
72
+ user: 'admin_user2'
73
+ },
74
+ exit_status: 0,
75
+ stdout: '',
76
+ stderr: ''
77
+ },
78
+ 'node2' => {
79
+ services: %w[service1 service2],
80
+ deployment_info: {
81
+ repo_name_0: 'platform',
82
+ commit_id_0: 'abcdef2',
83
+ exit_status: 0,
84
+ date: Time.parse('2019-08-22 10:12:15 UTC'),
85
+ user: 'admin_user1'
86
+ },
87
+ exit_status: 0,
88
+ stdout: '',
89
+ stderr: ''
90
+ }
67
91
  }
68
- end])
92
+ end
69
93
  exit_code, stdout, stderr = run 'last_deploys', '--sort-by', 'user'
70
94
  expect(exit_code).to eq 0
71
95
  expect(stdout).to eq(<<~EOS)
72
- +-------+---------------------+-------------+--------------------+-------+
73
- | Node | Date | Admin | Services | Error |
74
- +-------+---------------------+-------------+--------------------+-------+
75
- | node2 | 2019-08-22 10:12:15 | admin_user1 | service1, service2 | |
76
- | node1 | 2019-08-21 10:12:15 | admin_user2 | service1 | |
77
- +-------+---------------------+-------------+--------------------+-------+
96
+ +-------+-------------------------+-------------+--------------------+-------+
97
+ | Node | Date | Admin | Services | Error |
98
+ +-------+-------------------------+-------------+--------------------+-------+
99
+ | node2 | 2019-08-22 10:12:15 UTC | admin_user1 | service1, service2 | |
100
+ | node1 | 2019-08-21 10:12:15 UTC | admin_user2 | service1 | |
101
+ +-------+-------------------------+-------------+--------------------+-------+
78
102
  EOS
79
103
  expect(stderr).to eq ''
80
104
  end
@@ -82,33 +106,45 @@ describe 'last_deploys executable' do
82
106
 
83
107
  it 'sorts results by user descending' do
84
108
  with_test_platform_for_last_deploys do
85
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
86
- expect(actions).to eq(
87
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
88
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
89
- )
109
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
90
110
  {
91
- 'node1' => [0, <<~EOS, ''],
92
- date: 2019-08-21 10:12:15
93
- user: admin_user2
94
- services: service1
95
- EOS
96
- 'node2' => [0, <<~EOS, '']
97
- date: 2019-08-22 10:12:15
98
- user: admin_user1
99
- services: service1, service2
100
- EOS
111
+ 'node1' => {
112
+ services: %w[service1],
113
+ deployment_info: {
114
+ repo_name_0: 'platform',
115
+ commit_id_0: 'abcdef1',
116
+ exit_status: 0,
117
+ date: Time.parse('2019-08-21 10:12:15 UTC'),
118
+ user: 'admin_user2'
119
+ },
120
+ exit_status: 0,
121
+ stdout: '',
122
+ stderr: ''
123
+ },
124
+ 'node2' => {
125
+ services: %w[service1 service2],
126
+ deployment_info: {
127
+ repo_name_0: 'platform',
128
+ commit_id_0: 'abcdef2',
129
+ exit_status: 0,
130
+ date: Time.parse('2019-08-22 10:12:15 UTC'),
131
+ user: 'admin_user1'
132
+ },
133
+ exit_status: 0,
134
+ stdout: '',
135
+ stderr: ''
136
+ }
101
137
  }
102
- end])
138
+ end
103
139
  exit_code, stdout, stderr = run 'last_deploys', '--sort-by', 'user_desc'
104
140
  expect(exit_code).to eq 0
105
141
  expect(stdout).to eq(<<~EOS)
106
- +-------+---------------------+-------------+--------------------+-------+
107
- | Node | Date | Admin | Services | Error |
108
- +-------+---------------------+-------------+--------------------+-------+
109
- | node1 | 2019-08-21 10:12:15 | admin_user2 | service1 | |
110
- | node2 | 2019-08-22 10:12:15 | admin_user1 | service1, service2 | |
111
- +-------+---------------------+-------------+--------------------+-------+
142
+ +-------+-------------------------+-------------+--------------------+-------+
143
+ | Node | Date | Admin | Services | Error |
144
+ +-------+-------------------------+-------------+--------------------+-------+
145
+ | node1 | 2019-08-21 10:12:15 UTC | admin_user2 | service1 | |
146
+ | node2 | 2019-08-22 10:12:15 UTC | admin_user1 | service1, service2 | |
147
+ +-------+-------------------------+-------------+--------------------+-------+
112
148
  EOS
113
149
  expect(stderr).to eq ''
114
150
  end
@@ -116,24 +152,31 @@ describe 'last_deploys executable' do
116
152
 
117
153
  it 'displays only the selected nodes' do
118
154
  with_test_platform_for_last_deploys do
119
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
120
- expect(actions).to eq('node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" })
155
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1]) do
121
156
  {
122
- 'node1' => [0, <<~EOS, ''],
123
- date: 2019-08-21 10:12:15
124
- user: admin_user1
125
- services: service1
126
- EOS
157
+ 'node1' => {
158
+ services: %w[service1],
159
+ deployment_info: {
160
+ repo_name_0: 'platform',
161
+ commit_id_0: 'abcdef1',
162
+ exit_status: 0,
163
+ date: Time.parse('2019-08-21 10:12:15 UTC'),
164
+ user: 'admin_user1'
165
+ },
166
+ exit_status: 0,
167
+ stdout: '',
168
+ stderr: ''
169
+ }
127
170
  }
128
- end])
171
+ end
129
172
  exit_code, stdout, stderr = run 'last_deploys', '--node', 'node1'
130
173
  expect(exit_code).to eq 0
131
174
  expect(stdout).to eq(<<~EOS)
132
- +-------+---------------------+-------------+----------+-------+
133
- | Node | Date | Admin | Services | Error |
134
- +-------+---------------------+-------------+----------+-------+
135
- | node1 | 2019-08-21 10:12:15 | admin_user1 | service1 | |
136
- +-------+---------------------+-------------+----------+-------+
175
+ +-------+-------------------------+-------------+----------+-------+
176
+ | Node | Date | Admin | Services | Error |
177
+ +-------+-------------------------+-------------+----------+-------+
178
+ | node1 | 2019-08-21 10:12:15 UTC | admin_user1 | service1 | |
179
+ +-------+-------------------------+-------------+----------+-------+
137
180
  EOS
138
181
  expect(stderr).to eq ''
139
182
  end
@@ -141,30 +184,35 @@ describe 'last_deploys executable' do
141
184
 
142
185
  it 'displays errors when we can\'t get info from some nodes' do
143
186
  with_test_platform_for_last_deploys do
144
- expect_actions_executor_runs([proc do |actions, timeout: nil, concurrent: false, log_to_dir: 'run_logs', log_to_stdout: true|
145
- expect(actions).to eq(
146
- 'node1' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" },
147
- 'node2' => { remote_bash: "cd /var/log/deployments && ls -t | head -1 | xargs sed '/===== STDOUT =====/q'" }
148
- )
187
+ expect(test_deployer).to receive(:deployment_info_from).with(%w[node1 node2]) do
149
188
  {
150
- 'node1' => [:connection_error, 'Error on stdout', 'Error on stderr'],
151
- 'node2' => [0, <<~EOS, '']
152
- date: 2019-08-22 10:12:15
153
- user: admin_user1
154
- services: service1, service2
155
- EOS
189
+ 'node1' => {
190
+ error: 'Error while getting logs'
191
+ },
192
+ 'node2' => {
193
+ services: %w[service1 service2],
194
+ deployment_info: {
195
+ repo_name_0: 'platform',
196
+ commit_id_0: 'abcdef2',
197
+ exit_status: 0,
198
+ date: Time.parse('2019-08-22 10:12:15 UTC'),
199
+ user: 'admin_user2'
200
+ },
201
+ exit_status: 0,
202
+ stdout: '',
203
+ stderr: ''
204
+ }
156
205
  }
157
- end])
206
+ end
158
207
  exit_code, stdout, stderr = run 'last_deploys', '--sort-by', 'user_desc'
159
208
  expect(exit_code).to eq 0
160
209
  expect(stdout).to eq(<<~EOS)
161
- +-------+---------------------+-------------+--------------------+-------------------------+
162
- | Node | Date | Admin | Services | Error |
163
- +-------+---------------------+-------------+--------------------+-------------------------+
164
- | node2 | 2019-08-22 10:12:15 | admin_user1 | service1, service2 | |
165
- | node1 | | | | Error: connection_error |
166
- | | | | | Error on stderr |
167
- +-------+---------------------+-------------+--------------------+-------------------------+
210
+ +-------+-------------------------+-------------+--------------------+--------------------------+
211
+ | Node | Date | Admin | Services | Error |
212
+ +-------+-------------------------+-------------+--------------------+--------------------------+
213
+ | node2 | 2019-08-22 10:12:15 UTC | admin_user2 | service1, service2 | |
214
+ | node1 | | | | Error while getting logs |
215
+ +-------+-------------------------+-------------+--------------------+--------------------------+
168
216
  EOS
169
217
  expect(stderr).to eq ''
170
218
  end