mirror of
https://github.com/puppetlabs/vmpooler-provider-vsphere.git
synced 2026-01-26 03:18:41 -05:00
Added mock info for guest ip address, fix existing tests, add dns config
This commit is contained in:
parent
c0a23ff0d0
commit
08bc1ed814
2 changed files with 54 additions and 6 deletions
|
|
@ -198,13 +198,24 @@ MockVirtualDiskManager = Object
|
||||||
MockVirtualMachine = Struct.new(
|
MockVirtualMachine = Struct.new(
|
||||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.VirtualMachine.html
|
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.VirtualMachine.html
|
||||||
# From VirtualMachine
|
# From VirtualMachine
|
||||||
:config, :runtime, :snapshot, :summary,
|
:config, :runtime, :snapshot, :summary, :guest,
|
||||||
# From ManagedEntity
|
# From ManagedEntity
|
||||||
:name,
|
:name,
|
||||||
# From RbVmomi::VIM::ManagedEntity
|
# From RbVmomi::VIM::ManagedEntity
|
||||||
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/ManagedEntity.rb
|
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/ManagedEntity.rb
|
||||||
:path
|
:path
|
||||||
)
|
) do
|
||||||
|
# From RbVmomi::VIM::VirtualMachine
|
||||||
|
# https://github.com/ManageIQ/rbvmomi2/blob/59a5904031a0d7558f306e8d2a05001f9b6822de/lib/rbvmomi/vim/VirtualMachine.rb#L20
|
||||||
|
def guest_ip
|
||||||
|
g = self.guest
|
||||||
|
if g.ipAddress
|
||||||
|
g.ipAddress
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
MockVirtualMachineSnapshot = Struct.new(
|
MockVirtualMachineSnapshot = Struct.new(
|
||||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.Snapshot.html
|
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.Snapshot.html
|
||||||
|
|
@ -347,6 +358,12 @@ MockVirtualMachineGuestSummary = Struct.new(
|
||||||
:hostName
|
:hostName
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MockVirtualMachineGuestInfo = Struct.new(
|
||||||
|
# https://developer.vmware.com/apis/1311/vsphere
|
||||||
|
# From Data Object - GuestInfo(vim.vm.GuestInfo)
|
||||||
|
:ipAddress
|
||||||
|
)
|
||||||
|
|
||||||
MockVirtualMachineRuntimeInfo = Struct.new(
|
MockVirtualMachineRuntimeInfo = Struct.new(
|
||||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.RuntimeInfo.html
|
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.RuntimeInfo.html
|
||||||
# From VirtualMachineRuntimeInfo
|
# From VirtualMachineRuntimeInfo
|
||||||
|
|
@ -801,6 +818,7 @@ end
|
||||||
def mock_RbVmomi_VIM_VirtualMachine(options = {})
|
def mock_RbVmomi_VIM_VirtualMachine(options = {})
|
||||||
options[:snapshot_tree] = nil if options[:snapshot_tree].nil?
|
options[:snapshot_tree] = nil if options[:snapshot_tree].nil?
|
||||||
options[:name] = 'VM' + rand(65536).to_s if options[:name].nil?
|
options[:name] = 'VM' + rand(65536).to_s if options[:name].nil?
|
||||||
|
options[:ip] = '169.254.255.255' if options[:ip].nil?
|
||||||
options[:path] = [] if options[:path].nil?
|
options[:path] = [] if options[:path].nil?
|
||||||
|
|
||||||
mock = MockVirtualMachine.new()
|
mock = MockVirtualMachine.new()
|
||||||
|
|
@ -810,11 +828,13 @@ def mock_RbVmomi_VIM_VirtualMachine(options = {})
|
||||||
mock.summary.runtime = MockVirtualMachineRuntimeInfo.new()
|
mock.summary.runtime = MockVirtualMachineRuntimeInfo.new()
|
||||||
mock.summary.guest = MockVirtualMachineGuestSummary.new()
|
mock.summary.guest = MockVirtualMachineGuestSummary.new()
|
||||||
mock.runtime = mock.summary.runtime
|
mock.runtime = mock.summary.runtime
|
||||||
|
mock.guest = MockVirtualMachineGuestInfo.new()
|
||||||
|
|
||||||
mock.name = options[:name]
|
mock.name = options[:name]
|
||||||
mock.summary.guest.hostName = options[:hostname]
|
mock.summary.guest.hostName = options[:hostname]
|
||||||
mock.runtime.bootTime = options[:boottime]
|
mock.runtime.bootTime = options[:boottime]
|
||||||
mock.runtime.powerState = options[:powerstate]
|
mock.runtime.powerState = options[:powerstate]
|
||||||
|
mock.guest.ipAddress = options[:ip]
|
||||||
|
|
||||||
unless options[:snapshot_tree].nil?
|
unless options[:snapshot_tree].nil?
|
||||||
mock.snapshot = MockVirtualMachineSnapshotInfo.new()
|
mock.snapshot = MockVirtualMachineSnapshotInfo.new()
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,11 @@ describe 'Vmpooler::PoolManager::Provider::VSphere' do
|
||||||
:config:
|
:config:
|
||||||
max_tries: 3
|
max_tries: 3
|
||||||
retry_factor: 10
|
retry_factor: 10
|
||||||
|
:dns_configs:
|
||||||
|
:gcp-clouddns:
|
||||||
|
project: vmpooler-test
|
||||||
|
domain: vmpooler.example.com
|
||||||
|
dns_zone_resource_name: vmpooler-example-com
|
||||||
:providers:
|
:providers:
|
||||||
:vsphere:
|
:vsphere:
|
||||||
server: "vcenter.domain.local"
|
server: "vcenter.domain.local"
|
||||||
|
|
@ -71,6 +76,7 @@ describe 'Vmpooler::PoolManager::Provider::VSphere' do
|
||||||
ready_ttl: 1440
|
ready_ttl: 1440
|
||||||
clone_target: 'cluster1'
|
clone_target: 'cluster1'
|
||||||
provider: 'vsphere'
|
provider: 'vsphere'
|
||||||
|
dns_config: 'gcp-clouddns'
|
||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -535,7 +541,7 @@ EOT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when VM exists but is missing information' do
|
context 'when VM exists but is missing hostname, boottime, powerstate' do
|
||||||
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
||||||
:name => vmname,
|
:name => vmname,
|
||||||
})
|
})
|
||||||
|
|
@ -560,10 +566,25 @@ EOT
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when VM exists but is missing ip' do
|
||||||
|
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
||||||
|
:name => vmname,
|
||||||
|
:ip => '',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'should return empty for ip' do
|
||||||
|
result = subject.get_vm(poolname,vmname)
|
||||||
|
|
||||||
|
expect(result['ip']).to eq('')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when VM exists and contains all information' do
|
context 'when VM exists and contains all information' do
|
||||||
let(:vm_hostname) { "#{vmname}.demo.local" }
|
let(:vm_hostname) { "#{vmname}.demo.local" }
|
||||||
let(:boot_time) { Time.now }
|
let(:boot_time) { Time.now }
|
||||||
let(:power_state) { 'MockPowerState' }
|
let(:power_state) { 'MockPowerState' }
|
||||||
|
let(:ip) { '169.254.255.255' }
|
||||||
|
|
||||||
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
let(:vm_object) { mock_RbVmomi_VIM_VirtualMachine({
|
||||||
:name => vmname,
|
:name => vmname,
|
||||||
|
|
@ -622,6 +643,11 @@ EOT
|
||||||
expect(result['powerstate']).to eq(power_state)
|
expect(result['powerstate']).to eq(power_state)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should return the ip' do
|
||||||
|
result = subject.get_vm(poolname,vmname)
|
||||||
|
|
||||||
|
expect(result['ip']).to eq(ip)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1056,14 +1082,15 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#vm_ready?' do
|
describe '#vm_ready?' do
|
||||||
let(:domain) { nil }
|
let(:domain) { 'vmpooler.example.com' }
|
||||||
context 'When a VM is ready' do
|
context 'When a VM is ready' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
allow(subject).to receive(:domain).and_return('vmpooler.example.com')
|
||||||
expect(subject).to receive(:open_socket).with(vmname, domain)
|
expect(subject).to receive(:open_socket).with(vmname, domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return true' do
|
it 'should return true' do
|
||||||
expect(subject.vm_ready?(poolname,vmname)).to be true
|
expect(subject.vm_ready?(poolname, vmname)).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -1075,6 +1102,7 @@ EOT
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return true' do
|
it 'should return true' do
|
||||||
|
allow(subject).to receive(:domain).and_return('vmpooler.example.com')
|
||||||
expect(subject.vm_ready?('missing_pool',vmname)).to be true
|
expect(subject.vm_ready?('missing_pool',vmname)).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1390,7 +1418,7 @@ EOT
|
||||||
let(:TCPSocket) { double('tcpsocket') }
|
let(:TCPSocket) { double('tcpsocket') }
|
||||||
let(:socket) { double('tcpsocket') }
|
let(:socket) { double('tcpsocket') }
|
||||||
let(:hostname) { 'host' }
|
let(:hostname) { 'host' }
|
||||||
let(:domain) { 'domain.local'}
|
let(:domain) { 'vmpooler.example.com' }
|
||||||
let(:default_socket) { 22 }
|
let(:default_socket) { 22 }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue