foreman_openbolt 1.3.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7444805dbd4902da2b3b411388c28968cc4a893d00d244caacd8ed083cca78e
4
- data.tar.gz: 90aab4b505c4347d212324094d7d5d73b8a1dcc9148eafa40a2be77e8fdee083
3
+ metadata.gz: 71f5e8b870d9c27a1314ab3b2567fab231b6c23b460b615a10053003513ce619
4
+ data.tar.gz: b1454607486de4a76b8d2a9cf230f25d9ca5c47cbd70ae24384eddd9328fbbe2
5
5
  SHA512:
6
- metadata.gz: 40e72f42e822e1b4a488a71ef10b203db849ac69978fac1eb400c6be55e6d799262ed37f7dbfe039fded5cf4a2e18255c76bf24af6981d400ae63c6077019349
7
- data.tar.gz: 05dca9f1a59475878cc3435a1fa8fd21dbc6aee16346bb204a60980eafc3a881b1f431a4ab3d4b9043f92b6a4c46bc5b71129872af1fae5293910f5458a05566
6
+ metadata.gz: 9fbb0751b94c7173b802ff6a267f2e1ceaf5a8d34f6f1c1e93fe61e5561015623bc3dd9fd4d35af629ee8d8f3b48e6c060abc3a1b87bcc34eaf9e03ace4716db
7
+ data.tar.gz: 296caaa91415bddec17f00197ed7dcfdeff7ebe3dda78995e288e7ac3398d053422e0e8b2035270dcbb3c86bc589c2b6016c4e6cb830e19a079e2bb86b8a8d47
data/README.md CHANGED
@@ -5,8 +5,9 @@
5
5
  [![Release](https://github.com/overlookinfra/foreman_openbolt/actions/workflows/release.yml/badge.svg)](https://github.com/overlookinfra/foreman_openbolt/actions/workflows/release.yml)
6
6
  [![RubyGem Version](https://img.shields.io/gem/v/foreman_openbolt.svg)](https://rubygems.org/gems/foreman_openbolt)
7
7
  [![RubyGem Downloads](https://img.shields.io/gem/dt/foreman_openbolt.svg)](https://rubygems.org/gems/foreman_openbolt)
8
+ [![Foreman Landscape](https://img.shields.io/badge/Foreman-Landscape-blue.svg)](https://theforeman.github.io/foreman-plugin-overview/)
8
9
 
9
- Bringing OpenBolt Task & Plans into Foreman!
10
+ Bringing [OpenBolt](https://docs.openvoxproject.org/openbolt/latest/) Task & Plans into [Foreman](https://theforeman.org/)!
10
11
 
11
12
  ## Introduction
12
13
 
@@ -72,6 +73,7 @@ A handful of core/default Tasks & Plans are also included in the [OpenBolt rpm/d
72
73
  - [Development](docs/development.md): linting, unit tests, acceptance tests, building packages
73
74
  - [Releasing](docs/releasing.md): version locations, release steps, RPM/DEB packaging
74
75
  - [Choria Testing](docs/choria-testing.md): setting up Choria on a Foreman install for transport testing
76
+ - [Foreman + Choria Example Code](docs/choria.md): Example Hiera and Puppet code to get started with Foreman and OpenBolt and Choria
75
77
 
76
78
  ## Contributing & support
77
79
 
@@ -27,6 +27,7 @@ module Api
27
27
  property :description, String, allow_nil: true, desc: N_('Description of the launched Bolt task (or later, plan)')
28
28
  property :parameters, Hash, desc: N_('Parameters the job was launched with')
29
29
  property :targets, Array, of: String, desc: N_('Target hosts the job was launched against for tasks')
30
+ property :host_groups, Array, of: String, desc: N_('Host groups the job was launched against')
30
31
  property :smart_proxy, Hash, desc: N_('Smart proxy that executed the job') do
31
32
  property :id, Integer, desc: N_('Smart proxy ID')
32
33
  property :name, String, desc: N_('Smart proxy name')
@@ -67,6 +67,8 @@ module Api
67
67
  param :task_name, String, required: true, desc: N_('Name of the Bolt task to run')
68
68
  param :targets, String, required: true,
69
69
  desc: N_('Comma-separated list of target hosts the task should run on')
70
+ param :host_groups, String, required: false,
71
+ desc: N_('Comma-separated list of host groups the task was launched against')
70
72
  param :parameters, Hash, required: false,
71
73
  desc: N_('Task-specific parameters, keyed by parameter name')
72
74
  param :options, Hash, required: false,
@@ -33,6 +33,7 @@ module ForemanOpenbolt
33
33
  description: task_job.task_description,
34
34
  parameters: task_job.task_parameters,
35
35
  targets: task_job.targets,
36
+ host_groups: task_job.host_groups,
36
37
  smart_proxy: {
37
38
  id: task_job.smart_proxy_id,
38
39
  name: task_job.smart_proxy&.name || '(unknown)',
@@ -32,6 +32,7 @@ module ForemanOpenbolt
32
32
  openbolt_api: @openbolt_api,
33
33
  task_name: params[:task_name],
34
34
  targets: params[:targets],
35
+ host_groups: params[:host_groups] || '',
35
36
  parameters: params[:parameters] || {},
36
37
  options: params[:options] || {}
37
38
  )
@@ -42,9 +43,10 @@ module ForemanOpenbolt
42
43
  # Returns the proxy-issued job id. Failures after the proxy accepts the
43
44
  # launch raise PartialLaunchError. The proxy job keeps running and there
44
45
  # is no proxy-side cancel hook right now, so we only surface the failure.
45
- def dispatch_task(smart_proxy:, openbolt_api:, task_name:, targets:, parameters:, options:)
46
+ def dispatch_task(smart_proxy:, openbolt_api:, task_name:, targets:, host_groups:, parameters:, options:)
46
47
  task_name = task_name.to_s.strip
47
48
  targets = targets.to_s.strip
49
+ host_groups = host_groups.to_s.strip
48
50
  raise ForemanOpenbolt::Common::LaunchError, 'Task name and targets cannot be empty' if task_name.empty? || targets.empty?
49
51
 
50
52
  merged_options = merge_encrypted_defaults(options)
@@ -92,6 +94,7 @@ module ForemanOpenbolt
92
94
  task_name: task_name,
93
95
  task_description: metadata['description'] || '',
94
96
  targets: targets.split(',').map(&:strip),
97
+ host_groups: host_groups.split(',').map(&:strip),
95
98
  parameters: parameters,
96
99
  options: scrub_options_for_storage(merged_options),
97
100
  job_id: job_id
@@ -32,13 +32,14 @@ module ForemanOpenbolt
32
32
  after_update :cleanup_proxy_artifacts, if: :saved_result_and_log?
33
33
 
34
34
  # Class methods
35
- def self.create_from_execution!(proxy:, task_name:, task_description:, targets:, job_id:, parameters: {}, options: {})
35
+ def self.create_from_execution!(proxy:, task_name:, task_description:, targets:, host_groups:, job_id:, parameters: {}, options: {})
36
36
  create!(
37
37
  job_id: job_id,
38
38
  smart_proxy: proxy,
39
39
  task_name: task_name,
40
40
  task_description: task_description,
41
41
  targets: targets,
42
+ host_groups: host_groups,
42
43
  task_parameters: parameters,
43
44
  openbolt_options: options,
44
45
  status: 'pending',
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddHostGroupsToOpenboltTaskJobs < ActiveRecord::Migration[6.1]
4
+ def change
5
+ add_column :openbolt_task_jobs, :host_groups, :jsonb, default: []
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanOpenbolt
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_openbolt",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "OpenBolt integration into Foreman",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@
9
9
  FROM rockylinux:9
10
10
 
11
11
  # System packages -- cached across all Foreman versions.
12
+ # openssl-devel required by latest net-ssh gem
12
13
  RUN dnf module enable -y nodejs:22 postgresql:16 && \
13
14
  dnf install -y \
14
15
  ruby ruby-devel rubygem-bundler \
@@ -18,6 +19,7 @@ RUN dnf module enable -y nodejs:22 postgresql:16 && \
18
19
  libffi-devel \
19
20
  nodejs npm \
20
21
  git-core \
22
+ openssl-devel \
21
23
  redhat-rpm-config && \
22
24
  dnf clean all
23
25
 
@@ -40,6 +42,10 @@ RUN printf "test:\n adapter: postgresql\n host: db\n port: 5432\n username:
40
42
  # expensive layer but only changes when the Foreman version changes.
41
43
  ENV BUNDLE_WITHOUT="release console journald libvirt ec2 openstack vmware telemetry"
42
44
  ENV BUNDLE_PATH="/opt/bundle"
45
+
46
+ # workaround for json 3.x, which isn't compatible with Foreman 3.18 and older
47
+ RUN printf "gem 'json', '< 3'\n" > bundler.d/json.rb
48
+
43
49
  RUN bundle install --jobs=4
44
50
 
45
51
  COPY test/unit/docker/entrypoint.sh /entrypoint.sh
@@ -221,6 +221,7 @@ class TaskJobTest < ForemanOpenbolt::PluginTestCase
221
221
  task_name: 'mymod::mytask',
222
222
  task_description: 'Restart a service',
223
223
  targets: ['web1.example.com'],
224
+ host_groups: ['webservers', 'nginx'],
224
225
  job_id: 'exec-123',
225
226
  parameters: { 'service' => 'nginx' },
226
227
  options: { 'transport' => 'ssh' }
@@ -231,6 +232,7 @@ class TaskJobTest < ForemanOpenbolt::PluginTestCase
231
232
  assert_equal 'mymod::mytask', job.task_name
232
233
  assert_equal 'Restart a service', job.task_description
233
234
  assert_equal ['web1.example.com'], job.targets
235
+ assert_equal ['webservers', 'nginx'], job.host_groups
234
236
  assert_equal({ 'service' => 'nginx' }, job.task_parameters)
235
237
  assert_equal({ 'transport' => 'ssh' }, job.openbolt_options)
236
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 = ({ onChange, targetCount = 0 }) => {
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 => `hostgroup_fullname = "${g.name.replace(/"/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(hostNames);
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;
@@ -4,7 +4,7 @@ import { Provider } from 'react-redux';
4
4
  import { createStore } from 'redux';
5
5
  import { MemoryRouter } from 'react-router-dom';
6
6
  import { API } from 'foremanReact/redux/API';
7
- import LaunchTask, { buildLaunchPayload } from '../index';
7
+ import LaunchTask from '../index';
8
8
 
9
9
  // Mock HostSelector to avoid Apollo/GraphQL dependency chain
10
10
  jest.mock('../HostSelector', () => {
@@ -81,46 +81,3 @@ describe('LaunchTask', () => {
81
81
  });
82
82
  });
83
83
  });
84
-
85
- describe('buildLaunchPayload', () => {
86
- test('passes "parameters" key through correctly', () => {
87
- const body = buildLaunchPayload({
88
- proxyId: 1,
89
- taskName: 'mymod::install',
90
- targets: ['host1.example.com'],
91
- parameters: { name: 'nginx', version: '1.21' },
92
- options: { transport: 'ssh' },
93
- });
94
-
95
- expect(body).toHaveProperty('parameters', {
96
- name: 'nginx',
97
- version: '1.21',
98
- });
99
- });
100
-
101
- test('joins targets with comma into a single string', () => {
102
- const body = buildLaunchPayload({
103
- proxyId: 1,
104
- taskName: 'mymod::install',
105
- targets: ['host1', 'host2', 'host3'],
106
- parameters: {},
107
- options: {},
108
- });
109
-
110
- expect(body.targets).toBe('host1,host2,host3');
111
- });
112
-
113
- test('forwards smart_proxy_id, task_name, and options unchanged', () => {
114
- const body = buildLaunchPayload({
115
- proxyId: 42,
116
- taskName: 'puppet_conf::set',
117
- targets: ['host1'],
118
- parameters: {},
119
- options: { transport: 'choria', 'run-as': 'root' },
120
- });
121
-
122
- expect(body.smart_proxy_id).toBe(42);
123
- expect(body.task_name).toBe('puppet_conf::set');
124
- expect(body.options).toEqual({ transport: 'choria', 'run-as': 'root' });
125
- });
126
- });
@@ -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
+ });
@@ -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,29 +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
-
32
- // Exported so tests can use the launch wire format
33
- export const buildLaunchPayload = ({
34
- proxyId,
35
- taskName,
36
- targets,
37
- parameters,
38
- options,
39
- }) => ({
40
- smart_proxy_id: proxyId,
41
- task_name: taskName,
42
- targets: targets.join(','),
43
- parameters,
44
- options,
45
- });
31
+ import { buildLaunchPayload } from './helpers';
46
32
 
47
33
  const LaunchTask = () => {
48
34
  const history = useHistory();
35
+ const { state } = useLocation();
49
36
  const showMessage = useShowMessage();
50
37
 
51
38
  /* States */
52
39
  const [selectedProxy, setSelectedProxy] = useState('');
53
40
  const [targets, setTargets] = useState([]);
41
+ const [hostGroups, setHostGroups] = useState([]);
54
42
  const [isSubmitting, setIsSubmitting] = useState(false);
55
43
 
56
44
  /* Custom hooks for data fetching */
@@ -145,10 +133,11 @@ const LaunchTask = () => {
145
133
  }, [selectedProxy, fetchTasks]);
146
134
 
147
135
  const handleTargetsChange = useCallback(
148
- targetArray => {
149
- setTargets(targetArray);
136
+ value => {
137
+ setTargets(value.hostNames || []);
138
+ setHostGroups(value.hostGroupNames || []);
150
139
  },
151
- [setTargets]
140
+ [setTargets, setHostGroups]
152
141
  );
153
142
 
154
143
  const handleSubmit = useCallback(
@@ -184,6 +173,7 @@ const LaunchTask = () => {
184
173
  proxyId: selectedProxy,
185
174
  taskName: selectedTask,
186
175
  targets,
176
+ hostGroups,
187
177
  parameters: taskParameters,
188
178
  options: visibleOptions,
189
179
  });
@@ -208,15 +198,25 @@ const LaunchTask = () => {
208
198
  selectedProxy,
209
199
  selectedTask,
210
200
  targets,
201
+ hostGroups,
211
202
  taskParameters,
212
203
  openBoltOptions,
213
204
  openBoltOptionsMetadata,
214
- smartProxies,
215
205
  history,
216
206
  showMessage,
217
207
  ]
218
208
  );
219
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
+
220
220
  /* Rendering */
221
221
  const isFormValid =
222
222
  selectedProxy &&
@@ -232,7 +232,6 @@ const LaunchTask = () => {
232
232
  <Grid hasGutter>
233
233
  <GridItem span={12}>
234
234
  <Flex
235
- hasGutter
236
235
  alignItems={{ default: 'alignItemsCenter' }}
237
236
  justifyContent={{ default: 'justifyContentSpaceBetween' }}
238
237
  >
@@ -282,6 +281,8 @@ const LaunchTask = () => {
282
281
  </StackItem>
283
282
  <StackItem>
284
283
  <HostSelector
284
+ selectedHosts={targets}
285
+ selectedHostGroups={hostGroups}
285
286
  onChange={handleTargetsChange}
286
287
  targetCount={targets.length}
287
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;
@@ -21,6 +21,7 @@ const useJobPolling = jobId => {
21
21
  const [taskDescription, setTaskDescription] = useState(null);
22
22
  const [taskParameters, setTaskParameters] = useState({});
23
23
  const [targets, setTargets] = useState([]);
24
+ const [hostGroups, setHostGroups] = useState([]);
24
25
  const [smartProxy, setSmartProxy] = useState(null);
25
26
  const metadataLoaded = useRef(false);
26
27
 
@@ -59,6 +60,7 @@ const useJobPolling = jobId => {
59
60
  setTaskDescription(statusData.description || null);
60
61
  setTaskParameters(statusData.parameters || {});
61
62
  setTargets(statusData.targets || []);
63
+ setHostGroups(statusData.host_groups || []);
62
64
  setSmartProxy(statusData.smart_proxy || null);
63
65
  metadataLoaded.current = true;
64
66
  }
@@ -136,6 +138,7 @@ const useJobPolling = jobId => {
136
138
  taskDescription,
137
139
  taskParameters,
138
140
  targets,
141
+ hostGroups,
139
142
  smartProxy,
140
143
  };
141
144
  };
@@ -1,7 +1,14 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { useLocation, useHistory } from 'react-router-dom';
3
3
  import { translate as __ } from 'foremanReact/common/I18n';
4
- import { Alert, Button, Stack, StackItem } from '@patternfly/react-core';
4
+ import {
5
+ Alert,
6
+ Button,
7
+ Flex,
8
+ FlexItem,
9
+ Stack,
10
+ StackItem,
11
+ } from '@patternfly/react-core';
5
12
 
6
13
  import ExecutionDisplay from './ExecutionDisplay';
7
14
  import LoadingIndicator from './LoadingIndicator';
@@ -29,6 +36,7 @@ const TaskExecution = () => {
29
36
  taskDescription,
30
37
  taskParameters,
31
38
  targets,
39
+ hostGroups,
32
40
  smartProxy,
33
41
  } = useJobPolling(jobId);
34
42
 
@@ -70,13 +78,40 @@ const TaskExecution = () => {
70
78
  return (
71
79
  <Stack hasGutter>
72
80
  <StackItem>
73
- <Button
74
- variant="secondary"
75
- onClick={() => history.push(ROUTES.PAGES.LAUNCH_TASK)}
76
- className="pf-v5-u-mb-md"
81
+ <Flex
82
+ alignItems={{ default: 'alignItemsCenter' }}
83
+ justifyContent={{ default: 'justifyContent' }}
77
84
  >
78
- {__('Run Another Task')}
79
- </Button>
85
+ <FlexItem>
86
+ <Button
87
+ variant="secondary"
88
+ onClick={() => history.push(ROUTES.PAGES.LAUNCH_TASK)}
89
+ className="pf-v5-u-mb-md"
90
+ >
91
+ {__('Run Another Task')}
92
+ </Button>
93
+ </FlexItem>
94
+ <FlexItem>
95
+ <Button
96
+ variant="secondary"
97
+ onClick={() =>
98
+ history.push({
99
+ pathname: ROUTES.PAGES.LAUNCH_TASK,
100
+ state: {
101
+ smartProxy,
102
+ taskName,
103
+ taskParameters,
104
+ targets,
105
+ hostGroups,
106
+ },
107
+ })
108
+ }
109
+ className="pf-v5-u-mb-md"
110
+ >
111
+ {__('Re-Run Task')}
112
+ </Button>
113
+ </FlexItem>
114
+ </Flex>
80
115
  </StackItem>
81
116
 
82
117
  <StackItem>
@@ -86,6 +121,7 @@ const TaskExecution = () => {
86
121
  jobStatus={jobStatus}
87
122
  isPolling={isPolling}
88
123
  targets={targets}
124
+ hostGroups={hostGroups}
89
125
  submittedAt={submittedAt}
90
126
  completedAt={completedAt}
91
127
  taskName={taskName}
@@ -29,6 +29,7 @@ import {
29
29
  formatDate,
30
30
  } from '../common/helpers';
31
31
  import HostsPopover from '../common/HostsPopover';
32
+ import HostGroupsPopover from '../common/HostGroupsPopover';
32
33
  import TaskPopover from './TaskPopover';
33
34
 
34
35
  const getStatusLabel = status => {
@@ -127,6 +128,7 @@ const TaskHistory = () => {
127
128
  <Th modifier="wrap">{__('Task Name')}</Th>
128
129
  <Th modifier="wrap">{__('Status')}</Th>
129
130
  <Th modifier="wrap">{__('Targets')}</Th>
131
+ <Th modifier="wrap">{__('Host Groups')}</Th>
130
132
  <Th modifier="wrap">{__('Submitted')}</Th>
131
133
  <Th modifier="wrap">{__('Completed')}</Th>
132
134
  <Th modifier="wrap">{__('Duration')}</Th>
@@ -147,6 +149,9 @@ const TaskHistory = () => {
147
149
  <Td hasRightBorder>
148
150
  <HostsPopover targets={job.targets || []} />
149
151
  </Td>
152
+ <Td hasRightBorder>
153
+ <HostGroupsPopover hostGroups={job.host_groups || []} />
154
+ </Td>
150
155
  <Td hasRightBorder>{formatDate(job.submitted_at)}</Td>
151
156
  <Td hasRightBorder>
152
157
  {job.completed_at ? formatDate(job.completed_at) : ''}
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { sprintf, translate as __ } from 'foremanReact/common/I18n';
4
+ import { Popover, Button } from '@patternfly/react-core';
5
+ import { Table, Tbody, Tr, Td } from '@patternfly/react-table';
6
+
7
+ const HostGroupsPopover = ({ hostGroups }) => {
8
+ if (!hostGroups || hostGroups.length === 0) {
9
+ return <>{__('No host groups specified')}</>;
10
+ }
11
+
12
+ const popoverContent = (
13
+ <div
14
+ style={{
15
+ maxHeight: '300px',
16
+ overflowY: 'auto',
17
+ border: '1px solid var(--pf-v5-global--BorderColor--100)',
18
+ }}
19
+ >
20
+ <Table variant="compact" borders isStriped aria-label={__('Host groups')}>
21
+ <Tbody>
22
+ {hostGroups.map((hostGroup, index) => (
23
+ <Tr key={index}>
24
+ <Td className="pf-v5-u-font-family-monospace">{hostGroup}</Td>
25
+ </Tr>
26
+ ))}
27
+ </Tbody>
28
+ </Table>
29
+ </div>
30
+ );
31
+
32
+ return (
33
+ <Popover bodyContent={popoverContent} position="right" maxWidth="600px">
34
+ <Button
35
+ variant="link"
36
+ isInline
37
+ aria-label={sprintf(__('%s host groups'), hostGroups.length)}
38
+ >
39
+ {hostGroups.length}
40
+ </Button>
41
+ </Popover>
42
+ );
43
+ };
44
+
45
+ HostGroupsPopover.propTypes = {
46
+ hostGroups: PropTypes.arrayOf(PropTypes.string),
47
+ };
48
+
49
+ HostGroupsPopover.defaultProps = {
50
+ hostGroups: [],
51
+ };
52
+
53
+ export default HostGroupsPopover;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import HostGroupsPopover from '../HostGroupsPopover';
4
+
5
+ describe('HostGroupsPopover', () => {
6
+ test('shows "No host groups specified" when hostGroups is empty', () => {
7
+ render(<HostGroupsPopover hostGroups={[]} />);
8
+ expect(screen.getByText('No host groups specified')).toBeInTheDocument();
9
+ });
10
+
11
+ test('shows "No host groups specified" when hostGroups is not provided', () => {
12
+ render(<HostGroupsPopover />);
13
+ expect(screen.getByText('No host groups specified')).toBeInTheDocument();
14
+ });
15
+
16
+ test('shows host groups count as button when hostGroups exist', () => {
17
+ render(<HostGroupsPopover hostGroups={['webserver', 'nginx', 'php']} />);
18
+ expect(screen.getByText('3')).toBeInTheDocument();
19
+ });
20
+ });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_openbolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Overlook InfraTech
@@ -18,7 +18,7 @@ dependencies:
18
18
  version: 11.0.0
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
- version: '14'
21
+ version: '15'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  version: 11.0.0
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
- version: '14'
31
+ version: '15'
32
32
  description: This plugin adds OpenBolt integration into Foreman, allowing users to
33
33
  run tasks and plans present in their environment.
34
34
  email:
@@ -55,6 +55,7 @@ files:
55
55
  - db/migrate/20250925000000_add_command_to_openbolt_task_jobs.rb
56
56
  - db/migrate/20251001000000_add_task_description_to_task_jobs.rb
57
57
  - db/migrate/20260824000000_remove_view_smart_proxies_openbolt_permission.rb
58
+ - db/migrate/20261118000000_add_host_groups_to_openbolt_task_jobs.rb
58
59
  - db/seeds.d/001_add_openbolt_feature.rb
59
60
  - lib/foreman_openbolt.rb
60
61
  - lib/foreman_openbolt/engine.rb
@@ -135,6 +136,8 @@ files:
135
136
  - webpack/src/Components/LaunchTask/__tests__/ParametersSection.test.js
136
137
  - webpack/src/Components/LaunchTask/__tests__/SmartProxySelect.test.js
137
138
  - webpack/src/Components/LaunchTask/__tests__/TaskSelect.test.js
139
+ - webpack/src/Components/LaunchTask/__tests__/helpers.test.js
140
+ - webpack/src/Components/LaunchTask/helpers.js
138
141
  - webpack/src/Components/LaunchTask/hooks/__tests__/useOpenBoltOptions.test.js
139
142
  - webpack/src/Components/LaunchTask/hooks/__tests__/useSmartProxies.test.js
140
143
  - webpack/src/Components/LaunchTask/hooks/__tests__/useTasksData.test.js
@@ -160,7 +163,9 @@ files:
160
163
  - webpack/src/Components/TaskHistory/__tests__/TaskHistory.test.js
161
164
  - webpack/src/Components/TaskHistory/__tests__/TaskPopover.test.js
162
165
  - webpack/src/Components/TaskHistory/index.js
166
+ - webpack/src/Components/common/HostGroupsPopover.js
163
167
  - webpack/src/Components/common/HostsPopover.js
168
+ - webpack/src/Components/common/__tests__/HostGroupsPopover.test.js
164
169
  - webpack/src/Components/common/__tests__/HostsPopover.test.js
165
170
  - webpack/src/Components/common/__tests__/helpers.test.js
166
171
  - webpack/src/Components/common/constants.js
@@ -184,16 +189,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
189
  - - ">="
185
190
  - !ruby/object:Gem::Version
186
191
  version: '3.0'
187
- - - "<"
188
- - !ruby/object:Gem::Version
189
- version: '5'
190
192
  required_rubygems_version: !ruby/object:Gem::Requirement
191
193
  requirements:
192
194
  - - ">="
193
195
  - !ruby/object:Gem::Version
194
196
  version: '0'
195
197
  requirements: []
196
- rubygems_version: 4.0.16
198
+ rubygems_version: 4.0.20
197
199
  specification_version: 4
198
200
  summary: Foreman OpenBolt integration
199
201
  test_files: []