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.
- checksums.yaml +4 -4
- data/lib/fog/vsphere/compute.rb +12 -0
- data/lib/fog/vsphere/models/compute/nvmecontroller.rb +24 -0
- data/lib/fog/vsphere/models/compute/scsicontroller.rb +5 -1
- data/lib/fog/vsphere/models/compute/server.rb +33 -18
- data/lib/fog/vsphere/models/compute/volume.rb +1 -2
- data/lib/fog/vsphere/requests/compute/create_vm.rb +11 -4
- data/lib/fog/vsphere/requests/compute/get_vm_first_nvme_controller.rb +21 -0
- data/lib/fog/vsphere/requests/compute/list_vm_nvme_controllers.rb +29 -0
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +1 -1
- data/lib/fog/vsphere/version.rb +1 -1
- data/tests/class_from_string_tests.rb +33 -0
- data/tests/compute_tests.rb +53 -0
- data/tests/fixtures/vcr_cassettes/6_7/create_folder.yml +609 -0
- data/tests/fixtures/vcr_cassettes/6_7/folder_destroy.yml +823 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_cluster.yml +663 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_compute_resource.yml +1046 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_datacenter.yml +498 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_folder.yml +2038 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_host.yml +386 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_network.yml +932 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_storage_pod.yml +225 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_template.yml +329 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_virtual_machine.yml +329 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_vm_first_nvme_controller.yml +105 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_vm_first_sata_controller.yml +209 -0
- data/tests/fixtures/vcr_cassettes/6_7/get_vm_first_scsi_controller.yml +111 -0
- data/tests/fixtures/vcr_cassettes/6_7/shared.yml +164 -0
- data/tests/helper.rb +6 -0
- data/tests/helpers/mock_helper.rb +9 -0
- data/tests/models/compute/cluster_tests.rb +18 -0
- data/tests/models/compute/hosts_tests.rb +11 -0
- data/tests/models/compute/rules_tests.rb +28 -0
- data/tests/models/compute/server_tests.rb +74 -0
- data/tests/models/compute/server_unit_tests.rb +13 -0
- data/tests/models/compute/servers_tests.rb +14 -0
- data/tests/models/compute/ticket_tests.rb +12 -0
- data/tests/models/compute/tickets_tests.rb +8 -0
- data/tests/requests/compute/create_folder_tests.rb +19 -0
- data/tests/requests/compute/current_time_tests.rb +10 -0
- data/tests/requests/compute/folder_destroy_tests.rb +39 -0
- data/tests/requests/compute/get_cluster_tests.rb +19 -0
- data/tests/requests/compute/get_compute_resource_tests.rb +19 -0
- data/tests/requests/compute/get_datacenter_tests.rb +19 -0
- data/tests/requests/compute/get_folder_tests.rb +28 -0
- data/tests/requests/compute/get_host_tests.rb +19 -0
- data/tests/requests/compute/get_network_tests.rb +78 -0
- data/tests/requests/compute/get_storage_pod_tests.rb +19 -0
- data/tests/requests/compute/get_template_tests.rb +19 -0
- data/tests/requests/compute/get_virtual_machine_tests.rb +19 -0
- data/tests/requests/compute/get_vm_first_nvme_controller_tests.rb +19 -0
- data/tests/requests/compute/get_vm_first_sata_controller_tests.rb +19 -0
- data/tests/requests/compute/get_vm_first_scsi_controller_tests.rb +19 -0
- data/tests/requests/compute/list_child_snapshots_tests.rb +9 -0
- data/tests/requests/compute/list_clusters_tests.rb +10 -0
- data/tests/requests/compute/list_datastores_tests.rb +17 -0
- data/tests/requests/compute/list_hosts_tests.rb +10 -0
- data/tests/requests/compute/list_networks_tests.rb +17 -0
- data/tests/requests/compute/list_storage_pods_test.rb +9 -0
- data/tests/requests/compute/list_virtual_machines_tests.rb +34 -0
- data/tests/requests/compute/list_vm_cdroms_tests.rb +9 -0
- data/tests/requests/compute/list_vm_snapshots_tests.rb +9 -0
- data/tests/requests/compute/modify_vm_cdrom_tests.rb +20 -0
- data/tests/requests/compute/revert_to_snapshot_tests.rb +13 -0
- data/tests/requests/compute/set_vm_customvalue_tests.rb +18 -0
- data/tests/requests/compute/update_vm_tests.rb +13 -0
- data/tests/requests/compute/vm_clone_tests.rb +55 -0
- data/tests/requests/compute/vm_config_vnc_tests.rb +18 -0
- data/tests/requests/compute/vm_destroy_tests.rb +14 -0
- data/tests/requests/compute/vm_migrate_tests.rb +15 -0
- data/tests/requests/compute/vm_power_off_tests.rb +24 -0
- data/tests/requests/compute/vm_power_on_tests.rb +15 -0
- data/tests/requests/compute/vm_reboot_tests.rb +24 -0
- data/tests/requests/compute/vm_reconfig_cdrom_tests.rb +14 -0
- data/tests/requests/compute/vm_reconfig_cpus_tests.rb +17 -0
- data/tests/requests/compute/vm_reconfig_hardware_tests.rb +17 -0
- data/tests/requests/compute/vm_reconfig_memory_tests.rb +17 -0
- data/tests/requests/compute/vm_suspend_tests.rb +23 -0
- data/tests/requests/compute/vm_take_snapshot_tests.rb +17 -0
- data/tests/test_helper.rb +74 -0
- metadata +152 -19
- data/.github/workflows/ruby.yml +0 -42
- data/.gitignore +0 -25
- data/.rubocop.yml +0 -44
- data/.rubocop_todo.yml +0 -614
- data/CONTRIBUTING.md +0 -55
- data/Gemfile +0 -5
- data/Jenkinsfile +0 -10
- data/fog-vsphere.gemspec +0 -39
@@ -0,0 +1,11 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | hosts collection', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
cluster = compute.datacenters.first.clusters.get('Solutionscluster')
|
4
|
+
hosts = cluster.hosts
|
5
|
+
|
6
|
+
tests('The hosts collection') do
|
7
|
+
test('should not be empty') { !hosts.empty? }
|
8
|
+
test('should be a kind of Fog::Vsphere::Compute::Hosts') { hosts.is_a? Fog::Vsphere::Compute::Hosts }
|
9
|
+
test('should get hosts') { hosts.get('host1.example.com').name == 'host1.example.com' }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | rules collection', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
cluster = compute.datacenters.first.clusters.get('Solutionscluster')
|
4
|
+
servers = compute.servers
|
5
|
+
rules = cluster.rules
|
6
|
+
|
7
|
+
tests('The rules collection') do
|
8
|
+
test('should not be empty') { !rules.empty? }
|
9
|
+
test('should be a kind of Fog::Vsphere::Compute::Rules') { rules.is_a? Fog::Vsphere::Compute::Rules }
|
10
|
+
test('should get rules') { rules.get('anti-affinity-foo').key == 4242 }
|
11
|
+
test('should destroy rules') { rules.first.destroy; rules.reload; rules.empty? }
|
12
|
+
test('should create rules') do
|
13
|
+
r = rules.new(name: 'affinity-foo',
|
14
|
+
enabled: true,
|
15
|
+
type: RbVmomi::VIM::ClusterAffinityRuleSpec)
|
16
|
+
r.vms = [servers.get('5032c8a5-9c5e-ba7a-3804-832a03e16381'), servers.get('502916a3-b42e-17c7-43ce-b3206e9524dc')]
|
17
|
+
r.save
|
18
|
+
rules.reload
|
19
|
+
rules.get('affinity-foo').key > 0
|
20
|
+
end
|
21
|
+
raises(ArgumentError, 'should not create rules with <2 vms') do
|
22
|
+
rules.create(name: 'affinity-foo',
|
23
|
+
enabled: true,
|
24
|
+
type: RbVmomi::VIM::ClusterAffinityRuleSpec,
|
25
|
+
vm_ids: ['5032c8a5-9c5e-ba7a-3804-832a03e16381'])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | server model', ['vsphere']) do
|
2
|
+
servers = Fog::Compute[:vsphere].servers
|
3
|
+
server = servers.last
|
4
|
+
|
5
|
+
tests('The server model should') do
|
6
|
+
tests('have the action') do
|
7
|
+
test('reload') { server.respond_to? 'reload' }
|
8
|
+
%w[stop suspend destroy reboot].each do |action|
|
9
|
+
test(action) { server.respond_to? action }
|
10
|
+
test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
|
11
|
+
end
|
12
|
+
test('start') { server.respond_to?('start') }
|
13
|
+
test('start returns false, because it is already poweredOn') { server.start ? true : false }
|
14
|
+
test('guest_processes') { server.respond_to? 'guest_processes' }
|
15
|
+
test('take_snapshot') do
|
16
|
+
test('responds') { server.respond_to? 'take_snapshot' }
|
17
|
+
test('returns successfully') { server.take_snapshot('name' => 'foobar').is_a? Hash }
|
18
|
+
end
|
19
|
+
test('snapshots') do
|
20
|
+
test('responds') { server.respond_to? 'snapshots' }
|
21
|
+
test('returns successfully') { server.snapshots.is_a? Fog::Vsphere::Compute::Snapshots }
|
22
|
+
end
|
23
|
+
test('find_snapshot') do
|
24
|
+
test('responds') { server.respond_to? 'find_snapshot' }
|
25
|
+
test('returns successfully') do
|
26
|
+
server.find_snapshot('snapshot-0101').is_a? Fog::Vsphere::Compute::Snapshot
|
27
|
+
end
|
28
|
+
test('returns correct snapshot') do
|
29
|
+
server.find_snapshot('snapshot-0101').ref == 'snapshot-0101'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
tests('revert_snapshot') do
|
33
|
+
test('responds') { server.respond_to? 'revert_snapshot' }
|
34
|
+
tests('returns correctly') do
|
35
|
+
test('when correct input given') { server.revert_snapshot('snapshot-0101').is_a? Hash }
|
36
|
+
test('when incorrect input given') do
|
37
|
+
raises(ArgumentError) { server.revert_snapshot(1) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
test('tickets') do
|
42
|
+
test('acquire ticket successfully') { server.acquire_ticket.is_a? Fog::Vsphere::Compute::Ticket }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
tests('have attributes') do
|
46
|
+
model_attribute_hash = server.attributes
|
47
|
+
attributes = %i[id
|
48
|
+
instance_uuid
|
49
|
+
uuid
|
50
|
+
power_state
|
51
|
+
tools_state
|
52
|
+
mo_ref
|
53
|
+
tools_version
|
54
|
+
hostname
|
55
|
+
mac_addresses
|
56
|
+
operatingsystem
|
57
|
+
connection_state
|
58
|
+
hypervisor
|
59
|
+
name
|
60
|
+
public_ip_address]
|
61
|
+
tests('The server model should respond to') do
|
62
|
+
attributes.each do |attribute|
|
63
|
+
test(attribute.to_s) { server.respond_to? attribute }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
tests('The attributes hash should have key') do
|
67
|
+
attributes.each do |attribute|
|
68
|
+
test(attribute.to_s) { model_attribute_hash.key? attribute }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
test('be a kind of Fog::Vsphere::Compute::Server') { server.is_a? Fog::Vsphere::Compute::Server }
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../../helper'
|
2
|
+
|
3
|
+
require 'fog/vsphere/models/compute/server'
|
4
|
+
|
5
|
+
class TestServer < Minitest::Test
|
6
|
+
def test_tools_installed
|
7
|
+
server = Fog::Vsphere::Compute::Server.new
|
8
|
+
server.tools_state = 'toolsNotRunning'
|
9
|
+
server.tools_version = 'guestToolsNotInstalled'
|
10
|
+
|
11
|
+
assert_equal(false, server.tools_installed?)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | servers collection', ['vsphere']) do
|
2
|
+
servers = Fog::Compute[:vsphere].servers
|
3
|
+
|
4
|
+
tests('The servers collection') do
|
5
|
+
pending # Not mocked
|
6
|
+
test('should not be empty') { !servers.empty? }
|
7
|
+
tests('should be a kind of Fog::Vsphere::Compute::Servers').returns(Fog::Vsphere::Compute::Servers) { servers }
|
8
|
+
test('should be able to reload itself') { servers.reload }
|
9
|
+
tests('should be able to get a model') do
|
10
|
+
tests('by managed object reference').returns(String) { servers.get('jefftest') }
|
11
|
+
tests('by instance uuid').returns(String) { servers.get('5032c8a5-9c5e-ba7a-3804-832a03e16381') }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | hosts collection', ['vsphere']) do
|
2
|
+
servers = Fog::Compute[:vsphere].servers
|
3
|
+
server = servers.last
|
4
|
+
ticket = server.acquire_ticket
|
5
|
+
|
6
|
+
tests('A ticket') do
|
7
|
+
test('should have a ticket') { !ticket.ticket.empty? }
|
8
|
+
test('should have a host') { !ticket.host.empty? }
|
9
|
+
test('should have a port') { ticket.port.is_a?(Integer) }
|
10
|
+
test('should have a ssl ssl_thumbprint') { !ticket.ssl_thumbprint.empty? }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | hosts collection', ['vsphere']) do
|
2
|
+
service = Fog::Compute[:vsphere]
|
3
|
+
server = service.servers.last
|
4
|
+
|
5
|
+
tests('The tickets collection') do
|
6
|
+
test('should create a ticket for a server') { service.tickets(server: server).create.is_a? Fog::Vsphere::Compute::Ticket }
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#create_folder' do
|
12
|
+
it 'creates folder' do
|
13
|
+
with_webmock_cassette('create_folder') do
|
14
|
+
folder = compute.create_folder('BRQ', '/', 'TestFolder')
|
15
|
+
assert_equal(folder, 'TestFolder')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | current_time request', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
|
4
|
+
tests('The response should') do
|
5
|
+
response = compute.current_time
|
6
|
+
test('be a kind of Hash') { response.is_a? Hash }
|
7
|
+
test('have a current_time key') { response.key? 'current_time' }
|
8
|
+
test('have a current_time key with a Time value') { response['current_time'].is_a? Time }
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | folder_destroy request', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
|
4
|
+
empty_folder = '/Solutions/empty'
|
5
|
+
full_folder = '/Solutions/wibble'
|
6
|
+
datacenter = 'Solutions'
|
7
|
+
|
8
|
+
tests('The response should') do
|
9
|
+
response = compute.folder_destroy(empty_folder, datacenter)
|
10
|
+
test('be a kind of Hash') { response.is_a? Hash }
|
11
|
+
test('should have a task_state key') { response.key? 'task_state' }
|
12
|
+
end
|
13
|
+
|
14
|
+
tests('When folder is not empty') do
|
15
|
+
raises(Fog::Vsphere::Errors::ServiceError, 'raises ServiceError') do
|
16
|
+
compute.folder_destroy(full_folder, datacenter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe Fog::Vsphere::Compute::Real do
|
24
|
+
include Fog::Vsphere::TestHelper
|
25
|
+
|
26
|
+
before { Fog.unmock! }
|
27
|
+
after { Fog.mock! }
|
28
|
+
|
29
|
+
let(:compute) { prepare_compute }
|
30
|
+
|
31
|
+
describe '#folder_destroy' do
|
32
|
+
it 'destroys folder' do
|
33
|
+
with_webmock_cassette('folder_destroy') do
|
34
|
+
result = compute.folder_destroy('TestFolder', 'BRQ')
|
35
|
+
assert_equal result['task_state'], 'success'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_cluster' do
|
12
|
+
it 'gets cluster' do
|
13
|
+
with_webmock_cassette('get_cluster') do
|
14
|
+
cluster = compute.get_cluster('esxi.example.com', 'BRQ')
|
15
|
+
assert_equal(cluster[:name], 'esxi.example.com')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_compute_resource' do
|
12
|
+
it 'gets ComputeResource' do
|
13
|
+
with_webmock_cassette('get_compute_resource') do
|
14
|
+
cr = compute.get_compute_resource('esxi.example.com', 'BRQ')
|
15
|
+
assert_equal(cr[:name], 'esxi.example.com')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_datacenter' do
|
12
|
+
it 'gets datacenter' do
|
13
|
+
with_webmock_cassette('get_datacenter') do
|
14
|
+
dc = compute.get_datacenter('BRQ')
|
15
|
+
assert_equal(dc[:name], 'BRQ')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_folder' do
|
12
|
+
it 'gets any type of folder' do
|
13
|
+
with_webmock_cassette('get_folder') do
|
14
|
+
folder = compute.get_folder('TestFolder', 'BRQ', 'vm')
|
15
|
+
assert_equal(folder[:name], 'TestFolder')
|
16
|
+
|
17
|
+
folder = compute.get_folder('TestNwFolder', 'BRQ', 'network')
|
18
|
+
assert_equal(folder[:name], 'TestNwFolder')
|
19
|
+
|
20
|
+
folder = compute.get_folder('TestHostFolder', 'BRQ', 'host')
|
21
|
+
assert_equal(folder[:name], 'TestHostFolder')
|
22
|
+
|
23
|
+
folder = compute.get_folder('TestDsFolder', 'BRQ', 'datastore')
|
24
|
+
assert_equal(folder[:name], 'TestDsFolder')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_host' do
|
12
|
+
it 'gets host' do
|
13
|
+
with_webmock_cassette('get_host') do
|
14
|
+
host = compute.get_host('esxi.example.com', 'esxi.example.com', 'BRQ')
|
15
|
+
assert_equal(host[:name], 'esxi.example.com')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
Shindo.tests('Fog::Compute[:vsphere] | get_network request', ['vsphere']) do
|
4
|
+
compute = Fog::Compute[:vsphere]
|
5
|
+
|
6
|
+
before do
|
7
|
+
mocha_setup
|
8
|
+
end
|
9
|
+
after do
|
10
|
+
mocha_teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
def make_fake_dvs(args = {})
|
14
|
+
config = OpenStruct.new(
|
15
|
+
distributedVirtualSwitch: OpenStruct.new(name: args[:dvs_name])
|
16
|
+
)
|
17
|
+
network = stub(args.merge(config: config))
|
18
|
+
network.expects('is_a?')
|
19
|
+
.with(RbVmomi::VIM::DistributedVirtualPortgroup)
|
20
|
+
.returns(true)
|
21
|
+
network
|
22
|
+
end
|
23
|
+
|
24
|
+
def fake_networks
|
25
|
+
[
|
26
|
+
OpenStruct.new(_ref: 'network-1', name: 'non-dvs'),
|
27
|
+
make_fake_dvs(_ref: 'network-2', name: 'web1', dvs_name: 'dvs5', key: '4001'),
|
28
|
+
make_fake_dvs(_ref: 'network-3', name: 'web1', dvs_name: 'dvs11', key: '4001'),
|
29
|
+
make_fake_dvs(_ref: 'network-4', name: 'other', dvs_name: 'other', key: '4001')
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
tests('#choose_finder should') do
|
34
|
+
test('choose the network based on network name and dvs name') do
|
35
|
+
finder = compute.send(:choose_finder, 'web1', 'dvs11')
|
36
|
+
found_network = fake_networks.find { |n| finder.call(n) }
|
37
|
+
found_network.name == 'web1' && found_network.dvs_name == 'dvs11'
|
38
|
+
end
|
39
|
+
test('choose the network based on network name and any dvs') do
|
40
|
+
finder = compute.send(:choose_finder, 'web1', :dvs)
|
41
|
+
found_network = fake_networks.find { |n| finder.call(n) }
|
42
|
+
found_network.name == 'web1' && found_network.dvs_name == 'dvs5'
|
43
|
+
end
|
44
|
+
test('choose the network based on network name only') do
|
45
|
+
finder = compute.send(:choose_finder, 'other', nil)
|
46
|
+
found_network = fake_networks.find { |n| finder.call(n) }
|
47
|
+
found_network.name == 'other' && found_network.dvs_name == 'other'
|
48
|
+
end
|
49
|
+
test('choose the network based on network name only for non-dvs') do
|
50
|
+
finder = compute.send(:choose_finder, 'non-dvs', nil)
|
51
|
+
found_network = fake_networks.find { |n| finder.call(n) }
|
52
|
+
found_network.name == 'non-dvs' && found_network.class.name.to_s == 'OpenStruct'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
require_relative '../../test_helper'
|
58
|
+
|
59
|
+
describe Fog::Vsphere::Compute::Real do
|
60
|
+
include Fog::Vsphere::TestHelper
|
61
|
+
|
62
|
+
before { Fog.unmock! }
|
63
|
+
after { Fog.mock! }
|
64
|
+
|
65
|
+
let(:compute) { prepare_compute }
|
66
|
+
|
67
|
+
describe '#get_network' do
|
68
|
+
it 'gets network by name or ref' do
|
69
|
+
with_webmock_cassette('get_network') do
|
70
|
+
network = compute.get_network('InternalNetwork', 'BRQ')
|
71
|
+
assert_equal(network[:name], 'InternalNetwork')
|
72
|
+
|
73
|
+
network = compute.get_network('network-12', 'BRQ')
|
74
|
+
assert_equal(network[:id], 'network-12')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_storage_pod' do
|
12
|
+
it 'gets storage pod' do
|
13
|
+
with_webmock_cassette('get_storage_pod') do
|
14
|
+
pod = compute.get_storage_pod('devNullNoDRS', 'BRQ')
|
15
|
+
assert_equal(pod[:name], 'devNullNoDRS')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_template' do
|
12
|
+
it 'gets template by uuid' do
|
13
|
+
with_webmock_cassette('get_template') do
|
14
|
+
vm = compute.get_template('500e2be9-4762-1f52-5e7c-f37444be5f6e', 'BRQ')
|
15
|
+
assert_equal(vm['name'], 'fedora29')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_virtual_machine' do
|
12
|
+
it 'gets virtual machine by uuid' do
|
13
|
+
with_webmock_cassette('get_virtual_machine') do
|
14
|
+
vm = compute.get_virtual_machine('52d810bd-077b-368d-a86f-0b2ad84269f8', 'BRQ')
|
15
|
+
assert_equal(vm['name'], 'DC1')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_vm_first_nvme_controller' do
|
12
|
+
it 'gets virtual machine by uuid' do
|
13
|
+
with_webmock_cassette('get_vm_first_nvme_controller') do
|
14
|
+
controller = compute.get_vm_first_nvme_controller('500daa1c-abaf-7fe3-1a4a-5ce47e6f2b0a')
|
15
|
+
assert_equal(controller[:type], 'VirtualNVMEController')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_vm_first_sata_controller' do
|
12
|
+
it 'gets virtual machine by uuid' do
|
13
|
+
with_webmock_cassette('get_vm_first_sata_controller') do
|
14
|
+
controller = compute.get_vm_first_sata_controller('5030c6ce-c0b1-59d9-34ff-d8438e2f0339')
|
15
|
+
assert_equal(controller[:type], 'VirtualAHCIController')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Fog::Vsphere::Compute::Real do
|
4
|
+
include Fog::Vsphere::TestHelper
|
5
|
+
|
6
|
+
before { Fog.unmock! }
|
7
|
+
after { Fog.mock! }
|
8
|
+
|
9
|
+
let(:compute) { prepare_compute }
|
10
|
+
|
11
|
+
describe '#get_vm_first_scsi_controller' do
|
12
|
+
it 'gets virtual machine by uuid' do
|
13
|
+
with_webmock_cassette('get_vm_first_scsi_controller') do
|
14
|
+
controller = compute.get_vm_first_scsi_controller('52d810bd-077b-368d-a86f-0b2ad84269f8')
|
15
|
+
assert_equal(controller.type, 'VirtualLsiLogicSASController')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | list_child_snapshots request', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
|
4
|
+
tests('The response should') do
|
5
|
+
response = compute.list_child_snapshots('snapshot-0101')
|
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,10 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | list_clusters request', ['vsphere']) do
|
2
|
+
tests('When listing all clusters') do
|
3
|
+
response = Fog::Compute[:vsphere].list_clusters
|
4
|
+
test('Clusters extracted from folders... ') { response.length == 4 }
|
5
|
+
|
6
|
+
tests('The response data format ...') do
|
7
|
+
test('be a kind of Hash') { response.is_a? Array }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | list_datastores request', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
|
4
|
+
tests('The response with datastore filter should') do
|
5
|
+
response = compute.list_datastores(datacenter: 'Solutions')
|
6
|
+
test('be a kind of Array') { response.is_a? Array }
|
7
|
+
test('contain Hashes') { response.all? { |i| Hash === i } }
|
8
|
+
test('have 2 elements') { response.length == 2 }
|
9
|
+
end
|
10
|
+
|
11
|
+
tests('The response with cluster filter should') do
|
12
|
+
response = compute.list_datastores(datacenter: 'Solutions', cluster: 'Solutionscluster')
|
13
|
+
test('be a kind of Array') { response.is_a? Array }
|
14
|
+
test('contain Hashes') { response.all? { |i| Hash === i } }
|
15
|
+
test('have a single element') { response.length == 1 }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | list_hosts request', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
|
4
|
+
tests('The response should') do
|
5
|
+
response = compute.list_hosts(datacenter: 'Solutions', cluster: 'Solutionscluster')
|
6
|
+
test('be a kind of Array') { response.is_a? Array }
|
7
|
+
test('contain Hashes') { response.all? { |i| Hash === i } }
|
8
|
+
test('have 1 element') { response.length == 1 }
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | list_networks request', ['vsphere']) do
|
2
|
+
compute = Fog::Compute[:vsphere]
|
3
|
+
|
4
|
+
tests('The response with datastore filter should') do
|
5
|
+
response = compute.list_networks(datacenter: 'Solutions')
|
6
|
+
test('be a kind of Array') { response.is_a? Array }
|
7
|
+
test('contain Hashes') { response.all? { |i| Hash === i } }
|
8
|
+
test('have 2 elements') { response.length == 2 }
|
9
|
+
end
|
10
|
+
|
11
|
+
tests('The response with cluster filter should') do
|
12
|
+
response = compute.list_networks(datacenter: 'Solutions', cluster: 'Solutionscluster')
|
13
|
+
test('be a kind of Array') { response.is_a? Array }
|
14
|
+
test('contain Hashes') { response.all? { |i| Hash === i } }
|
15
|
+
test('have a single element') { response.length == 1 }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Shindo.tests('Fog::Compute[:vsphere] | list_storage_pods request', ['vsphere']) do
|
2
|
+
tests('When listing all storage pods') do
|
3
|
+
response = Fog::Compute[:vsphere].list_storage_pods
|
4
|
+
|
5
|
+
tests('The response data format ...') do
|
6
|
+
test('be a kind of Hash') { response.is_a? Array }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|