Project

General

Profile

« Previous | Next » 

Revision 1799cee8

Added by Shimon Shtein about 8 years ago

Fixes #10183 - Added a default results transformation for status action

View differences:

test/unit/power_manager_test.rb
host.unstub(:queue_compute)
host.stubs(:compute_resource).returns(compute_resource_mock)
host.power.send(:action_map).values.uniq.each do |action|
(actions_list(host) - ['virt_state']).each do |action|
vm_mock.expects(action.to_sym).at_least_once.returns(true)
end
vm_mock.expects('state').at_least_once.returns('On')
vm_mock.stubs(:reload).returns(true)
PowerManager::SUPPORTED_ACTIONS.each do |action|
......
host.stubs(:bmc_proxy).returns(bmc_proxy_mock)
host.stubs(:bmc_available?).returns(true)
(host.power.send(:action_map).values.uniq - ['status']).each do |action|
(actions_list(host) - ['status', 'ready?']).each do |action|
bmc_proxy_mock.expects(:power).with(:action => action).at_least_once.returns(true)
end
bmc_proxy_mock.expects(:power).with(:action => 'status').at_least_once.returns('on')
......
assert_includes PowerManager::SUPPORTED_ACTIONS, action
end
end
context '#status' do
setup do
@vm_mock = mock('vm')
compute_resource_mock = mock('compute_resource')
compute_resource_mock.stubs(:find_vm_by_uuid).returns(@vm_mock)
@host = FactoryGirl.build(:host, :on_compute_resource)
@host.unstub(:queue_compute)
@host.stubs(:compute_resource).returns(compute_resource_mock)
@vm_mock.stubs(:reload).returns(true)
end
test "should respond correctly to status when compute resource is started" do
@vm_mock.expects(:state).at_least_once.returns('Started')
result = @host.power.status
assert_equal 'on', result
end
test "should respond correctly to status when compute resource is paused" do
@vm_mock.expects(:state).at_least_once.returns('Paused')
result = @host.power.state
assert_equal 'off', result
end
end
def actions_list(host)
action_map = host.power.send(:action_map)
actions = PowerManager::SUPPORTED_ACTIONS - action_map.keys.map { |k| k.to_s }
action_map.each do |key, value|
action_entry = value
action_entry = {:action => value.to_sym} unless value.is_a?(Hash)
action = action_entry[:action]
actions << action.to_s if action
end
actions.uniq
end
end

Also available in: Unified diff