forked from nsidc/vagrant-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone_spec.rb
129 lines (113 loc) · 4.4 KB
/
clone_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require 'spec_helper'
CUSTOM_VM_FOLDER = 'custom_vm_folder'
describe VagrantPlugins::VSphere::Action::Clone do
before :each do
@env[:vSphere_connection] = @vim
end
it "should create a CloneVM task with template's parent" do
call
expect(@template).to have_received(:CloneVM_Task).with(
folder: @data_center,
name: NAME,
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec }
)
end
it 'should create a CloneVM task with custom folder when given vm base path' do
custom_base_folder = double(CUSTOM_VM_FOLDER,
pretty_path: "#{@data_center.pretty_path}/#{CUSTOM_VM_FOLDER}")
@machine.provider_config.stub(:vm_base_path).and_return(CUSTOM_VM_FOLDER)
@data_center.vmFolder.stub(:traverse).with(CUSTOM_VM_FOLDER, RbVmomi::VIM::Folder, true).and_return(custom_base_folder)
call
expect(@template).to have_received(:CloneVM_Task).with(
folder: custom_base_folder,
name: NAME,
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec }
)
end
it 'should set the machine id to be the new UUID' do
call
expect(@machine).to have_received(:id=).with(NEW_UUID)
end
it 'should call the next item in the middleware stack' do
call
expect(@app).to have_received :call
end
it 'should create a CloneVM spec with configured vlan' do
@machine.provider_config.stub(:vlan).and_return('vlan')
network = double('network', name: 'vlan')
network.stub(:config).and_raise(StandardError)
@data_center.stub(:network).and_return([network])
call
expected_config = RbVmomi::VIM.VirtualMachineConfigSpec(deviceChange: Array.new)
expected_dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: @device, operation: 'edit')
expected_config[:deviceChange].push expected_dev_spec
expect(@template).to have_received(:CloneVM_Task).with(
folder: @data_center,
name: NAME,
spec: { location: { pool: @child_resource_pool },
config: expected_config
}
)
end
it 'should create a CloneVM spec with configured memory_mb' do
@machine.provider_config.stub(:memory_mb).and_return(2048)
call
expect(@template).to have_received(:CloneVM_Task).with(
folder: @data_center,
name: NAME,
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec(memoryMB: 2048) }
)
end
it 'should create a CloneVM spec with configured number of cpus' do
@machine.provider_config.stub(:cpu_count).and_return(4)
call
expect(@template).to have_received(:CloneVM_Task).with(
folder: @data_center,
name: NAME,
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec(numCPUs: 4) }
)
end
it 'should set static IP when given config spec' do
@machine.provider_config.stub(:customization_spec_name).and_return('spec')
call
expect(@ip).to have_received(:ipAddress=).with('0.0.0.0')
end
it 'should use root resource pool when cloning from template and no resource pool specified' do
@machine.provider_config.stub(:resource_pool_name).and_return(nil)
call
expect(@template).to have_received(:CloneVM_Task).with(
folder: @data_center,
name: NAME,
spec: { location: { pool: @root_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec }
)
end
it 'should set extraConfig if specified' do
@machine.provider_config.stub(:extra_config).and_return(
'guestinfo.hostname' => 'somehost.testvm')
expected_config = RbVmomi::VIM.VirtualMachineConfigSpec(extraConfig: [
{ 'key' => 'guestinfo.hostname', 'value' => 'somehost.testvm' }
])
call
expect(@template).to have_received(:CloneVM_Task).with(
folder: @data_center,
name: NAME,
spec: { location: { pool: @child_resource_pool },
config: expected_config }
)
end
it 'should set custom notes when they are specified' do
@machine.provider_config.stub(:notes).and_return('custom_notes')
call
expect(@template).to have_received(:CloneVM_Task).with(
folder: @data_center,
name: NAME,
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec(annotation: 'custom_notes') }
)
end
end