[PATCH/foreman 1/1] fixes #1186 foreman does not forward sparc dhcp vendor options when creating a sparc Solaris host

Signed-off-by: Ohad Levy <ohadlevy@gmail.com>

··· --- app/models/orchestration/dhcp.rb | 4 ++-- app/models/solaris.rb | 17 +++++++++-------- lib/net.rb | 2 -- lib/net/dhcp.rb | 6 ++++++ lib/net/{dhcp_record.rb => dhcp/record.rb} | 4 ++-- lib/net/dhcp/sparc_record.rb | 25 +++++++++++++++++++++++++ lib/proxy_api.rb | 9 +++++++-- test/lib/net/dhcp_test.rb | 14 +++++++------- test/lib/net/net_test.rb | 8 ++++---- test/unit/orchestration/dhcp_test.rb | 22 ++++++++++++---------- 10 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 lib/net/dhcp.rb rename lib/net/{dhcp_record.rb => dhcp/record.rb} (97%) create mode 100644 lib/net/dhcp/sparc_record.rb

diff --git a/app/models/orchestration/dhcp.rb b/app/models/orchestration/dhcp.rb
index 0d21675…7df33a0 100644
— a/app/models/orchestration/dhcp.rb
+++ b/app/models/orchestration/dhcp.rb
@@ -20,12 +20,12 @@ module Orchestration::DHCP

 def dhcp_record
   return unless dhcp?
  •  @dhcp_record ||= Net::DhcpRecord.new dhcp_attrs
    
  •  @dhcp_record ||= jumpstart? ? Net::DHCP::SparcRecord.new(dhcp_attrs) : Net::DHCP::Record.new(dhcp_attrs)
    

    end

    def sp_dhcp_record
    return unless sp_dhcp?

  •  @sp_dhcp_record ||= Net::DhcpRecord.new sp_dhcp_attrs
    
  •  @sp_dhcp_record ||= Net::DHCP::Record.new sp_dhcp_attrs
    

    end

    protected
    diff --git a/app/models/solaris.rb b/app/models/solaris.rb
    index c5b0281…3290b63 100644
    — a/app/models/solaris.rb
    +++ b/app/models/solaris.rb
    @@ -92,14 +92,15 @@ class Solaris < Operatingsystem
    ipath = interpolate_medium_vars(host.medium.media_dir, host.architecture.name, self)

    {

  • “<#{vendor}>root_server_ip” => server_ip, # 192.168.216.241
  • “<#{vendor}>root_server_hostname” => server_name, # mediahost
  • “<#{vendor}>root_path_name” => “#{ipath}/Solaris_#{minor}/Tools/Boot”, # /vol/solgi_5.10/sol10_hw0910/Solaris_10/Tools/Boot
  • “<#{vendor}>install_server_ip” => server_ip, # 192.168.216.241
  • “<#{vendor}>install_server_name” => server_name, # mediahost
  • “<#{vendor}>install_path” => ipath, # /vol/solgi_5.10/sol10_hw0910
  • “<#{vendor}>sysid_server_path” => “#{jpath}/sysidcfg/sysidcfg_primary”, # 192.168.216.241:/vol/jumpstart/sysidcfg/sysidcfg_primary
  • “<#{vendor}>jumpstart_server_path” => jpath, # 192.168.216.241:/vol/jumpstart
  •  :vendor => "<#{vendor}>",
    
  •  :root_server_ip        => server_ip,                              # 192.168.216.241
    
  •  :root_server_hostname  => server_name,                            # mediahost
    
  •  :root_path_name        => "#{ipath}/Solaris_#{minor}/Tools/Boot", # /vol/solgi_5.10/sol10_hw0910/Solaris_10/Tools/Boot
    
  •  :install_server_ip     => server_ip,                              # 192.168.216.241
    
  •  :install_server_name   => server_name,                            # mediahost
    
  •  :install_path          => ipath,                                  # /vol/solgi_5.10/sol10_hw0910
    
  •  :sysid_server_path     => "#{jpath}/sysidcfg/sysidcfg_primary",   # 192.168.216.241:/vol/jumpstart/sysidcfg/sysidcfg_primary
    
  •  :jumpstart_server_path => jpath,                                  # 192.168.216.241:/vol/jumpstart
    
    }
    end

diff --git a/lib/net.rb b/lib/net.rb
index 7085540…5f39100 100644
— a/lib/net.rb
+++ b/lib/net.rb
@@ -1,6 +1,4 @@
module Net

  • autoload :DhcpRecord, “net/dhcp_record.rb”
  • class Record
    include Net::Validations
    attr_accessor :hostname, :proxy, :logger
    diff --git a/lib/net/dhcp.rb b/lib/net/dhcp.rb
    new file mode 100644
    index 0000000…56f719f
    — /dev/null
    +++ b/lib/net/dhcp.rb
    @@ -0,0 +1,6 @@
    +module Net
  • module DHCP
  • autoload :Record, “net/dhcp/record.rb”
  • autoload :SparcRecord, “net/dhcp/sparc_record.rb”
  • end
    +end
    diff --git a/lib/net/dhcp_record.rb b/lib/net/dhcp/record.rb
    similarity index 97%
    rename from lib/net/dhcp_record.rb
    rename to lib/net/dhcp/record.rb
    index d7955d0…1ec639c 100644
    — a/lib/net/dhcp_record.rb
    +++ b/lib/net/dhcp/record.rb
    @@ -1,5 +1,5 @@
    -module Net
  • class DhcpRecord < Record
    +module Net::DHCP
  • class Record < Net::Record
    attr_accessor :ip, :mac, :network, :nextServer, :filename

    def initialize opts = { }
    diff --git a/lib/net/dhcp/sparc_record.rb b/lib/net/dhcp/sparc_record.rb
    new file mode 100644
    index 0000000…221f0f0
    — /dev/null
    +++ b/lib/net/dhcp/sparc_record.rb
    @@ -0,0 +1,25 @@
    +module Net::DHCP

  • class SparcRecord < Record

  • attr_accessor :vendor, :root_path_name, :sysid_server_path,

  •  :install_server_name, :install_server_ip, :jumpstart_server_path,
    
  •  :root_server_hostname, :root_server_ip, :install_path
    
  • def initialize opts = { }

  •  super(opts)
    
  •  raise "Must define a dhcp vendor" if vendor.blank?
    
  • end

  • def attrs

  •  super.merge({
    
  •    "#{vendor}root_path_name"        => root_path_name,
    
  •    "#{vendor}sysid_server_path"     => sysid_server_path,
    
  •    "#{vendor}install_server_ip"     => install_server_ip,
    
  •    "#{vendor}jumpstart_server_path" => jumpstart_server_path,
    
  •    "#{vendor}install_server_name"   => install_server_name,
    
  •    "#{vendor}root_server_hostname"  => root_server_hostname,
    
  •    "#{vendor}root_server_ip"        => root_server_ip,
    
  •    "#{vendor}install_path"          => install_path
    
  •  }).delete_if { |k, v| v.nil? }
    
  • end

  • end
    +end
    diff --git a/lib/proxy_api.rb b/lib/proxy_api.rb
    index ef4292b…b71ddce 100644
    — a/lib/proxy_api.rb
    +++ b/lib/proxy_api.rb
    @@ -155,9 +155,14 @@ module ProxyAPI

    Returns : Hash or false

    def record subnet, mac
    response = parse(get("#{subnet}/#{mac}"))

  •  Net::DhcpRecord.new response.merge(:network => subnet, :proxy => self)
    
  •  attrs = response.merge(:network => subnet, :proxy => self)
    
  •  if response.keys.grep(/Sun/i).empty?
    
  •    Net::DHCP::SparcRecord.new attrs
    
  •  else
    
  •    Net::DHCP::Record.new attrs
    
  •  end
    
    rescue RestClient::ResourceNotFound
  •  false
    
  •  nil
    

    end

    Sets a DHCP entry

diff --git a/test/lib/net/dhcp_test.rb b/test/lib/net/dhcp_test.rb
index 025ef38…acab80c 100644
— a/test/lib/net/dhcp_test.rb
+++ b/test/lib/net/dhcp_test.rb
@@ -5,33 +5,33 @@ class DhcpTest < ActiveSupport::TestCase

test “dhcp record should not be created without a mac” do
assert_raise Net::Validations::Error do

  •  Net::DhcpRecord.new :name => "test", "proxy" => smart_proxies(:one)
    
  •  Net::DHCP::Record.new :hostname => "test", "proxy" => smart_proxies(:one)
    

    end
    end

    test “dhcp record should not be created without a network” do
    assert_raise Net::Validations::Error do

  •  Net::DhcpRecord.new :name => "test", :mac => "aa:bb:cc:dd:ee:ff", "proxy" => smart_proxies(:one)
    
  •  Net::DHCP::Record.new :hostname => "test", :mac => "aa:bb:cc:dd:ee:ff", "proxy" => smart_proxies(:one)
    

    end
    end

    test “dhcp record should not be created without an ip” do
    assert_raise Net::Validations::Error do

  •  Net::DhcpRecord.new :name => "test", :mac => "aa:bb:cc:dd:ee:ff", :network => "127.0.0.0", "proxy" => smart_proxies(:one)
    
  •  Net::DHCP::Record.new :hostname => "test", :mac => "aa:bb:cc:dd:ee:ff", :network => "127.0.0.0", "proxy" => smart_proxies(:one)
    

    end
    end

    test “record should have dhcp attributes” do

  • record = Net::DhcpRecord.new(:name => “test”, :mac => “aa:bb:cc:dd:ee:ff”,
  • record = Net::DHCP::Record.new(:hostname => “test”, :mac => “aa:bb:cc:dd:ee:ff”,
    :network => “127.0.0.0”, :ip => “127.0.0.1”, “proxy” => smart_proxies(:one))
  • assert_equal({:name => “test”, :mac => “aa:bb:cc:dd:ee:ff”,:network => “127.0.0.0”, :ip => “127.0.0.1”}, record.send(:attrs))
  • assert_equal({:hostname => “test”, :mac => “aa:bb:cc:dd:ee:ff”,:network => “127.0.0.0”, :ip => “127.0.0.1”}, record.send(:attrs))

end

test “record should be equal if their attrs are the same” do

  • record1 = Net::DhcpRecord.new(:name => “test”, :mac => “aa:bb:cc:dd:ee:ff”,
  • record1 = Net::DHCP::Record.new(:hostname => “test”, :mac => “aa:bb:cc:dd:ee:ff”,
    :network => “127.0.0.0”, :ip => “127.0.0.1”, “proxy” => smart_proxies(:one))
  • record2 = Net::DhcpRecord.new(:name => “test”, :mac => “aa:bb:cc:dd:ee:ff”,
  • record2 = Net::DHCP::Record.new(:hostname => “test”, :mac => “aa:bb:cc:dd:ee:ff”,
    :network => “127.0.0.0”, :ip => “127.0.0.1”, “proxy” => smart_proxies(:one))
    assert_equal record1, record2
    end
    diff --git a/test/lib/net/net_test.rb b/test/lib/net/net_test.rb
    index 4369e21…4fa8d5c 100644
    — a/test/lib/net/net_test.rb
    +++ b/test/lib/net/net_test.rb
    @@ -4,17 +4,17 @@ require 'net’
    class NetTest < ActiveSupport::TestCase

test “Net record should auto assign attributes” do

  • record = Net::Record.new :name => “test”, “proxy” => smart_proxies(:one)
  • assert_equal “test”, record.name
  • record = Net::Record.new :hostname => “test”, “proxy” => smart_proxies(:one)
  • assert_equal “test”, record.hostname
    end

test “should have a logger” do

  • record = Net::Record.new :name => “test”, “proxy” => smart_proxies(:one)
  • record = Net::Record.new :hostname => “test”, “proxy” => smart_proxies(:one)
    assert_not_nil record.logger
    end

test “should default logger to rails logger” do

  • record = Net::Record.new :name => “test”, “proxy” => smart_proxies(:one)
  • record = Net::Record.new :hostname => “test”, “proxy” => smart_proxies(:one)
    assert_equal logger, record.logger
    end
    end
    diff --git a/test/unit/orchestration/dhcp_test.rb b/test/unit/orchestration/dhcp_test.rb
    index a1917e3…da80748 100644
    — a/test/unit/orchestration/dhcp_test.rb
    +++ b/test/unit/orchestration/dhcp_test.rb
    @@ -10,7 +10,7 @@ class DhcpOrchestrationTest < ActiveSupport::TestCase
    h = hosts(:one)
    assert h.valid?
    assert h.dhcp?
  •  assert_instance_of Net::DhcpRecord, h.dhcp_record
    
  •  assert_instance_of Net::DHCP::Record, h.dhcp_record
    
    end
    end

@@ -28,15 +28,17 @@ class DhcpOrchestrationTest < ActiveSupport::TestCase
Resolv::DNS.any_instance.stubs(:getaddress).with(“brsla01.yourdomain.net”).returns(“2.3.4.5”).once
#User.current = users(:admin)
result = h.os.jumpstart_params h, h.model.vendor_class

  • assert_equal result, {“install_path” => “/vol/solgi_5.10/sol10_hw0910_sparc”,
  •                      "<Sun-Fire-V210>install_server_ip" => "2.3.4.5",
    
  •                      "<Sun-Fire-V210>install_server_name" => "brsla01",
    
  •                      "<Sun-Fire-V210>jumpstart_server_path" => "2.3.4.5:/vol/jumpstart",
    
  •                      "<Sun-Fire-V210>root_path_name" => "/vol/solgi_5.10/sol10_hw0910_sparc/Solaris_10/Tools/Boot",
    
  •                      "<Sun-Fire-V210>root_server_hostname" => "brsla01",
    
  •                      "<Sun-Fire-V210>root_server_ip" => "2.3.4.5",
    
  •                      "<Sun-Fire-V210>sysid_server_path" => "2.3.4.5:/vol/jumpstart/sysidcfg/sysidcfg_primary"
    
  •                      }
    
  • assert_equal result, {
  •  :vendor                => "<Sun-Fire-V210>",
    
  •  :install_path          => "/vol/solgi_5.10/sol10_hw0910_sparc",
    
  •  :install_server_ip     => "2.3.4.5",
    
  •  :install_server_name   => "brsla01",
    
  •  :jumpstart_server_path => "2.3.4.5:/vol/jumpstart",
    
  •  :root_path_name        => "/vol/solgi_5.10/sol10_hw0910_sparc/Solaris_10/Tools/Boot",
    
  •  :root_server_hostname  => "brsla01",
    
  •  :root_server_ip        => "2.3.4.5",
    
  •  :sysid_server_path     => "2.3.4.5:/vol/jumpstart/sysidcfg/sysidcfg_primary"
    
  • }
    end

end

1.7.6.2