-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from nasark/vm_events
VM event parsing specs (cherry picked from commit 41cd387)
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
spec/models/manageiq/providers/kubevirt/infra_manager/event_parser_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |