foreman_puppet 10.0.0 → 10.1.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/app/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller.rb +102 -0
- data/app/services/concerns/foreman_puppet/extensions/bulk_hosts_manager.rb +24 -0
- data/config/api_routes.rb +11 -0
- data/lib/foreman_puppet/engine.rb +1 -0
- data/lib/foreman_puppet/register.rb +2 -0
- data/lib/foreman_puppet/version.rb +1 -1
- data/test/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller_test.rb +171 -0
- data/test/services/foreman_puppet/bulk_hosts_manager_test.rb +33 -0
- data/webpack/global_index.js +42 -0
- data/webpack/src/Extends/Hosts/ActionsBar/ActionsBar.scss +14 -0
- data/webpack/src/Extends/Hosts/ActionsBar/index.js +73 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/__tests__/actions.test.js +78 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/actions.js +36 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/index.js +252 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetCAProxy/__tests__/index.test.js +66 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetCAProxy/index.js +40 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetProxy/__tests__/index.test.js +66 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetProxy/index.js +40 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/__tests__/actions.test.js +64 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/actions.js +24 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/index.js +164 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy/__tests__/index.test.js +65 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy/index.js +39 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy/__tests__/index.test.js +61 -0
- data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy/index.js +39 -0
- data/webpack/src/Extends/Hosts/BulkActions/__tests__/toastHelpers.test.js +55 -0
- data/webpack/src/Extends/Hosts/BulkActions/toastHelpers.js +17 -0
- data/webpack/src/foreman_puppet_host_form.test.js +4 -4
- metadata +26 -2
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { FormattedMessage } from 'react-intl';
|
|
4
|
+
import { useDispatch, useSelector } from 'react-redux';
|
|
5
|
+
import {
|
|
6
|
+
Alert,
|
|
7
|
+
Modal,
|
|
8
|
+
Button,
|
|
9
|
+
TextContent,
|
|
10
|
+
Text,
|
|
11
|
+
Select,
|
|
12
|
+
SelectOption,
|
|
13
|
+
SelectList,
|
|
14
|
+
MenuToggle,
|
|
15
|
+
} from '@patternfly/react-core';
|
|
16
|
+
import { addToast } from 'foremanReact/components/ToastsList/slice';
|
|
17
|
+
import { sprintf, translate as __ } from 'foremanReact/common/I18n';
|
|
18
|
+
import { foremanUrl } from 'foremanReact/common/helpers';
|
|
19
|
+
import { APIActions } from 'foremanReact/redux/API';
|
|
20
|
+
import { STATUS } from 'foremanReact/constants';
|
|
21
|
+
import {
|
|
22
|
+
selectAPIStatus,
|
|
23
|
+
selectAPIResponse,
|
|
24
|
+
} from 'foremanReact/redux/API/APISelectors';
|
|
25
|
+
import {
|
|
26
|
+
HOSTS_API_PATH,
|
|
27
|
+
API_REQUEST_KEY,
|
|
28
|
+
} from 'foremanReact/routes/Hosts/constants';
|
|
29
|
+
import {
|
|
30
|
+
fetchSmartProxies,
|
|
31
|
+
SMART_PROXY_KEY,
|
|
32
|
+
bulkChangePuppetProxy,
|
|
33
|
+
BULK_CHANGE_PUPPET_PROXY_KEY,
|
|
34
|
+
BULK_CHANGE_PUPPET_CA_PROXY_KEY,
|
|
35
|
+
} from './actions';
|
|
36
|
+
import { bulkActionErrorToastParams } from '../toastHelpers';
|
|
37
|
+
|
|
38
|
+
const BulkChangeProxyCommon = ({
|
|
39
|
+
isOpen,
|
|
40
|
+
closeModal,
|
|
41
|
+
selectAllHostsMode,
|
|
42
|
+
selectedCount,
|
|
43
|
+
fetchBulkParams,
|
|
44
|
+
selectMessage,
|
|
45
|
+
handleErrorMessage,
|
|
46
|
+
changeMessage,
|
|
47
|
+
allHostsMessage,
|
|
48
|
+
someHostsMessage,
|
|
49
|
+
isCAProxy,
|
|
50
|
+
}) => {
|
|
51
|
+
const dispatch = useDispatch();
|
|
52
|
+
const [smartProxyId, setSmartProxyId] = useState('');
|
|
53
|
+
const [smartProxySelectOpen, setSmartProxySelectOpen] = useState(false);
|
|
54
|
+
|
|
55
|
+
const actionKey = isCAProxy
|
|
56
|
+
? BULK_CHANGE_PUPPET_CA_PROXY_KEY
|
|
57
|
+
: BULK_CHANGE_PUPPET_PROXY_KEY;
|
|
58
|
+
const smartProxyFeature = isCAProxy ? 'Puppet CA' : 'Puppet';
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
dispatch(fetchSmartProxies(smartProxyFeature));
|
|
62
|
+
}, [dispatch, smartProxyFeature]);
|
|
63
|
+
|
|
64
|
+
const smartProxies = useSelector(state =>
|
|
65
|
+
selectAPIResponse(state, SMART_PROXY_KEY)
|
|
66
|
+
);
|
|
67
|
+
const smartProxyStatus = useSelector(state =>
|
|
68
|
+
selectAPIStatus(state, SMART_PROXY_KEY)
|
|
69
|
+
);
|
|
70
|
+
const hasSmartProxies = smartProxies?.results?.length > 0;
|
|
71
|
+
|
|
72
|
+
const onToggleClick = () => {
|
|
73
|
+
setSmartProxySelectOpen(!smartProxySelectOpen);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const handleSmartProxySelect = (event, selection) => {
|
|
77
|
+
setSmartProxyId(selection);
|
|
78
|
+
setSmartProxySelectOpen(false);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const getSmartProxyLabel = id => id.substring(id.indexOf('-') + 1);
|
|
82
|
+
|
|
83
|
+
const toggle = toggleRef => (
|
|
84
|
+
<MenuToggle
|
|
85
|
+
ref={toggleRef}
|
|
86
|
+
onClick={onToggleClick}
|
|
87
|
+
isExpanded={smartProxySelectOpen}
|
|
88
|
+
style={{ width: '500px' }}
|
|
89
|
+
>
|
|
90
|
+
{smartProxyId ? getSmartProxyLabel(smartProxyId) : selectMessage}
|
|
91
|
+
</MenuToggle>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const handleModalClose = () => {
|
|
95
|
+
setSmartProxyId('');
|
|
96
|
+
closeModal();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const handleError = response => {
|
|
100
|
+
handleModalClose();
|
|
101
|
+
dispatch(
|
|
102
|
+
addToast(
|
|
103
|
+
bulkActionErrorToastParams(response, handleErrorMessage, actionKey)
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handleSuccess = response => {
|
|
109
|
+
dispatch(
|
|
110
|
+
addToast({
|
|
111
|
+
type: 'success',
|
|
112
|
+
message: response.data.message,
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
dispatch(
|
|
116
|
+
APIActions.get({
|
|
117
|
+
key: API_REQUEST_KEY,
|
|
118
|
+
url: foremanUrl(HOSTS_API_PATH),
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
handleModalClose();
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handleConfirm = () => {
|
|
125
|
+
const requestBody = {
|
|
126
|
+
included: {
|
|
127
|
+
search: fetchBulkParams(),
|
|
128
|
+
},
|
|
129
|
+
proxy_id: smartProxyId.split('-')[0],
|
|
130
|
+
ca_proxy: isCAProxy,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
dispatch(
|
|
134
|
+
bulkChangePuppetProxy(requestBody, handleSuccess, handleError, actionKey)
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const modalActions = [
|
|
139
|
+
<Button
|
|
140
|
+
key="add"
|
|
141
|
+
ouiaId="bulk-change-proxy-common-modal-add-button"
|
|
142
|
+
variant="primary"
|
|
143
|
+
onClick={handleConfirm}
|
|
144
|
+
isDisabled={smartProxyId === ''}
|
|
145
|
+
isLoading={smartProxyStatus === STATUS.PENDING}
|
|
146
|
+
>
|
|
147
|
+
{changeMessage}
|
|
148
|
+
</Button>,
|
|
149
|
+
<Button
|
|
150
|
+
key="cancel"
|
|
151
|
+
ouiaId="bulk-change-proxy-common-modal-cancel-button"
|
|
152
|
+
variant="link"
|
|
153
|
+
onClick={handleModalClose}
|
|
154
|
+
>
|
|
155
|
+
{__('Cancel')}
|
|
156
|
+
</Button>,
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<Modal
|
|
161
|
+
isOpen={isOpen}
|
|
162
|
+
onClose={handleModalClose}
|
|
163
|
+
onEscapePress={handleModalClose}
|
|
164
|
+
title={changeMessage}
|
|
165
|
+
width="50%"
|
|
166
|
+
position="top"
|
|
167
|
+
actions={modalActions}
|
|
168
|
+
id="bulk-change-proxy-common"
|
|
169
|
+
key="bulk-change-proxy-common"
|
|
170
|
+
ouiaId="bulk-change-proxy-common"
|
|
171
|
+
>
|
|
172
|
+
{(smartProxyStatus !== STATUS.RESOLVED || hasSmartProxies) && (
|
|
173
|
+
<TextContent>
|
|
174
|
+
<Text ouiaId="bulk-change-proxy-common-options">
|
|
175
|
+
{selectAllHostsMode ? (
|
|
176
|
+
<FormattedMessage
|
|
177
|
+
id="bulk-change-proxy-common-warning-message-all"
|
|
178
|
+
defaultMessage={allHostsMessage}
|
|
179
|
+
values={{
|
|
180
|
+
boldCount: <strong>{__('All')}</strong>,
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
) : (
|
|
184
|
+
<FormattedMessage
|
|
185
|
+
id="bulk-change-proxy-common-warning-message"
|
|
186
|
+
defaultMessage={someHostsMessage}
|
|
187
|
+
values={{
|
|
188
|
+
count: selectedCount,
|
|
189
|
+
boldCount: <strong>{selectedCount}</strong>,
|
|
190
|
+
}}
|
|
191
|
+
/>
|
|
192
|
+
)}
|
|
193
|
+
</Text>
|
|
194
|
+
</TextContent>
|
|
195
|
+
)}
|
|
196
|
+
{smartProxyStatus === STATUS.RESOLVED && hasSmartProxies && (
|
|
197
|
+
<Select
|
|
198
|
+
id="single-grouped-select"
|
|
199
|
+
isOpen={smartProxySelectOpen}
|
|
200
|
+
selected={smartProxyId}
|
|
201
|
+
onSelect={handleSmartProxySelect}
|
|
202
|
+
onOpenChange={isSelectOpen => setSmartProxySelectOpen(isSelectOpen)}
|
|
203
|
+
toggle={toggle}
|
|
204
|
+
shouldFocusToggleOnSelect
|
|
205
|
+
ouiaId="bulk-change-proxy-common-select"
|
|
206
|
+
>
|
|
207
|
+
{smartProxies && (
|
|
208
|
+
<SelectList>
|
|
209
|
+
{smartProxies.results?.map(sp => (
|
|
210
|
+
<SelectOption key={`${sp.id}`} value={`${sp.id}-${sp.name}`}>
|
|
211
|
+
{sp.name}
|
|
212
|
+
</SelectOption>
|
|
213
|
+
))}
|
|
214
|
+
</SelectList>
|
|
215
|
+
)}
|
|
216
|
+
</Select>
|
|
217
|
+
)}
|
|
218
|
+
{smartProxyStatus === STATUS.RESOLVED && !hasSmartProxies && (
|
|
219
|
+
<Alert
|
|
220
|
+
ouiaId="foreman-puppet-no-proxy-alert"
|
|
221
|
+
isInline
|
|
222
|
+
variant="warning"
|
|
223
|
+
title={sprintf(
|
|
224
|
+
__("There is no Smart Proxy with the feature '%s' available."),
|
|
225
|
+
smartProxyFeature
|
|
226
|
+
)}
|
|
227
|
+
/>
|
|
228
|
+
)}
|
|
229
|
+
</Modal>
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
BulkChangeProxyCommon.propTypes = {
|
|
234
|
+
isOpen: PropTypes.bool,
|
|
235
|
+
closeModal: PropTypes.func,
|
|
236
|
+
fetchBulkParams: PropTypes.func.isRequired,
|
|
237
|
+
selectedCount: PropTypes.number.isRequired,
|
|
238
|
+
selectAllHostsMode: PropTypes.bool.isRequired,
|
|
239
|
+
selectMessage: PropTypes.string.isRequired,
|
|
240
|
+
handleErrorMessage: PropTypes.string.isRequired,
|
|
241
|
+
changeMessage: PropTypes.string.isRequired,
|
|
242
|
+
allHostsMessage: PropTypes.string.isRequired,
|
|
243
|
+
someHostsMessage: PropTypes.string.isRequired,
|
|
244
|
+
isCAProxy: PropTypes.bool.isRequired,
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
BulkChangeProxyCommon.defaultProps = {
|
|
248
|
+
isOpen: false,
|
|
249
|
+
closeModal: () => {},
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export default BulkChangeProxyCommon;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from '@theforeman/test';
|
|
3
|
+
|
|
4
|
+
import { openBulkModal } from 'foremanReact/common/BulkModalStateHelper';
|
|
5
|
+
import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
|
|
6
|
+
|
|
7
|
+
import BulkChangePuppetCAProxyScene from '../index';
|
|
8
|
+
import BulkChangeProxyCommon from '../../BulkChangeProxyCommon';
|
|
9
|
+
|
|
10
|
+
jest.mock('foremanReact/components/HostDetails/ActionsBar', () => ({
|
|
11
|
+
ForemanActionsBarContext: jest.requireActual('react').createContext(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('../../BulkChangeProxyCommon', () => ({
|
|
15
|
+
__esModule: true,
|
|
16
|
+
default: jest.fn(() => null),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe('BulkChangePuppetCAProxyScene', () => {
|
|
20
|
+
const fetchBulkParams = jest.fn();
|
|
21
|
+
const contextValue = {
|
|
22
|
+
selectAllHostsMode: false,
|
|
23
|
+
selectedCount: 2,
|
|
24
|
+
selectedResults: [1, 2],
|
|
25
|
+
fetchBulkParams,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
openBulkModal('bulk-change-puppet-ca-proxy', false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('opens with bulk modal state and passes expected CA proxy props', () => {
|
|
34
|
+
openBulkModal('bulk-change-puppet-ca-proxy', true);
|
|
35
|
+
const wrapper = mount(
|
|
36
|
+
<ForemanActionsBarContext.Provider value={contextValue}>
|
|
37
|
+
<BulkChangePuppetCAProxyScene />
|
|
38
|
+
</ForemanActionsBarContext.Provider>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const componentType =
|
|
42
|
+
BulkChangeProxyCommon.default || BulkChangeProxyCommon;
|
|
43
|
+
const props = wrapper.find(componentType).props();
|
|
44
|
+
|
|
45
|
+
expect(props).toEqual(
|
|
46
|
+
expect.objectContaining({
|
|
47
|
+
isCAProxy: true,
|
|
48
|
+
fetchBulkParams,
|
|
49
|
+
selectedCount: 2,
|
|
50
|
+
selectedResults: [1, 2],
|
|
51
|
+
selectAllHostsMode: false,
|
|
52
|
+
isOpen: true,
|
|
53
|
+
closeModal: expect.any(Function),
|
|
54
|
+
selectMessage: 'Select a Puppet CA Proxy',
|
|
55
|
+
handleErrorMessage: 'Failed to change Puppet CA Proxy',
|
|
56
|
+
changeMessage: 'Change Puppet CA Proxy',
|
|
57
|
+
allHostsMessage:
|
|
58
|
+
'Changing the Puppet CA proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet CA proxy.',
|
|
59
|
+
someHostsMessage:
|
|
60
|
+
'Changing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet CA proxy.',
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
wrapper.unmount();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
|
3
|
+
import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
|
|
4
|
+
import { useBulkModalOpen } from 'foremanReact/common/BulkModalStateHelper';
|
|
5
|
+
|
|
6
|
+
import BulkChangeProxyCommon from '../BulkChangeProxyCommon';
|
|
7
|
+
|
|
8
|
+
const BulkChangePuppetCAProxyScene = () => {
|
|
9
|
+
const {
|
|
10
|
+
selectAllHostsMode,
|
|
11
|
+
selectedCount,
|
|
12
|
+
selectedResults,
|
|
13
|
+
fetchBulkParams,
|
|
14
|
+
} = useContext(ForemanActionsBarContext);
|
|
15
|
+
const { isOpen, close: closeModal } = useBulkModalOpen(
|
|
16
|
+
'bulk-change-puppet-ca-proxy'
|
|
17
|
+
);
|
|
18
|
+
return (
|
|
19
|
+
<BulkChangeProxyCommon
|
|
20
|
+
isCAProxy
|
|
21
|
+
fetchBulkParams={fetchBulkParams}
|
|
22
|
+
selectedCount={selectedCount}
|
|
23
|
+
selectedResults={selectedResults}
|
|
24
|
+
selectAllHostsMode={selectAllHostsMode}
|
|
25
|
+
isOpen={isOpen}
|
|
26
|
+
closeModal={closeModal}
|
|
27
|
+
selectMessage={__('Select a Puppet CA Proxy')}
|
|
28
|
+
handleErrorMessage={__('Failed to change Puppet CA Proxy')}
|
|
29
|
+
changeMessage={__('Change Puppet CA Proxy')}
|
|
30
|
+
allHostsMessage={__(
|
|
31
|
+
'Changing the Puppet CA proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet CA proxy.'
|
|
32
|
+
)}
|
|
33
|
+
someHostsMessage={__(
|
|
34
|
+
'Changing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet CA proxy.'
|
|
35
|
+
)}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default BulkChangePuppetCAProxyScene;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from '@theforeman/test';
|
|
3
|
+
|
|
4
|
+
import { openBulkModal } from 'foremanReact/common/BulkModalStateHelper';
|
|
5
|
+
import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
|
|
6
|
+
|
|
7
|
+
import BulkChangePuppetProxyScene from '../index';
|
|
8
|
+
import BulkChangeProxyCommon from '../../BulkChangeProxyCommon';
|
|
9
|
+
|
|
10
|
+
jest.mock('foremanReact/components/HostDetails/ActionsBar', () => ({
|
|
11
|
+
ForemanActionsBarContext: jest.requireActual('react').createContext(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('../../BulkChangeProxyCommon', () => ({
|
|
15
|
+
__esModule: true,
|
|
16
|
+
default: jest.fn(() => null),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe('BulkChangePuppetProxyScene', () => {
|
|
20
|
+
const fetchBulkParams = jest.fn();
|
|
21
|
+
const contextValue = {
|
|
22
|
+
selectAllHostsMode: false,
|
|
23
|
+
selectedCount: 2,
|
|
24
|
+
selectedResults: [1, 2],
|
|
25
|
+
fetchBulkParams,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
openBulkModal('bulk-change-puppet-proxy', false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('opens with bulk modal state and passes expected props', () => {
|
|
34
|
+
openBulkModal('bulk-change-puppet-proxy', true);
|
|
35
|
+
const wrapper = mount(
|
|
36
|
+
<ForemanActionsBarContext.Provider value={contextValue}>
|
|
37
|
+
<BulkChangePuppetProxyScene />
|
|
38
|
+
</ForemanActionsBarContext.Provider>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const componentType =
|
|
42
|
+
BulkChangeProxyCommon.default || BulkChangeProxyCommon;
|
|
43
|
+
const props = wrapper.find(componentType).props();
|
|
44
|
+
|
|
45
|
+
expect(props).toEqual(
|
|
46
|
+
expect.objectContaining({
|
|
47
|
+
isCAProxy: false,
|
|
48
|
+
fetchBulkParams,
|
|
49
|
+
selectedCount: 2,
|
|
50
|
+
selectedResults: [1, 2],
|
|
51
|
+
selectAllHostsMode: false,
|
|
52
|
+
isOpen: true,
|
|
53
|
+
closeModal: expect.any(Function),
|
|
54
|
+
selectMessage: 'Select a Puppet Proxy',
|
|
55
|
+
handleErrorMessage: 'Failed to change Puppet Proxy',
|
|
56
|
+
changeMessage: 'Change Puppet Proxy',
|
|
57
|
+
allHostsMessage:
|
|
58
|
+
'Changing the Puppet proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet proxy.',
|
|
59
|
+
someHostsMessage:
|
|
60
|
+
'Changing the Puppet proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet proxy.',
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
wrapper.unmount();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
|
|
3
|
+
import { useBulkModalOpen } from 'foremanReact/common/BulkModalStateHelper';
|
|
4
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
|
5
|
+
|
|
6
|
+
import BulkChangeProxyCommon from '../BulkChangeProxyCommon';
|
|
7
|
+
|
|
8
|
+
const BulkChangePuppetProxyScene = () => {
|
|
9
|
+
const {
|
|
10
|
+
selectAllHostsMode,
|
|
11
|
+
selectedCount,
|
|
12
|
+
selectedResults,
|
|
13
|
+
fetchBulkParams,
|
|
14
|
+
} = useContext(ForemanActionsBarContext);
|
|
15
|
+
const { isOpen, close: closeModal } = useBulkModalOpen(
|
|
16
|
+
'bulk-change-puppet-proxy'
|
|
17
|
+
);
|
|
18
|
+
return (
|
|
19
|
+
<BulkChangeProxyCommon
|
|
20
|
+
isCAProxy={false}
|
|
21
|
+
fetchBulkParams={fetchBulkParams}
|
|
22
|
+
selectedCount={selectedCount}
|
|
23
|
+
selectedResults={selectedResults}
|
|
24
|
+
selectAllHostsMode={selectAllHostsMode}
|
|
25
|
+
isOpen={isOpen}
|
|
26
|
+
closeModal={closeModal}
|
|
27
|
+
selectMessage={__('Select a Puppet Proxy')}
|
|
28
|
+
handleErrorMessage={__('Failed to change Puppet Proxy')}
|
|
29
|
+
changeMessage={__('Change Puppet Proxy')}
|
|
30
|
+
allHostsMessage={__(
|
|
31
|
+
'Changing the Puppet proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet proxy.'
|
|
32
|
+
)}
|
|
33
|
+
someHostsMessage={__(
|
|
34
|
+
'Changing the Puppet proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet proxy.'
|
|
35
|
+
)}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default BulkChangePuppetProxyScene;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { APIActions } from 'foremanReact/redux/API';
|
|
2
|
+
import { foremanUrl } from 'foremanReact/common/helpers';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
bulkRemovePuppetProxyAction,
|
|
6
|
+
BULK_REMOVE_PUPPET_PROXY_KEY,
|
|
7
|
+
BULK_REMOVE_PUPPET_CA_PROXY_KEY,
|
|
8
|
+
} from '../actions';
|
|
9
|
+
|
|
10
|
+
jest.mock('foremanReact/redux/API', () => ({
|
|
11
|
+
APIActions: {
|
|
12
|
+
put: jest.fn(),
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
describe('BulkRemoveProxyCommon actions', () => {
|
|
17
|
+
const url = foremanUrl('/api/v2/hosts/bulk/remove_puppet_proxy');
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.clearAllMocks();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('calls bulk remove puppet proxy endpoint for Puppet Proxy removal', () => {
|
|
24
|
+
const params = { included: { ids: [1] }, ca_proxy: false };
|
|
25
|
+
const handleSuccess = jest.fn();
|
|
26
|
+
const handleError = jest.fn();
|
|
27
|
+
|
|
28
|
+
bulkRemovePuppetProxyAction(
|
|
29
|
+
BULK_REMOVE_PUPPET_PROXY_KEY,
|
|
30
|
+
params,
|
|
31
|
+
handleSuccess,
|
|
32
|
+
handleError
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(APIActions.put).toHaveBeenCalledWith({
|
|
36
|
+
key: BULK_REMOVE_PUPPET_PROXY_KEY,
|
|
37
|
+
url,
|
|
38
|
+
handleSuccess,
|
|
39
|
+
handleError,
|
|
40
|
+
params,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('calls bulk remove puppet proxy endpoint for Puppet CA Proxy removal', () => {
|
|
45
|
+
const params = { included: { ids: [1] }, ca_proxy: true };
|
|
46
|
+
const handleSuccess = jest.fn();
|
|
47
|
+
const handleError = jest.fn();
|
|
48
|
+
|
|
49
|
+
bulkRemovePuppetProxyAction(
|
|
50
|
+
BULK_REMOVE_PUPPET_CA_PROXY_KEY,
|
|
51
|
+
params,
|
|
52
|
+
handleSuccess,
|
|
53
|
+
handleError
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect(APIActions.put).toHaveBeenCalledWith({
|
|
57
|
+
key: BULK_REMOVE_PUPPET_CA_PROXY_KEY,
|
|
58
|
+
url,
|
|
59
|
+
handleSuccess,
|
|
60
|
+
handleError,
|
|
61
|
+
params,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { APIActions } from 'foremanReact/redux/API';
|
|
2
|
+
import { foremanUrl } from 'foremanReact/common/helpers';
|
|
3
|
+
|
|
4
|
+
export const BULK_REMOVE_PUPPET_PROXY_KEY = 'BULK_REMOVE_PUPPET_PROXY_KEY';
|
|
5
|
+
export const BULK_REMOVE_PUPPET_CA_PROXY_KEY =
|
|
6
|
+
'BULK_REMOVE_PUPPET_CA_PROXY_KEY';
|
|
7
|
+
|
|
8
|
+
export const bulkRemovePuppetProxyAction = (
|
|
9
|
+
key,
|
|
10
|
+
params,
|
|
11
|
+
handleSuccess,
|
|
12
|
+
handleError
|
|
13
|
+
) => {
|
|
14
|
+
const url = foremanUrl(`/api/v2/hosts/bulk/remove_puppet_proxy`);
|
|
15
|
+
return APIActions.put({
|
|
16
|
+
key,
|
|
17
|
+
url,
|
|
18
|
+
handleSuccess,
|
|
19
|
+
handleError,
|
|
20
|
+
params,
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default bulkRemovePuppetProxyAction;
|