foreman_fog_proxmox 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of foreman_fog_proxmox might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88c0db5bfdca9f434f07d13fd1d18b55b4cb041d093a75e30698182f8f16d533
4
- data.tar.gz: 3e9cf561af0f98223a17edbe1a7bf0489379a26eada8152d62990476bce30091
3
+ metadata.gz: 2037b59b19ef9a750b13401e696fb2d460f24df0c5988edc0bd3136c4ab1e836
4
+ data.tar.gz: 22ba3c4a47a6a2ebdb4ce05b72c2e3e6fbc44144a42cadcc1b54440c6cdf577c
5
5
  SHA512:
6
- metadata.gz: f505da06a2573c212f4438d82fa0da3c565ca23747c03d6716ae1dafa82f4dd9aae20ddfa31994fea759ba068a1490cd0f8f38426c9de3906da7854902452eeb
7
- data.tar.gz: 3c5c3d8d77c936b8368ce68c1b5ede56c9933bcded2b225976cd75b0cbf85f049a63d5015933de7261a544bcd300f628a142fe859b14faae87118fbfe4131824
6
+ metadata.gz: 1720a971f5238f516e61e669607133ae6f9662d236a41a667cba1ce3e068710e1620eac645f5e6c8f0d135320dc4fe930faa9ffb582081fb970e209e71b9516d
7
+ data.tar.gz: d0ccf273ed786ba2253ff9d1b39f7dacd247f83853283b115f4aa727440a9dcfff8d4e09d484aac230c1c55e5421291bff5031b2c04912e435056a0e556762e3
data/README.md CHANGED
@@ -24,9 +24,10 @@ You can support the plugin development via the following methods:
24
24
  |Fog-proxmox|Proxmox|Foreman-fog-proxmox|Foreman|Ruby|
25
25
  |--|--|--|--|--|
26
26
  |<0.6|<5.3|<0.6|<=1.20|>=2.3|
27
- |=0.6|=5.3|=0.6|=1.21|>=2.3|
28
- |<=0.8 |=5.4|>=0.7|>=1.22|>=2.3|
29
- |>=0.9 |>=5.4|>=0.9|>=1.22|>=2.3|
27
+ |=0.6|<5.4|=0.6|=1.21|>=2.3|
28
+ |<=0.8 |<6.0|>=0.7|>=1.22|>=2.3|
29
+ |<0.9 |<6.0|=0.9|>=1.22|>=2.3|
30
+ |>=0.9 |>=5.4|>=0.9.1|>=1.22|>=2.3|
30
31
 
31
32
  ## Installation
32
33
 
@@ -48,7 +48,7 @@ module ForemanFogProxmox
48
48
  vm.move(id, volume_attributes['storage'])
49
49
  else
50
50
  options = volume_options(vm, id, volume_attributes)
51
- vm.attach({:id => disk.id, :volid => disk.volid, :size => disk.size}, options)
51
+ vm.attach({ :id => disk.id, :volid => disk.volid, :size => disk.size }, options)
52
52
  end
53
53
  end
54
54
 
@@ -18,5 +18,5 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  module ForemanFogProxmox
21
- VERSION = '0.9.0'
21
+ VERSION = '0.9.1'
22
22
  end
@@ -27,7 +27,7 @@ module ForemanFogProxmox
27
27
  describe 'clone_from_image' do
28
28
  before do
29
29
  @cr = FactoryBot.build_stubbed(:proxmox_cr)
30
- @args = {:name => 'name'}
30
+ @args = { :name => 'name' }
31
31
  @image_id = 100
32
32
  @vmid = 101
33
33
  @image = mock('vm')
@@ -36,14 +36,14 @@ module ForemanFogProxmox
36
36
  @clone = mock('vm')
37
37
  end
38
38
  it 'clones server from image' do
39
- @clone.expects(:update).with({:name => 'name'})
39
+ @clone.expects(:update).with(:name => 'name')
40
40
  @clone.stubs(:container?).returns(false)
41
41
  @cr.stubs(:find_vm_by_uuid).with(@vmid).returns(@clone)
42
42
  @cr.clone_from_image(@image_id, @args, @vmid)
43
43
  end
44
44
  it 'clones container from image' do
45
45
  @clone.stubs(:container?).returns(true)
46
- @clone.expects(:update).with({:hostname => 'name'})
46
+ @clone.expects(:update).with(:hostname => 'name')
47
47
  @cr.stubs(:find_vm_by_uuid).with(@vmid).returns(@clone)
48
48
  @cr.clone_from_image(@image_id, @args, @vmid)
49
49
  end
@@ -151,7 +151,7 @@ module ForemanFogProxmox
151
151
  vm.expects(:update, expected_config_attr)
152
152
  @cr.save_vm(uuid, new_attributes)
153
153
  end
154
-
154
+
155
155
  it 'saves modified container config with modified volumes options' do
156
156
  uuid = '100'
157
157
  config = mock('config')
@@ -191,7 +191,7 @@ module ForemanFogProxmox
191
191
  }.with_indifferent_access
192
192
  @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
193
193
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
194
- expected_volume_attr = {:id => 'mp0', :volid => 'local-lvm:vm-100-disk-0', :size => 1_073_741_824}, {:mp => '/opt/toto'}
194
+ expected_volume_attr = { :id => 'mp0', :volid => 'local-lvm:vm-100-disk-0', :size => 1_073_741_824 }, { :mp => '/opt/toto' }
195
195
  vm.expects(:attach, expected_volume_attr)
196
196
  vm.expects(:update, expected_config_attr)
197
197
  @cr.save_vm(uuid, new_attributes)
@@ -67,93 +67,6 @@ module ForemanFogProxmox
67
67
  @cr.save_vm(uuid, attr)
68
68
  end
69
69
 
70
- it 'saves modified server config with added volumes' do
71
- uuid = '100'
72
- config = mock('config')
73
- disks = mock('disks')
74
- disk = mock('disk')
75
- disk.stubs(:size).returns(1_073_741_824)
76
- disk.stubs(:storage).returns('local-lvm')
77
- disk.stubs(:id).returns('scsi0')
78
- disks.stubs(:get).returns
79
- config.stubs(:disks).returns(disks)
80
- config.stubs(:attributes).returns(:cores => '')
81
- vm = mock('vm')
82
- vm.stubs(:config).returns(config)
83
- vm.stubs(:container?).returns(false)
84
- vm.stubs(:type).returns('qemu')
85
- @cr.stubs(:find_vm_by_uuid).returns(vm)
86
- new_attributes = {
87
- 'templated' => '0',
88
- 'config_attributes' => {
89
- 'cores' => '1',
90
- 'cpulimit' => '1'
91
- },
92
- 'volumes_attributes' => {
93
- '0' => {
94
- 'id' => 'scsi0',
95
- '_delete' => '',
96
- 'device' => '0',
97
- 'controller' => 'scsi',
98
- 'storage' => 'local-lvm',
99
- 'size' => '2147483648',
100
- 'cache' => 'none'
101
- }
102
- }
103
- }.with_indifferent_access
104
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
105
- expected_config_attr = { :cores => '1', :cpulimit => '1' }
106
- expected_volume_attr = { id: 'scsi0', storage: 'local:lvm', size: (2_147_483_648 / GIGA).to_s }
107
- vm.expects(:attach, expected_volume_attr)
108
- vm.expects(:update, expected_config_attr)
109
- @cr.save_vm(uuid, new_attributes)
110
- end
111
-
112
- it 'saves modified server config with removed volumes' do
113
- uuid = '100'
114
- config = mock('config')
115
- disks = mock('disks')
116
- disk = mock('disk')
117
- disk.stubs(:size).returns(1_073_741_824)
118
- disk.stubs(:storage).returns('local-lvm')
119
- disk.stubs(:id).returns('virtio0')
120
- disks.stubs(:get).returns(disk)
121
- config.stubs(:disks).returns(disks)
122
- config.stubs(:attributes).returns(:cores => '')
123
- vm = mock('vm')
124
- vm.stubs(:config).returns(config)
125
- vm.stubs(:container?).returns(false)
126
- vm.stubs(:templated?).returns(false)
127
- vm.stubs(:type).returns('qemu')
128
- @cr.stubs(:find_vm_by_uuid).returns(vm)
129
- new_attributes = {
130
- 'templated' => '0',
131
- 'config_attributes' => {
132
- 'cores' => '1',
133
- 'cpulimit' => '1'
134
- },
135
- 'volumes_attributes' => {
136
- '0' => {
137
- '_delete' => '1',
138
- 'id' => 'scsi0',
139
- 'volid' => 'local-lvm:vm-100-disk-0',
140
- 'device' => '0',
141
- 'controller' => 'scsi',
142
- 'storage' => 'local-lvm',
143
- 'size' => '2147483648',
144
- 'cache' => 'none'
145
- }
146
- }
147
- }.with_indifferent_access
148
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
149
- expected_config_attr = { :cores => '1', :cpulimit => '1' }
150
- expected_volume_attr = 'scsi0'
151
- vm.expects(:detach, expected_volume_attr)
152
- vm.expects(:detach, 'unused0')
153
- vm.expects(:update, expected_config_attr)
154
- @cr.save_vm(uuid, new_attributes)
155
- end
156
-
157
70
  it 'saves modified server config with removed interfaces' do
158
71
  uuid = '100'
159
72
  config = mock('config')
@@ -193,176 +106,6 @@ module ForemanFogProxmox
193
106
  vm.expects(:update, expected_config_attr)
194
107
  @cr.save_vm(uuid, new_attributes)
195
108
  end
196
-
197
- it 'saves modified server config with resized volumes' do
198
- uuid = '100'
199
- config = mock('config')
200
- disks = mock('disks')
201
- disk = mock('disk')
202
- disk.stubs(:size).returns(1_073_741_824)
203
- disk.stubs(:storage).returns('local-lvm')
204
- disks.stubs(:get).returns(disk)
205
- config.stubs(:disks).returns(disks)
206
- config.stubs(:attributes).returns(:cores => '')
207
- vm = mock('vm')
208
- vm.stubs(:config).returns(config)
209
- vm.stubs(:container?).returns(false)
210
- vm.stubs(:templated?).returns(false)
211
- vm.stubs(:type).returns('qemu')
212
- @cr.stubs(:find_vm_by_uuid).returns(vm)
213
- new_attributes = {
214
- 'templated' => '0',
215
- 'config_attributes' => {
216
- 'cores' => '1',
217
- 'cpulimit' => '1'
218
- },
219
- 'volumes_attributes' => {
220
- '0' => {
221
- 'id' => 'scsi0',
222
- '_delete' => '',
223
- 'volid' => 'local-lvm:vm-100-disk-0',
224
- 'device' => '0',
225
- 'controller' => 'scsi',
226
- 'storage' => 'local-lvm',
227
- 'size' => '2147483648',
228
- 'cache' => 'none'
229
- }
230
- }
231
- }.with_indifferent_access
232
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
233
- expected_config_attr = { :cores => '1', :cpulimit => '1' }
234
- expected_volume_attr = ['scsi0', '+1G']
235
- vm.expects(:extend, expected_volume_attr)
236
- vm.expects(:update, expected_config_attr)
237
- @cr.save_vm(uuid, new_attributes)
238
- end
239
-
240
- it 'raises error unable to shrink volumes' do
241
- uuid = '100'
242
- config = mock('config')
243
- disks = mock('disks')
244
- disk = mock('disk')
245
- disk.stubs(:size).returns(1_073_741_824)
246
- disk.stubs(:storage).returns('local-lvm')
247
- disks.stubs(:get).returns(disk)
248
- config.stubs(:disks).returns(disks)
249
- config.stubs(:attributes).returns(:cores => '')
250
- vm = mock('vm')
251
- vm.stubs(:config).returns(config)
252
- vm.stubs(:container?).returns(false)
253
- vm.stubs(:type).returns('qemu')
254
- @cr.stubs(:find_vm_by_uuid).returns(vm)
255
- new_attributes = {
256
- 'templated' => '0',
257
- 'config_attributes' => {
258
- 'cores' => '1',
259
- 'cpulimit' => '1'
260
- },
261
- 'volumes_attributes' => {
262
- '0' => {
263
- 'id' => 'scsi0',
264
- '_delete' => '',
265
- 'volid' => 'local-lvm:vm-100-disk-0',
266
- 'device' => '0',
267
- 'controller' => 'scsi',
268
- 'storage' => 'local-lvm',
269
- 'size' => '2',
270
- 'cache' => 'none'
271
- }
272
- }
273
- }.with_indifferent_access
274
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
275
- err = assert_raises Foreman::Exception do
276
- @cr.save_vm(uuid, new_attributes)
277
- end
278
- assert err.message.end_with?('Unable to shrink scsi0 size. Proxmox allows only increasing size.')
279
- end
280
-
281
- it 'saves modified server config with moved volumes' do
282
- uuid = '100'
283
- config = mock('config')
284
- disks = mock('disks')
285
- disk = mock('disk')
286
- disk.stubs(:size).returns(1_073_741_824)
287
- disk.stubs(:storage).returns('local-lvm')
288
- disks.stubs(:get).returns(disk)
289
- config.stubs(:disks).returns(disks)
290
- config.stubs(:attributes).returns(:cores => '')
291
- vm = mock('vm')
292
- vm.stubs(:config).returns(config)
293
- vm.stubs(:container?).returns(false)
294
- vm.stubs(:type).returns('qemu')
295
- @cr.stubs(:find_vm_by_uuid).returns(vm)
296
- new_attributes = {
297
- 'templated' => '0',
298
- 'config_attributes' => {
299
- 'cores' => '1',
300
- 'cpulimit' => '1'
301
- },
302
- 'volumes_attributes' => {
303
- '0' => {
304
- 'id' => 'scsi0',
305
- '_delete' => '',
306
- 'volid' => 'local-lvm:vm-100-disk-0',
307
- 'device' => '0',
308
- 'controller' => 'scsi',
309
- 'storage' => 'local-lvm2',
310
- 'size' => '1073741824',
311
- 'cache' => 'none'
312
- }
313
- }
314
- }.with_indifferent_access
315
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
316
- expected_config_attr = { :cores => '1', :cpulimit => '1' }
317
- expected_volume_attr = ['scsi0', 'local-lvm2']
318
- vm.expects(:move, expected_volume_attr)
319
- vm.expects(:update, expected_config_attr)
320
- @cr.save_vm(uuid, new_attributes)
321
- end
322
-
323
- it 'saves modified server config with modified volumes options' do
324
- uuid = '100'
325
- config = mock('config')
326
- disks = mock('disks')
327
- disk = mock('disk')
328
- disk.stubs(:size).returns(1_073_741_824)
329
- disk.stubs(:storage).returns('local-lvm')
330
- disk.stubs(:volid).returns('local-lvm:vm-100-disk-0')
331
- disk.stubs(:id).returns('scsi0')
332
- disks.stubs(:get).returns(disk)
333
- config.stubs(:disks).returns(disks)
334
- config.stubs(:attributes).returns(:cores => '')
335
- vm = mock('vm')
336
- vm.stubs(:config).returns(config)
337
- vm.stubs(:container?).returns(false)
338
- vm.stubs(:type).returns('qemu')
339
- @cr.stubs(:find_vm_by_uuid).returns(vm)
340
- new_attributes = {
341
- 'templated' => '0',
342
- 'config_attributes' => {
343
- 'cores' => '1',
344
- 'cpulimit' => '1'
345
- },
346
- 'volumes_attributes' => {
347
- '0' => {
348
- 'id' => 'scsi0',
349
- '_delete' => '',
350
- 'volid' => 'local-lvm:vm-100-disk-0',
351
- 'device' => '0',
352
- 'controller' => 'scsi',
353
- 'storage' => 'local-lvm',
354
- 'size' => '1073741824',
355
- 'cache' => 'directsync'
356
- }
357
- }
358
- }.with_indifferent_access
359
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
360
- expected_config_attr = { :cores => '1', :cpulimit => '1' }
361
- expected_volume_attr = {:id => 'scsi0', :volid => 'local-lvm:vm-100-disk-0', :size => 1_073_741_824}, {:cache => 'directsync'}
362
- vm.expects(:attach, expected_volume_attr)
363
- vm.expects(:update, expected_config_attr)
364
- @cr.save_vm(uuid, new_attributes)
365
- end
366
109
  end
367
110
  end
368
111
  end
@@ -0,0 +1,296 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # ForemanFogProxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'test_plugin_helper'
21
+ require 'models/compute_resources/compute_resource_test_helpers'
22
+ require 'factories/foreman_fog_proxmox/proxmox_node_mock_factory'
23
+ require 'factories/foreman_fog_proxmox/proxmox_server_mock_factory'
24
+ require 'active_support/core_ext/hash/indifferent_access'
25
+
26
+ module ForemanFogProxmox
27
+ class ProxmoxVmCommandsServerUpdateTest < ActiveSupport::TestCase
28
+ include ComputeResourceTestHelpers
29
+ include ProxmoxNodeMockFactory
30
+ include ProxmoxServerMockFactory
31
+ include ProxmoxVmHelper
32
+
33
+ describe 'save_vm' do
34
+ before do
35
+ @cr = FactoryBot.build_stubbed(:proxmox_cr)
36
+ end
37
+
38
+ it 'saves modified server config with added volumes' do
39
+ uuid = '100'
40
+ config = mock('config')
41
+ disks = mock('disks')
42
+ disk = mock('disk')
43
+ disk.stubs(:size).returns(1_073_741_824)
44
+ disk.stubs(:storage).returns('local-lvm')
45
+ disk.stubs(:id).returns('scsi0')
46
+ disks.stubs(:get).returns
47
+ config.stubs(:disks).returns(disks)
48
+ config.stubs(:attributes).returns(:cores => '')
49
+ vm = mock('vm')
50
+ vm.stubs(:config).returns(config)
51
+ vm.stubs(:container?).returns(false)
52
+ vm.stubs(:type).returns('qemu')
53
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
54
+ new_attributes = {
55
+ 'templated' => '0',
56
+ 'config_attributes' => {
57
+ 'cores' => '1',
58
+ 'cpulimit' => '1'
59
+ },
60
+ 'volumes_attributes' => {
61
+ '0' => {
62
+ 'id' => 'scsi0',
63
+ '_delete' => '',
64
+ 'device' => '0',
65
+ 'controller' => 'scsi',
66
+ 'storage' => 'local-lvm',
67
+ 'size' => '2147483648',
68
+ 'cache' => 'none'
69
+ }
70
+ }
71
+ }.with_indifferent_access
72
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
73
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
74
+ expected_volume_attr = { id: 'scsi0', storage: 'local:lvm', size: (2_147_483_648 / GIGA).to_s }
75
+ vm.expects(:attach, expected_volume_attr)
76
+ vm.expects(:update, expected_config_attr)
77
+ @cr.save_vm(uuid, new_attributes)
78
+ end
79
+
80
+ it 'saves modified server config with removed volumes' do
81
+ uuid = '100'
82
+ config = mock('config')
83
+ disks = mock('disks')
84
+ disk = mock('disk')
85
+ disk.stubs(:size).returns(1_073_741_824)
86
+ disk.stubs(:storage).returns('local-lvm')
87
+ disk.stubs(:id).returns('virtio0')
88
+ disks.stubs(:get).returns(disk)
89
+ config.stubs(:disks).returns(disks)
90
+ config.stubs(:attributes).returns(:cores => '')
91
+ vm = mock('vm')
92
+ vm.stubs(:config).returns(config)
93
+ vm.stubs(:container?).returns(false)
94
+ vm.stubs(:templated?).returns(false)
95
+ vm.stubs(:type).returns('qemu')
96
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
97
+ new_attributes = {
98
+ 'templated' => '0',
99
+ 'config_attributes' => {
100
+ 'cores' => '1',
101
+ 'cpulimit' => '1'
102
+ },
103
+ 'volumes_attributes' => {
104
+ '0' => {
105
+ '_delete' => '1',
106
+ 'id' => 'scsi0',
107
+ 'volid' => 'local-lvm:vm-100-disk-0',
108
+ 'device' => '0',
109
+ 'controller' => 'scsi',
110
+ 'storage' => 'local-lvm',
111
+ 'size' => '2147483648',
112
+ 'cache' => 'none'
113
+ }
114
+ }
115
+ }.with_indifferent_access
116
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
117
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
118
+ expected_volume_attr = 'scsi0'
119
+ vm.expects(:detach, expected_volume_attr)
120
+ vm.expects(:detach, 'unused0')
121
+ vm.expects(:update, expected_config_attr)
122
+ @cr.save_vm(uuid, new_attributes)
123
+ end
124
+
125
+ it 'saves modified server config with resized volumes' do
126
+ uuid = '100'
127
+ config = mock('config')
128
+ disks = mock('disks')
129
+ disk = mock('disk')
130
+ disk.stubs(:size).returns(1_073_741_824)
131
+ disk.stubs(:storage).returns('local-lvm')
132
+ disks.stubs(:get).returns(disk)
133
+ config.stubs(:disks).returns(disks)
134
+ config.stubs(:attributes).returns(:cores => '')
135
+ vm = mock('vm')
136
+ vm.stubs(:config).returns(config)
137
+ vm.stubs(:container?).returns(false)
138
+ vm.stubs(:templated?).returns(false)
139
+ vm.stubs(:type).returns('qemu')
140
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
141
+ new_attributes = {
142
+ 'templated' => '0',
143
+ 'config_attributes' => {
144
+ 'cores' => '1',
145
+ 'cpulimit' => '1'
146
+ },
147
+ 'volumes_attributes' => {
148
+ '0' => {
149
+ 'id' => 'scsi0',
150
+ '_delete' => '',
151
+ 'volid' => 'local-lvm:vm-100-disk-0',
152
+ 'device' => '0',
153
+ 'controller' => 'scsi',
154
+ 'storage' => 'local-lvm',
155
+ 'size' => '2147483648',
156
+ 'cache' => 'none'
157
+ }
158
+ }
159
+ }.with_indifferent_access
160
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
161
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
162
+ expected_volume_attr = ['scsi0', '+1G']
163
+ vm.expects(:extend, expected_volume_attr)
164
+ vm.expects(:update, expected_config_attr)
165
+ @cr.save_vm(uuid, new_attributes)
166
+ end
167
+
168
+ it 'raises error unable to shrink volumes' do
169
+ uuid = '100'
170
+ config = mock('config')
171
+ disks = mock('disks')
172
+ disk = mock('disk')
173
+ disk.stubs(:size).returns(1_073_741_824)
174
+ disk.stubs(:storage).returns('local-lvm')
175
+ disks.stubs(:get).returns(disk)
176
+ config.stubs(:disks).returns(disks)
177
+ config.stubs(:attributes).returns(:cores => '')
178
+ vm = mock('vm')
179
+ vm.stubs(:config).returns(config)
180
+ vm.stubs(:container?).returns(false)
181
+ vm.stubs(:type).returns('qemu')
182
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
183
+ new_attributes = {
184
+ 'templated' => '0',
185
+ 'config_attributes' => {
186
+ 'cores' => '1',
187
+ 'cpulimit' => '1'
188
+ },
189
+ 'volumes_attributes' => {
190
+ '0' => {
191
+ 'id' => 'scsi0',
192
+ '_delete' => '',
193
+ 'volid' => 'local-lvm:vm-100-disk-0',
194
+ 'device' => '0',
195
+ 'controller' => 'scsi',
196
+ 'storage' => 'local-lvm',
197
+ 'size' => '2',
198
+ 'cache' => 'none'
199
+ }
200
+ }
201
+ }.with_indifferent_access
202
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
203
+ err = assert_raises Foreman::Exception do
204
+ @cr.save_vm(uuid, new_attributes)
205
+ end
206
+ assert err.message.end_with?('Unable to shrink scsi0 size. Proxmox allows only increasing size.')
207
+ end
208
+
209
+ it 'saves modified server config with moved volumes' do
210
+ uuid = '100'
211
+ config = mock('config')
212
+ disks = mock('disks')
213
+ disk = mock('disk')
214
+ disk.stubs(:size).returns(1_073_741_824)
215
+ disk.stubs(:storage).returns('local-lvm')
216
+ disks.stubs(:get).returns(disk)
217
+ config.stubs(:disks).returns(disks)
218
+ config.stubs(:attributes).returns(:cores => '')
219
+ vm = mock('vm')
220
+ vm.stubs(:config).returns(config)
221
+ vm.stubs(:container?).returns(false)
222
+ vm.stubs(:type).returns('qemu')
223
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
224
+ new_attributes = {
225
+ 'templated' => '0',
226
+ 'config_attributes' => {
227
+ 'cores' => '1',
228
+ 'cpulimit' => '1'
229
+ },
230
+ 'volumes_attributes' => {
231
+ '0' => {
232
+ 'id' => 'scsi0',
233
+ '_delete' => '',
234
+ 'volid' => 'local-lvm:vm-100-disk-0',
235
+ 'device' => '0',
236
+ 'controller' => 'scsi',
237
+ 'storage' => 'local-lvm2',
238
+ 'size' => '1073741824',
239
+ 'cache' => 'none'
240
+ }
241
+ }
242
+ }.with_indifferent_access
243
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
244
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
245
+ expected_volume_attr = ['scsi0', 'local-lvm2']
246
+ vm.expects(:move, expected_volume_attr)
247
+ vm.expects(:update, expected_config_attr)
248
+ @cr.save_vm(uuid, new_attributes)
249
+ end
250
+
251
+ it 'saves modified server config with modified volumes options' do
252
+ uuid = '100'
253
+ config = mock('config')
254
+ disks = mock('disks')
255
+ disk = mock('disk')
256
+ disk.stubs(:size).returns(1_073_741_824)
257
+ disk.stubs(:storage).returns('local-lvm')
258
+ disk.stubs(:volid).returns('local-lvm:vm-100-disk-0')
259
+ disk.stubs(:id).returns('scsi0')
260
+ disks.stubs(:get).returns(disk)
261
+ config.stubs(:disks).returns(disks)
262
+ config.stubs(:attributes).returns(:cores => '')
263
+ vm = mock('vm')
264
+ vm.stubs(:config).returns(config)
265
+ vm.stubs(:container?).returns(false)
266
+ vm.stubs(:type).returns('qemu')
267
+ @cr.stubs(:find_vm_by_uuid).returns(vm)
268
+ new_attributes = {
269
+ 'templated' => '0',
270
+ 'config_attributes' => {
271
+ 'cores' => '1',
272
+ 'cpulimit' => '1'
273
+ },
274
+ 'volumes_attributes' => {
275
+ '0' => {
276
+ 'id' => 'scsi0',
277
+ '_delete' => '',
278
+ 'volid' => 'local-lvm:vm-100-disk-0',
279
+ 'device' => '0',
280
+ 'controller' => 'scsi',
281
+ 'storage' => 'local-lvm',
282
+ 'size' => '1073741824',
283
+ 'cache' => 'directsync'
284
+ }
285
+ }
286
+ }.with_indifferent_access
287
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
288
+ expected_config_attr = { :cores => '1', :cpulimit => '1' }
289
+ expected_volume_attr = { :id => 'scsi0', :volid => 'local-lvm:vm-100-disk-0', :size => 1_073_741_824 }, { :cache => 'directsync' }
290
+ vm.expects(:attach, expected_volume_attr)
291
+ vm.expects(:update, expected_config_attr)
292
+ @cr.save_vm(uuid, new_attributes)
293
+ end
294
+ end
295
+ end
296
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_fog_proxmox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Robert
@@ -29,14 +29,14 @@ dependencies:
29
29
  name: fog-proxmox
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0.8'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0.8'
42
42
  - !ruby/object:Gem::Dependency
@@ -192,6 +192,7 @@ files:
192
192
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
193
193
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb
194
194
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb
195
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb
195
196
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb
196
197
  - test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb
197
198
  - test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb
@@ -224,6 +225,7 @@ test_files:
224
225
  - test/functional/compute_resources_controller_test.rb
225
226
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb
226
227
  - test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb
228
+ - test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb
227
229
  - test/unit/foreman_fog_proxmox/proxmox_version_test.rb
228
230
  - test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb
229
231
  - test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb