foreman_openbolt 1.2.1 → 1.4.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.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/app/controllers/api/v2/openbolt_jobs_controller.rb +78 -0
- data/app/controllers/api/v2/openbolt_tasks_controller.rb +85 -0
- data/app/controllers/concerns/foreman_openbolt/common.rb +121 -0
- data/app/controllers/concerns/foreman_openbolt/jobs.rb +85 -0
- data/app/controllers/concerns/foreman_openbolt/tasks.rb +143 -0
- data/app/controllers/foreman_openbolt/task_controller.rb +12 -291
- data/app/lib/actions/foreman_openbolt/cleanup_proxy_artifacts.rb +4 -2
- data/app/lib/actions/foreman_openbolt/poll_task_status.rb +48 -29
- data/app/models/foreman_openbolt/task_job.rb +11 -3
- data/config/routes.rb +39 -4
- data/db/migrate/20260824000000_remove_view_smart_proxies_openbolt_permission.rb +18 -0
- data/db/migrate/20261118000000_add_host_groups_to_openbolt_task_jobs.rb +7 -0
- data/lib/foreman_openbolt/engine.rb +15 -7
- data/lib/foreman_openbolt/version.rb +1 -1
- data/lib/proxy_api/openbolt.rb +64 -13
- data/package.json +1 -1
- data/test/acceptance/api_acceptance_helper.rb +109 -0
- data/test/acceptance/tests/api/authn_authz_test.rb +82 -0
- data/test/acceptance/tests/api/jobs_test.rb +77 -0
- data/test/acceptance/tests/api/launch_test.rb +79 -0
- data/test/acceptance/tests/api/proxy_tasks_test.rb +51 -0
- data/test/unit/controllers/api/v2/openbolt_jobs_controller_test.rb +251 -0
- data/test/unit/controllers/api/v2/openbolt_tasks_controller_test.rb +438 -0
- data/test/unit/controllers/task_controller_test.rb +197 -39
- data/test/unit/docker/Dockerfile +7 -0
- data/test/unit/lib/actions/poll_task_status_test.rb +112 -34
- data/test/unit/lib/proxy_api/openbolt_test.rb +121 -6
- data/test/unit/models/task_job_test.rb +13 -0
- data/webpack/src/Components/LaunchTask/HostSelector/index.js +31 -5
- data/webpack/src/Components/LaunchTask/__tests__/helpers.test.js +60 -0
- data/webpack/src/Components/LaunchTask/helpers.js +16 -0
- data/webpack/src/Components/LaunchTask/hooks/__tests__/useOpenBoltOptions.test.js +3 -0
- data/webpack/src/Components/LaunchTask/hooks/__tests__/useTasksData.test.js +5 -4
- data/webpack/src/Components/LaunchTask/hooks/useOpenBoltOptions.js +1 -1
- data/webpack/src/Components/LaunchTask/hooks/useTasksData.js +4 -1
- data/webpack/src/Components/LaunchTask/index.js +29 -13
- data/webpack/src/Components/TaskExecution/ExecutionDetails.js +8 -0
- data/webpack/src/Components/TaskExecution/ExecutionDisplay.js +4 -0
- data/webpack/src/Components/TaskExecution/__tests__/TaskExecution.test.js +1 -1
- data/webpack/src/Components/TaskExecution/hooks/__tests__/useJobPolling.test.js +8 -8
- data/webpack/src/Components/TaskExecution/hooks/useJobPolling.js +6 -3
- data/webpack/src/Components/TaskExecution/index.js +43 -7
- data/webpack/src/Components/TaskHistory/__tests__/TaskHistory.test.js +6 -6
- data/webpack/src/Components/TaskHistory/index.js +8 -3
- data/webpack/src/Components/common/HostGroupsPopover.js +53 -0
- data/webpack/src/Components/common/__tests__/HostGroupsPopover.test.js +20 -0
- metadata +22 -7
|
@@ -29,11 +29,11 @@ class ProxyApiOpenboltTest < ForemanOpenbolt::PluginTestCase
|
|
|
29
29
|
assert_equal tasks, result
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
test '
|
|
32
|
+
test 'wraps proxy HTTP errors as ProxyException' do
|
|
33
33
|
stub_request(:get, "#{PROXY_URL}/openbolt/tasks")
|
|
34
34
|
.to_return(status: 500, body: 'Internal Server Error')
|
|
35
35
|
|
|
36
|
-
assert_raises(
|
|
36
|
+
assert_raises(ProxyAPI::ProxyException) { @api.fetch_tasks }
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
test 'raises ProxyException on unparseable response body' do
|
|
@@ -159,16 +159,131 @@ class ProxyApiOpenboltTest < ForemanOpenbolt::PluginTestCase
|
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
context 'connection errors' do
|
|
162
|
-
test '
|
|
162
|
+
test 'wraps timeouts as ProxyException' do
|
|
163
163
|
stub_request(:get, "#{PROXY_URL}/openbolt/tasks").to_timeout
|
|
164
164
|
|
|
165
|
-
assert_raises(
|
|
165
|
+
assert_raises(ProxyAPI::ProxyException) { @api.fetch_tasks }
|
|
166
166
|
end
|
|
167
167
|
|
|
168
|
-
test '
|
|
168
|
+
test 'wraps connection refused as ProxyException' do
|
|
169
169
|
stub_request(:get, "#{PROXY_URL}/openbolt/tasks").to_raise(Errno::ECONNREFUSED)
|
|
170
170
|
|
|
171
|
-
assert_raises(
|
|
171
|
+
assert_raises(ProxyAPI::ProxyException) { @api.fetch_tasks }
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
test 'wraps SocketError as ProxyException' do
|
|
175
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks").to_raise(SocketError.new('host not found'))
|
|
176
|
+
|
|
177
|
+
assert_raises(ProxyAPI::ProxyException) { @api.fetch_tasks }
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
test 'wraps SSL errors as ProxyException' do
|
|
181
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks")
|
|
182
|
+
.to_raise(OpenSSL::SSL::SSLError.new('bad cert'))
|
|
183
|
+
|
|
184
|
+
assert_raises(ProxyAPI::ProxyException) { @api.fetch_tasks }
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# The proxy reports domain errors as HTTP 200 with {"error": {"message":
|
|
189
|
+
# ...}}. ProxyReportedError makes those loud everywhere except launch_task,
|
|
190
|
+
# which passes the envelope through so the caller renders a 400.
|
|
191
|
+
context 'proxy-reported errors (200 + error envelope)' do
|
|
192
|
+
error_body = { 'error' => { 'message' => 'Job not found: bogus' } }.to_json
|
|
193
|
+
|
|
194
|
+
test 'fetch_tasks raises ProxyReportedError' do
|
|
195
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks")
|
|
196
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
197
|
+
|
|
198
|
+
error = assert_raises(ProxyAPI::Openbolt::ProxyReportedError) { @api.fetch_tasks }
|
|
199
|
+
assert_match(/Job not found: bogus/, error.message)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
test 'reload_tasks raises ProxyReportedError' do
|
|
203
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks/reload")
|
|
204
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
205
|
+
|
|
206
|
+
assert_raises(ProxyAPI::Openbolt::ProxyReportedError) { @api.reload_tasks }
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
test 'openbolt_options raises ProxyReportedError' do
|
|
210
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks/options")
|
|
211
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
212
|
+
|
|
213
|
+
assert_raises(ProxyAPI::Openbolt::ProxyReportedError) { @api.openbolt_options }
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
test 'job_status raises ProxyReportedError' do
|
|
217
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/job/test-123/status")
|
|
218
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
219
|
+
|
|
220
|
+
assert_raises(ProxyAPI::Openbolt::ProxyReportedError) { @api.job_status(job_id: 'test-123') }
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
test 'job_result raises ProxyReportedError' do
|
|
224
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/job/test-123/result")
|
|
225
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
226
|
+
|
|
227
|
+
assert_raises(ProxyAPI::Openbolt::ProxyReportedError) { @api.job_result(job_id: 'test-123') }
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
test 'delete_job_artifacts raises ProxyReportedError' do
|
|
231
|
+
stub_request(:delete, "#{PROXY_URL}/openbolt/job/test-123/artifacts")
|
|
232
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
233
|
+
|
|
234
|
+
assert_raises(ProxyAPI::Openbolt::ProxyReportedError) { @api.delete_job_artifacts(job_id: 'test-123') }
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
test 'launch_task returns the error envelope unchanged' do
|
|
238
|
+
stub_request(:post, "#{PROXY_URL}/openbolt/launch/task")
|
|
239
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
240
|
+
|
|
241
|
+
result = @api.launch_task(name: 'bogus', targets: 'host1', parameters: {}, options: {})
|
|
242
|
+
assert_equal('Job not found: bogus', result['error']['message'])
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
test 'launch_task still wraps transport errors' do
|
|
246
|
+
stub_request(:post, "#{PROXY_URL}/openbolt/launch/task").to_timeout
|
|
247
|
+
|
|
248
|
+
assert_raises(ProxyAPI::ProxyException) do
|
|
249
|
+
@api.launch_task(name: 'mymod::install', targets: 'host1', parameters: {}, options: {})
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
test 'ProxyReportedError is a ProxyException so existing rescue_from chains catch it' do
|
|
254
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks")
|
|
255
|
+
.to_return(status: 200, body: error_body, headers: { 'Content-Type' => 'application/json' })
|
|
256
|
+
|
|
257
|
+
assert_raises(ProxyAPI::ProxyException) { @api.fetch_tasks }
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
test 'a task named error does not raise ProxyReportedError' do
|
|
261
|
+
tasks = {
|
|
262
|
+
'error' => { 'description' => 'Raise an error on the target' },
|
|
263
|
+
'mymod::install' => { 'description' => 'Install a package' },
|
|
264
|
+
}
|
|
265
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks")
|
|
266
|
+
.to_return(status: 200, body: tasks.to_json, headers: { 'Content-Type' => 'application/json' })
|
|
267
|
+
|
|
268
|
+
assert_equal tasks, @api.fetch_tasks
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
test 'top-level error key with a string value is not treated as an envelope' do
|
|
272
|
+
body = { 'error' => 'Plain string error' }
|
|
273
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks")
|
|
274
|
+
.to_return(status: 200, body: body.to_json,
|
|
275
|
+
headers: { 'Content-Type' => 'application/json' })
|
|
276
|
+
|
|
277
|
+
assert_equal body, @api.fetch_tasks
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
test 'error hash without a message key is not treated as an envelope' do
|
|
281
|
+
body = { 'error' => { 'code' => 42 } }
|
|
282
|
+
stub_request(:get, "#{PROXY_URL}/openbolt/tasks")
|
|
283
|
+
.to_return(status: 200, body: body.to_json,
|
|
284
|
+
headers: { 'Content-Type' => 'application/json' })
|
|
285
|
+
|
|
286
|
+
assert_equal body, @api.fetch_tasks
|
|
172
287
|
end
|
|
173
288
|
end
|
|
174
289
|
end
|
|
@@ -200,6 +200,17 @@ class TaskJobTest < ForemanOpenbolt::PluginTestCase
|
|
|
200
200
|
end
|
|
201
201
|
assert_equal({ 'items' => [] }, job.reload.result)
|
|
202
202
|
end
|
|
203
|
+
|
|
204
|
+
test 'cleanup_proxy_artifacts schedules Dynflow action when log is saved without result' do
|
|
205
|
+
job = FactoryBot.create(:task_job, status: 'success', completed_at: Time.current)
|
|
206
|
+
ForemanTasks.expects(:async_task).with(
|
|
207
|
+
::Actions::ForemanOpenbolt::CleanupProxyArtifacts,
|
|
208
|
+
job.smart_proxy_id,
|
|
209
|
+
job.job_id
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
job.update!(log: 'task finished')
|
|
213
|
+
end
|
|
203
214
|
end
|
|
204
215
|
|
|
205
216
|
context 'create_from_execution!' do
|
|
@@ -210,6 +221,7 @@ class TaskJobTest < ForemanOpenbolt::PluginTestCase
|
|
|
210
221
|
task_name: 'mymod::mytask',
|
|
211
222
|
task_description: 'Restart a service',
|
|
212
223
|
targets: ['web1.example.com'],
|
|
224
|
+
host_groups: ['webservers', 'nginx'],
|
|
213
225
|
job_id: 'exec-123',
|
|
214
226
|
parameters: { 'service' => 'nginx' },
|
|
215
227
|
options: { 'transport' => 'ssh' }
|
|
@@ -220,6 +232,7 @@ class TaskJobTest < ForemanOpenbolt::PluginTestCase
|
|
|
220
232
|
assert_equal 'mymod::mytask', job.task_name
|
|
221
233
|
assert_equal 'Restart a service', job.task_description
|
|
222
234
|
assert_equal ['web1.example.com'], job.targets
|
|
235
|
+
assert_equal ['webservers', 'nginx'], job.host_groups
|
|
223
236
|
assert_equal({ 'service' => 'nginx' }, job.task_parameters)
|
|
224
237
|
assert_equal({ 'transport' => 'ssh' }, job.openbolt_options)
|
|
225
238
|
assert_equal 'pending', job.status
|
|
@@ -35,7 +35,12 @@ const ERROR_MESSAGES = {
|
|
|
35
35
|
searchQuery: () => __('Please enter a search query'),
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const HostSelector = ({
|
|
38
|
+
const HostSelector = ({
|
|
39
|
+
selectedHosts,
|
|
40
|
+
selectedHostGroups,
|
|
41
|
+
onChange,
|
|
42
|
+
targetCount = 0,
|
|
43
|
+
}) => {
|
|
39
44
|
const [hostMethod, setHostMethod] = useState('hosts');
|
|
40
45
|
const [isOpen, setIsOpen] = useState(false);
|
|
41
46
|
const [errorText, setErrorText] = useState('');
|
|
@@ -86,9 +91,13 @@ const HostSelector = ({ onChange, targetCount = 0 }) => {
|
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
// Add host groups
|
|
94
|
+
const hostGroupNames = [];
|
|
89
95
|
if (selectedTargets.hostGroups.length > 0) {
|
|
90
96
|
const groupQueries = selectedTargets.hostGroups
|
|
91
|
-
.map(g =>
|
|
97
|
+
.map(g => {
|
|
98
|
+
hostGroupNames.push(g.name);
|
|
99
|
+
return `hostgroup_fullname = "${g.name.replace(/"/g, '\\"')}"`;
|
|
100
|
+
})
|
|
92
101
|
.join(' or ');
|
|
93
102
|
searchParts.push(`(${groupQueries})`);
|
|
94
103
|
}
|
|
@@ -99,7 +108,7 @@ const HostSelector = ({ onChange, targetCount = 0 }) => {
|
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
if (searchParts.length === 0) {
|
|
102
|
-
onChange(
|
|
111
|
+
onChange({});
|
|
103
112
|
return;
|
|
104
113
|
}
|
|
105
114
|
|
|
@@ -119,12 +128,15 @@ const HostSelector = ({ onChange, targetCount = 0 }) => {
|
|
|
119
128
|
if (!cancelled) {
|
|
120
129
|
const hostNames =
|
|
121
130
|
response.data?.results?.map(host => host.name) || [];
|
|
122
|
-
onChange(
|
|
131
|
+
onChange({
|
|
132
|
+
hostNames,
|
|
133
|
+
hostGroupNames,
|
|
134
|
+
});
|
|
123
135
|
}
|
|
124
136
|
} catch (error) {
|
|
125
137
|
if (!cancelled) {
|
|
126
138
|
setFetchError(extractErrorMessage(error));
|
|
127
|
-
onChange(
|
|
139
|
+
onChange({});
|
|
128
140
|
}
|
|
129
141
|
} finally {
|
|
130
142
|
if (!cancelled) {
|
|
@@ -162,6 +174,13 @@ const HostSelector = ({ onChange, targetCount = 0 }) => {
|
|
|
162
174
|
</MenuToggle>
|
|
163
175
|
);
|
|
164
176
|
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
setSelectedTargets({
|
|
179
|
+
hosts: selectedHosts?.map(name => ({ id: -1, name })),
|
|
180
|
+
hostGroups: selectedHostGroups?.map(name => ({ id: -1, name })),
|
|
181
|
+
});
|
|
182
|
+
}, [selectedHosts, selectedHostGroups]);
|
|
183
|
+
|
|
165
184
|
return (
|
|
166
185
|
<div className="host-selector">
|
|
167
186
|
<FormGroup fieldId="host-selector" label={__('Hosts')}>
|
|
@@ -251,6 +270,13 @@ const HostSelector = ({ onChange, targetCount = 0 }) => {
|
|
|
251
270
|
HostSelector.propTypes = {
|
|
252
271
|
onChange: PropTypes.func.isRequired,
|
|
253
272
|
targetCount: PropTypes.number.isRequired,
|
|
273
|
+
selectedHosts: PropTypes.array,
|
|
274
|
+
selectedHostGroups: PropTypes.array,
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
HostSelector.defaultProps = {
|
|
278
|
+
selectedHosts: null,
|
|
279
|
+
selectedHostGroups: null,
|
|
254
280
|
};
|
|
255
281
|
|
|
256
282
|
export default HostSelector;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { buildLaunchPayload } from '../helpers';
|
|
2
|
+
|
|
3
|
+
describe('buildLaunchPayload', () => {
|
|
4
|
+
test('passes "parameters" key through correctly', () => {
|
|
5
|
+
const body = buildLaunchPayload({
|
|
6
|
+
proxyId: 1,
|
|
7
|
+
taskName: 'mymod::install',
|
|
8
|
+
targets: ['host1.example.com'],
|
|
9
|
+
hostGroups: [],
|
|
10
|
+
parameters: { name: 'nginx', version: '1.21' },
|
|
11
|
+
options: { transport: 'ssh' },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(body).toHaveProperty('parameters', {
|
|
15
|
+
name: 'nginx',
|
|
16
|
+
version: '1.21',
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('joins targets with comma into a single string', () => {
|
|
21
|
+
const body = buildLaunchPayload({
|
|
22
|
+
proxyId: 1,
|
|
23
|
+
taskName: 'mymod::install',
|
|
24
|
+
targets: ['host1', 'host2', 'host3'],
|
|
25
|
+
hostGroups: [],
|
|
26
|
+
parameters: {},
|
|
27
|
+
options: {},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
expect(body.targets).toBe('host1,host2,host3');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('joins host groups with comma into a single string', () => {
|
|
34
|
+
const body = buildLaunchPayload({
|
|
35
|
+
proxyId: 1,
|
|
36
|
+
taskName: 'mymod::install',
|
|
37
|
+
targets: ['host1', 'host2', 'host3'],
|
|
38
|
+
hostGroups: ['webservers', 'debian'],
|
|
39
|
+
parameters: {},
|
|
40
|
+
options: {},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
expect(body.host_groups).toBe('webservers,debian');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('forwards smart_proxy_id, task_name, and options unchanged', () => {
|
|
47
|
+
const body = buildLaunchPayload({
|
|
48
|
+
proxyId: 42,
|
|
49
|
+
taskName: 'puppet_conf::set',
|
|
50
|
+
targets: ['host1'],
|
|
51
|
+
hostGroups: [],
|
|
52
|
+
parameters: {},
|
|
53
|
+
options: { transport: 'choria', 'run-as': 'root' },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(body.smart_proxy_id).toBe(42);
|
|
57
|
+
expect(body.task_name).toBe('puppet_conf::set');
|
|
58
|
+
expect(body.options).toEqual({ transport: 'choria', 'run-as': 'root' });
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Exported so tests can use the launch wire format
|
|
2
|
+
export const buildLaunchPayload = ({
|
|
3
|
+
proxyId,
|
|
4
|
+
taskName,
|
|
5
|
+
targets,
|
|
6
|
+
hostGroups,
|
|
7
|
+
parameters,
|
|
8
|
+
options,
|
|
9
|
+
}) => ({
|
|
10
|
+
smart_proxy_id: proxyId,
|
|
11
|
+
task_name: taskName,
|
|
12
|
+
targets: targets.join(','),
|
|
13
|
+
host_groups: hostGroups.join(','),
|
|
14
|
+
parameters,
|
|
15
|
+
options,
|
|
16
|
+
});
|
|
@@ -42,6 +42,9 @@ describe('useOpenBoltOptions', () => {
|
|
|
42
42
|
await result.current.fetchOpenBoltOptions(42);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
expect(API.get).toHaveBeenCalledWith(
|
|
46
|
+
expect.stringContaining('smart_proxy_id=42')
|
|
47
|
+
);
|
|
45
48
|
expect(result.current.openBoltOptionsMetadata).toEqual(options);
|
|
46
49
|
expect(result.current.openBoltOptions).toEqual({
|
|
47
50
|
transport: 'ssh',
|
|
@@ -42,14 +42,14 @@ describe('useTasksData', () => {
|
|
|
42
42
|
expect.stringContaining('fetch_tasks')
|
|
43
43
|
);
|
|
44
44
|
expect(API.get).toHaveBeenCalledWith(
|
|
45
|
-
expect.stringContaining('
|
|
45
|
+
expect.stringContaining('smart_proxy_id=42')
|
|
46
46
|
);
|
|
47
47
|
expect(result.current.taskMetadata).toEqual(tasks);
|
|
48
48
|
expect(result.current.isLoadingTasks).toBe(false);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
test('fetchTasks uses reload endpoint when forceReload is true', async () => {
|
|
52
|
-
API.
|
|
51
|
+
test('fetchTasks uses POST to the reload endpoint when forceReload is true', async () => {
|
|
52
|
+
API.post.mockResolvedValue({ data: {} });
|
|
53
53
|
|
|
54
54
|
const { result } = renderHook(() => useTasksData(), { wrapper });
|
|
55
55
|
|
|
@@ -57,9 +57,10 @@ describe('useTasksData', () => {
|
|
|
57
57
|
await result.current.fetchTasks(42, true);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
expect(API.
|
|
60
|
+
expect(API.post).toHaveBeenCalledWith(
|
|
61
61
|
expect.stringContaining('reload_tasks')
|
|
62
62
|
);
|
|
63
|
+
expect(API.get).not.toHaveBeenCalled();
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
test('fetchTasks resets state before fetching', async () => {
|
|
@@ -21,7 +21,7 @@ export const useOpenBoltOptions = () => {
|
|
|
21
21
|
|
|
22
22
|
try {
|
|
23
23
|
const { data } = await API.get(
|
|
24
|
-
`${ROUTES.API.FETCH_OPENBOLT_OPTIONS}?
|
|
24
|
+
`${ROUTES.API.FETCH_OPENBOLT_OPTIONS}?smart_proxy_id=${proxyId}`
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
setOpenBoltOptionsMetadata(data || {});
|
|
@@ -24,7 +24,10 @@ export const useTasksData = () => {
|
|
|
24
24
|
const endpoint = forceReload
|
|
25
25
|
? ROUTES.API.RELOAD_TASKS
|
|
26
26
|
: ROUTES.API.FETCH_TASKS;
|
|
27
|
-
const
|
|
27
|
+
const method = forceReload ? 'post' : 'get';
|
|
28
|
+
const { data } = await API[method](
|
|
29
|
+
`${endpoint}?smart_proxy_id=${proxyId}`
|
|
30
|
+
);
|
|
28
31
|
|
|
29
32
|
setTaskMetadata(data || {});
|
|
30
33
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useState, useCallback } from 'react';
|
|
2
|
-
import { useHistory } from 'react-router-dom';
|
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { useLocation, useHistory } from 'react-router-dom';
|
|
3
3
|
import { sprintf, translate as __ } from 'foremanReact/common/I18n';
|
|
4
4
|
|
|
5
5
|
import { API } from 'foremanReact/redux/API';
|
|
@@ -28,14 +28,17 @@ import { useSmartProxies } from './hooks/useSmartProxies';
|
|
|
28
28
|
import { useTasksData } from './hooks/useTasksData';
|
|
29
29
|
import { useOpenBoltOptions } from './hooks/useOpenBoltOptions';
|
|
30
30
|
import { useShowMessage, extractErrorMessage } from '../common/helpers';
|
|
31
|
+
import { buildLaunchPayload } from './helpers';
|
|
31
32
|
|
|
32
33
|
const LaunchTask = () => {
|
|
33
34
|
const history = useHistory();
|
|
35
|
+
const { state } = useLocation();
|
|
34
36
|
const showMessage = useShowMessage();
|
|
35
37
|
|
|
36
38
|
/* States */
|
|
37
39
|
const [selectedProxy, setSelectedProxy] = useState('');
|
|
38
40
|
const [targets, setTargets] = useState([]);
|
|
41
|
+
const [hostGroups, setHostGroups] = useState([]);
|
|
39
42
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
40
43
|
|
|
41
44
|
/* Custom hooks for data fetching */
|
|
@@ -130,10 +133,11 @@ const LaunchTask = () => {
|
|
|
130
133
|
}, [selectedProxy, fetchTasks]);
|
|
131
134
|
|
|
132
135
|
const handleTargetsChange = useCallback(
|
|
133
|
-
|
|
134
|
-
setTargets(
|
|
136
|
+
value => {
|
|
137
|
+
setTargets(value.hostNames || []);
|
|
138
|
+
setHostGroups(value.hostGroupNames || []);
|
|
135
139
|
},
|
|
136
|
-
[setTargets]
|
|
140
|
+
[setTargets, setHostGroups]
|
|
137
141
|
);
|
|
138
142
|
|
|
139
143
|
const handleSubmit = useCallback(
|
|
@@ -165,13 +169,14 @@ const LaunchTask = () => {
|
|
|
165
169
|
}
|
|
166
170
|
);
|
|
167
171
|
|
|
168
|
-
const body = {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
targets
|
|
172
|
-
|
|
172
|
+
const body = buildLaunchPayload({
|
|
173
|
+
proxyId: selectedProxy,
|
|
174
|
+
taskName: selectedTask,
|
|
175
|
+
targets,
|
|
176
|
+
hostGroups,
|
|
177
|
+
parameters: taskParameters,
|
|
173
178
|
options: visibleOptions,
|
|
174
|
-
};
|
|
179
|
+
});
|
|
175
180
|
|
|
176
181
|
const { data } = await API.post(ROUTES.API.LAUNCH_TASK, body);
|
|
177
182
|
|
|
@@ -193,15 +198,25 @@ const LaunchTask = () => {
|
|
|
193
198
|
selectedProxy,
|
|
194
199
|
selectedTask,
|
|
195
200
|
targets,
|
|
201
|
+
hostGroups,
|
|
196
202
|
taskParameters,
|
|
197
203
|
openBoltOptions,
|
|
198
204
|
openBoltOptionsMetadata,
|
|
199
|
-
smartProxies,
|
|
200
205
|
history,
|
|
201
206
|
showMessage,
|
|
202
207
|
]
|
|
203
208
|
);
|
|
204
209
|
|
|
210
|
+
/* Restore values from state */
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
if (state?.smartProxy?.id)
|
|
213
|
+
handleProxyChange(null, String(state.smartProxy.id));
|
|
214
|
+
if (state?.taskName) handleTaskChange(null, state.taskName);
|
|
215
|
+
if (state?.taskParameters) setTaskParameters(state.taskParameters);
|
|
216
|
+
if (state?.targets) setTargets(state.targets);
|
|
217
|
+
if (state?.hostGroups) setHostGroups(state.hostGroups);
|
|
218
|
+
}, []);
|
|
219
|
+
|
|
205
220
|
/* Rendering */
|
|
206
221
|
const isFormValid =
|
|
207
222
|
selectedProxy &&
|
|
@@ -217,7 +232,6 @@ const LaunchTask = () => {
|
|
|
217
232
|
<Grid hasGutter>
|
|
218
233
|
<GridItem span={12}>
|
|
219
234
|
<Flex
|
|
220
|
-
hasGutter
|
|
221
235
|
alignItems={{ default: 'alignItemsCenter' }}
|
|
222
236
|
justifyContent={{ default: 'justifyContentSpaceBetween' }}
|
|
223
237
|
>
|
|
@@ -267,6 +281,8 @@ const LaunchTask = () => {
|
|
|
267
281
|
</StackItem>
|
|
268
282
|
<StackItem>
|
|
269
283
|
<HostSelector
|
|
284
|
+
selectedHosts={targets}
|
|
285
|
+
selectedHostGroups={hostGroups}
|
|
270
286
|
onChange={handleTargetsChange}
|
|
271
287
|
targetCount={targets.length}
|
|
272
288
|
/>
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import { formatDuration, formatDate } from '../common/helpers';
|
|
25
25
|
import { STATUS, POLLING_CONFIG } from '../common/constants';
|
|
26
26
|
import HostsPopover from '../common/HostsPopover';
|
|
27
|
+
import HostGroupsPopover from '../common/HostGroupsPopover';
|
|
27
28
|
|
|
28
29
|
const STATUS_CONFIGS = {
|
|
29
30
|
[STATUS.SUCCESS]: {
|
|
@@ -116,6 +117,7 @@ const ExecutionDetails = ({
|
|
|
116
117
|
jobStatus,
|
|
117
118
|
isPolling,
|
|
118
119
|
targets,
|
|
120
|
+
hostGroups,
|
|
119
121
|
submittedAt,
|
|
120
122
|
completedAt,
|
|
121
123
|
}) => (
|
|
@@ -138,6 +140,10 @@ const ExecutionDetails = ({
|
|
|
138
140
|
<HostsPopover targets={targets} />
|
|
139
141
|
</DescriptionItem>
|
|
140
142
|
|
|
143
|
+
<DescriptionItem label={__('Host Groups')}>
|
|
144
|
+
<HostGroupsPopover hostGroups={hostGroups} />
|
|
145
|
+
</DescriptionItem>
|
|
146
|
+
|
|
141
147
|
<DescriptionItem label={__('Status')}>
|
|
142
148
|
<StatusLabel status={jobStatus} isPolling={isPolling} />
|
|
143
149
|
</DescriptionItem>
|
|
@@ -175,6 +181,7 @@ ExecutionDetails.propTypes = {
|
|
|
175
181
|
jobStatus: PropTypes.string.isRequired,
|
|
176
182
|
isPolling: PropTypes.bool.isRequired,
|
|
177
183
|
targets: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
184
|
+
hostGroups: PropTypes.arrayOf(PropTypes.string),
|
|
178
185
|
submittedAt: PropTypes.string,
|
|
179
186
|
completedAt: PropTypes.string,
|
|
180
187
|
};
|
|
@@ -183,6 +190,7 @@ ExecutionDetails.defaultProps = {
|
|
|
183
190
|
smartProxy: null,
|
|
184
191
|
submittedAt: null,
|
|
185
192
|
completedAt: null,
|
|
193
|
+
hostGroups: null,
|
|
186
194
|
};
|
|
187
195
|
|
|
188
196
|
export default ExecutionDetails;
|
|
@@ -14,6 +14,7 @@ const ExecutionDisplay = ({
|
|
|
14
14
|
jobStatus,
|
|
15
15
|
isPolling,
|
|
16
16
|
targets,
|
|
17
|
+
hostGroups,
|
|
17
18
|
submittedAt,
|
|
18
19
|
completedAt,
|
|
19
20
|
taskName,
|
|
@@ -44,6 +45,7 @@ const ExecutionDisplay = ({
|
|
|
44
45
|
jobStatus={jobStatus}
|
|
45
46
|
isPolling={isPolling}
|
|
46
47
|
targets={targets}
|
|
48
|
+
hostGroups={hostGroups}
|
|
47
49
|
submittedAt={submittedAt}
|
|
48
50
|
completedAt={completedAt}
|
|
49
51
|
/>
|
|
@@ -79,6 +81,7 @@ ExecutionDisplay.propTypes = {
|
|
|
79
81
|
jobStatus: PropTypes.string.isRequired,
|
|
80
82
|
isPolling: PropTypes.bool.isRequired,
|
|
81
83
|
targets: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
84
|
+
hostGroups: PropTypes.arrayOf(PropTypes.string),
|
|
82
85
|
submittedAt: PropTypes.string,
|
|
83
86
|
completedAt: PropTypes.string,
|
|
84
87
|
taskName: PropTypes.string,
|
|
@@ -93,6 +96,7 @@ ExecutionDisplay.defaultProps = {
|
|
|
93
96
|
taskName: null,
|
|
94
97
|
taskDescription: null,
|
|
95
98
|
taskParameters: {},
|
|
99
|
+
hostGroups: null,
|
|
96
100
|
};
|
|
97
101
|
|
|
98
102
|
export default ExecutionDisplay;
|
|
@@ -53,7 +53,7 @@ describe('TaskExecution', () => {
|
|
|
53
53
|
test('strips ANSI codes from log output when result is available', async () => {
|
|
54
54
|
const statusData = {
|
|
55
55
|
status: 'success',
|
|
56
|
-
|
|
56
|
+
name: 'test::task',
|
|
57
57
|
targets: ['host1'],
|
|
58
58
|
submitted_at: '2026-01-01T00:00:00Z',
|
|
59
59
|
completed_at: '2026-01-01T00:01:00Z',
|
|
@@ -22,9 +22,9 @@ describe('useJobPolling', () => {
|
|
|
22
22
|
status: 'success',
|
|
23
23
|
submitted_at: '2026-01-01T00:00:00Z',
|
|
24
24
|
completed_at: '2026-01-01T00:01:00Z',
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
name: 'test::task',
|
|
26
|
+
description: 'A test task',
|
|
27
|
+
parameters: { name: 'nginx' },
|
|
28
28
|
targets: ['host1.example.com'],
|
|
29
29
|
smart_proxy: { id: 1, name: 'proxy1' },
|
|
30
30
|
};
|
|
@@ -60,7 +60,7 @@ describe('useJobPolling', () => {
|
|
|
60
60
|
test('does not fetch result for INVALID status', async () => {
|
|
61
61
|
const statusData = {
|
|
62
62
|
status: 'invalid',
|
|
63
|
-
|
|
63
|
+
name: 'broken::task',
|
|
64
64
|
targets: [],
|
|
65
65
|
};
|
|
66
66
|
|
|
@@ -96,7 +96,7 @@ describe('useJobPolling', () => {
|
|
|
96
96
|
test('handles result fetch failure gracefully', async () => {
|
|
97
97
|
const statusData = {
|
|
98
98
|
status: 'success',
|
|
99
|
-
|
|
99
|
+
name: 'test::task',
|
|
100
100
|
targets: [],
|
|
101
101
|
};
|
|
102
102
|
|
|
@@ -119,7 +119,7 @@ describe('useJobPolling', () => {
|
|
|
119
119
|
test('cancels polling on unmount', async () => {
|
|
120
120
|
const statusData = {
|
|
121
121
|
status: 'running',
|
|
122
|
-
|
|
122
|
+
name: 'long::task',
|
|
123
123
|
targets: [],
|
|
124
124
|
};
|
|
125
125
|
API.get.mockResolvedValue({ data: statusData });
|
|
@@ -145,12 +145,12 @@ describe('useJobPolling', () => {
|
|
|
145
145
|
test('loads metadata only once across multiple polls', async () => {
|
|
146
146
|
API.get
|
|
147
147
|
.mockResolvedValueOnce({
|
|
148
|
-
data: { status: 'running',
|
|
148
|
+
data: { status: 'running', name: 'my::task', targets: ['host1'] },
|
|
149
149
|
})
|
|
150
150
|
.mockResolvedValueOnce({
|
|
151
151
|
data: {
|
|
152
152
|
status: 'success',
|
|
153
|
-
|
|
153
|
+
name: 'changed::name',
|
|
154
154
|
targets: ['host2'],
|
|
155
155
|
},
|
|
156
156
|
})
|