foreman_snapshot_management 1.7.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/Rakefile +7 -2
  4. data/app/controllers/api/v2/snapshots_controller.rb +22 -6
  5. data/app/models/foreman_snapshot_management/proxmox_extensions.rb +1 -1
  6. data/app/models/foreman_snapshot_management/snapshot.rb +4 -0
  7. data/app/views/api/v2/snapshots/base.json.rabl +2 -0
  8. data/app/views/foreman_snapshot_management/snapshots/_index.html.erb +12 -80
  9. data/app/views/hosts/_snapshots_tab.html.erb +8 -0
  10. data/lib/foreman_snapshot_management/engine.rb +22 -21
  11. data/lib/foreman_snapshot_management/version.rb +1 -1
  12. data/lib/tasks/foreman_snapshot_management_tasks.rake +2 -2
  13. data/locale/de/LC_MESSAGES/foreman_snapshot_management.mo +0 -0
  14. data/locale/de/foreman_snapshot_management.po +52 -19
  15. data/locale/en/LC_MESSAGES/foreman_snapshot_management.mo +0 -0
  16. data/locale/en/foreman_snapshot_management.po +44 -11
  17. data/locale/foreman_snapshot_management.pot +87 -25
  18. data/package.json +46 -0
  19. data/test/controllers/api/v2/snapshots_test.rb +232 -109
  20. data/test/controllers/foreman_snapshot_management/snapshots_controller_test.rb +1 -1
  21. data/test/factories/proxmox_factory.rb +1 -1
  22. data/webpack/components/SnapshotManagement/SnapshotManagement.js +84 -0
  23. data/webpack/components/SnapshotManagement/SnapshotManagementActions.js +212 -0
  24. data/webpack/components/SnapshotManagement/SnapshotManagementConstants.js +9 -0
  25. data/webpack/components/SnapshotManagement/SnapshotManagementReducer.js +100 -0
  26. data/webpack/components/SnapshotManagement/SnapshotManagementSelectors.js +8 -0
  27. data/webpack/components/SnapshotManagement/__tests__/SnapshotManagementActions.test.js +123 -0
  28. data/webpack/components/SnapshotManagement/__tests__/SnapshotManagementReducer.test.js +157 -0
  29. data/webpack/components/SnapshotManagement/__tests__/__snapshots__/SnapshotManagementActions.test.js.snap +314 -0
  30. data/webpack/components/SnapshotManagement/__tests__/__snapshots__/SnapshotManagementReducer.test.js.snap +214 -0
  31. data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotForm.js +118 -0
  32. data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotFormConstants.js +5 -0
  33. data/webpack/components/SnapshotManagement/components/SnapshotForm/__tests__/SnapshotForm.test.js +26 -0
  34. data/webpack/components/SnapshotManagement/components/SnapshotForm/__tests__/__snapshots__/SnapshotForm.test.js.snap +476 -0
  35. data/webpack/components/SnapshotManagement/components/SnapshotForm/index.js +19 -0
  36. data/webpack/components/SnapshotManagement/components/SnapshotForm/snapshotForm.scss +3 -0
  37. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/SnapshotFormModal.js +37 -0
  38. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/SnapshotFormModalConstants.js +1 -0
  39. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/__tests__/SnapshotFormModal.test.js +19 -0
  40. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/__tests__/__snapshots__/SnapshotFormModal.test.js.snap +19 -0
  41. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/index.js +12 -0
  42. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/useSnapshotFormModal.js +7 -0
  43. data/webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js +314 -0
  44. data/webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js +70 -0
  45. data/webpack/components/SnapshotManagement/components/SnapshotList/__tests__/SnapshotList.test.js +88 -0
  46. data/webpack/components/SnapshotManagement/components/SnapshotList/__tests__/__snapshots__/SnapshotList.test.js.snap +1081 -0
  47. data/webpack/components/SnapshotManagement/components/SnapshotList/snapshotList.scss +13 -0
  48. data/webpack/components/SnapshotManagement/index.js +33 -0
  49. data/webpack/components/SnapshotManagement/snapshotManagement.scss +5 -0
  50. data/webpack/global_index.js +7 -0
  51. data/webpack/global_test_setup.js +11 -0
  52. data/webpack/index.js +8 -0
  53. data/webpack/reducers.js +7 -0
  54. data/webpack/test_setup.js +17 -0
  55. metadata +39 -33
@@ -0,0 +1,157 @@
1
+ import { testReducerSnapshotWithFixtures } from 'react-redux-test-utils';
2
+ import Immutable from 'seamless-immutable';
3
+
4
+ import { actionTypeGenerator } from 'foremanReact/redux/API';
5
+
6
+ import {
7
+ SNAPSHOT_LIST,
8
+ SNAPSHOT_DELETE,
9
+ SNAPSHOT_ROLLBACK,
10
+ SNAPSHOT_UPDATE,
11
+ } from '../SnapshotManagementConstants';
12
+ import reducer, { initialState } from '../SnapshotManagementReducer';
13
+
14
+ const listTypes = actionTypeGenerator(SNAPSHOT_LIST);
15
+ const deleteTypes = actionTypeGenerator(SNAPSHOT_DELETE);
16
+ const rollbackTypes = actionTypeGenerator(SNAPSHOT_ROLLBACK);
17
+ const updateTypes = actionTypeGenerator(SNAPSHOT_UPDATE);
18
+
19
+ const idleState = Immutable({
20
+ isLoading: false,
21
+ isWorking: false,
22
+ hasError: false,
23
+ snapshots: [
24
+ {
25
+ id: 'snapshot-15776',
26
+ name: 'test',
27
+ description: '123 testSnapshot',
28
+ created_at: '2021-01-19 15:03:47 UTC',
29
+ parent_id: null,
30
+ children_ids: null,
31
+ },
32
+ ],
33
+ });
34
+
35
+ const fixtures = {
36
+ 'should return initial state': {
37
+ state: initialState,
38
+ action: {
39
+ type: undefined,
40
+ payload: {},
41
+ },
42
+ },
43
+ 'should handle LIST_REQUEST': {
44
+ state: idleState,
45
+ action: {
46
+ type: listTypes.REQUEST,
47
+ // response: ,
48
+ },
49
+ },
50
+ 'should handle LIST_SUCCESS': {
51
+ state: idleState,
52
+ action: {
53
+ type: listTypes.SUCCESS,
54
+ payload: {},
55
+ response: {
56
+ results: [],
57
+ },
58
+ },
59
+ },
60
+ 'should handle LIST_FAILURE': {
61
+ state: idleState,
62
+ action: {
63
+ type: listTypes.FAILURE,
64
+ payload: {},
65
+ response: {
66
+ message: 'Something went wrong',
67
+ },
68
+ },
69
+ },
70
+ 'should handle ROLLBACK_REQUEST': {
71
+ state: idleState,
72
+ action: {
73
+ type: rollbackTypes.REQUEST,
74
+ // response: ,
75
+ },
76
+ },
77
+ 'should handle ROLLBACK_SUCCESS': {
78
+ state: idleState,
79
+ action: {
80
+ type: rollbackTypes.SUCCESS,
81
+ payload: {},
82
+ response: {
83
+ results: [],
84
+ },
85
+ },
86
+ },
87
+ 'should handle ROLLBACK_FAILURE': {
88
+ state: idleState,
89
+ action: {
90
+ type: rollbackTypes.FAILURE,
91
+ payload: {},
92
+ response: {
93
+ message: 'Something went wrong',
94
+ },
95
+ },
96
+ },
97
+ 'should handle DELETE_REQUEST': {
98
+ state: idleState,
99
+ action: {
100
+ type: deleteTypes.REQUEST,
101
+ // response: ,
102
+ },
103
+ },
104
+ 'should handle DELETE_SUCCESS': {
105
+ state: idleState,
106
+ action: {
107
+ type: deleteTypes.SUCCESS,
108
+ payload: {},
109
+ response: {
110
+ results: [],
111
+ },
112
+ },
113
+ },
114
+ 'should handle DELETE_FAILURE': {
115
+ state: idleState,
116
+ action: {
117
+ type: deleteTypes.FAILURE,
118
+ payload: {},
119
+ response: {
120
+ message: 'Something went wrong',
121
+ },
122
+ },
123
+ },
124
+ 'should handle UPDATE_REQUEST': {
125
+ state: idleState,
126
+ action: {
127
+ type: updateTypes.REQUEST,
128
+ // response: ,
129
+ },
130
+ },
131
+ 'should handle UPDATE_SUCCESS': {
132
+ state: idleState,
133
+ action: {
134
+ type: updateTypes.SUCCESS,
135
+ payload: {},
136
+ response: {
137
+ id: 'snapshot-15776',
138
+ name: 'test snapshot',
139
+ description: 'My most important snapshot.',
140
+ created_at: '2021-01-19 15:03:47 UTC',
141
+ },
142
+ },
143
+ },
144
+ 'should handle UPDATE_FAILURE': {
145
+ state: idleState,
146
+ action: {
147
+ type: updateTypes.FAILURE,
148
+ payload: {},
149
+ response: {
150
+ message: 'Something went wrong',
151
+ },
152
+ },
153
+ },
154
+ };
155
+
156
+ describe('SnapshotManagementReducer', () =>
157
+ testReducerSnapshotWithFixtures(reducer, fixtures));
@@ -0,0 +1,314 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Snapshot list actions should load snapshots and fail 1`] = `
4
+ Array [
5
+ Array [
6
+ Object {
7
+ "payload": Object {
8
+ "hostId": 42,
9
+ },
10
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_LIST_REQUEST",
11
+ },
12
+ ],
13
+ Array [
14
+ Object {
15
+ "payload": Object {
16
+ "hostId": 42,
17
+ },
18
+ "response": [Error: some-error],
19
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_LIST_FAILURE",
20
+ },
21
+ ],
22
+ ]
23
+ `;
24
+
25
+ exports[`Snapshot list actions should load snapshots and success 1`] = `
26
+ Array [
27
+ Array [
28
+ Object {
29
+ "payload": Object {
30
+ "hostId": 42,
31
+ },
32
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_LIST_REQUEST",
33
+ },
34
+ ],
35
+ Array [
36
+ Object {
37
+ "payload": Object {
38
+ "hostId": 42,
39
+ },
40
+ "response": "some-data",
41
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_LIST_SUCCESS",
42
+ },
43
+ ],
44
+ ]
45
+ `;
46
+
47
+ exports[`Snapshot snapshot-delete actions should delete snapshot and success 1`] = `
48
+ Array [
49
+ Array [
50
+ Object {
51
+ "payload": Object {
52
+ "host": Object {
53
+ "id": 42,
54
+ "name": "deep.thought",
55
+ },
56
+ "id": "snapshot-0815",
57
+ },
58
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_REQUEST",
59
+ },
60
+ ],
61
+ Array [
62
+ Object {
63
+ "payload": Object {
64
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_SUCCESS",
65
+ "message": Object {
66
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_SUCCESS",
67
+ "message": "Successfully removed Snapshot \\"Savegame\\" from host deep.thought",
68
+ "type": "success",
69
+ },
70
+ },
71
+ "type": "TOASTS_ADD",
72
+ },
73
+ ],
74
+ Array [
75
+ [Function],
76
+ ],
77
+ Array [
78
+ Object {
79
+ "payload": Object {
80
+ "host": Object {
81
+ "id": 42,
82
+ "name": "deep.thought",
83
+ },
84
+ "id": "snapshot-0815",
85
+ },
86
+ "response": "some-data",
87
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_SUCCESS",
88
+ },
89
+ ],
90
+ ]
91
+ `;
92
+
93
+ exports[`Snapshot snapshot-delete actions should load snapshots and fail 1`] = `
94
+ Array [
95
+ Array [
96
+ Object {
97
+ "payload": Object {
98
+ "host": Object {
99
+ "id": 42,
100
+ "name": "deep.thought",
101
+ },
102
+ "id": "snapshot-0815",
103
+ },
104
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_REQUEST",
105
+ },
106
+ ],
107
+ Array [
108
+ Object {
109
+ "payload": Object {
110
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_FAILURE",
111
+ "message": Object {
112
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_FAILURE",
113
+ "message": "Error occurred while removing Snapshot: Error: some-error",
114
+ "type": "error",
115
+ },
116
+ },
117
+ "type": "TOASTS_ADD",
118
+ },
119
+ ],
120
+ Array [
121
+ Object {
122
+ "payload": Object {
123
+ "host": Object {
124
+ "id": 42,
125
+ "name": "deep.thought",
126
+ },
127
+ "id": "snapshot-0815",
128
+ },
129
+ "response": [Error: some-error],
130
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_DELETE_FAILURE",
131
+ },
132
+ ],
133
+ ]
134
+ `;
135
+
136
+ exports[`Snapshot snapshot-rollback actions should load snapshots and fail 1`] = `
137
+ Array [
138
+ Array [
139
+ Object {
140
+ "payload": Object {
141
+ "host": Object {
142
+ "id": 42,
143
+ "name": "deep.thought",
144
+ },
145
+ "id": "snapshot-0815",
146
+ },
147
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_REQUEST",
148
+ },
149
+ ],
150
+ Array [
151
+ Object {
152
+ "payload": Object {
153
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_FAILURE",
154
+ "message": Object {
155
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_FAILURE",
156
+ "message": "Error occurred while rolling back VM: Error: some-error",
157
+ "type": "error",
158
+ },
159
+ },
160
+ "type": "TOASTS_ADD",
161
+ },
162
+ ],
163
+ Array [
164
+ Object {
165
+ "payload": Object {
166
+ "host": Object {
167
+ "id": 42,
168
+ "name": "deep.thought",
169
+ },
170
+ "id": "snapshot-0815",
171
+ },
172
+ "response": [Error: some-error],
173
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_FAILURE",
174
+ },
175
+ ],
176
+ ]
177
+ `;
178
+
179
+ exports[`Snapshot snapshot-rollback actions should rollback snapshot and success 1`] = `
180
+ Array [
181
+ Array [
182
+ Object {
183
+ "payload": Object {
184
+ "host": Object {
185
+ "id": 42,
186
+ "name": "deep.thought",
187
+ },
188
+ "id": "snapshot-0815",
189
+ },
190
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_REQUEST",
191
+ },
192
+ ],
193
+ Array [
194
+ Object {
195
+ "payload": Object {
196
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_SUCCESS",
197
+ "message": Object {
198
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_SUCCESS",
199
+ "message": "Successfully rolled back Snapshot \\"Savegame\\" on host deep.thought",
200
+ "type": "success",
201
+ },
202
+ },
203
+ "type": "TOASTS_ADD",
204
+ },
205
+ ],
206
+ Array [
207
+ Object {
208
+ "payload": Object {
209
+ "host": Object {
210
+ "id": 42,
211
+ "name": "deep.thought",
212
+ },
213
+ "id": "snapshot-0815",
214
+ },
215
+ "response": "some-data",
216
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_ROLLBACK_SUCCESS",
217
+ },
218
+ ],
219
+ ]
220
+ `;
221
+
222
+ exports[`Snapshot snapshot-update actions should load snapshots and fail 1`] = `
223
+ Array [
224
+ Array [
225
+ Object {
226
+ "payload": Object {
227
+ "host": Object {
228
+ "id": 42,
229
+ "name": "deep.thought",
230
+ },
231
+ "id": "snapshot-0815",
232
+ "snapshot": Object {
233
+ "description": "Saw the three headed monkey!",
234
+ "name": "Savegame",
235
+ },
236
+ },
237
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_REQUEST",
238
+ },
239
+ ],
240
+ Array [
241
+ Object {
242
+ "payload": Object {
243
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_FAILURE",
244
+ "message": Object {
245
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_FAILURE",
246
+ "message": "Error occurred while updating Snapshot: Error: some-error",
247
+ "type": "error",
248
+ },
249
+ },
250
+ "type": "TOASTS_ADD",
251
+ },
252
+ ],
253
+ Array [
254
+ Object {
255
+ "payload": Object {
256
+ "host": Object {
257
+ "id": 42,
258
+ "name": "deep.thought",
259
+ },
260
+ "id": "snapshot-0815",
261
+ },
262
+ "response": [Error: some-error],
263
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_FAILURE",
264
+ },
265
+ ],
266
+ ]
267
+ `;
268
+
269
+ exports[`Snapshot snapshot-update actions should update snapshot and success 1`] = `
270
+ Array [
271
+ Array [
272
+ Object {
273
+ "payload": Object {
274
+ "host": Object {
275
+ "id": 42,
276
+ "name": "deep.thought",
277
+ },
278
+ "id": "snapshot-0815",
279
+ "snapshot": Object {
280
+ "description": "Saw the three headed monkey!",
281
+ "name": "Savegame",
282
+ },
283
+ },
284
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_REQUEST",
285
+ },
286
+ ],
287
+ Array [
288
+ Object {
289
+ "payload": Object {
290
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_SUCCESS",
291
+ "message": Object {
292
+ "key": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_SUCCESS",
293
+ "message": "Successfully updated Snapshot \\"Savegame\\"",
294
+ "type": "success",
295
+ },
296
+ },
297
+ "type": "TOASTS_ADD",
298
+ },
299
+ ],
300
+ Array [
301
+ Object {
302
+ "payload": Object {
303
+ "host": Object {
304
+ "id": 42,
305
+ "name": "deep.thought",
306
+ },
307
+ "id": "snapshot-0815",
308
+ },
309
+ "response": "some-data",
310
+ "type": "FOREMAN_SNAPSHOT_MANAGEMENT_SNAPSHOT_UPDATE_SUCCESS",
311
+ },
312
+ ],
313
+ ]
314
+ `;