fog-vsphere 3.6.5 → 3.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fog/vsphere/compute.rb +12 -0
  3. data/lib/fog/vsphere/models/compute/nvmecontroller.rb +24 -0
  4. data/lib/fog/vsphere/models/compute/scsicontroller.rb +5 -1
  5. data/lib/fog/vsphere/models/compute/server.rb +33 -18
  6. data/lib/fog/vsphere/models/compute/volume.rb +1 -2
  7. data/lib/fog/vsphere/requests/compute/create_vm.rb +11 -4
  8. data/lib/fog/vsphere/requests/compute/get_vm_first_nvme_controller.rb +21 -0
  9. data/lib/fog/vsphere/requests/compute/list_vm_nvme_controllers.rb +29 -0
  10. data/lib/fog/vsphere/requests/compute/vm_clone.rb +1 -1
  11. data/lib/fog/vsphere/version.rb +1 -1
  12. data/tests/class_from_string_tests.rb +33 -0
  13. data/tests/compute_tests.rb +53 -0
  14. data/tests/fixtures/vcr_cassettes/6_7/create_folder.yml +609 -0
  15. data/tests/fixtures/vcr_cassettes/6_7/folder_destroy.yml +823 -0
  16. data/tests/fixtures/vcr_cassettes/6_7/get_cluster.yml +663 -0
  17. data/tests/fixtures/vcr_cassettes/6_7/get_compute_resource.yml +1046 -0
  18. data/tests/fixtures/vcr_cassettes/6_7/get_datacenter.yml +498 -0
  19. data/tests/fixtures/vcr_cassettes/6_7/get_folder.yml +2038 -0
  20. data/tests/fixtures/vcr_cassettes/6_7/get_host.yml +386 -0
  21. data/tests/fixtures/vcr_cassettes/6_7/get_network.yml +932 -0
  22. data/tests/fixtures/vcr_cassettes/6_7/get_storage_pod.yml +225 -0
  23. data/tests/fixtures/vcr_cassettes/6_7/get_template.yml +329 -0
  24. data/tests/fixtures/vcr_cassettes/6_7/get_virtual_machine.yml +329 -0
  25. data/tests/fixtures/vcr_cassettes/6_7/get_vm_first_nvme_controller.yml +105 -0
  26. data/tests/fixtures/vcr_cassettes/6_7/get_vm_first_sata_controller.yml +209 -0
  27. data/tests/fixtures/vcr_cassettes/6_7/get_vm_first_scsi_controller.yml +111 -0
  28. data/tests/fixtures/vcr_cassettes/6_7/shared.yml +164 -0
  29. data/tests/helper.rb +6 -0
  30. data/tests/helpers/mock_helper.rb +9 -0
  31. data/tests/models/compute/cluster_tests.rb +18 -0
  32. data/tests/models/compute/hosts_tests.rb +11 -0
  33. data/tests/models/compute/rules_tests.rb +28 -0
  34. data/tests/models/compute/server_tests.rb +74 -0
  35. data/tests/models/compute/server_unit_tests.rb +13 -0
  36. data/tests/models/compute/servers_tests.rb +14 -0
  37. data/tests/models/compute/ticket_tests.rb +12 -0
  38. data/tests/models/compute/tickets_tests.rb +8 -0
  39. data/tests/requests/compute/create_folder_tests.rb +19 -0
  40. data/tests/requests/compute/current_time_tests.rb +10 -0
  41. data/tests/requests/compute/folder_destroy_tests.rb +39 -0
  42. data/tests/requests/compute/get_cluster_tests.rb +19 -0
  43. data/tests/requests/compute/get_compute_resource_tests.rb +19 -0
  44. data/tests/requests/compute/get_datacenter_tests.rb +19 -0
  45. data/tests/requests/compute/get_folder_tests.rb +28 -0
  46. data/tests/requests/compute/get_host_tests.rb +19 -0
  47. data/tests/requests/compute/get_network_tests.rb +78 -0
  48. data/tests/requests/compute/get_storage_pod_tests.rb +19 -0
  49. data/tests/requests/compute/get_template_tests.rb +19 -0
  50. data/tests/requests/compute/get_virtual_machine_tests.rb +19 -0
  51. data/tests/requests/compute/get_vm_first_nvme_controller_tests.rb +19 -0
  52. data/tests/requests/compute/get_vm_first_sata_controller_tests.rb +19 -0
  53. data/tests/requests/compute/get_vm_first_scsi_controller_tests.rb +19 -0
  54. data/tests/requests/compute/list_child_snapshots_tests.rb +9 -0
  55. data/tests/requests/compute/list_clusters_tests.rb +10 -0
  56. data/tests/requests/compute/list_datastores_tests.rb +17 -0
  57. data/tests/requests/compute/list_hosts_tests.rb +10 -0
  58. data/tests/requests/compute/list_networks_tests.rb +17 -0
  59. data/tests/requests/compute/list_storage_pods_test.rb +9 -0
  60. data/tests/requests/compute/list_virtual_machines_tests.rb +34 -0
  61. data/tests/requests/compute/list_vm_cdroms_tests.rb +9 -0
  62. data/tests/requests/compute/list_vm_snapshots_tests.rb +9 -0
  63. data/tests/requests/compute/modify_vm_cdrom_tests.rb +20 -0
  64. data/tests/requests/compute/revert_to_snapshot_tests.rb +13 -0
  65. data/tests/requests/compute/set_vm_customvalue_tests.rb +18 -0
  66. data/tests/requests/compute/update_vm_tests.rb +13 -0
  67. data/tests/requests/compute/vm_clone_tests.rb +55 -0
  68. data/tests/requests/compute/vm_config_vnc_tests.rb +18 -0
  69. data/tests/requests/compute/vm_destroy_tests.rb +14 -0
  70. data/tests/requests/compute/vm_migrate_tests.rb +15 -0
  71. data/tests/requests/compute/vm_power_off_tests.rb +24 -0
  72. data/tests/requests/compute/vm_power_on_tests.rb +15 -0
  73. data/tests/requests/compute/vm_reboot_tests.rb +24 -0
  74. data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +14 -0
  75. data/tests/requests/compute/vm_reconfig_cpus_tests.rb +17 -0
  76. data/tests/requests/compute/vm_reconfig_hardware_tests.rb +17 -0
  77. data/tests/requests/compute/vm_reconfig_memory_tests.rb +17 -0
  78. data/tests/requests/compute/vm_suspend_tests.rb +23 -0
  79. data/tests/requests/compute/vm_take_snapshot_tests.rb +17 -0
  80. data/tests/test_helper.rb +74 -0
  81. metadata +152 -19
  82. data/.github/workflows/ruby.yml +0 -42
  83. data/.gitignore +0 -25
  84. data/.rubocop.yml +0 -44
  85. data/.rubocop_todo.yml +0 -614
  86. data/CONTRIBUTING.md +0 -55
  87. data/Gemfile +0 -5
  88. data/Jenkinsfile +0 -10
  89. data/fog-vsphere.gemspec +0 -39
@@ -0,0 +1,34 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | list_virtual_machines request', ['vsphere']) do
2
+ tests('When listing all machines') do
3
+ response = Fog::Compute[:vsphere].list_virtual_machines
4
+
5
+ tests('The response data format ...') do
6
+ test('be a kind of Hash') { response.is_a? Array }
7
+ end
8
+ end
9
+
10
+ tests('When providing an instance_uuid') do
11
+ # pending unless Fog.mock?
12
+
13
+ tests('that does exist') do
14
+ uuid = '5029c440-85ee-c2a1-e9dd-b63e39364603'
15
+ response = Fog::Compute[:vsphere].list_virtual_machines('instance_uuid' => uuid)
16
+
17
+ tests('The response should') do
18
+ test('contain one vm') { response.length == 1 }
19
+ test('contain that is an attribute hash') { response[0].is_a? Hash }
20
+ test('find jefftest') { response.first['name'] == 'jefftest' }
21
+ end
22
+ end
23
+
24
+ tests('that does not exist or is a template') do
25
+ %w[does-not-exist-and-is-not-a-uuid 50323f93-6835-1178-8b8f-9e2109890e1a].each do |uuid|
26
+ response = Fog::Compute[:vsphere].list_virtual_machines('instance_uuid' => uuid)
27
+
28
+ tests('The response should') do
29
+ test('be empty') { response.empty? }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | list_vm_cdroms request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ tests('The response should') do
5
+ response = compute.list_vm_cdroms('5032c8a5-9c5e-ba7a-3804-832a03e16381')
6
+ test('be a kind of Array') { response.is_a? Array }
7
+ test('it should contains Hashes') { response.all? { |i| Hash === i } }
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | list_vm_snapshots request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ tests('The response should') do
5
+ response = compute.list_vm_snapshots('5032c8a5-9c5e-ba7a-3804-832a03e16381')
6
+ test('be a kind of Array') { response.is_a? Array }
7
+ test('it should contains Hashes') { response.all? { |i| Hash === i } }
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | modify_vm_cdrom request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ modify_target = '5032c8a5-9c5e-ba7a-3804-832a03e16381'
5
+ modify_cdrom = compute.cdroms.new(
6
+ instance_uuid: modify_target
7
+ )
8
+
9
+ tests('When adding a cdrom the response should') do
10
+ response = compute.add_vm_cdrom(modify_cdrom)
11
+ test('be a kind of Hash') { response.is_a? Hash }
12
+ test('should have a task_state key') { response.key? 'task_state' }
13
+ end
14
+
15
+ tests('When destroying a cdrom the response should') do
16
+ response = compute.destroy_vm_cdrom(modify_cdrom)
17
+ test('be a kind of Hash') { response.is_a? Hash }
18
+ test('should have a task_state key') { response.key? 'task_state' }
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | revert_to_snapshot request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ tests('The response should') do
5
+ response = compute.revert_to_snapshot(Fog::Vsphere::Compute::Snapshot.new(service: 1))
6
+ test('be a kind of Hash') { response.is_a? Hash }
7
+ test('should have a task_state key') { response.key? 'state' }
8
+ end
9
+
10
+ tests('The expected options') do
11
+ raises(ArgumentError, 'raises ArgumentError when input param is missing') { compute.revert_to_snapshot(nil) }
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | set_vm_customvalue request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ instance_uuid = '50137835-88a1-436e-768e-9b2677076e67'
5
+ custom_key = nil
6
+ custom_value = nil
7
+
8
+ tests('The response should') do
9
+ response = compute.set_vm_customvalue(instance_uuid, custom_key, custom_value)
10
+ test('be nil') { response.nil? }
11
+ end
12
+
13
+ tests('The expected options') do
14
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.set_vm_customvalue }
15
+ raises(ArgumentError, 'raises ArgumentError when custom_key option is missing') { compute.set_vm_customvalue(instance_uuid) }
16
+ raises(ArgumentError, 'raises ArgumentError when custom_value option is missing') { compute.set_vm_customvalue(instance_uuid, custom_key) }
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require 'ostruct'
2
+
3
+ Shindo.tests('Fog::Compute[:vsphere] | update_vm request', 'vsphere') do
4
+ compute = Fog::Compute[:vsphere]
5
+ server = Fog::Vsphere::Compute::Server.new
6
+
7
+ tests('UPDATE vm | The return value should') do
8
+ response = compute.update_vm(server)
9
+ test('be a kind of Hash') { response.is_a? Hash }
10
+ test('should have a task_state key') { response.key? 'task_state' }
11
+ test('be a kind of Hash') { response.is_a? Hash }
12
+ end
13
+ end
@@ -0,0 +1,55 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_clone request', ['vsphere']) do
2
+ # require 'guid'
3
+ compute = Fog::Compute[:vsphere]
4
+ response = nil
5
+ response_linked = nil
6
+
7
+ template = 'rhel64'
8
+ datacenter = 'Solutions'
9
+ default_params = {
10
+ 'datacenter' => datacenter,
11
+ 'template_path' => template,
12
+ 'resource_pool' => ['Solutionscluster', 'Resources']
13
+ }
14
+
15
+ tests('Standard Clone | The return value should') do
16
+ servers_size = compute.servers.size
17
+ response = compute.vm_clone(default_params.merge('name' => 'cloning_vm', 'wait' => true))
18
+ test('be a kind of Hash') { response.is_a? Hash }
19
+ %w[vm_ref new_vm task_ref].each do |key|
20
+ test("have a #{key} key") { response.key? key }
21
+ end
22
+ test('creates a new server') { compute.servers.size == servers_size + 1 }
23
+ test('new server name is set') { compute.get_virtual_machine(response['new_vm']['id'])['name'] == 'cloning_vm' }
24
+ end
25
+
26
+ tests('Standard Clone setting ram and cpu | The return value should') do
27
+ servers_size = compute.servers.size
28
+ response = compute.vm_clone(default_params.merge('name' => 'cloning_vm', 'memoryMB' => '8192', 'numCPUs' => '8', 'wait' => true))
29
+ test('be a kind of Hash') { response.is_a? Hash }
30
+ %w[vm_ref new_vm task_ref].each do |key|
31
+ test("have a #{key} key") { response.key? key }
32
+ end
33
+ test('creates a new server') { compute.servers.size == servers_size + 1 }
34
+ test('new server name is set') { compute.get_virtual_machine(response['new_vm']['id'])['name'] == 'cloning_vm' }
35
+ end
36
+
37
+ tests('Linked Clone | The return value should') do
38
+ servers_size = compute.servers.size
39
+ response = compute.vm_clone(default_params.merge('name' => 'cloning_vm_linked', 'wait' => 1, 'linked_clone' => true))
40
+ test('be a kind of Hash') { response.is_a? Hash }
41
+ %w[vm_ref new_vm task_ref].each do |key|
42
+ test("have a #{key} key") { response.key? key }
43
+ end
44
+ test('creates a new server') { compute.servers.size == servers_size + 1 }
45
+ test('new server name is set') { compute.get_virtual_machine(response['new_vm']['id'])['name'] == 'cloning_vm_linked' }
46
+ end
47
+
48
+ tests('When invalid input is presented') do
49
+ raises(ArgumentError, 'it should raise ArgumentError') { compute.vm_clone(foo: 1) }
50
+ raises(Fog::Vsphere::Compute::NotFound, 'it should raise Fog::Vsphere::Compute::NotFound when the UUID is not a string') do
51
+ pending # require 'guid'
52
+ compute.vm_clone('instance_uuid' => Guid.from_s(template), 'name' => 'jefftestfoo')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,18 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_config_vnc request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ reconfig_target = '50137835-88a1-436e-768e-9b2677076e67'
5
+ vnc_spec = { port: '5900', password: 'ssaaa', enabled: 'true' }
6
+
7
+ tests('The response should') do
8
+ response = compute.vm_config_vnc('instance_uuid' => reconfig_target).merge(vnc_spec)
9
+ test('be a kind of Hash') { response.is_a? Hash }
10
+ test('should have a task_state key') { response.key? 'task_state' }
11
+ end
12
+
13
+ tests('VNC attrs response should') do
14
+ response = compute.vm_get_vnc(reconfig_target)
15
+ test('be a kind of Hash') { response.is_a? Hash }
16
+ test('should have a port key') { response.key? :port }
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_destroy request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ booted_vm = '5032c8a5-9c5e-ba7a-3804-832a03e16381'
5
+
6
+ tests('The response should') do
7
+ response = compute.vm_destroy('instance_uuid' => booted_vm)
8
+ test('be a kind of Hash') { response.is_a? Hash }
9
+ test('should have a task_state key') { response.key? 'task_state' }
10
+ end
11
+ tests('The expected options') do
12
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_destroy }
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_migrate request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ powered_on_vm = '50137835-88a1-436e-768e-9b2677076e67'
5
+
6
+ tests('The response should') do
7
+ response = compute.vm_migrate('instance_uuid' => powered_on_vm)
8
+ test('be a kind of Hash') { response.is_a? Hash }
9
+ test('should have a task_state key') { response.key? 'task_state' }
10
+ end
11
+
12
+ tests('The expected options') do
13
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_migrate }
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_power_off request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ powered_on_vm = '5032c8a5-9c5e-ba7a-3804-832a03e16381'
5
+
6
+ tests('The response should') do
7
+ response = compute.vm_power_off('instance_uuid' => powered_on_vm)
8
+ test('be a kind of Hash') { response.is_a? Hash }
9
+ test('should have a task_state key') { response.key? 'task_state' }
10
+ test('should have a power_off_type key') { response.key? 'power_off_type' }
11
+ end
12
+
13
+ # When forcing the shutdown, we expect the result to be
14
+ { true => 'cut_power', false => 'shutdown_guest' }.each do |force, expected|
15
+ tests("When 'force' => #{force}") do
16
+ response = compute.vm_power_off('instance_uuid' => powered_on_vm, 'force' => force)
17
+ test("should retur power_off_type of #{expected}") { response['power_off_type'] == expected }
18
+ end
19
+ end
20
+
21
+ tests('The expected options') do
22
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_power_off }
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_power_on request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ powered_off_vm = nil
5
+
6
+ tests('The response should') do
7
+ response = compute.vm_power_on('instance_uuid' => powered_off_vm)
8
+ test('be a kind of Hash') { response.is_a? Hash }
9
+ test('should have a task_state key') { response.key? 'task_state' }
10
+ end
11
+
12
+ tests('The expected options') do
13
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_power_on }
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_reboot request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ powered_on_vm = '5032c8a5-9c5e-ba7a-3804-832a03e16381'
5
+
6
+ tests('The response should') do
7
+ response = compute.vm_reboot('instance_uuid' => powered_on_vm)
8
+ test('be a kind of Hash') { response.is_a? Hash }
9
+ test('should have a task_state key') { response.key? 'task_state' }
10
+ test('should have a reboot_type key') { response.key? 'reboot_type' }
11
+ end
12
+
13
+ # When forcing the shutdown, we expect the result to be
14
+ { true => 'reset_power', false => 'reboot_guest' }.each do |force, expected|
15
+ tests("When force => #{force}") do
16
+ response = compute.vm_reboot('instance_uuid' => powered_on_vm, 'force' => force)
17
+ test("should return reboot_type of #{expected}") { response['reboot_type'] == expected }
18
+ end
19
+ end
20
+
21
+ tests('The expected options') do
22
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_reboot }
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_reconfig_cdrom request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ reconfig_target = '5032c8a5-9c5e-ba7a-3804-832a03e16381'
5
+ reconfig_spec = {
6
+ 'start_connected' => false
7
+ }
8
+
9
+ tests('the response should') do
10
+ response = compute.vm_reconfig_cdrom('instance_uuid' => reconfig_target, 'hardware_spec' => reconfig_spec)
11
+ test('be a kind of Hash') { response.is_a? Hash }
12
+ test('should have a task_state key') { response.key? 'task_state' }
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_reconfig_cpus request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ reconfig_target = '50137835-88a1-436e-768e-9b2677076e67'
5
+ reconfig_spec = 2
6
+
7
+ tests('The response should') do
8
+ response = compute.vm_reconfig_cpus('instance_uuid' => reconfig_target, 'cpus' => reconfig_spec)
9
+ test('be a kind of Hash') { response.is_a? Hash }
10
+ test('should have a task_state key') { response.key? 'task_state' }
11
+ end
12
+
13
+ tests('The expected options') do
14
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_reconfig_cpus('cpus' => reconfig_spec) }
15
+ raises(ArgumentError, 'raises ArgumentError when cpus option is missing') { compute.vm_reconfig_cpus('instance_uuid' => reconfig_target) }
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_reconfig_hardware request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ reconfig_target = '50137835-88a1-436e-768e-9b2677076e67'
5
+ reconfig_spec = { 'guestId' => 'rhel5_64Guest' }
6
+
7
+ tests('The response should') do
8
+ response = compute.vm_reconfig_hardware('instance_uuid' => reconfig_target, 'hardware_spec' => reconfig_spec)
9
+ test('be a kind of Hash') { response.is_a? Hash }
10
+ test('should have a task_state key') { response.key? 'task_state' }
11
+ end
12
+
13
+ tests('The expected options') do
14
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_reconfig_hardware('hardware_spec' => reconfig_spec) }
15
+ raises(ArgumentError, 'raises ArgumentError when hardware_spec option is missing') { compute.vm_reconfig_hardware('instance_uuid' => reconfig_target) }
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_reconfig_memory request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ reconfig_target = '50137835-88a1-436e-768e-9b2677076e67'
5
+ reconfig_spec = 4096
6
+
7
+ tests('The response should') do
8
+ response = compute.vm_reconfig_memory('instance_uuid' => reconfig_target, 'memory' => reconfig_spec)
9
+ test('be a kind of Hash') { response.is_a? Hash }
10
+ test('should have a task_state key') { response.key? 'task_state' }
11
+ end
12
+
13
+ tests('The expected options') do
14
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_reconfig_memory('memory' => reconfig_spec) }
15
+ raises(ArgumentError, 'raises ArgumentError when memory option is missing') { compute.vm_reconfig_memory('instance_uuid' => reconfig_target) }
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_suspend request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+ powered_on_vm = '5032c8a5-9c5e-ba7a-3804-832a03e16381'
4
+
5
+ tests('The response should') do
6
+ response = compute.vm_suspend('instance_uuid' => powered_on_vm)
7
+ test('be a kind of Hash') { response.is_a?(Hash) }
8
+ test('should have a task_state key') { response.key? 'task_state' }
9
+ test('should have a suspend_type key') { response.key? 'suspend_type' }
10
+ end
11
+
12
+ # When forcing the shutdown, we expect the result to be
13
+ { true => 'suspend', false => 'standby_guest' }.each do |force, expected|
14
+ tests("When 'force' => #{force}") do
15
+ response = compute.vm_suspend('instance_uuid' => powered_on_vm, 'force' => force)
16
+ test("should return suspend_type of #{expected}") { response['suspend_type'] == expected }
17
+ end
18
+ end
19
+
20
+ tests('The expected options') do
21
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_suspend }
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | vm_take_snapshot request', ['vsphere']) do
2
+ compute = Fog::Compute[:vsphere]
3
+
4
+ powered_off_vm = nil
5
+
6
+ tests('The response should') do
7
+ response = compute.vm_take_snapshot('instance_uuid' => powered_off_vm, 'name' => 'foobar')
8
+ test('be a kind of Hash') { response.is_a? Hash }
9
+ test('should have a task_state key') { response.key? 'task_state' }
10
+ test('should have a was_cancelled key') { response.key? 'was_cancelled' }
11
+ end
12
+
13
+ tests('The expected options') do
14
+ raises(ArgumentError, 'raises ArgumentError when instance_uuid option is missing') { compute.vm_take_snapshot('name' => 'foobar') }
15
+ raises(ArgumentError, 'raises ArgumentError when name option is missing') { compute.vm_take_snapshot('instance_uuid' => powered_off_vm) }
16
+ end
17
+ end
@@ -0,0 +1,74 @@
1
+ require 'mocha/minitest'
2
+ require 'vcr'
3
+ require 'webmock/minitest'
4
+
5
+ VCR.configure do |config|
6
+ config.cassette_library_dir = "tests/fixtures/vcr_cassettes/6_7"
7
+ config.hook_into :webmock
8
+ config.default_cassette_options = { match_requests_on: [:body] }
9
+ end
10
+
11
+ # Makes these parameters available to the cassettes for easier recording
12
+ module Fog
13
+ module Vsphere
14
+ # Allows to skip writing of shared examples.
15
+ module VCRCasseteFilterShared
16
+ def record_http_interaction(interaction)
17
+ @shared_cassette ||= VCR::Cassette.new('shared', erb: TestConfig.load.to_h)
18
+ return if @shared_cassette.http_interactions.has_interaction_matching?(interaction.request)
19
+ interaction.request.uri = "https://<%= vsphere_server %>/sdk"
20
+ super(interaction)
21
+ end
22
+ end
23
+ ::VCR::Cassette.send(:prepend, VCRCasseteFilterShared)
24
+
25
+ module TestHelper
26
+ def prepare_compute
27
+ Fog::Compute.new(TestConfig.load.to_h.merge(provider: 'vsphere'))
28
+ end
29
+
30
+ # Records new cassette, but before writing removes the examples already in *shared* cassette.
31
+ def recording_webmock_cassette(name, options = {}, &block)
32
+ WebMock::Config.instance.net_http_connect_on_start = true
33
+ VCR.use_cassette(name, options, &block)
34
+ ensure
35
+ WebMock::Config.instance.net_http_connect_on_start = false
36
+ end
37
+
38
+ def with_webmock_cassette(name, options = {}, &block)
39
+ VCR.use_cassette('shared', erb: TestConfig.load.to_h, allow_playback_repeats: true) do
40
+ VCR.use_cassette(name, options.merge(erb: TestConfig.load.to_h), &block)
41
+ end
42
+ end
43
+ end
44
+
45
+ class TestConfig
46
+ FILE = File.join(File.dirname(__FILE__), 'vsphere_config.yml')
47
+ ATTRIBUTES = %w[server username password rev expected_pubkey_hash].freeze
48
+ DEFAULTS = {
49
+ vsphere_server: '127.0.0.1',
50
+ vsphere_username: 'Administrator@example.com',
51
+ vsphere_password: 'StrongAdminPassword'
52
+ }.freeze
53
+
54
+ def self.load
55
+ @loaded ||= new(File.exist?(FILE) ? YAML.load_file(FILE) : DEFAULTS)
56
+ end
57
+
58
+ def initialize(config = {})
59
+ @config = parse(config)
60
+ end
61
+
62
+ def to_h
63
+ @config.dup
64
+ end
65
+
66
+ def parse(config, prefix = 'vsphere')
67
+ ATTRIBUTES.each_with_object({}) do |attr_name, parsed|
68
+ full_name = "#{prefix}_#{attr_name}"
69
+ parsed[full_name.to_sym] = config[full_name.to_sym] || config[full_name] || config[attr_name]
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end