forked from ManageIQ/manageiq-providers-proxmox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefresher_spec.rb
More file actions
210 lines (181 loc) · 6.36 KB
/
refresher_spec.rb
File metadata and controls
210 lines (181 loc) · 6.36 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
describe ManageIQ::Providers::Proxmox::InfraManager::Refresher do
include Spec::Support::EmsRefreshHelper
let(:ems) { FactoryBot.create(:ems_proxmox_with_vcr_authentication) }
describe ".refresh" do
context "full-refresh" do
it "performs a full refresh" do
with_vcr { described_class.refresh([ems]) }
assert_counts
assert_ems_counts
assert_specific_cluster
assert_specific_host
assert_specific_vm
assert_specific_template
end
context "with an archived VM" do
let!(:archived_vm) { FactoryBot.create(:vm_proxmox, :ems_ref => "100") }
it "doesn't reconnect an archived VM with the same ems_ref" do
with_vcr { described_class.refresh([ems]) }
expect(archived_vm.reload).to be_archived
expect(ems.vms.find_by(:ems_ref => "100")).not_to eq(archived_vm)
end
end
end
context "targeted-refresh" do
let(:targets) { [target] }
before { with_vcr { described_class.refresh([ems]) } }
context "with a Host target" do
let(:target) { ems.hosts.find_by(:ems_ref => "vmpvetest") }
before { with_vcr("targeted-refresh/host") { described_class.refresh(targets) } }
it "doesn't impact unrelated inventory" do
assert_counts
assert_ems_counts
assert_specific_cluster
assert_specific_vm
assert_specific_template
end
it "updates the host's power state" do
expect(target.reload.power_state).to eq("on")
end
end
context "with a VM target" do
let(:target) { ems.vms.find_by(:ems_ref => "100") }
before { with_vcr("targeted-refresh/vm") { described_class.refresh(targets) } }
it "doesn't impact unrelated inventory" do
assert_counts
assert_ems_counts
assert_specific_cluster
assert_specific_host
assert_specific_template
end
it "updates the VMs's power state" do
expect(target.reload.power_state).to eq("on")
end
end
end
end
def assert_counts
expect(Vm.count).to eq(6)
expect(MiqTemplate.count).to eq(14)
expect(Host.count).to eq(2)
expect(Storage.count).to eq(4)
expect(EmsCluster.count).to eq(1)
end
def assert_ems_counts
expect(ems.vms.count).to eq(6)
expect(ems.miq_templates.count).to eq(14)
expect(ems.hosts.count).to eq(2)
expect(ems.storages.count).to eq(4)
expect(ems.ems_clusters.count).to eq(1)
end
def assert_specific_cluster
cluster = ems.ems_clusters.find_by(:ems_ref => "cluster")
expect(cluster).to have_attributes(
:name => "pvetest",
:uid_ems => "cluster",
:ems_ref => "cluster"
)
end
def assert_specific_host
host = ems.hosts.find_by(:ems_ref => "vmpvetest")
expect(host).to have_attributes(
:name => "vmpvetest",
:vmm_vendor => "proxmox",
:vmm_version => nil,
:vmm_product => "Proxmox VE",
:vmm_buildnumber => nil,
:power_state => "on",
:uid_ems => "vmpvetest",
:ems_ref => "vmpvetest",
:ems_cluster => ems.ems_clusters.find_by(:ems_ref => "cluster")
)
expect(host.hardware).to have_attributes(
:cpu_total_cores => 8,
:memory_mb => 32_096
)
end
def assert_specific_vm
vm = ems.vms.find_by(:ems_ref => "100")
expect(vm).to have_attributes(
:vendor => "proxmox",
:name => "vmpvevm1",
:location => "vmpvetest/100",
:host => ems.hosts.find_by(:ems_ref => "vmpvetest"),
:ems_cluster => ems.ems_clusters.find_by(:ems_ref => "cluster"),
:uid_ems => "100",
:ems_ref => "100",
:power_state => "on",
:raw_power_state => "running",
:tools_status => "toolsOk"
)
assert_specific_vm_hardware(vm)
assert_specific_vm_disks(vm)
assert_specific_vm_networks(vm)
assert_specific_vm_os(vm)
end
def assert_specific_vm_hardware(vm)
expect(vm.hardware).to have_attributes(
:cpu_total_cores => 4,
:memory_mb => 2048,
:disk_capacity => 10_737_418_240
)
end
def assert_specific_vm_disks(vm)
expect(vm.hardware.disks.count).to be >= 3
scsi0 = vm.hardware.disks.find_by(:device_name => "scsi0")
expect(scsi0).to have_attributes(
:device_type => "disk",
:controller_type => "scsi",
:size => 10_737_418_240,
:location => "scsi0",
:filename => "local-lvm:vm-100-disk-1"
)
scsi1 = vm.hardware.disks.find_by(:device_name => "scsi1")
expect(scsi1).to have_attributes(
:device_type => "disk",
:controller_type => "scsi",
:size => 2_147_483_648,
:location => "scsi1"
)
scsi2 = vm.hardware.disks.find_by(:device_name => "scsi2")
expect(scsi2).to have_attributes(
:device_type => "disk",
:controller_type => "scsi",
:size => 3_221_225_472,
:location => "scsi2"
)
end
def assert_specific_vm_networks(vm)
expect(vm.hardware.networks.count).to be >= 1
ens18 = vm.hardware.networks.find_by(:description => "ens18")
expect(ens18).to have_attributes(
:hostname => "vmpvevm1",
:ipaddress => "192.0.2.253"
)
guest_device = vm.hardware.guest_devices.find_by(:device_name => "ens18")
expect(guest_device).to have_attributes(
:device_type => "ethernet",
:controller_type => "ethernet",
:address => "bc:24:11:e2:9f:14"
)
end
def assert_specific_vm_os(vm)
expect(vm.operating_system).to have_attributes(
:product_name => "Debian GNU/Linux 13 (trixie)"
)
end
def assert_specific_template
template = ems.miq_templates.find_by(:ems_ref => "900")
expect(template).to have_attributes(
:vendor => "proxmox",
:name => "debian-13-2025-11-17T19-50-19Z-00000000",
:location => "vmpvetest/900",
:host => ems.hosts.find_by(:ems_ref => "vmpvetest"),
:ems_cluster => ems.ems_clusters.find_by(:ems_ref => "cluster"),
:uid_ems => "900",
:ems_ref => "900",
:power_state => "never",
:raw_power_state => "never"
)
end
end