forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathems_event_helper_spec.rb
138 lines (125 loc) · 8.25 KB
/
ems_event_helper_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
130
131
132
133
134
135
136
137
138
RSpec.describe EmsEventHelper do
context "fb12322 - MiqAeEvent.build_evm_event blows up expecting inputs[:policy] to be an instance of MiqPolicy, but it is a hash of { :vmdb_class => 'MiqPolicy', :vmdb_id => 42}" do
before do
[Zone, ExtManagementSystem, Host, Vm, Storage, EmsEvent, MiqEventDefinition, MiqPolicy, MiqAction, MiqPolicyContent, MiqPolicySet].each(&:delete_all)
@zone = FactoryBot.create(:zone)
@ems = FactoryBot.create(:ems_vmware,
:zone => @zone,
:name => 'vc7',
:hostname => 'vc7.manageiq.com',
:ipaddress => '10.10.10.2'
)
@storage = FactoryBot.create(:storage,
:name => 'StarM1-Demo5',
:store_type => 'VMFS'
)
@host = FactoryBot.create(:host,
:name => 'host7',
:ext_management_system => @ems,
:vmm_vendor => 'vmware',
:vmm_version => '4.0.0',
:vmm_product => 'ESX',
:vmm_buildnumber => 261974,
:ipaddress => '192.168.252.28',
:hostname => 'host7.manageiq.com'
)
@vm = FactoryBot.create(:vm_vmware,
:ext_management_system => @ems,
:name => 'vm42',
:location => 'vm42/vm42.vmx',
:storage => @storage
)
@username = 'fred'
@chain_id = 12345
@ems_events = []
@ems_events << FactoryBot.create(:ems_event,
:event_type => 'PowerOnVM_Task',
:message => 'Task: Power On virtual machine',
:host_name => @host.ipaddress,
:timestamp => Time.now,
:ext_management_system => @ems,
:host => @host,
:vm => @vm,
:vm_name => @vm.name,
:vm_location => @vm.path,
:source => 'VC',
:chain_id => @chain_id,
:is_task => false,
:username => @username
)
@ems_events << FactoryBot.create(:ems_event,
:event_type => 'VmStartingEvent',
:message => "#{@vm.name} on host #{@host.ipaddress} in DC1 is starting",
:host_name => @host.ipaddress,
:timestamp => Time.now,
:ext_management_system => @ems,
:host => @host,
:vm => @vm,
:vm_name => @vm.name,
:vm_location => @vm.path,
:source => 'VC',
:chain_id => @chain_id,
:is_task => false,
:username => @username
)
@ems_events << FactoryBot.create(:ems_event,
:event_type => 'VmPoweredOnEvent',
:message => "#{@vm.name} on #{@host.ipaddress} in DC1 is powered on",
:host_name => @host.ipaddress,
:timestamp => Time.now,
:ext_management_system => @ems,
:host => @host,
:vm => @vm,
:vm_name => @vm.name,
:vm_location => @vm.path,
:source => 'VC',
:chain_id => @chain_id,
:is_task => false,
:username => @username
)
@ems_events << FactoryBot.create(:ems_event,
:event_type => 'PowerOnVM_Task_Complete',
:message => 'PowerOnVM_Task Completed',
:host_name => @host.ipaddress,
:timestamp => Time.now,
:ext_management_system => @ems,
:host => @host,
:vm => @vm,
:vm_name => @vm.name,
:vm_location => @vm.path,
:source => 'EVM',
:chain_id => 12345,
:is_task => false,
:username => @username
)
@miq_event_vm_start = FactoryBot.create(:miq_event_definition, :name => 'vm_start', :description => 'VM Power On')
@policy_set = FactoryBot.create(:miq_policy_set)
@policy = FactoryBot.create(:miq_policy, :towhat => 'Vm', :active => true, :mode => 'control')
automate_options = {:ae_message => 'create', :ae_hash => {"kevin" => "1", "q" => "1"}}
@action = FactoryBot.create(:miq_action, :description => 'create_incident', :action_type => 'custom_automation', :options => automate_options)
@policy_set.add_member(@policy)
@policy_content = FactoryBot.create(:miq_policy_content,
:miq_policy => @policy,
:miq_action => @action,
:miq_event_definition => @miq_event_vm_start,
:qualifier => 'success',
:success_sequence => 1,
:success_synchronous => true)
@vm.add_policy(@policy)
end
it "should handle event properly" do
routine = [ { "policy" => ["src_vm", "vm_start"] } ]
policy = routine.first["policy"]
event = @ems_events.last
expect { event.policy(policy[0], policy[1]) }.to_not raise_error
end
it "should build evm event properly calling MiqAeEvent.build_evm_event" do
inputs = {:ae_message => 'create', :ae_hash => {"kevin" => "1", "q" => "1"}, :vm => @vm}
aevent = MiqAeEvent.build_evm_event("vm_start", inputs)
expect(aevent[:vm_id]).to eq(@vm.id)
expect(aevent["VmOrTemplate::vm"]).to eq(@vm.id)
expect(aevent[:ae_hash]["kevin"]).to eq("1")
expect(aevent[:ae_hash]["q"]).to eq("1")
end
end
end