Skip to content

Commit cfd2f3f

Browse files
committed
Merge pull request josqu4red#1 from vinted/master
Implementation for set_persistent_boot
2 parents 92184dc + bfbcec2 commit cfd2f3f

File tree

8 files changed

+231
-12
lines changed

8 files changed

+231
-12
lines changed

Gemfile.lock

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,40 @@ PATH
88
GEM
99
remote: https://rubygems.org/
1010
specs:
11+
addressable (2.3.5)
12+
coderay (1.0.9)
13+
crack (0.4.1)
14+
safe_yaml (~> 0.9.0)
15+
diff-lcs (1.2.4)
16+
method_source (0.8.1)
1117
mini_portile (0.5.0)
1218
nokogiri (1.6.0)
1319
mini_portile (~> 0.5.0)
1420
nori (2.2.0)
21+
pry (0.9.12.2)
22+
coderay (~> 1.0.5)
23+
method_source (~> 0.8)
24+
slop (~> 3.4)
25+
rspec (2.14.1)
26+
rspec-core (~> 2.14.0)
27+
rspec-expectations (~> 2.14.0)
28+
rspec-mocks (~> 2.14.0)
29+
rspec-core (2.14.3)
30+
rspec-expectations (2.14.0)
31+
diff-lcs (>= 1.1.3, < 2.0)
32+
rspec-mocks (2.14.1)
33+
safe_yaml (0.9.4)
34+
slop (3.4.5)
35+
webmock (1.13.0)
36+
addressable (>= 2.2.7)
37+
crack (>= 0.3.2)
1538

1639
PLATFORMS
1740
ruby
1841

1942
DEPENDENCIES
2043
bundler (~> 1.2)
2144
ilorb!
45+
pry
46+
rspec (~> 2.14)
47+
webmock (~> 1.13)

ilorb.gemspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
2020
spec.require_paths = ["lib"]
2121

2222
spec.add_development_dependency "bundler", "~> 1.2"
23+
spec.add_development_dependency "rspec", "~> 2.14"
24+
spec.add_development_dependency "webmock", "~> 1.13"
25+
spec.add_development_dependency "pry"
2326
spec.add_dependency "nokogiri"
2427
spec.add_dependency "nori"
2528
end

lib/ilorb/definitions/server.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
attributes :value
3737
end
3838
write_cmd :set_persistent_boot do
39-
not_implemented
39+
elements :device => [ :value ]
4040
end
4141
write_cmd :set_power_cap do
4242
attributes :power_cap

lib/ilorb/ilo.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def method_missing(name, *args, &block)
3636

3737
params = args.first || {}
3838
attributes = {}
39-
elements = {}
4039
element_map = nil
4140

4241
#TODO check for text
@@ -48,23 +47,32 @@ def method_missing(name, *args, &block)
4847
end
4948

5049
element_map = command.map_elements
51-
params.each do |key, value|
52-
# Elements are not mandatory for now
53-
elements.store(key, @ribcl.encode(params.delete(key))) if element_map.has_key?(key)
50+
51+
elements_array = []
52+
53+
[ params ].flatten.each do |params_hash|
54+
elements = {}
55+
params_hash.each do |key, value|
56+
# Elements are not mandatory for now
57+
elements.store(key, @ribcl.encode(params_hash.delete(key))) if element_map.has_key?(key)
58+
end
59+
elements_array << elements
5460
end
5561

5662
#TODO check for CDATA
5763

5864
@log.info("Calling method #{name}")
5965
request = ribcl_request(command, attributes) do |xml|
60-
elements.each do |key, value|
61-
elt = command.get_elements[element_map[key].first]
62-
if elt.is_a?(Array)
63-
attrs = Hash[elt.map{|x| [x, elements.delete(element_map.invert[[element_map[key].first, x]])]}]
64-
else
65-
attrs = {element_map[key].last => value}
66+
elements_array.each do |elements_hash|
67+
elements_hash.each do |key, value|
68+
elt = command.get_elements[element_map[key].first]
69+
if elt.is_a?(Array)
70+
attrs = Hash[elt.map{|x| [x, elements_hash.delete(element_map.invert[[element_map[key].first, x]])]}]
71+
else
72+
attrs = {element_map[key].last => value}
73+
end
74+
xml.send(element_map[key].first, attrs)
6675
end
67-
xml.send(element_map[key].first, attrs)
6876
end
6977
end
7078

spec/assets/basic_response.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<RIBCL VERSION="2.22">
3+
<RESPONSE
4+
STATUS="0x0000"
5+
MESSAGE='No error'
6+
/>
7+
</RIBCL>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0"?>
2+
<RIBCL VERSION="2.22">
3+
<RESPONSE
4+
STATUS="0x0000"
5+
MESSAGE='No error'
6+
/>
7+
<GET_NETWORK_SETTINGS>
8+
<ENABLE_NIC VALUE="Y"/>
9+
<SHARED_NETWORK_PORT VALUE="N"/>
10+
<VLAN_ENABLED VALUE="N"/>
11+
<VLAN_ID VALUE="0"/>
12+
<SPEED_AUTOSELECT VALUE="Y"/>
13+
<NIC_SPEED VALUE="Automatic"/>
14+
<FULL_DUPLEX VALUE="Automatic"/>
15+
<DHCP_ENABLE VALUE="Y"/>
16+
<DHCP_GATEWAY VALUE="N"/>
17+
<DHCP_DNS_SERVER VALUE="Y"/>
18+
<DHCP_WINS_SERVER VALUE="N"/>
19+
<DHCP_STATIC_ROUTE VALUE="N"/>
20+
<DHCP_DOMAIN_NAME VALUE="N"/>
21+
<DHCP_SNTP_SETTINGS VALUE="Y"/>
22+
<REG_WINS_SERVER VALUE="N"/>
23+
<REG_DDNS_SERVER VALUE="N"/>
24+
<PING_GATEWAY VALUE="N"/>
25+
<MAC_ADDRESS VALUE="1c:c1:de:17:b3:90"/>
26+
<IP_ADDRESS VALUE="192.168.1.13"/>
27+
<SUBNET_MASK VALUE="255.255.255.0"/>
28+
<GATEWAY_IP_ADDRESS VALUE="0.0.0.0"/>
29+
<DNS_NAME VALUE="weezer"/>
30+
<DOMAIN_NAME VALUE="ilotest.com."/>
31+
<PRIM_DNS_SERVER VALUE="0.0.0.0"/>
32+
<SEC_DNS_SERVER VALUE="0.0.0.0"/>
33+
<TER_DNS_SERVER VALUE="0.0.0.0"/>
34+
<PRIM_WINS_SERVER VALUE="0.0.0.0"/>
35+
<SEC_WINS_SERVER VALUE="0.0.0.0"/>
36+
<SNTP_SERVER1 VALUE="192.168.1.5"/>
37+
<SNTP_SERVER2 VALUE=""/>
38+
<TIMEZONE VALUE="CST6CDT"/>
39+
<STATIC_ROUTE_1 DEST="0.0.0.0"
40+
MASK="0.0.0.0"
41+
GATEWAY="0.0.0.0"/>
42+
<STATIC_ROUTE_2 DEST="0.0.0.0"
43+
MASK="0.0.0.0"
44+
GATEWAY="0.0.0.0"/>
45+
<STATIC_ROUTE_3 DEST="0.0.0.0"
46+
MASK="0.0.0.0"
47+
GATEWAY="0.0.0.0"/>
48+
<IPV6_ADDRESS VALUE="2001:2:1::15"
49+
PREFIXLEN="64"
50+
ADDR_SOURCE="STATIC"
51+
ADDR_STATUS="ACTIVE"/>
52+
<IPV6_ADDRESS VALUE="2001:db8:1::50"
53+
PREFIXLEN="64"
54+
ADDR_SOURCE="STATIC"
55+
ADDR_STATUS="ACTIVE"/>
56+
<IPV6_ADDRESS VALUE="fe80::1ec1:deff:fe17:b390"
57+
PREFIXLEN="64"
58+
ADDR_SOURCE="SLAAC"
59+
ADDR_STATUS="ACTIVE"/>
60+
<IPV6_ADDRESS VALUE="2001:2:1:0:1ec1:deff:fe17:b390"
61+
PREFIXLEN="64"
62+
ADDR_SOURCE="SLAAC"
63+
ADDR_STATUS="ACTIVE"/>
64+
<IPV6_STATIC_ROUTE_1
65+
IPV6_DEST="2001:2:2::20"
66+
PREFIXLEN="64"
67+
IPV6_GATEWAY="fe80::1:2:3"
68+
ADDR_STATUS="ACTIVE"/>
69+
<IPV6_STATIC_ROUTE_2
70+
IPV6_DEST="::"
71+
PREFIXLEN="0"
72+
IPV6_GATEWAY="::"
73+
ADDR_STATUS="INACTIVE"/>
74+
<IPV6_STATIC_ROUTE_3
75+
IPV6_DEST="2001:1001:2002:3003::"
76+
PREFIXLEN="64"
77+
IPV6_GATEWAY="2001:db8:1::40"
78+
ADDR_STATUS="ACTIVE"/>
79+
<IPV6_PRIM_DNS_SERVER VALUE="2001:1:2::5"/>
80+
<IPV6_SEC_DNS_SERVER VALUE="2001:1:2::6"/>
81+
<IPV6_TER_DNS_SERVER VALUE="::"/>
82+
<IPV6_DEFAULT_GATEWAY VALUE="fe80::21c:c4ff:fe18:9cbd"/>
83+
<IPV6_PREFERRED_PROTOCOL VALUE="Y"/>
84+
<IPV6_ADDR_AUTOCFG VALUE="Y"/>
85+
<IPV6_REG_DDNS_SERVER VALUE="Y"/>
86+
</GET_NETWORK_SETTINGS>
87+
</RIBCL>

spec/ilo_spec.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
require 'spec_helper'
2+
3+
describe ILORb::ILO do
4+
let(:hostname) { "10.200.0.1" }
5+
let(:login) { "Admin" }
6+
let(:password) { "SECRET" }
7+
let(:ilo) { ILORb::ILO.new(hostname: hostname, login: login, password: password) }
8+
9+
describe "#get_network_settings" do
10+
before do
11+
stub_request(:post, "https://10.200.0.1/ribcl").
12+
with(:body => "<?xml version=\"1.0\"?>\n<ribcl version=\"2.0\">\n <login password=\"SECRET\" user_login=\"Admin\">\n <rib_info mode=\"read\">\n <get_network_settings/>\n </rib_info>\n </login>\n</ribcl>\n").
13+
to_return(:status => 200, :body => asset_file('get_network_settings_response.xml'))
14+
end
15+
16+
subject { ilo.get_network_settings }
17+
18+
its([:status]) { should include(code: 0, message: 'No error') }
19+
its([:get_network_settings]) { should_not be_empty }
20+
end
21+
22+
describe "#set_one_time_boot" do
23+
before do
24+
stub_request(:post, "https://10.200.0.1/ribcl").
25+
with(:body => "<?xml version=\"1.0\"?>\n<ribcl version=\"2.0\">\n <login password=\"SECRET\" user_login=\"Admin\">\n <server_info mode=\"write\">\n <set_one_time_boot value=\"FLOPPY\"/>\n </server_info>\n </login>\n</ribcl>\n").
26+
to_return(:status => 200, :body => asset_file('basic_response.xml'))
27+
end
28+
29+
subject { ilo.set_one_time_boot(value: "FLOPPY") }
30+
31+
its([:status]) { should include(code: 0, message: 'No error') }
32+
end
33+
34+
describe "#set_pwreg" do
35+
before do
36+
stub_request(:post, "https://10.200.0.1/ribcl").
37+
with(:body => "<?xml version=\"1.0\"?>\n<ribcl version=\"2.0\">\n <login password=\"SECRET\" user_login=\"Admin\">\n <server_info mode=\"write\">\n <set_pwreg>\n <pwralert type=\"PEAK\"/>\n <pwralert_settings threshold=\"200\" duration=\"35\"/>\n </set_pwreg>\n </server_info>\n </login>\n</ribcl>\n").
38+
to_return(:status => 200, :body => asset_file('basic_response.xml'))
39+
end
40+
41+
subject { ilo.set_pwreg pwralert_type: "PEAK",
42+
pwralert_settings_threshold: 200,
43+
pwralert_settings_duration: 35 }
44+
45+
its([:status]) { should include(code: 0, message: 'No error') }
46+
end
47+
48+
describe "#set_one_time_boot" do
49+
before do
50+
stub_request(:post, "https://10.200.0.1/ribcl").
51+
with(:body => "<?xml version=\"1.0\"?>\n<ribcl version=\"2.0\">\n <login password=\"SECRET\" user_login=\"Admin\">\n <server_info mode=\"write\">\n <set_one_time_boot value=\"FLOPPY\"/>\n </server_info>\n </login>\n</ribcl>\n").
52+
to_return(:status => 200, :body => asset_file('basic_response.xml'))
53+
end
54+
55+
subject { ilo.set_one_time_boot(value: "FLOPPY") }
56+
57+
its([:status]) { should include(code: 0, message: 'No error') }
58+
end
59+
60+
describe "#set_persistent_boot" do
61+
before do
62+
stub_request(:post, "https://10.200.0.1/ribcl").
63+
with(:body => "<?xml version=\"1.0\"?>\n<ribcl version=\"2.0\">\n <login password=\"SECRET\" user_login=\"Admin\">\n <server_info mode=\"write\">\n <set_persistent_boot>\n <device value=\"FLOPPY\"/>\n <device value=\"CDROM\"/>\n </set_persistent_boot>\n </server_info>\n </login>\n</ribcl>\n").
64+
to_return(:status => 200, :body => asset_file('basic_response.xml'))
65+
end
66+
67+
subject { ilo.set_persistent_boot([{ device_value: "FLOPPY" },
68+
{ device_value: "CDROM" }]) }
69+
70+
its([:status]) { should include(code: 0, message: 'No error') }
71+
end
72+
73+
private
74+
75+
def asset_file(asset)
76+
path = File.join(File.dirname(__FILE__), 'assets', asset)
77+
File.new(path)
78+
end
79+
end

spec/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'rubygems'
2+
require 'bundler/setup'
3+
require 'ilorb'
4+
require 'webmock/rspec'
5+
require 'pry'
6+
7+
RSpec.configure do |config|
8+
config.order = "random"
9+
end

0 commit comments

Comments
 (0)