hybrid_platforms_conductor 33.3.0 → 33.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +31 -2
  4. data/docs/config_dsl.md +45 -0
  5. data/docs/plugins/cmdb/host_keys.md +3 -1
  6. data/docs/plugins/connector/ssh.md +1 -0
  7. data/lib/hybrid_platforms_conductor/actions_executor.rb +29 -1
  8. data/lib/hybrid_platforms_conductor/bitbucket.rb +134 -90
  9. data/lib/hybrid_platforms_conductor/cmd_runner.rb +4 -4
  10. data/lib/hybrid_platforms_conductor/common_config_dsl/bitbucket.rb +12 -44
  11. data/lib/hybrid_platforms_conductor/common_config_dsl/github.rb +9 -31
  12. data/lib/hybrid_platforms_conductor/config.rb +2 -0
  13. data/lib/hybrid_platforms_conductor/confluence.rb +93 -88
  14. data/lib/hybrid_platforms_conductor/connector.rb +5 -2
  15. data/lib/hybrid_platforms_conductor/credentials.rb +122 -97
  16. data/lib/hybrid_platforms_conductor/deployer.rb +7 -9
  17. data/lib/hybrid_platforms_conductor/github.rb +39 -0
  18. data/lib/hybrid_platforms_conductor/hpc_plugins/action/bash.rb +1 -1
  19. data/lib/hybrid_platforms_conductor/hpc_plugins/action/remote_bash.rb +27 -17
  20. data/lib/hybrid_platforms_conductor/hpc_plugins/cmdb/host_keys.rb +13 -12
  21. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/local.rb +6 -4
  22. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/my_connector.rb.sample +1 -1
  23. data/lib/hybrid_platforms_conductor/hpc_plugins/connector/ssh.rb +37 -25
  24. data/lib/hybrid_platforms_conductor/hpc_plugins/log/remote_fs.rb +5 -6
  25. data/lib/hybrid_platforms_conductor/hpc_plugins/platform_handler/serverless_chef.rb +1 -1
  26. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/docker.rb +1 -1
  27. data/lib/hybrid_platforms_conductor/hpc_plugins/provisioner/proxmox.rb +7 -4
  28. data/lib/hybrid_platforms_conductor/hpc_plugins/report/confluence.rb +3 -1
  29. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/keepass.rb +3 -2
  30. data/lib/hybrid_platforms_conductor/hpc_plugins/secrets_reader/thycotic.rb +3 -1
  31. data/lib/hybrid_platforms_conductor/hpc_plugins/test/bitbucket_conf.rb +4 -1
  32. data/lib/hybrid_platforms_conductor/hpc_plugins/test/check_deploy_and_idempotence.rb +17 -3
  33. data/lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_removes_root_access.rb +30 -10
  34. data/lib/hybrid_platforms_conductor/hpc_plugins/test/file_system.rb +1 -1
  35. data/lib/hybrid_platforms_conductor/hpc_plugins/test/github_ci.rb +4 -1
  36. data/lib/hybrid_platforms_conductor/hpc_plugins/test/hostname.rb +1 -2
  37. data/lib/hybrid_platforms_conductor/hpc_plugins/test/idempotence.rb +1 -1
  38. data/lib/hybrid_platforms_conductor/hpc_plugins/test/ip.rb +1 -2
  39. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_conf.rb +7 -3
  40. data/lib/hybrid_platforms_conductor/hpc_plugins/test/jenkins_ci_masters_ok.rb +8 -4
  41. data/lib/hybrid_platforms_conductor/hpc_plugins/test/local_users.rb +1 -2
  42. data/lib/hybrid_platforms_conductor/hpc_plugins/test/mounts.rb +1 -2
  43. data/lib/hybrid_platforms_conductor/hpc_plugins/test/orphan_files.rb +1 -2
  44. data/lib/hybrid_platforms_conductor/hpc_plugins/test/spectre.rb +1 -1
  45. data/lib/hybrid_platforms_conductor/hpc_plugins/test/vulnerabilities.rb +1 -2
  46. data/lib/hybrid_platforms_conductor/hpc_plugins/test_report/confluence.rb +3 -1
  47. data/lib/hybrid_platforms_conductor/logger_helpers.rb +24 -1
  48. data/lib/hybrid_platforms_conductor/test.rb +21 -7
  49. data/lib/hybrid_platforms_conductor/tests_runner.rb +7 -6
  50. data/lib/hybrid_platforms_conductor/thycotic.rb +80 -75
  51. data/lib/hybrid_platforms_conductor/version.rb +1 -1
  52. data/spec/hybrid_platforms_conductor_test.rb +6 -0
  53. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/bash_spec.rb +15 -0
  54. data/spec/hybrid_platforms_conductor_test/api/actions_executor/actions/remote_bash_spec.rb +32 -0
  55. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/local/remote_actions_spec.rb +87 -0
  56. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/connections_spec.rb +30 -0
  57. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/global_helpers_spec.rb +10 -0
  58. data/spec/hybrid_platforms_conductor_test/api/actions_executor/connectors/ssh/remote_actions_spec.rb +38 -0
  59. data/spec/hybrid_platforms_conductor_test/api/actions_executor/helpers_spec.rb +195 -0
  60. data/spec/hybrid_platforms_conductor_test/api/cmd_runner_spec.rb +14 -0
  61. data/spec/hybrid_platforms_conductor_test/api/config_spec.rb +11 -0
  62. data/spec/hybrid_platforms_conductor_test/api/credentials_spec.rb +251 -0
  63. data/spec/hybrid_platforms_conductor_test/api/deployer/log_plugins/remote_fs_spec.rb +215 -0
  64. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/keepass_spec.rb +280 -319
  65. data/spec/hybrid_platforms_conductor_test/api/deployer/secrets_reader_plugins/thycotic_spec.rb +2 -2
  66. data/spec/hybrid_platforms_conductor_test/api/nodes_handler/cmdbs/host_keys_spec.rb +49 -10
  67. data/spec/hybrid_platforms_conductor_test/api/platform_handlers/serverless_chef/services_deployment_spec.rb +38 -0
  68. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/bitbucket_conf_spec.rb +49 -69
  69. data/spec/hybrid_platforms_conductor_test/api/tests_runner/test_plugins/github_ci_spec.rb +29 -39
  70. data/spec/hybrid_platforms_conductor_test/helpers/connector_ssh_helpers.rb +5 -3
  71. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/1_local_node/chef_versions.yml +3 -0
  72. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/1_local_node/nodes/node.json +15 -0
  73. data/spec/hybrid_platforms_conductor_test/serverless_chef_repositories/1_local_node/policyfiles/test_policy.rb +3 -0
  74. data/spec/hybrid_platforms_conductor_test/shared_examples/deployer.rb +134 -0
  75. data/spec/hybrid_platforms_conductor_test/test_connector.rb +2 -2
  76. metadata +36 -2
@@ -39,9 +39,9 @@ describe HybridPlatformsConductor::Deployer do
39
39
  if user.nil?
40
40
  user = 'thycotic_user_from_netrc'
41
41
  password = 'thycotic_password_from_netrc'
42
- expect(HybridPlatformsConductor::Credentials).to receive(:with_credentials_for) do |id, _logger, _logger_stderr, url: nil, &client_code|
42
+ expect(test_deployer.instance_variable_get(:@secrets_readers)[:thycotic]).to receive(:with_credentials_for) do |id, resource: nil, &client_code|
43
43
  expect(id).to eq :thycotic
44
- expect(url).to eq thycotic_url
44
+ expect(resource).to eq thycotic_url
45
45
  client_code.call user, password
46
46
  end
47
47
  end
@@ -4,7 +4,7 @@ describe HybridPlatformsConductor::NodesHandler do
4
4
 
5
5
  it 'makes sure to have hostname or host_ip set to compute host_keys' do
6
6
  with_test_platform({}) do
7
- expect(cmdb(:host_keys).property_dependencies[:host_keys].sort).to eq %i[hostname host_ip].sort
7
+ expect(cmdb(:host_keys).property_dependencies[:host_keys].sort).to eq %i[hostname host_ip ssh_port].sort
8
8
  end
9
9
  end
10
10
 
@@ -17,17 +17,27 @@ describe HybridPlatformsConductor::NodesHandler do
17
17
  it 'returns host keys when hostname is set' do
18
18
  with_test_platform({ nodes: { 'test_node' => {} } }) do
19
19
  with_cmd_runner_mocked [
20
- ['ssh-keyscan my_host.my_domain', proc { [0, "my_host.my_domain ssh-rsa fake_host_key\n", ''] }]
20
+ ['ssh-keyscan -p 22 my_host.my_domain', proc { [0, "my_host.my_domain ssh-rsa fake_host_key\n", ''] }]
21
21
  ] do
22
22
  expect(cmdb(:host_keys).get_host_keys(['test_node'], { 'test_node' => { hostname: 'my_host.my_domain' } })).to eq('test_node' => ['ssh-rsa fake_host_key'])
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
+ it 'returns host keys for the correct ssh port' do
28
+ with_test_platform({ nodes: { 'test_node' => {} } }) do
29
+ with_cmd_runner_mocked [
30
+ ['ssh-keyscan -p 666 my_host.my_domain', proc { [0, "my_host.my_domain ssh-rsa fake_host_key\n", ''] }]
31
+ ] do
32
+ expect(cmdb(:host_keys).get_host_keys(['test_node'], { 'test_node' => { hostname: 'my_host.my_domain', ssh_port: 666 } })).to eq('test_node' => ['ssh-rsa fake_host_key'])
33
+ end
34
+ end
35
+ end
36
+
27
37
  it 'returns host keys when host_ip is set' do
28
38
  with_test_platform({ nodes: { 'test_node' => {} } }) do
29
39
  with_cmd_runner_mocked [
30
- ['ssh-keyscan 192.168.42.42', proc { [0, "192.168.42.42 ssh-rsa fake_host_key\n", ''] }]
40
+ ['ssh-keyscan -p 22 192.168.42.42', proc { [0, "192.168.42.42 ssh-rsa fake_host_key\n", ''] }]
31
41
  ] do
32
42
  expect(cmdb(:host_keys).get_host_keys(['test_node'], { 'test_node' => { host_ip: '192.168.42.42' } })).to eq('test_node' => ['ssh-rsa fake_host_key'])
33
43
  end
@@ -37,7 +47,7 @@ describe HybridPlatformsConductor::NodesHandler do
37
47
  it 'returns several host keys' do
38
48
  with_test_platform({ nodes: { 'test_node' => {} } }) do
39
49
  with_cmd_runner_mocked [
40
- ['ssh-keyscan 192.168.42.42', proc do
50
+ ['ssh-keyscan -p 22 192.168.42.42', proc do
41
51
  [0, <<~EO_STDOUT, '']
42
52
  192.168.42.42 ssh-rsa fake_host_key_rsa
43
53
  192.168.42.42 ssh-ed25519 fake_host_key_ed25519
@@ -55,7 +65,7 @@ describe HybridPlatformsConductor::NodesHandler do
55
65
  it 'returns several host keys and ignores comments from ssh-keyscan' do
56
66
  with_test_platform({ nodes: { 'test_node' => {} } }) do
57
67
  with_cmd_runner_mocked [
58
- ['ssh-keyscan 192.168.42.42', proc do
68
+ ['ssh-keyscan -p 22 192.168.42.42', proc do
59
69
  [0, <<~EO_STDOUT, '']
60
70
  # That's a comment
61
71
  192.168.42.42 ssh-rsa fake_host_key_rsa
@@ -78,7 +88,7 @@ describe HybridPlatformsConductor::NodesHandler do
78
88
  it 'returns host keys sorted' do
79
89
  with_test_platform({ nodes: { 'test_node' => {} } }) do
80
90
  with_cmd_runner_mocked [
81
- ['ssh-keyscan 192.168.42.42', proc do
91
+ ['ssh-keyscan -p 22 192.168.42.42', proc do
82
92
  [0, <<~EO_STDOUT, '']
83
93
  192.168.42.42 ssh-dsa fake_host_key_dsa
84
94
  192.168.42.42 ssh-rsa fake_host_key_rsa
@@ -100,7 +110,7 @@ describe HybridPlatformsConductor::NodesHandler do
100
110
  it 'does not return host keys when ssh-keyscan can\'t retrieve them' do
101
111
  with_test_platform({ nodes: { 'test_node' => {} } }) do
102
112
  with_cmd_runner_mocked [
103
- ['ssh-keyscan 192.168.42.42', proc { [0, '', ''] }]
113
+ ['ssh-keyscan -p 22 192.168.42.42', proc { [0, '', ''] }]
104
114
  ] do
105
115
  expect(cmdb(:host_keys).get_host_keys(['test_node'], { 'test_node' => { host_ip: '192.168.42.42' } })).to eq({})
106
116
  end
@@ -119,9 +129,9 @@ describe HybridPlatformsConductor::NodesHandler do
119
129
  }
120
130
  ) do
121
131
  with_cmd_runner_mocked [
122
- ['ssh-keyscan 192.168.42.1', proc { [0, "192.168.42.1 ssh-rsa fake_host_key_1\n", ''] }],
123
- ['ssh-keyscan 192.168.42.2', proc { [0, '', ''] }],
124
- ['ssh-keyscan my_host_4.my_domain', proc { [0, "my_host_4.my_domain ssh-rsa fake_host_key_4\n", ''] }]
132
+ ['ssh-keyscan -p 22 192.168.42.1', proc { [0, "192.168.42.1 ssh-rsa fake_host_key_1\n", ''] }],
133
+ ['ssh-keyscan -p 22 192.168.42.2', proc { [0, '', ''] }],
134
+ ['ssh-keyscan -p 22 my_host_4.my_domain', proc { [0, "my_host_4.my_domain ssh-rsa fake_host_key_4\n", ''] }]
125
135
  ] do
126
136
  expect(
127
137
  cmdb(:host_keys).get_host_keys(
@@ -141,6 +151,35 @@ describe HybridPlatformsConductor::NodesHandler do
141
151
  end
142
152
  end
143
153
 
154
+ it 'returns different host keys for hosts having the same IPs but different SSH ports' do
155
+ with_test_platform(
156
+ {
157
+ nodes: {
158
+ 'test_node1' => {},
159
+ 'test_node2' => {}
160
+ }
161
+ }
162
+ ) do
163
+ with_cmd_runner_mocked [
164
+ ['ssh-keyscan -p 6661 192.168.42.1', proc { [0, "192.168.42.1 ssh-rsa fake_host_key_1\n", ''] }],
165
+ ['ssh-keyscan -p 6662 192.168.42.1', proc { [0, "192.168.42.1 ssh-rsa fake_host_key_2\n", ''] }]
166
+ ] do
167
+ expect(
168
+ cmdb(:host_keys).get_host_keys(
169
+ ['test_node'],
170
+ {
171
+ 'test_node1' => { host_ip: '192.168.42.1', ssh_port: 6661 },
172
+ 'test_node2' => { host_ip: '192.168.42.1', ssh_port: 6662 }
173
+ }
174
+ )
175
+ ).to eq(
176
+ 'test_node1' => ['ssh-rsa fake_host_key_1'],
177
+ 'test_node2' => ['ssh-rsa fake_host_key_2']
178
+ )
179
+ end
180
+ end
181
+ end
182
+
144
183
  end
145
184
 
146
185
  end
@@ -256,6 +256,44 @@ describe HybridPlatformsConductor::HpcPlugins::PlatformHandler::ServerlessChef d
256
256
 
257
257
  end
258
258
 
259
+ context 'with a platform having 1 local node' do
260
+
261
+ it 'returns actions to deploy on this node' do
262
+ with_serverless_chef_platforms('1_local_node') do |platform, repository|
263
+ mock_package(repository)
264
+ platform.prepare_for_deploy(
265
+ services: { 'node' => %w[test_policy] },
266
+ secrets: {},
267
+ local_environment: false,
268
+ why_run: false
269
+ )
270
+ with_cmd_runner_mocked [
271
+ ['whoami', proc { [0, 'test_user', ''] }]
272
+ ] do
273
+ expect(platform.actions_to_deploy_on('node', 'test_policy', use_why_run: false)).to eq expected_actions_to_deploy_chef(repository)
274
+ end
275
+ end
276
+ end
277
+
278
+ it 'returns actions to deploy on this node as root' do
279
+ with_serverless_chef_platforms('1_local_node') do |platform, repository|
280
+ mock_package(repository)
281
+ platform.prepare_for_deploy(
282
+ services: { 'node' => %w[test_policy] },
283
+ secrets: {},
284
+ local_environment: false,
285
+ why_run: false
286
+ )
287
+ with_cmd_runner_mocked [
288
+ ['whoami', proc { [0, 'root', ''] }]
289
+ ] do
290
+ expect(platform.actions_to_deploy_on('node', 'test_policy', use_why_run: false)).to eq expected_actions_to_deploy_chef(repository, sudo: '')
291
+ end
292
+ end
293
+ end
294
+
295
+ end
296
+
259
297
  context 'with a platform having several nodes' do
260
298
 
261
299
  it 'deploys services declared on 1 node on another node if asked' do
@@ -5,8 +5,9 @@ describe HybridPlatformsConductor::TestsRunner do
5
5
  context 'with bitbucket_conf' do
6
6
 
7
7
  it 'iterates over defined Bitbucket repos' do
8
- with_repository do
9
- platforms = <<~EO_CONFIG
8
+ with_test_platform(
9
+ { nodes: { 'node' => {} } },
10
+ additional_config: <<~EO_CONFIG
10
11
  bitbucket_repos(
11
12
  url: 'https://my_bb1.my_domain.com',
12
13
  project: 'PR1',
@@ -34,73 +35,52 @@ describe HybridPlatformsConductor::TestsRunner do
34
35
  }
35
36
  )
36
37
  EO_CONFIG
37
- with_platforms platforms do
38
- repos = []
39
- test_config.for_each_bitbucket_repo do |bitbucket, repo_info|
40
- repos << {
41
- bitbucket_url: bitbucket.bitbucket_url,
42
- repo_info: repo_info
43
- }
44
- end
45
- expect(repos).to eq [
46
- {
47
- bitbucket_url: 'https://my_bb1.my_domain.com',
48
- repo_info: {
49
- name: 'repo1',
50
- project: 'PR1',
51
- url: 'https://my_bb1.my_domain.com/scm/pr1/repo1.git',
52
- jenkins_ci_url: nil,
53
- checks: {}
54
- }
55
- },
56
- {
57
- bitbucket_url: 'https://my_bb1.my_domain.com',
58
- repo_info: {
59
- name: 'repo2',
60
- project: 'PR1',
61
- url: 'https://my_bb1.my_domain.com/scm/pr1/repo2.git',
62
- jenkins_ci_url: nil,
63
- checks: {}
64
- }
65
- },
66
- {
67
- bitbucket_url: 'https://my_bb2.my_domain.com',
68
- repo_info: {
69
- name: 'repo3',
70
- project: 'PR2',
71
- url: 'https://my_bb2.my_domain.com/scm/pr2/repo3.git',
72
- jenkins_ci_url: 'https://my_jenkins.com/job/repo3',
73
- checks: {
74
- branch_permissions: [
75
- {
76
- type: 'fast-forward-only',
77
- branch: 'master',
78
- exempted_users: ['toto']
79
- }
80
- ]
81
- }
82
- }
83
- },
84
- {
85
- bitbucket_url: 'https://my_bb2.my_domain.com',
86
- repo_info: {
87
- name: 'repo4',
88
- project: 'PR2',
89
- url: 'https://my_bb2.my_domain.com/scm/pr2/repo4.git',
90
- jenkins_ci_url: 'https://my_jenkins.com/job/repo4',
91
- checks: {
92
- branch_permissions: [
93
- {
94
- type: 'fast-forward-only',
95
- branch: 'master',
96
- exempted_users: ['toto']
97
- }
98
- ]
99
- }
100
- }
101
- }
102
- ]
103
- end
38
+ ) do
39
+ test_tests_runner.tests = [:bitbucket_conf]
40
+ WebMock.disable_net_connect!
41
+ stub_request(:get, 'https://my_bb1.my_domain.com/rest/api/1.0/projects/PR1/repos/repo1/settings/pull-requests').to_return(body: {}.to_json)
42
+ stub_request(:get, 'https://my_bb1.my_domain.com/rest/default-reviewers/1.0/projects/PR1/repos/repo1/conditions').to_return(body: {}.to_json)
43
+ expect(Git).to receive(:ls_remote).with('https://my_bb1.my_domain.com/scm/pr1/repo1.git').and_return(
44
+ 'branches' => { 'master' => { sha: '12345' } },
45
+ 'tags' => { 'v1.0.0' => { sha: '12345' } }
46
+ )
47
+ stub_request(:get, 'https://my_bb1.my_domain.com/rest/api/1.0/projects/PR1/repos/repo2/settings/pull-requests').to_return(body: {}.to_json)
48
+ stub_request(:get, 'https://my_bb1.my_domain.com/rest/default-reviewers/1.0/projects/PR1/repos/repo2/conditions').to_return(body: {}.to_json)
49
+ expect(Git).to receive(:ls_remote).with('https://my_bb1.my_domain.com/scm/pr1/repo2.git').and_return(
50
+ 'branches' => { 'master' => { sha: '12345' } },
51
+ 'tags' => { 'v1.0.0' => { sha: '12345' } }
52
+ )
53
+ stub_request(:get, 'https://my_bb2.my_domain.com/rest/api/1.0/projects/PR2/repos/repo3/settings/pull-requests').to_return(body: {}.to_json)
54
+ stub_request(:get, 'https://my_bb2.my_domain.com/rest/default-reviewers/1.0/projects/PR2/repos/repo3/conditions').to_return(body: {}.to_json)
55
+ stub_request(:get, 'https://my_bb2.my_domain.com/rest/branch-permissions/2.0/projects/PR2/repos/repo3/restrictions').to_return(body: {
56
+ 'values' => [{
57
+ 'type' => 'fast-forward-only',
58
+ 'matcher' => { 'id' => 'refs/heads/master' },
59
+ 'users' => [{ 'name' => 'toto' }],
60
+ 'groups' => [],
61
+ 'accessKeys' => []
62
+ }]
63
+ }.to_json)
64
+ expect(Git).to receive(:ls_remote).with('https://my_bb2.my_domain.com/scm/pr2/repo3.git').and_return(
65
+ 'branches' => { 'master' => { sha: '12345' } },
66
+ 'tags' => { 'v1.0.0' => { sha: '12345' } }
67
+ )
68
+ stub_request(:get, 'https://my_bb2.my_domain.com/rest/api/1.0/projects/PR2/repos/repo4/settings/pull-requests').to_return(body: {}.to_json)
69
+ stub_request(:get, 'https://my_bb2.my_domain.com/rest/default-reviewers/1.0/projects/PR2/repos/repo4/conditions').to_return(body: {}.to_json)
70
+ stub_request(:get, 'https://my_bb2.my_domain.com/rest/branch-permissions/2.0/projects/PR2/repos/repo4/restrictions').to_return(body: {
71
+ 'values' => [{
72
+ 'type' => 'fast-forward-only',
73
+ 'matcher' => { 'id' => 'refs/heads/master' },
74
+ 'users' => [{ 'name' => 'toto' }],
75
+ 'groups' => [],
76
+ 'accessKeys' => []
77
+ }]
78
+ }.to_json)
79
+ expect(Git).to receive(:ls_remote).with('https://my_bb2.my_domain.com/scm/pr2/repo4.git').and_return(
80
+ 'branches' => { 'master' => { sha: '12345' } },
81
+ 'tags' => { 'v1.0.0' => { sha: '12345' } }
82
+ )
83
+ expect(test_tests_runner.run_tests(%w[node])).to eq 0
104
84
  end
105
85
  end
106
86
 
@@ -1,3 +1,5 @@
1
+ require 'octokit'
2
+
1
3
  describe HybridPlatformsConductor::TestsRunner do
2
4
 
3
5
  context 'when checking test plugins' do
@@ -5,8 +7,9 @@ describe HybridPlatformsConductor::TestsRunner do
5
7
  context 'with github_ci' do
6
8
 
7
9
  it 'iterates over defined Github repos' do
8
- with_repository do
9
- platforms = <<~EO_CONFIG
10
+ with_test_platform(
11
+ { nodes: { 'node' => {} } },
12
+ additional_config: <<~EO_CONFIG
10
13
  github_repos(
11
14
  url: 'https://my_gh.my_domain.com',
12
15
  user: 'GH-User1',
@@ -23,45 +26,32 @@ describe HybridPlatformsConductor::TestsRunner do
23
26
  ]
24
27
  )
25
28
  EO_CONFIG
26
- with_platforms platforms do
27
- repos = []
28
- test_config.for_each_github_repo do |github, repo_info|
29
- repos << {
30
- github_url: github.api_endpoint,
31
- repo_info: repo_info
32
- }
29
+ ) do
30
+ ENV['hpc_user_for_github'] = 'test-github-user'
31
+ ENV['hpc_password_for_github'] = 'GHTestToken'
32
+ test_tests_runner.tests = [:github_ci]
33
+ first_time = true
34
+ expect(Octokit::Client).to receive(:new).with(access_token: 'GHTestToken').twice do
35
+ mocked_client = instance_double(Octokit::Client)
36
+ if first_time
37
+ expect(mocked_client).to receive(:repository_workflow_runs).with('GH-User1/repo1').and_return(
38
+ workflow_runs: [{ head_branch: 'master', created_at: '2021-12-01 12:45:11', conclusion: 'success' }]
39
+ )
40
+ expect(mocked_client).to receive(:repository_workflow_runs).with('GH-User1/repo2').and_return(
41
+ workflow_runs: [{ head_branch: 'master', created_at: '2021-12-01 12:45:11', conclusion: 'success' }]
42
+ )
43
+ first_time = false
44
+ else
45
+ expect(mocked_client).to receive(:repository_workflow_runs).with('GH-User2/repo3').and_return(
46
+ workflow_runs: [{ head_branch: 'master', created_at: '2021-12-01 12:45:11', conclusion: 'success' }]
47
+ )
48
+ expect(mocked_client).to receive(:repository_workflow_runs).with('GH-User2/repo4').and_return(
49
+ workflow_runs: [{ head_branch: 'master', created_at: '2021-12-01 12:45:11', conclusion: 'success' }]
50
+ )
33
51
  end
34
- expect(repos).to eq [
35
- {
36
- github_url: 'https://my_gh.my_domain.com/',
37
- repo_info: {
38
- name: 'repo1',
39
- slug: 'GH-User1/repo1'
40
- }
41
- },
42
- {
43
- github_url: 'https://my_gh.my_domain.com/',
44
- repo_info: {
45
- name: 'repo2',
46
- slug: 'GH-User1/repo2'
47
- }
48
- },
49
- {
50
- github_url: 'https://api.github.com/',
51
- repo_info: {
52
- name: 'repo3',
53
- slug: 'GH-User2/repo3'
54
- }
55
- },
56
- {
57
- github_url: 'https://api.github.com/',
58
- repo_info: {
59
- name: 'repo4',
60
- slug: 'GH-User2/repo4'
61
- }
62
- }
63
- ]
52
+ mocked_client
64
53
  end
54
+ expect(test_tests_runner.run_tests(%w[node])).to eq 0
65
55
  end
66
56
  end
67
57
 
@@ -11,6 +11,7 @@ module HybridPlatformsConductorTest
11
11
  # * *nodes_connections* (Hash<String, Hash<Symbol,Object> >): Nodes' connections info, per node name:
12
12
  # * *connection* (String): Connection string (fqdn, IP...) used by SSH
13
13
  # * *ip* (String): IP used by SSH (can be different from connection in case of transformed SSH) [default: connection]
14
+ # * *port* (Integer): SSH port used [default: 22]
14
15
  # * *user* (String): User used by SSH
15
16
  # * *times* (Integer): Number of times this connection should be used [default: 1]
16
17
  # * *control_master_create_error* (String or nil): Error to simulate during the SSH ControlMaster creation, or nil for none [default: nil]
@@ -37,6 +38,7 @@ module HybridPlatformsConductorTest
37
38
  )
38
39
  nodes_connections.map do |node, node_connection_info|
39
40
  node_connection_info[:times] = 1 unless node_connection_info.key?(:times)
41
+ node_connection_info[:port] = 22 unless node_connection_info.key?(:port)
40
42
  ssh_commands_once = []
41
43
  ssh_commands_per_connection = []
42
44
  if with_strict_host_key_checking
@@ -44,7 +46,7 @@ module HybridPlatformsConductorTest
44
46
  ssh_commands_once.concat(
45
47
  [
46
48
  [
47
- "ssh-keyscan #{ip}",
49
+ "ssh-keyscan -p #{node_connection_info[:port]} #{ip}",
48
50
  proc { [0, "#{ip} ssh-rsa fake_host_key_for_#{ip}", ''] }
49
51
  ]
50
52
  ]
@@ -67,7 +69,7 @@ module HybridPlatformsConductorTest
67
69
  %r{^xterm -e '.+/ssh -o ControlMaster=yes -o ControlPersist=yes hpc\.#{Regexp.escape(node)}'$}
68
70
  end,
69
71
  proc do
70
- control_file = test_actions_executor.connector(:ssh).send(:control_master_file, node_connection_info[:connection], '22', node_connection_info[:user])
72
+ control_file = test_actions_executor.connector(:ssh).send(:control_master_file, node_connection_info[:connection], node_connection_info[:port].to_s, node_connection_info[:user])
71
73
  # Fail if the ControlMaster file already exists, as would SSH do if the file is stalled
72
74
  if File.exist?(control_file)
73
75
  [255, '', "Control file #{control_file} already exists"]
@@ -97,7 +99,7 @@ module HybridPlatformsConductorTest
97
99
  %r{^.+/ssh -O exit hpc\.#{Regexp.escape(node)} 2>&1 \| grep -v 'Exit request sent\.'$},
98
100
  proc do
99
101
  # Really mock the control file deletion
100
- File.unlink(test_actions_executor.connector(:ssh).send(:control_master_file, node_connection_info[:connection], '22', node_connection_info[:user]))
102
+ File.unlink(test_actions_executor.connector(:ssh).send(:control_master_file, node_connection_info[:connection], node_connection_info[:port].to_s, node_connection_info[:user]))
101
103
  [1, '', '']
102
104
  end,
103
105
  { optional: with_control_master_destroy_optional }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "node",
3
+ "normal": {
4
+ "description": "Single test node",
5
+ "image": "debian_9",
6
+ "private_ips": ["172.16.0.1"],
7
+ "local_node": true,
8
+ "property_1": {
9
+ "property_11": "value11"
10
+ },
11
+ "property_2": "value2"
12
+ },
13
+ "policy_name": "test_policy",
14
+ "policy_group": "test_group"
15
+ }