foreman/test/unit/proxy_api/bmc_test.rb @ 9d43fc71
f2b2117f | Corey Osman | require 'test_helper'
|
|
feacea35 | Amos Benari | require "mocha/setup"
|
|
f2b2117f | Corey Osman | ||
class ProxyApiBmcTest < ActiveSupport::TestCase
|
|||
def setup
|
|||
df1215f9 | Lukas Zapletal | @url = "http://dummyproxy.theforeman.org:8443"
|
|
f2b2117f | Corey Osman | @options = {:username => "testuser", :password => "fakepass"}
|
|
@testbmc = ProxyAPI::BMC.new({:user => "admin", :password => "secretpass", :url => @url})
|
|||
end
|
|||
test "constructor should complete" do
|
|||
assert_not_nil(@testbmc)
|
|||
end
|
|||
test "base url should equal /bmc" do
|
|||
9d43fc71 | Michael Moll | expected = @url + "/bmc"
|
|
f2b2117f | Corey Osman | assert_equal(expected, @testbmc.url)
|
|
end
|
|||
test "providers should get list of providers" do
|
|||
expected = ["freeipmi", "ipmitool"]
|
|||
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(expected))
|
|
f2b2117f | Corey Osman | assert_equal(expected, @testbmc.providers)
|
|
end
|
|||
test "providers installed should get list of installed providers" do
|
|||
expected = ["freeipmi", "ipmitool"]
|
|||
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(expected))
|
|
f2b2117f | Corey Osman | assert_equal(expected, @testbmc.providers_installed)
|
|
end
|
|||
test "boot function should raise nomethod exception when function does not exist" do
|
|||
assert_raise NoMethodError do
|
|||
@testbmc.boot_fake(@options)
|
|||
end
|
|||
end
|
|||
test "power function should raise nomethod exception when function does not exist" do
|
|||
assert_raise NoMethodError do
|
|||
@testbmc.power_fake(@options)
|
|||
end
|
|||
end
|
|||
test "identify function should raise nomethod exception when function does not exist" do
|
|||
assert_raise NoMethodError do
|
|||
@testbmc.identify_fake(@options)
|
|||
end
|
|||
end
|
|||
test "lan function should raise nomethod exception when function does not exist" do
|
|||
assert_raise NoMethodError do
|
|||
@testbmc.lan_fake(@options)
|
|||
end
|
|||
end
|
|||
test "boot function should not raise nomethod exception when function does exist" do
|
|||
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
0fe147c7 | Joseph Mitchell Magen | @testbmc.boot_pxe(@options)
|
|
f2b2117f | Corey Osman | end
|
|
test "boot function should create correct url for bootdevice pxe" do
|
|||
device = "pxe"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:function => "bootdevice", :device => device})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.boot_pxe(@options)
|
|||
end
|
|||
test "boot function should create correct url for bootdevice disk" do
|
|||
device = "disk"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:function => "bootdevice", :device => device})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.boot_disk(@options)
|
|||
end
|
|||
test "boot function should create correct url for bootdevice cdrom" do
|
|||
device = "cdrom"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:function => "bootdevice", :device => device})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.boot_cdrom(@options)
|
|||
end
|
|||
test "boot function should create correct url for bootdevice bios" do
|
|||
device = "bios"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/config/bootdevice/#{device}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:function => "bootdevice", :device => device})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.boot_bios(@options)
|
|||
end
|
|||
test "power function should create correct url for off" do
|
|||
action = "off"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/power/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.power_off(@options)
|
|||
end
|
|||
test "power function should create correct url for on" do
|
|||
action = "on"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/power/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.power_on(@options)
|
|||
end
|
|||
test "power function should create correct url for cycle" do
|
|||
action = "cycle"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/power/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.power_cycle(@options)
|
|||
end
|
|||
test "power function should create correct url for soft" do
|
|||
action = "soft"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/power/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response({"result" => true}))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.power_soft(@options)
|
|||
end
|
|||
test "power function should create correct url for off?" do
|
|||
action = "off"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/power/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.power_off?(@options)
|
|||
end
|
|||
test "power function should create correct url for on?" do
|
|||
action = "on"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/power/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.power_on?(@options)
|
|||
end
|
|||
test "power function should create correct url for status" do
|
|||
action = "status"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/power/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.power_status(@options)
|
|||
end
|
|||
test "identify function should create correct url for off" do
|
|||
action = "off"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/identify/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.identify_off(@options)
|
|||
end
|
|||
test "identify function should create correct url for on" do
|
|||
action = "on"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/identify/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:put).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:put).with(data, expected_path).at_least_once
|
|
@testbmc.identify_on(@options)
|
|||
end
|
|||
test "identify function should create correct url for status" do
|
|||
action = "status"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/chassis/identify/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.identify_status(@options)
|
|||
end
|
|||
test "lan function should create correct url for ip" do
|
|||
action = "ip"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/lan/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.lan_ip(@options)
|
|||
end
|
|||
test "lan function should create correct url for netmask" do
|
|||
action = "netmask"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/lan/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.lan_netmask(@options)
|
|||
end
|
|||
test "lan function should create correct url for gateway" do
|
|||
action = "gateway"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/lan/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.lan_gateway(@options)
|
|||
end
|
|||
test "lan function should create correct url for mac" do
|
|||
action = "mac"
|
|||
1377f89a | Greg Sutcliffe | expected_path = "/127.0.0.1/lan/#{action}"
|
|
f2b2117f | Corey Osman | data = @options.merge({:action => action})
|
|
6e7af6fc | Dominic Cleal | @testbmc.stubs(:get).returns(fake_rest_client_response(["fakedata"]))
|
|
f2b2117f | Corey Osman | @testbmc.expects(:get).with(expected_path, data).at_least_once
|
|
@testbmc.lan_mac(@options)
|
|||
end
|
|||
01ffb230 | Timo Goebel | ||
context '#power' do
|
|||
test "should return true when result was true" do
|
|||
data = stub_bmc_power_response('cycle', true)
|
|||
assert_equal true, @testbmc.power(data)
|
|||
end
|
|||
test "should return true when result was ok" do
|
|||
data = stub_bmc_power_response('cycle', "127.0.0.1: ok\n")
|
|||
assert_equal true, @testbmc.power(data)
|
|||
end
|
|||
test "should return false when result was not ok" do
|
|||
data = stub_bmc_power_response('cycle', 'error')
|
|||
assert_equal false, @testbmc.power(data)
|
|||
end
|
|||
end
|
|||
private
|
|||
def stub_bmc_power_response(action, result)
|
|||
data = @options.merge({:action => action})
|
|||
@testbmc.stubs(:put).returns(
|
|||
fake_rest_client_response(
|
|||
{
|
|||
'action' => action,
|
|||
'result' => result
|
|||
}
|
|||
)
|
|||
)
|
|||
data
|
|||
end
|
|||
1377f89a | Greg Sutcliffe | end
|