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
@@ -5,7 +5,7 @@
5
5
  #
6
6
  msgid ""
7
7
  msgstr ""
8
- "Project-Id-Version: foreman_snapshot_management 1.7.0\n"
8
+ "Project-Id-Version: foreman_snapshot_management 1.8.1\n"
9
9
  "Report-Msgid-Bugs-To: \n"
10
10
  "PO-Revision-Date: 2020-03-02 10:27+0000\n"
11
11
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
@@ -20,16 +20,13 @@ msgstr ""
20
20
  msgid "Action"
21
21
  msgstr ""
22
22
 
23
- msgid "Are you sure to delete this Snapshot?"
23
+ msgid "Action with sub plans"
24
24
  msgstr ""
25
25
 
26
- msgid "Are you sure to revert this Snapshot?"
27
- msgstr ""
28
-
29
- msgid "Create"
26
+ msgid "Create Snapshot"
30
27
  msgstr ""
31
28
 
32
- msgid "Create Snapshot"
29
+ msgid "Create Snapshot for %s"
33
30
  msgstr ""
34
31
 
35
32
  msgid "Create a snapshot"
@@ -38,10 +35,13 @@ msgstr ""
38
35
  msgid "Created %{snapshots} for %{num} %{hosts}"
39
36
  msgstr ""
40
37
 
41
- msgid "Delete a snapshot"
38
+ msgid "Delete"
39
+ msgstr ""
40
+
41
+ msgid "Delete Snapshot \"%s\"?"
42
42
  msgstr ""
43
43
 
44
- msgid "Deleting..."
44
+ msgid "Delete a snapshot"
45
45
  msgstr ""
46
46
 
47
47
  msgid "Description"
@@ -62,12 +62,24 @@ msgstr ""
62
62
  msgid "Error occurred while rolling back VM: %s"
63
63
  msgstr ""
64
64
 
65
+ msgid "Error occurred while updating Snapshot: %s"
66
+ msgstr ""
67
+
68
+ msgid "Failed to load snapshot list"
69
+ msgstr ""
70
+
65
71
  msgid "Failed to update Snapshot: %s"
66
72
  msgstr ""
67
73
 
68
74
  msgid "Foreman-plugin to manage snapshots in a virtual-hardware environments."
69
75
  msgstr ""
70
76
 
77
+ msgid "Import Puppet classes"
78
+ msgstr ""
79
+
80
+ msgid "Import facts"
81
+ msgstr ""
82
+
71
83
  msgid "Include RAM"
72
84
  msgstr ""
73
85
 
@@ -77,6 +89,12 @@ msgstr ""
77
89
  msgid "Loading Snapshots information ..."
78
90
  msgstr ""
79
91
 
92
+ msgid "N/A"
93
+ msgstr ""
94
+
95
+ msgid "Name"
96
+ msgstr ""
97
+
80
98
  msgid "Name must contain at least 2 characters starting with alphabet. Valid characters are A-Z a-z 0-9 _"
81
99
  msgstr ""
82
100
 
@@ -95,10 +113,10 @@ msgstr ""
95
113
  msgid "Revert Host to a snapshot"
96
114
  msgstr ""
97
115
 
98
- msgid "Reverting..."
116
+ msgid "Rollback"
99
117
  msgstr ""
100
118
 
101
- msgid "Rollback"
119
+ msgid "Rollback to \"%s\"?"
102
120
  msgstr ""
103
121
 
104
122
  msgid "Snapshot"
@@ -109,12 +127,24 @@ msgstr[1] ""
109
127
  msgid "Snapshot name cannot be changed"
110
128
  msgstr ""
111
129
 
130
+ msgid "Snapshot successfully created!"
131
+ msgstr ""
132
+
112
133
  msgid "Snapshots"
113
134
  msgstr ""
114
135
 
115
136
  msgid "Something went wrong while selecting hosts - %s"
116
137
  msgstr ""
117
138
 
139
+ msgid "Successfully removed Snapshot \"%s\" from host %s"
140
+ msgstr ""
141
+
142
+ msgid "Successfully rolled back Snapshot \"%s\" on host %s"
143
+ msgstr ""
144
+
145
+ msgid "Successfully updated Snapshot \"%s\""
146
+ msgstr ""
147
+
118
148
  msgid "Unable to create Proxmox Snapshot"
119
149
  msgstr ""
120
150
 
@@ -148,6 +178,9 @@ msgstr ""
148
178
  msgid "Whether to include the RAM state in the snapshot"
149
179
  msgstr ""
150
180
 
181
+ msgid "edit entry"
182
+ msgstr ""
183
+
151
184
  msgid "host"
152
185
  msgid_plural "hosts"
153
186
  msgstr[0] ""
@@ -8,8 +8,8 @@ msgid ""
8
8
  msgstr ""
9
9
  "Project-Id-Version: foreman_snapshot_management 1.0.0\n"
10
10
  "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2020-03-02 15:24+0000\n"
12
- "PO-Revision-Date: 2020-03-02 15:24+0000\n"
11
+ "POT-Creation-Date: 2021-05-07 09:44+0000\n"
12
+ "PO-Revision-Date: 2021-05-07 09:44+0000\n"
13
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
15
15
  "Language: \n"
@@ -55,6 +55,7 @@ msgid "Error occurred while creating Snapshot: %s"
55
55
  msgstr ""
56
56
 
57
57
  #: ../app/controllers/foreman_snapshot_management/snapshots_controller.rb:48
58
+ #: ../webpack/components/SnapshotManagement/SnapshotManagementActions.js:81
58
59
  msgid "Error occurred while removing Snapshot: %s"
59
60
  msgstr ""
60
61
 
@@ -63,6 +64,7 @@ msgid "VM successfully rolled back."
63
64
  msgstr ""
64
65
 
65
66
  #: ../app/controllers/foreman_snapshot_management/snapshots_controller.rb:60
67
+ #: ../webpack/components/SnapshotManagement/SnapshotManagementActions.js:199
66
68
  msgid "Error occurred while rolling back VM: %s"
67
69
  msgstr ""
68
70
 
@@ -80,8 +82,8 @@ msgstr ""
80
82
 
81
83
  #: ../app/controllers/foreman_snapshot_management/snapshots_controller.rb:95
82
84
  #: ../app/models/foreman_snapshot_management/snapshot.rb:52
83
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:5
84
85
  #: ../app/views/foreman_snapshot_management/snapshots/select_multiple_host.html.erb:8
86
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js:156
85
87
  msgid "Snapshot"
86
88
  msgid_plural "Snapshots"
87
89
  msgstr[0] ""
@@ -107,6 +109,7 @@ msgstr ""
107
109
 
108
110
  #:
109
111
  #: ../app/helpers/concerns/foreman_snapshot_management/hosts_helper_extension.rb:6
112
+ #: ../webpack/components/SnapshotManagement/SnapshotManagement.js:46
110
113
  msgid "Create Snapshot"
111
114
  msgstr ""
112
115
 
@@ -152,55 +155,114 @@ msgstr ""
152
155
  msgid "Unable to update VMWare Snapshot"
153
156
  msgstr ""
154
157
 
155
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:6
158
+ #:
159
+ #: ../app/views/foreman_snapshot_management/snapshots/select_multiple_host.html.erb:4
160
+ msgid "No capable hosts selected"
161
+ msgstr ""
162
+
163
+ #:
156
164
  #: ../app/views/foreman_snapshot_management/snapshots/select_multiple_host.html.erb:11
165
+ #: ../webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotForm.js:75
166
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js:162
157
167
  msgid "Description"
158
168
  msgstr ""
159
169
 
160
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:8
170
+ #:
161
171
  #: ../app/views/foreman_snapshot_management/snapshots/select_multiple_host.html.erb:14
172
+ #: ../webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotForm.js:81
162
173
  msgid "Include RAM"
163
174
  msgstr ""
164
175
 
165
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:10
166
- msgid "Action"
176
+ #: ../app/views/hosts/_snapshots_tab.html.erb:13
177
+ msgid "Loading Snapshots information ..."
167
178
  msgstr ""
168
179
 
169
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:28
170
- msgid "Create"
180
+ #: ../lib/foreman_snapshot_management/engine.rb:64
181
+ msgid "Snapshots"
171
182
  msgstr ""
172
183
 
173
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:55
174
- msgid "Rollback"
184
+ #: ../webpack/components/SnapshotManagement/SnapshotManagementActions.js:60
185
+ msgid "Successfully removed Snapshot \"%s\" from host %s"
186
+ msgstr ""
187
+
188
+ #: ../webpack/components/SnapshotManagement/SnapshotManagementActions.js:126
189
+ msgid "Successfully updated Snapshot \"%s\""
175
190
  msgstr ""
176
191
 
177
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:55
178
- msgid "Are you sure to revert this Snapshot?"
192
+ #: ../webpack/components/SnapshotManagement/SnapshotManagementActions.js:145
193
+ msgid "Error occurred while updating Snapshot: %s"
179
194
  msgstr ""
180
195
 
181
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:55
182
- msgid "Reverting..."
196
+ #: ../webpack/components/SnapshotManagement/SnapshotManagementActions.js:180
197
+ msgid "Successfully rolled back Snapshot \"%s\" on host %s"
183
198
  msgstr ""
184
199
 
185
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:56
186
- msgid "Are you sure to delete this Snapshot?"
200
+ #:
201
+ #: ../webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotForm.js:52
202
+ msgid "Snapshot successfully created!"
187
203
  msgstr ""
188
204
 
189
- #: ../app/views/foreman_snapshot_management/snapshots/_index.html.erb:56
190
- msgid "Deleting..."
205
+ #:
206
+ #: ../webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotForm.js:69
207
+ msgid "Name"
191
208
  msgstr ""
192
209
 
193
210
  #:
194
- #: ../app/views/foreman_snapshot_management/snapshots/select_multiple_host.html.erb:4
195
- msgid "No capable hosts selected"
211
+ #: ../webpack/components/SnapshotManagement/components/SnapshotFormModal/SnapshotFormModal.js:14
212
+ msgid "Create Snapshot for %s"
196
213
  msgstr ""
197
214
 
198
- #: ../app/views/hosts/_snapshots_tab.html.erb:5
199
- msgid "Loading Snapshots information ..."
215
+ #:
216
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js:122
217
+ msgid "N/A"
200
218
  msgstr ""
201
219
 
202
- #: ../lib/foreman_snapshot_management/engine.rb:61
203
- msgid "Snapshots"
220
+ #:
221
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js:171
222
+ msgid "Action"
223
+ msgstr ""
224
+
225
+ #:
226
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js:203
227
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js:205
228
+ msgid "Failed to load snapshot list"
229
+ msgstr ""
230
+
231
+ #:
232
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js:28
233
+ msgid "edit entry"
234
+ msgstr ""
235
+
236
+ #:
237
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js:42
238
+ msgid "Rollback to \"%s\"?"
239
+ msgstr ""
240
+
241
+ #:
242
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js:46
243
+ msgid "Rollback"
244
+ msgstr ""
245
+
246
+ #:
247
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js:60
248
+ msgid "Delete Snapshot \"%s\"?"
249
+ msgstr ""
250
+
251
+ #:
252
+ #: ../webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js:64
253
+ msgid "Delete"
254
+ msgstr ""
255
+
256
+ #: action_names.rb:2
257
+ msgid "Import Puppet classes"
258
+ msgstr ""
259
+
260
+ #: action_names.rb:3
261
+ msgid "Import facts"
262
+ msgstr ""
263
+
264
+ #: action_names.rb:4
265
+ msgid "Action with sub plans"
204
266
  msgstr ""
205
267
 
206
268
  #: gemspec.rb:4
data/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "foreman_snapshot_management",
3
+ "version": "2.0.0",
4
+ "description": "Foreman-plugin to manage snapshots in a virtual-hardware environments.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "lint": "tfm-lint --plugin -d /webpack",
8
+ "stylelint": "stylelint webpack/**/*.scss",
9
+ "test": "tfm-test --config jest.config.js",
10
+ "test:watch": "tfm-test --plugin --watchAll",
11
+ "test:current": "tfm-test --plugin --watch",
12
+ "publish-coverage": "tfm-publish-coverage",
13
+ "stories": "tfm-stories --plugin",
14
+ "stories:build": "tfm-build-stories --plugin",
15
+ "create-react-component": "yo react-domain"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/ATIX-AG/foreman_snapshot_management.git"
20
+ },
21
+ "bugs": {
22
+ "url": "http://projects.theforeman.org/projects/foreman_snapshot_management/issues"
23
+ },
24
+ "peerDependencies": {
25
+ "@theforeman/vendor": ">= 4.0.0"
26
+ },
27
+ "dependencies": {
28
+ "react-intl": "^2.8.0"
29
+ },
30
+ "devDependencies": {
31
+ "@babel/core": "^7.7.0",
32
+ "@sheerun/mutationobserver-shim": "^0.3.3",
33
+ "@theforeman/builder": "^4.0.0",
34
+ "@theforeman/eslint-plugin-foreman": "6.0.0",
35
+ "@theforeman/find-foreman": "^4.8.0",
36
+ "@theforeman/stories": "^7.0.0",
37
+ "@theforeman/test": "^8.0.0",
38
+ "@theforeman/vendor-dev": "^4.0.0",
39
+ "babel-eslint": "^10.0.3",
40
+ "eslint": "^6.7.2",
41
+ "prettier": "^1.19.1",
42
+ "react-redux-test-utils": "^0.2.0",
43
+ "stylelint": "^9.3.0",
44
+ "stylelint-config-standard": "^18.0.0"
45
+ }
46
+ }
@@ -13,137 +13,260 @@ class Api::V2::SnapshotsControllerTest < ActionController::TestCase
13
13
  let(:host) { FactoryBot.create(:host, :managed, :compute_resource => compute_resource, :uuid => uuid) }
14
14
  let(:snapshot_id) { 'snapshot-0101' }
15
15
  let(:proxmox_compute_resource) do
16
- FactoryBot.create(:proxmox_cr)
17
- ComputeResource.find_by(type: 'ForemanFogProxmox::Proxmox')
16
+ cr = FactoryBot.create(:proxmox_cr)
17
+ ComputeResource.find_by(id: cr.id)
18
18
  end
19
19
  let(:vmid) { '100' }
20
- let(:proxmox_host) { FactoryBot.create(:host, :managed, :compute_resource => proxmox_compute_resource, :uuid => vmid) }
20
+ let(:proxmox_host) { FactoryBot.create(:host, :managed, :compute_resource => proxmox_compute_resource, :uuid => "1_#{vmid}") }
21
21
  let(:proxmox_snapshot) { 'snapshot1' }
22
+ let(:manager_user) do
23
+ roles = [Role.find_by(name: 'Snapshot Manager')]
24
+ FactoryBot.create(:user, :organizations => [tax_organization], :locations => [tax_location], :roles => roles)
25
+ end
26
+ let(:view_user) do
27
+ roles = [Role.find_by(name: 'Snapshot Viewer')]
28
+ FactoryBot.create(:user, :organizations => [tax_organization], :locations => [tax_location], :roles => roles)
29
+ end
22
30
  setup { ::Fog.mock! }
23
31
  teardown { ::Fog.unmock! }
24
32
 
25
- test 'should get index of Vmware Snapshots' do
26
- get :index, params: { :host_id => host.to_param }
27
- assert_response :success
28
- assert_not_nil assigns(:snapshots)
29
- body = ActiveSupport::JSON.decode(@response.body)
30
- assert_not_empty body
31
- assert_not_empty body['results']
32
- end
33
+ context 'view user' do
34
+ setup do
35
+ # Make sure that test-hosts are created here (by the admin-user)
36
+ host
37
+ proxmox_host
38
+ @orig_user = User.current
39
+ User.current = view_user
40
+ end
41
+ teardown do
42
+ User.current = @orig_user
43
+ end
33
44
 
34
- test 'should get index of Proxmox Snapshots' do
35
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
36
- get :index, params: { :host_id => proxmox_host.to_param }
37
- assert_response :success
38
- assert_not_nil assigns(:snapshots)
39
- body = ActiveSupport::JSON.decode(@response.body)
40
- assert_not_empty body
41
- assert_not_empty body['results']
42
- end
45
+ test 'should get index of Vmware Snapshots' do
46
+ get :index, params: { :host_id => host.to_param }
47
+ assert_response :success
48
+ assert_not_nil assigns(:snapshots)
49
+ body = ActiveSupport::JSON.decode(@response.body)
50
+ assert_not_empty body
51
+ assert_not_empty body['results']
52
+ end
43
53
 
44
- test 'should search VMware snapshot' do
45
- get :index, params: { :host_id => host.to_param, :search => 'name= clean' }
46
- assert_response :success
47
- assert_not_nil assigns(:snapshots)
48
- body = ActiveSupport::JSON.decode(@response.body)
49
- assert_not_empty body
50
- assert_not_empty body['results']
51
- assert body['results'].count == 1
52
- end
54
+ test 'should get index of Proxmox Snapshots' do
55
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
56
+ get :index, params: { :host_id => proxmox_host.to_param }
57
+ assert_response :success
58
+ assert_not_nil assigns(:snapshots)
59
+ body = ActiveSupport::JSON.decode(@response.body)
60
+ assert_not_empty body
61
+ assert_not_empty body['results']
62
+ end
53
63
 
54
- test 'should search Proxmox snapshot' do
55
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
56
- get :index, params: { :host_id => proxmox_host.to_param, :search => 'name= snapshot1' }
57
- assert_response :success
58
- assert_not_nil assigns(:snapshots)
59
- body = ActiveSupport::JSON.decode(@response.body)
60
- assert_not_empty body
61
- assert_not_empty body['results']
62
- assert body['results'].count == 1
63
- end
64
+ test 'should search VMware snapshot' do
65
+ get :index, params: { :host_id => host.to_param, :search => 'name= clean' }
66
+ assert_response :success
67
+ assert_not_nil assigns(:snapshots)
68
+ body = ActiveSupport::JSON.decode(@response.body)
69
+ assert_not_empty body
70
+ assert_not_empty body['results']
71
+ assert_equal body['results'].count, 1
72
+ end
64
73
 
65
- test 'should refute search Vmware snapshot' do
66
- get :index, params: { :host_id => host.to_param, :search => 'name != clean' }
67
- assert_response :internal_server_error
68
- end
74
+ test 'should search Proxmox snapshot' do
75
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
76
+ get :index, params: { :host_id => proxmox_host.to_param, :search => 'name= snapshot1' }
77
+ assert_response :success
78
+ assert_not_nil assigns(:snapshots)
79
+ body = ActiveSupport::JSON.decode(@response.body)
80
+ assert_not_empty body
81
+ assert_not_empty body['results']
82
+ assert_equal body['results'].count, 1
83
+ end
69
84
 
70
- test 'should show Vmware snapshot' do
71
- get :show, params: { :host_id => host.to_param, :id => snapshot_id }
72
- assert_not_nil assigns(:snapshot)
73
- assert_response :success
74
- body = ActiveSupport::JSON.decode(@response.body)
75
- assert_not_empty body
76
- end
85
+ test 'should refute search Vmware snapshot' do
86
+ get :index, params: { :host_id => host.to_param, :search => 'name != clean' }
87
+ assert_response :internal_server_error
88
+ end
77
89
 
78
- test 'should show Proxmox snapshot' do
79
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
80
- get :show, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot }
81
- assert_not_nil assigns(:snapshot)
82
- assert_response :success
83
- body = ActiveSupport::JSON.decode(@response.body)
84
- assert_not_empty body
85
- end
90
+ test 'should show Vmware snapshot' do
91
+ get :show, params: { :host_id => host.to_param, :id => snapshot_id }
92
+ assert_not_nil assigns(:snapshot)
93
+ assert_response :success
94
+ body = ActiveSupport::JSON.decode(@response.body)
95
+ assert_not_empty body
96
+ end
86
97
 
87
- test 'should 404 for unknown Vmware snapshot' do
88
- get :show, params: { :host_id => host.to_param, :id => 'does-not-exist' }
89
- assert_response :not_found
90
- end
98
+ test 'should show Proxmox snapshot' do
99
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
100
+ get :show, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot }
101
+ assert_not_nil assigns(:snapshot)
102
+ assert_response :success
103
+ body = ActiveSupport::JSON.decode(@response.body)
104
+ assert_not_empty body
105
+ end
91
106
 
92
- test 'should create Vmware snapshot' do
93
- post :create, params: { :host_id => host.to_param, :name => 'test' }
94
- assert_response :created
95
- assert_not_nil assigns(:snapshot)
96
- end
107
+ test 'should 404 for unknown Vmware snapshot' do
108
+ get :show, params: { :host_id => host.to_param, :id => 'does-not-exist' }
109
+ assert_response :not_found
110
+ end
97
111
 
98
- test 'should create Proxmox snapshot' do
99
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
100
- post :create, params: { :host_id => proxmox_host.to_param, :name => 'test' }
101
- assert_response :created
102
- assert_not_nil assigns(:snapshot)
103
- end
112
+ test 'should refute create Vmware snapshot' do
113
+ post :create, params: { :host_id => host.to_param, :name => 'test' }
114
+ assert_response :forbidden
115
+ end
104
116
 
105
- test 'should update Vmware snapshot' do
106
- name = 'test'
107
- put :update, params: { :host_id => host.to_param, :id => snapshot_id.to_param, :name => name.to_param }
108
- assert_response :success
109
- end
117
+ test 'should refute update Vmware snapshot' do
118
+ name = 'test'
119
+ put :update, params: { :host_id => host.to_param, :id => snapshot_id.to_param, :name => name.to_param }
120
+ assert_response :forbidden
121
+ end
110
122
 
111
- test 'should update Proxmox snapshot' do
112
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
113
- description = 'snapshot1 updated'
114
- put :update, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param, :description => description.to_param }
115
- assert_response :success
116
- end
123
+ test 'should refute destroy Vmware snapshot' do
124
+ delete :destroy, params: { :host_id => host.to_param, :id => snapshot_id.to_param }
125
+ assert_response :forbidden
126
+ end
117
127
 
118
- test 'should refute update Proxmox snapshot name' do
119
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
120
- name = 'test'
121
- put :update, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param, :name => name.to_param }
122
- assert_response :unprocessable_entity
128
+ test 'should refute revert Proxmox snapshot' do
129
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
130
+ put :revert, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param }
131
+ assert_response :forbidden
132
+ end
123
133
  end
124
134
 
125
- test 'should destroy Vmware snapshot' do
126
- delete :destroy, params: { :host_id => host.to_param, :id => snapshot_id.to_param }
127
- assert_response :success
128
- end
135
+ context 'manager user' do
136
+ setup do
137
+ # Make sure that test-hosts are created here (by the admin-user)
138
+ host
139
+ proxmox_host
140
+ @orig_user = User.current
141
+ User.current = manager_user
142
+ end
143
+ teardown do
144
+ User.current = @orig_user
145
+ end
129
146
 
130
- test 'should destroy Proxmox snapshot' do
131
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
132
- delete :destroy, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param }
133
- assert_response :success
134
- body = ActiveSupport::JSON.decode(@response.body)
135
- assert_not_nil body['name']
136
- assert_nil body['id']
137
- end
147
+ test 'should get index of Vmware Snapshots' do
148
+ get :index, params: { :host_id => host.to_param }
149
+ assert_response :success
150
+ assert_not_nil assigns(:snapshots)
151
+ body = ActiveSupport::JSON.decode(@response.body)
152
+ assert_not_empty body
153
+ assert_not_empty body['results']
154
+ end
138
155
 
139
- test 'should revert Vmware snapshot' do
140
- put :revert, params: { :host_id => host.to_param, :id => snapshot_id.to_param }
141
- assert_response :success
142
- end
156
+ test 'should get index of Proxmox Snapshots' do
157
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
158
+ get :index, params: { :host_id => proxmox_host.to_param }
159
+ assert_response :success
160
+ assert_not_nil assigns(:snapshots)
161
+ body = ActiveSupport::JSON.decode(@response.body)
162
+ assert_not_empty body
163
+ assert_not_empty body['results']
164
+ end
165
+
166
+ test 'should search VMware snapshot' do
167
+ get :index, params: { :host_id => host.to_param, :search => 'name= clean' }
168
+ assert_response :success
169
+ assert_not_nil assigns(:snapshots)
170
+ body = ActiveSupport::JSON.decode(@response.body)
171
+ assert_not_empty body
172
+ assert_not_empty body['results']
173
+ assert_equal body['results'].count, 1
174
+ end
175
+
176
+ test 'should search Proxmox snapshot' do
177
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
178
+ get :index, params: { :host_id => proxmox_host.to_param, :search => 'name= snapshot1' }
179
+ assert_response :success
180
+ assert_not_nil assigns(:snapshots)
181
+ body = ActiveSupport::JSON.decode(@response.body)
182
+ assert_not_empty body
183
+ assert_not_empty body['results']
184
+ assert_equal body['results'].count, 1
185
+ end
186
+
187
+ test 'should refute search Vmware snapshot' do
188
+ get :index, params: { :host_id => host.to_param, :search => 'name != clean' }
189
+ assert_response :internal_server_error
190
+ end
191
+
192
+ test 'should show Vmware snapshot' do
193
+ get :show, params: { :host_id => host.to_param, :id => snapshot_id }
194
+ assert_not_nil assigns(:snapshot)
195
+ assert_response :success
196
+ body = ActiveSupport::JSON.decode(@response.body)
197
+ assert_not_empty body
198
+ end
199
+
200
+ test 'should show Proxmox snapshot' do
201
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
202
+ get :show, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot }
203
+ assert_not_nil assigns(:snapshot)
204
+ assert_response :success
205
+ body = ActiveSupport::JSON.decode(@response.body)
206
+ assert_not_empty body
207
+ end
208
+
209
+ test 'should 404 for unknown Vmware snapshot' do
210
+ get :show, params: { :host_id => host.to_param, :id => 'does-not-exist' }
211
+ assert_response :not_found
212
+ end
213
+
214
+ test 'should create Vmware snapshot' do
215
+ post :create, params: { :host_id => host.to_param, :name => 'test' }
216
+ assert_response :created
217
+ assert_not_nil assigns(:snapshot)
218
+ end
219
+
220
+ test 'should create Proxmox snapshot' do
221
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
222
+ post :create, params: { :host_id => proxmox_host.to_param, :name => 'test' }
223
+ assert_response :created
224
+ assert_not_nil assigns(:snapshot)
225
+ end
226
+
227
+ test 'should update Vmware snapshot' do
228
+ name = 'test'
229
+ put :update, params: { :host_id => host.to_param, :id => snapshot_id.to_param, :name => name.to_param }
230
+ assert_response :success
231
+ end
232
+
233
+ test 'should update Proxmox snapshot' do
234
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
235
+ description = 'snapshot1 updated'
236
+ put :update, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param, :description => description.to_param }
237
+ assert_response :success
238
+ end
239
+
240
+ test 'should refute update Proxmox snapshot name' do
241
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
242
+ name = 'test'
243
+ put :update, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param, :name => name.to_param }
244
+ assert_response :unprocessable_entity
245
+ end
246
+
247
+ test 'should destroy Vmware snapshot' do
248
+ delete :destroy, params: { :host_id => host.to_param, :id => snapshot_id.to_param }
249
+ assert_response :success
250
+ end
251
+
252
+ test 'should destroy Proxmox snapshot' do
253
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
254
+ delete :destroy, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param }
255
+ assert_response :success
256
+ body = ActiveSupport::JSON.decode(@response.body)
257
+ assert_not_nil body['name']
258
+ assert_nil body['id']
259
+ end
260
+
261
+ test 'should revert Vmware snapshot' do
262
+ put :revert, params: { :host_id => host.to_param, :id => snapshot_id.to_param }
263
+ assert_response :success
264
+ end
143
265
 
144
- test 'should revert Proxmox snapshot' do
145
- Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
146
- put :revert, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param }
147
- assert_response :success
266
+ test 'should revert Proxmox snapshot' do
267
+ Host::Managed.any_instance.stubs(:vm_exists?).returns(false)
268
+ put :revert, params: { :host_id => proxmox_host.to_param, :id => proxmox_snapshot.to_param }
269
+ assert_response :success
270
+ end
148
271
  end
149
272
  end