foreman_acd 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +75 -0
  3. data/app/controllers/foreman_acd/app_instances_controller.rb +19 -2
  4. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +1 -1
  5. data/app/controllers/foreman_acd/remote_execution_controller.rb +37 -21
  6. data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +12 -7
  7. data/app/lib/actions/foreman_acd/run_configurator.rb +10 -7
  8. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +2 -2
  9. data/app/models/foreman_acd/acd_provider.rb +7 -1
  10. data/app/models/foreman_acd/ansible_playbook.rb +2 -1
  11. data/app/models/foreman_acd/app_instance.rb +1 -1
  12. data/app/services/foreman_acd/acd_proxy_proxy_selector.rb +17 -0
  13. data/app/services/foreman_acd/app_configurator.rb +59 -15
  14. data/app/services/foreman_acd/app_deployer.rb +8 -2
  15. data/app/services/foreman_acd/inventory_creator.rb +14 -0
  16. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +41 -7
  17. data/app/views/foreman_acd/app_definitions/_form.html.erb +1 -1
  18. data/app/views/foreman_acd/app_instances/_form.html.erb +1 -1
  19. data/app/views/foreman_acd/app_instances/index.html.erb +5 -3
  20. data/app/views/foreman_acd/app_instances/report.html.erb +1 -1
  21. data/app/views/templates/job/run_acd_ansible_playbook.erb +1 -1
  22. data/config/routes.rb +3 -0
  23. data/db/migrate/20210316151145_add_git_commit_to_ansible_playbooks.rb +8 -0
  24. data/db/migrate/20210503122809_add_git_url_to_ansible_playbooks.rb +8 -0
  25. data/db/seeds.d/75-job_templates.rb +1 -1
  26. data/lib/foreman_acd.rb +12 -0
  27. data/lib/foreman_acd/engine.rb +26 -4
  28. data/lib/foreman_acd/plugin.rb +0 -9
  29. data/lib/foreman_acd/version.rb +1 -1
  30. data/lib/tasks/foreman_acd_tasks.rake +0 -12
  31. data/package.json +8 -8
  32. data/test/controllers/ansible_playbooks_controller_test.rb +1 -1
  33. data/test/controllers/app_instances_controller_test.rb +8 -3
  34. data/test/controllers/ui_acd_controller_test.rb +22 -6
  35. data/test/factories/foreman_acd_factories.rb +18 -4
  36. data/test/models/acd_provider_test.rb +37 -0
  37. data/test/models/ansible_playbook_test.rb +11 -0
  38. data/test/models/app_definition_test.rb +1 -1
  39. data/test/models/app_instance_test.rb +2 -0
  40. data/test/models/concerns/host_extensions_test.rb +26 -0
  41. data/test/models/foreman_host_test.rb +12 -0
  42. data/webpack/__mocks__/foremanReact/API.js +2 -0
  43. data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
  44. data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
  45. data/webpack/__mocks__/foremanReact/components/ForemanModal.js +7 -0
  46. data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
  47. data/webpack/__mocks__/foremanReact/components/common/forms/TextInput.js +2 -0
  48. data/webpack/__mocks__/foremanReact/components/hosts/powerStatus.js +1 -0
  49. data/webpack/__snapshots__/helper.test.js.snap +14 -0
  50. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +1 -1
  51. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionConfData_1.fixtures.js +288 -0
  52. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionReducer.fixtures.js +79 -0
  53. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +25 -0
  54. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionReducer.test.js +119 -0
  55. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +41 -0
  56. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +200 -0
  57. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionReducer.test.js.snap +3033 -0
  58. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +299 -0
  59. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +1 -0
  60. data/webpack/components/ApplicationDefinition/components/__tests__/AnsiblePlaybookSelector.test.js +41 -0
  61. data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +121 -0
  62. data/webpack/components/ApplicationInstance/ApplicationInstance.js +3 -5
  63. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceConfData_1.fixtures.js +263 -0
  64. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +78 -0
  65. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +23 -0
  66. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +119 -0
  67. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +44 -0
  68. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +209 -0
  69. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +2719 -0
  70. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +276 -0
  71. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportData_1.fixtures.js +349 -0
  72. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportReducer.fixtures.js +20 -0
  73. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +47 -0
  74. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportReducer.test.js +41 -0
  75. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportSelectors.test.js +26 -0
  76. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +130 -0
  77. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +718 -0
  78. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportSelectors.test.js.snap +347 -0
  79. data/webpack/components/ApplicationInstanceReport/components/__tests__/ReportViewer.test.js +24 -0
  80. data/webpack/components/ApplicationInstanceReport/components/__tests__/__snapshots__/ReportViewer.test.js.snap +24 -0
  81. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +2 -21
  82. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +116 -84
  83. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +10 -4
  84. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +36 -46
  85. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +31 -25
  86. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  87. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +2 -126
  88. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +1483 -872
  89. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +117 -79
  90. data/webpack/components/SyncGitRepo/SyncGitRepo.js +210 -0
  91. data/webpack/components/SyncGitRepo/SyncGitRepo.scss +1 -0
  92. data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +124 -0
  93. data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +9 -0
  94. data/webpack/components/SyncGitRepo/SyncGitRepoReducer.js +80 -0
  95. data/webpack/components/SyncGitRepo/SyncGitRepoSelectors.js +6 -0
  96. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoConfData_1.fixtures.js +7 -0
  97. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoReducer.fixtures.js +44 -0
  98. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepo.test.js +27 -0
  99. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoReducer.test.js +95 -0
  100. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoSelectors.test.js +32 -0
  101. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +30 -0
  102. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoReducer.test.js.snap +137 -0
  103. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoSelectors.test.js.snap +13 -0
  104. data/webpack/components/SyncGitRepo/components/FormTextInput.js +42 -0
  105. data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +46 -0
  106. data/webpack/components/SyncGitRepo/index.js +28 -0
  107. data/webpack/components/common/ExtTextInput.js +43 -0
  108. data/webpack/components/common/__tests__/EditTableEntry.test.js +53 -0
  109. data/webpack/components/common/__tests__/LockTableEntry.test.js +35 -0
  110. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +2 -2
  111. data/webpack/components/common/__tests__/__snapshots__/EditTableEntry.test.js.snap +81 -0
  112. data/webpack/components/common/__tests__/__snapshots__/LockTableEntry.test.js.snap +60 -0
  113. data/webpack/helper.js +15 -1
  114. data/webpack/helper.test.js +37 -0
  115. data/webpack/index.js +2 -0
  116. data/webpack/reducer.js +4 -0
  117. metadata +92 -11
  118. data/webpack/components/common/EasyHeaderFormatter.js +0 -18
  119. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
  120. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module ForemanAcd
6
+ # ACD Provider Test
7
+ class AcdProviderTest < ActiveSupport::TestCase
8
+ describe '.provider_names' do
9
+ let(:provider_names) { AcdProvider.provider_names }
10
+
11
+ it 'returns only strings' do
12
+ provider_names.each do |name|
13
+ _(name).must_be_kind_of String
14
+ end
15
+ end
16
+
17
+ context 'provider is registetered under :custom symbol' do
18
+ before { AcdProvider.register(:ACD, String) }
19
+ it { _(provider_names).must_include 'ACD' }
20
+ end
21
+ end
22
+
23
+ describe AcdProvider do
24
+ before { User.current = FactoryBot.build(:user, :admin) }
25
+ after { User.current = nil }
26
+
27
+ before do
28
+ Setting::RemoteExecution.load_defaults
29
+ end
30
+
31
+ let(:job_invocation) { FactoryBot.create(:job_invocation, :with_template) }
32
+ let(:template_invocation) { job_invocation.pattern_template_invocations.first }
33
+ let(:host) { FactoryBot.create(:host) }
34
+ let(:proxy_options) { AcdProvider.proxy_command_options(template_invocation, host) }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module ForemanAcd
6
+ # Ansible Playbook Model tests
7
+ class AnsiblePlaybookTest < ActiveSupport::TestCase
8
+ should validate_presence_of(:name)
9
+ should validate_uniqueness_of(:name)
10
+ end
11
+ end
@@ -7,7 +7,7 @@ module ForemanAcd
7
7
  class AppDefinitionTest < ActiveSupport::TestCase
8
8
  should validate_presence_of(:name)
9
9
  should validate_uniqueness_of(:name)
10
- should belong_to(:hostgroup)
10
+ should belong_to(:ansible_playbook)
11
11
  should have_many(:app_instances).dependent(:destroy)
12
12
  end
13
13
  end
@@ -7,5 +7,7 @@ module ForemanAcd
7
7
  class AppInstanceTest < ActiveSupport::TestCase
8
8
  should validate_presence_of(:name)
9
9
  should belong_to(:app_definition)
10
+ should belong_to(:location)
11
+ should belong_to(:organization)
10
12
  end
11
13
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module ForemanAcd
6
+ # Host Extensions Test
7
+ class HostExtensionsTest < ActiveSupport::TestCase
8
+ setup do
9
+ User.current = users :admin
10
+ end
11
+
12
+ test 'host was deployed via acd?' do
13
+ host = FactoryBot.create :host
14
+ app = FactoryBot.create :app_instance
15
+
16
+ foreman_host = app.foreman_hosts.create(:hostname => host.name,
17
+ :service => 'DB',
18
+ :description => 'Description',
19
+ :foremanParameters => nil,
20
+ :ansibleParameters => nil)
21
+ foreman_host.host = host
22
+ foreman_host.save
23
+ assert host.deployed_via_acd?
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module ForemanAcd
6
+ # ForemanHost Model tests
7
+ class ForemanHostTest < ActiveSupport::TestCase
8
+ should validate_presence_of(:hostname)
9
+ should belong_to(:app_instance)
10
+ should belong_to(:host)
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ const API = () => jest.fn();
2
+ export default API;
@@ -0,0 +1,3 @@
1
+ export const translate = s => s;
2
+ export const ngettext = s => s;
3
+ export const documentLocale = () => 'en';
@@ -0,0 +1,2 @@
1
+ export const propsToSnakeCase = s => s;
2
+ export const propsToCamelCase = s => s;
@@ -0,0 +1,7 @@
1
+ const ForemanModal = () => {};
2
+ const Header = s => s;
3
+ const Footer = s => s;
4
+
5
+ ForemanModal.Header = Header;
6
+ ForemanModal.Footer = Footer;
7
+ export default ForemanModal;
@@ -0,0 +1,2 @@
1
+ const CommonForm = () => jest.fn();
2
+ export default CommonForm;
@@ -0,0 +1,2 @@
1
+ const TextInput = () => jest.fn();
2
+ export default TextInput;
@@ -0,0 +1 @@
1
+ export const PowerStatus = () => jest.fn();
@@ -0,0 +1,14 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`helper creates a object from an array 1`] = `
4
+ <TableHeading
5
+ align=""
6
+ aria-label="TheLabel"
7
+ className=""
8
+ p1="1"
9
+ sort={false}
10
+ sortDirection=""
11
+ >
12
+ MyValue
13
+ </TableHeading>
14
+ `;
@@ -12,9 +12,9 @@ import ParameterSelection from '../ParameterSelection';
12
12
  import AddTableEntry from '../common/AddTableEntry';
13
13
  import DeleteTableEntry from '../common/DeleteTableEntry';
14
14
  import RailsData from '../common/RailsData';
15
- import EasyHeaderFormatter from '../common/EasyHeaderFormatter';
16
15
  import AnsiblePlaybookSelector from './components/AnsiblePlaybookSelector';
17
16
  import { translate as __ } from 'foremanReact/common/I18n';
17
+ import { EasyHeaderFormatter } from '../../helper';
18
18
 
19
19
  import {
20
20
  Table,
@@ -0,0 +1,288 @@
1
+ export const applicationDefinitionConfData_1 = {
2
+ name: false,
3
+ error: {
4
+ errorMsg: '',
5
+ status: '',
6
+ statusText: ''
7
+ },
8
+ columns: [
9
+ {
10
+ property: 'name',
11
+ header: {
12
+ label: 'Name',
13
+ formatters: [
14
+ null
15
+ ],
16
+ props: {
17
+ index: 0,
18
+ style: {
19
+ width: '15%'
20
+ }
21
+ }
22
+ },
23
+ cell: {
24
+ formatters: [
25
+ null
26
+ ]
27
+ }
28
+ },
29
+ {
30
+ property: 'description',
31
+ header: {
32
+ label: 'Description',
33
+ formatters: [
34
+ null
35
+ ],
36
+ props: {
37
+ index: 1,
38
+ style: {
39
+ width: '10%'
40
+ }
41
+ }
42
+ },
43
+ cell: {
44
+ formatters: [
45
+ null
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ property: 'hostgroup',
51
+ header: {
52
+ label: 'Hostgroup',
53
+ formatters: [
54
+ null
55
+ ],
56
+ props: {
57
+ index: 2,
58
+ style: {
59
+ width: '20%'
60
+ }
61
+ }
62
+ },
63
+ cell: {
64
+ formatters: [
65
+ null
66
+ ]
67
+ }
68
+ },
69
+ {
70
+ property: 'ansibleGroup',
71
+ header: {
72
+ label: 'Ansible Group',
73
+ formatters: [
74
+ null
75
+ ],
76
+ props: {
77
+ index: 3,
78
+ style: {
79
+ width: '20%'
80
+ }
81
+ }
82
+ },
83
+ cell: {
84
+ formatters: [
85
+ null
86
+ ]
87
+ }
88
+ },
89
+ {
90
+ property: 'minCount',
91
+ header: {
92
+ label: 'min count',
93
+ formatters: [
94
+ null
95
+ ],
96
+ props: {
97
+ index: 4,
98
+ style: {
99
+ width: '10%'
100
+ }
101
+ }
102
+ },
103
+ cell: {
104
+ formatters: [
105
+ null
106
+ ]
107
+ }
108
+ },
109
+ {
110
+ property: 'maxCount',
111
+ header: {
112
+ label: 'max count',
113
+ formatters: [
114
+ null
115
+ ],
116
+ props: {
117
+ index: 5,
118
+ style: {
119
+ width: '10%'
120
+ }
121
+ }
122
+ },
123
+ cell: {
124
+ formatters: [
125
+ null
126
+ ]
127
+ }
128
+ },
129
+ {
130
+ property: 'actions',
131
+ header: {
132
+ label: 'Actions',
133
+ formatters: [
134
+ null
135
+ ],
136
+ props: {
137
+ index: 6,
138
+ style: {
139
+ width: '15%'
140
+ }
141
+ }
142
+ },
143
+ cell: {
144
+ formatters: [
145
+ null
146
+ ]
147
+ }
148
+ }
149
+ ],
150
+ ansiblePlaybook: {
151
+ id: 2,
152
+ name: 'LAMP',
153
+ groups: {
154
+ webservers: [
155
+ {
156
+ id: 0,
157
+ name: 'dummy_var',
158
+ value: '0'
159
+ }
160
+ ],
161
+ dbservers: [
162
+ {
163
+ id: 0,
164
+ name: 'mysqlservice',
165
+ value: 'mysqld'
166
+ },
167
+ {
168
+ id: 1,
169
+ name: 'mysql_port',
170
+ value: '3306'
171
+ },
172
+ {
173
+ id: 2,
174
+ name: 'dbuser',
175
+ value: 'webapp'
176
+ },
177
+ {
178
+ id: 3,
179
+ name: 'dbname',
180
+ value: 'ANSAP01'
181
+ },
182
+ {
183
+ id: 4,
184
+ name: 'upassword',
185
+ value: 'Bond@007'
186
+ },
187
+ {
188
+ id: 5,
189
+ name: 'masterpassword',
190
+ value: 'MySQL@007'
191
+ }
192
+ ],
193
+ all: [
194
+ {
195
+ id: 0,
196
+ name: 'repository',
197
+ value: 'https://github.com/bennojoy/mywebapp.git'
198
+ }
199
+ ]
200
+ }
201
+ },
202
+ services: [
203
+ {
204
+ id: 1,
205
+ name: 'web',
206
+ description: '',
207
+ hostgroup: '1',
208
+ ansibleGroup: 'webservers',
209
+ minCount: '2',
210
+ maxCount: '',
211
+ foremanParameters: [
212
+ {
213
+ id: 1,
214
+ locked: false,
215
+ name: 'CP',
216
+ description: '',
217
+ type: 'computeprofile',
218
+ value: '1'
219
+ },
220
+ {
221
+ id: 2,
222
+ locked: true,
223
+ name: 'LE',
224
+ description: '',
225
+ type: 'lifecycleenv',
226
+ value: '1'
227
+ }
228
+ ],
229
+ ansibleParameters: [
230
+ {
231
+ id: 0,
232
+ name: 'dummy_var',
233
+ value: '0'
234
+ }
235
+ ]
236
+ },
237
+ {
238
+ id: 2,
239
+ name: 'db',
240
+ description: '',
241
+ hostgroup: '1',
242
+ ansibleGroup: 'dbservers',
243
+ minCount: '1',
244
+ maxCount: '',
245
+ foremanParameters: [],
246
+ ansibleParameters: [
247
+ {
248
+ id: 0,
249
+ name: 'mysqlservice',
250
+ value: 'mysqld'
251
+ },
252
+ {
253
+ id: 1,
254
+ name: 'mysql_port',
255
+ value: '3306',
256
+ locked: true
257
+ },
258
+ {
259
+ id: 2,
260
+ name: 'dbuser',
261
+ value: 'webapp'
262
+ },
263
+ {
264
+ id: 3,
265
+ name: 'dbname',
266
+ value: 'ANSAP01'
267
+ },
268
+ {
269
+ id: 4,
270
+ name: 'upassword',
271
+ value: 'Bond@007'
272
+ },
273
+ {
274
+ id: 5,
275
+ name: 'masterpassword',
276
+ value: 'MySQL@007'
277
+ }
278
+ ]
279
+ }
280
+ ],
281
+ ansibleVarsAll: [
282
+ {
283
+ id: 0,
284
+ name: 'repository',
285
+ value: 'https://github.com/bennojoy/mywebapp.git'
286
+ }
287
+ ]
288
+ }