Skip to content

Commit

Permalink
Merge pull request #258 from nasark/vm_events
Browse files Browse the repository at this point in the history
VM event parsing specs

(cherry picked from commit 41cd387)
  • Loading branch information
agrare authored and Fryguy committed Jan 7, 2025
1 parent 09b3f4d commit c182027
Showing 1 changed file with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
describe ManageIQ::Providers::Kubevirt::InfraManager::EventParser do
let(:vm_started) do
{
"object" => {
"involvedObject" => {
"kind" => "VirtualMachine",
"namespace" => "test-namespace",
"name" => "test-vm",
"uid" => "123-456-789"
},
"metadata" => {
"uid" => "987-654-321"
},
"reason" => "Started",
"message" => "VirtualMachine started",
"lastTimestamp" => "2024-11-19T16:29:11Z"
}
}
end

let(:vmi_shutdown) do
{
"object" => {
"involvedObject" => {
"kind" => "VirtualMachineInstance",
"namespace" => "test-namespace",
"name" => "test-vm",
"uid" => "123-456-789"
},
"metadata" => {
"uid" => "987-654-321"
},
"reason" => "ShuttingDown",
"message" => "VirtualMachineInstance shuttingdown",
"lastTimestamp" => "2024-11-19T16:29:11Z"
}
}
end

context 'event_to_hash' do
it 'parses vm started into event' do
event = RecursiveOpenStruct.new(vm_started, :recurse_over_arrays => true)
hash = described_class.event_to_hash(event, nil, "KUBEVIRT")

expect(hash).to include(
:event_type => 'VIRTUALMACHINE_STARTED',
:source => 'KUBEVIRT',
:timestamp => "2024-11-19T16:29:11Z",
:message => "VirtualMachine started",
:container_namespace => "test-namespace",
:full_data => event.to_h,
:ems_id => nil,
:ems_ref => "987-654-321",
:vm_name => "test-vm",
:vm_ems_ref => "123-456-789"
)
end

it 'parses vmi shutdown into event' do
event = RecursiveOpenStruct.new(vmi_shutdown, :recurse_over_arrays => true)
hash = described_class.event_to_hash(event, nil, "KUBEVIRT")

expect(hash).to include(
:event_type => 'VIRTUALMACHINEINSTANCE_SHUTTINGDOWN',
:source => 'KUBEVIRT',
:timestamp => "2024-11-19T16:29:11Z",
:message => "VirtualMachineInstance shuttingdown",
:container_namespace => "test-namespace",
:full_data => event.to_h,
:ems_id => nil,
:ems_ref => "987-654-321",
:vm_name => "test-vm",
:vm_ems_ref => "123-456-789"
)
end
end
end

0 comments on commit c182027

Please sign in to comment.