vm_shepherd 1.11.3 → 1.11.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ea022dca3043409c217daf3acaffbcc0ee73205
4
- data.tar.gz: 33265e1f41141d6bcf281f58d887369fb880484a
3
+ metadata.gz: 82f7c7627b1e94f6470ded478ab7ea83b2c29416
4
+ data.tar.gz: 6724ee44b46ca3e1a5ca046425cbda5070ccfd4d
5
5
  SHA512:
6
- metadata.gz: 074f1d4cdc3b3d965e2d8a0c4e5dd25a5d0c747a19787c044af44aa64517fab81166b03b7d8f7217801f55b369c4565e22ae03ac12956501f6334680d1c65737
7
- data.tar.gz: c15a7975823d8532fd886488b04bcefed4129ef1b67b92cb8a665fa89447bc2c09a41836dea396e165db633fd513899e33f4a38246b1b928570369d884bc2c61
6
+ metadata.gz: df11263d19bdeb301a263a1892a749c243ab55ed333a968d9d309fb5fce2c942219705fc9afe3c6ae1742a4344d5fe012c9d0bc8ae5fb9ee3db39eb387576bd0
7
+ data.tar.gz: 845334333f9acd9fc64051142e169a060b7934600ea7f3c02716333495fda93adb2b312e7dea5c945db84fdbf1fd4eef110517a4f943ef5833e203ec5070203c
@@ -2,12 +2,12 @@ module VmShepherd
2
2
  module Vcloud
3
3
  class Destroyer
4
4
  def initialize(client:, vdc_name:)
5
- @client = client
5
+ @client = client
6
6
  @vdc_name = vdc_name
7
7
  end
8
8
 
9
- def delete_catalog_and_vms(catalog, vapp_names, logger)
10
- delete_vms_in_vapps(vapp_names, logger)
9
+ def clean_catalog_and_vapps(catalog:, vapp_names:, logger:, delete_vapps:)
10
+ clean_vapps(vapp_names, logger, delete_vapps)
11
11
  delete_catalog(catalog)
12
12
  end
13
13
 
@@ -17,21 +17,18 @@ module VmShepherd
17
17
  @vdc ||= @client.find_vdc_by_name(@vdc_name)
18
18
  end
19
19
 
20
- def delete_vms_in_vapps(vapp_names, logger)
20
+ def clean_vapps(vapp_names, logger, delete_vapps)
21
21
  vapp_names.each do |vapp_name|
22
22
  begin
23
- delete_vms_in_vapp(vapp_name)
23
+ clean_vapp(vapp_name)
24
+ delete_vapp(vapp_name) if delete_vapps
24
25
  rescue VCloudSdk::ObjectNotFoundError => e
25
26
  logger.debug "Could not delete vapp '#{vapp_name}': #{e.inspect}"
26
27
  end
27
28
  end
28
29
  end
29
30
 
30
- def delete_catalog(catalog)
31
- @client.delete_catalog_by_name(catalog) if @client.catalog_exists?(catalog)
32
- end
33
-
34
- def delete_vms_in_vapp(vapp_name)
31
+ def clean_vapp(vapp_name)
35
32
  vapp = vdc.find_vapp_by_name(vapp_name)
36
33
  vapp.vms.map do |vm|
37
34
  vm.independent_disks.map do |disk|
@@ -40,6 +37,16 @@ module VmShepherd
40
37
  end
41
38
  end
42
39
  end
40
+
41
+ def delete_vapp(vapp_name)
42
+ vapp = vdc.find_vapp_by_name(vapp_name)
43
+ vapp.power_off
44
+ vapp.delete
45
+ end
46
+
47
+ def delete_catalog(catalog)
48
+ @client.delete_catalog_by_name(catalog) if @client.catalog_exists?(catalog)
49
+ end
43
50
  end
44
51
  end
45
52
  end
@@ -35,11 +35,12 @@ module VmShepherd
35
35
 
36
36
  def destroy(vapp_names, catalog)
37
37
  VmShepherd::Vcloud::Destroyer.new(client: client, vdc_name: @vdc_name).
38
- delete_catalog_and_vms(catalog, vapp_names, @logger)
38
+ clean_catalog_and_vapps(catalog: catalog, vapp_names: vapp_names, logger: @logger, delete_vapps: true)
39
39
  end
40
40
 
41
41
  def clean_environment(vapp_names, catalog)
42
- destroy(vapp_names, catalog)
42
+ VmShepherd::Vcloud::Destroyer.new(client: client, vdc_name: @vdc_name).
43
+ clean_catalog_and_vapps(catalog: catalog, vapp_names: vapp_names, logger: @logger, delete_vapps: false)
43
44
  end
44
45
 
45
46
  private
@@ -1,3 +1,3 @@
1
1
  module VmShepherd
2
- VERSION = '1.11.3'.freeze
2
+ VERSION = '1.11.4'.freeze
3
3
  end
@@ -28,14 +28,14 @@ module VmShepherd
28
28
  allow(vm).to receive(:detach_disk)
29
29
  end
30
30
 
31
- describe '#delete_catalog_and_vms' do
31
+ describe '#clean_catalog_and_vapps' do
32
32
  context 'when the catalog exists' do
33
33
  before do
34
34
  allow(client).to receive(:catalog_exists?).with('CATALOG_NAME').and_return(true)
35
35
  end
36
36
 
37
37
  it 'deletes the catalog' do
38
- destroyer.delete_catalog_and_vms('CATALOG_NAME', [], fake_logger)
38
+ destroyer.clean_catalog_and_vapps(catalog: 'CATALOG_NAME', vapp_names: [], logger: fake_logger, delete_vapps: false)
39
39
 
40
40
  expect(client).to have_received(:delete_catalog_by_name).with('CATALOG_NAME')
41
41
  end
@@ -47,18 +47,36 @@ module VmShepherd
47
47
  end
48
48
 
49
49
  it 'skips deleting the catalog' do
50
- destroyer.delete_catalog_and_vms('CATALOG_NAME', [], fake_logger)
50
+ destroyer.clean_catalog_and_vapps(catalog: 'CATALOG_NAME', vapp_names: [], logger: fake_logger, delete_vapps: false)
51
51
 
52
52
  expect(client).not_to have_received(:delete_catalog_by_name).with('CATALOG_NAME')
53
53
  end
54
54
  end
55
55
 
56
56
  it 'detaches and deletes persistent disks' do
57
- destroyer.delete_catalog_and_vms('CATALOG_NAME', ['VAPP_NAME'], fake_logger)
57
+ destroyer.clean_catalog_and_vapps(catalog: 'CATALOG_NAME', vapp_names: ['VAPP_NAME'], logger: fake_logger, delete_vapps: false)
58
58
 
59
59
  expect(vm).to have_received(:detach_disk).with(disk)
60
60
  expect(vdc).to have_received(:delete_disk_by_name).with('DISK_NAME')
61
61
  end
62
+
63
+ context 'when the delete_vapps flag is true' do
64
+ it 'deletes the vapps' do
65
+ destroyer.clean_catalog_and_vapps(catalog: 'CATALOG_NAME', vapp_names: ['VAPP_NAME'], logger: fake_logger, delete_vapps: true)
66
+
67
+ expect(vapp).to have_received(:power_off).ordered
68
+ expect(vapp).to have_received(:delete).ordered
69
+ end
70
+ end
71
+
72
+ context 'when the delete_vapps flag is false' do
73
+ it 'does not delete the vapps' do
74
+ destroyer.clean_catalog_and_vapps(catalog: 'CATALOG_NAME', vapp_names: ['VAPP_NAME'], logger: fake_logger, delete_vapps: false)
75
+
76
+ expect(vapp).not_to have_received(:power_off)
77
+ expect(vapp).not_to have_received(:delete)
78
+ end
79
+ end
62
80
  end
63
81
  end
64
82
  end
@@ -264,101 +264,37 @@ module VmShepherd
264
264
 
265
265
  describe '#destroy' do
266
266
  let(:client) { instance_double(VCloudSdk::Client) }
267
- let(:vdc) { instance_double(VCloudSdk::VDC) }
268
- let(:vapp) { instance_double(VCloudSdk::VApp) }
269
267
  let(:vapp_name) { 'FAKE_VAPP_NAME' }
270
268
  let(:vapp_catalog) { 'FAKE_VAPP_CATALOG' }
271
- let(:vm) { instance_double(VCloudSdk::VM) }
272
- let(:disk) { instance_double(VCloudSdk::InternalDisk, name: 'disk name') }
273
269
 
274
270
  before do
275
- allow(vapp).to receive(:vms).and_return([vm])
276
- allow(vm).to receive(:independent_disks).and_return([disk])
271
+ allow(VCloudSdk::Client).to receive(:new).and_return(client)
277
272
  end
278
273
 
279
- context 'when the catalog exists' do
280
- before do
281
- allow(client).to receive(:catalog_exists?).with(vapp_catalog).and_return(true)
282
- end
283
-
284
- it 'uses VCloudSdk::Client to delete the vApp' do
285
- expect(client).to receive(:find_vdc_by_name).with(vdc_name).and_return(vdc)
286
- expect(vdc).to receive(:find_vapp_by_name).with(vapp_name).and_return(vapp)
287
- expect(vm).to receive(:detach_disk).with(disk)
288
- expect(vdc).to receive(:delete_disk_by_name).with('disk name')
289
- expect(client).to receive(:delete_catalog_by_name).with(vapp_catalog)
290
-
291
- expect(VCloudSdk::Client).to receive(:new).with(
292
- login_info.fetch(:url),
293
- [login_info.fetch(:user), login_info.fetch(:organization)].join('@'),
294
- login_info.fetch(:password),
295
- {},
296
- logger,
297
- ).and_return(client)
298
-
299
- vcloud_manager.destroy([vapp_name], vapp_catalog)
300
- end
301
-
302
- context 'when an VCloudSdk::ObjectNotFoundError is thrown' do
303
- before do
304
- allow(VCloudSdk::Client).to receive(:new).and_return(client)
305
- allow(client).to receive(:find_vdc_by_name).and_return(vdc)
306
- allow(vdc).to receive(:find_vapp_by_name).and_return(vapp)
307
- allow(vm).to receive(:detach_disk)
308
- allow(vdc).to receive(:delete_disk_by_name)
309
- allow(vapp).to receive(:power_off)
310
- allow(vapp).to receive(:delete)
311
-
312
- allow(client).to receive(:delete_catalog_by_name)
313
- end
314
-
315
- it 'catches the error' do
316
- allow(vdc).to receive(:find_vapp_by_name).and_raise(VCloudSdk::ObjectNotFoundError)
317
-
318
- expect { vcloud_manager.destroy([vapp_name], vapp_catalog) }.not_to raise_error
319
- end
320
-
321
- it 'deletes to catalog' do
322
- expect(client).to receive(:delete_catalog_by_name).with(vapp_catalog)
274
+ it 'destroys everything including vapps' do
275
+ destroyer = instance_double(VmShepherd::Vcloud::Destroyer)
276
+ expect(VmShepherd::Vcloud::Destroyer).to receive(:new).with(client: client, vdc_name: vdc_name).and_return(destroyer)
277
+ expect(destroyer).to receive(:clean_catalog_and_vapps).with(catalog: vapp_catalog, vapp_names: [vapp_name], logger: logger, delete_vapps: true)
323
278
 
324
- vcloud_manager.destroy([vapp_name], vapp_catalog)
325
- end
326
- end
327
- end
328
-
329
- context 'when the catalog does not exist' do
330
- before do
331
- allow(client).to receive(:catalog_exists?).with(vapp_catalog).and_return(false)
332
- end
333
-
334
- it 'uses VCloudSdk::Client to delete the vApp' do
335
- expect(client).to receive(:find_vdc_by_name).with(vdc_name).and_return(vdc)
336
- expect(vdc).to receive(:find_vapp_by_name).with(vapp_name).and_return(vapp)
337
- expect(vm).to receive(:detach_disk).with(disk)
338
- expect(vdc).to receive(:delete_disk_by_name).with('disk name')
339
- expect(client).not_to receive(:delete_catalog_by_name).with(vapp_catalog)
340
-
341
- expect(VCloudSdk::Client).to receive(:new).with(
342
- login_info.fetch(:url),
343
- [login_info.fetch(:user), login_info.fetch(:organization)].join('@'),
344
- login_info.fetch(:password),
345
- {},
346
- logger,
347
- ).and_return(client)
348
-
349
- vcloud_manager.destroy([vapp_name], vapp_catalog)
350
- end
279
+ vcloud_manager.destroy([vapp_name], vapp_catalog)
351
280
  end
352
281
  end
353
282
 
354
283
  describe '#clean_environment' do
355
- let(:vapp_names) { ['VAPP_ONE', 'VAPP_TWO'] }
284
+ let(:client) { instance_double(VCloudSdk::Client) }
285
+ let(:vapp_name) { ['VAPP_ONE', 'VAPP_TWO'] }
356
286
  let(:vapp_catalog) { 'VAPP_CATALOG' }
357
287
 
358
- it 'calls #destroy' do
359
- expect(vcloud_manager).to receive(:destroy).with(vapp_names, vapp_catalog)
288
+ before do
289
+ allow(VCloudSdk::Client).to receive(:new).and_return(client)
290
+ end
291
+
292
+ it 'destroys the environment expect for vapps' do
293
+ destroyer = instance_double(VmShepherd::Vcloud::Destroyer)
294
+ expect(VmShepherd::Vcloud::Destroyer).to receive(:new).with(client: client, vdc_name: vdc_name).and_return(destroyer)
295
+ expect(destroyer).to receive(:clean_catalog_and_vapps).with(catalog: vapp_catalog, vapp_names: [vapp_name], logger: logger, delete_vapps: false)
360
296
 
361
- vcloud_manager.clean_environment(vapp_names, vapp_catalog)
297
+ vcloud_manager.clean_environment([vapp_name], vapp_catalog)
362
298
  end
363
299
  end
364
300
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vm_shepherd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.3
4
+ version: 1.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ops Manager Team