commit 77e0262c639e14949a56a6c98d14fb9f37f52320
Author: Lukas Zapletal <lzap+git@redhat.com>
Date:   Thu Sep 3 13:49:02 2015 +0200

    Fixes #11676 - added dhcp_server option

diff --git a/config/settings.d/dhcp.yml.example b/config/settings.d/dhcp.yml.example
index 7bb9bab..a7eed58 100644
--- a/config/settings.d/dhcp.yml.example
+++ b/config/settings.d/dhcp.yml.example
@@ -7,6 +7,8 @@
 #   - native_ms (Microsoft native implementation)
 #   - virsh (simple implementation for libvirt)
 #:dhcp_vendor: isc
+#:dhcp_server: 127.0.0.1
+#:dhcp_omapi_port: 7911
 # dhcp_subnets is an ISC &  Native MS implementation setting. It restricts the subnets queried to a
 # subset, so as to reduce the query time.
 #:dhcp_subnets: [192.168.205.0/255.255.255.128, 192.168.205.128/255.255.255.128]
@@ -21,4 +23,3 @@
 #:dhcp_leases: /var/lib/dhcpd/dhcpd.leases
 #:dhcp_key_name: secret_key_name
 #:dhcp_key_secret: secret_key
-#:dhcp_omapi_port: 7911
diff --git a/modules/dhcp/dhcp_api.rb b/modules/dhcp/dhcp_api.rb
index a9401ea..fffa845 100644
--- a/modules/dhcp/dhcp_api.rb
+++ b/modules/dhcp/dhcp_api.rb
@@ -14,7 +14,7 @@ class Proxy::DhcpApi < ::Sinatra::Base
           && File.exist?(Proxy::DhcpPlugin.settings.dhcp_config) && File.exist?(Proxy::DhcpPlugin.settings.dhcp_leases)
           log_halt 400, "Unable to find the DHCP configuration or lease files"
         end
-        @server = Proxy::DHCP::ISC.new(:name => "127.0.0.1",
+        @server = Proxy::DHCP::ISC.new(:name => Proxy::DhcpPlugin.settings.dhcp_server,
                                        :config => Proxy::DhcpPlugin.settings.dhcp_config,
                                        :leases => Proxy::DhcpPlugin.settings.dhcp_leases)
       when "native_ms"
diff --git a/modules/dhcp/dhcp_plugin.rb b/modules/dhcp/dhcp_plugin.rb
index 5268ee0..7da8ee1 100644
--- a/modules/dhcp/dhcp_plugin.rb
+++ b/modules/dhcp/dhcp_plugin.rb
@@ -2,6 +2,6 @@ class Proxy::DhcpPlugin < ::Proxy::Plugin
   http_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__))
   https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__))
 
-  default_settings :dhcp_provider => 'isc', :dhcp_omapi_port => '7911'
+  default_settings :dhcp_provider => 'isc', :dhcp_server => '127.0.0.1', :dhcp_omapi_port => '7911'
   plugin :dhcp, ::Proxy::VERSION
 end
diff --git a/test/dhcp/dhcp_config_test.rb b/test/dhcp/dhcp_config_test.rb
index 606e979..942bf68 100644
--- a/test/dhcp/dhcp_config_test.rb
+++ b/test/dhcp/dhcp_config_test.rb
@@ -5,6 +5,7 @@ class DhcpConfigTest < Test::Unit::TestCase
   def test_omitted_settings_have_default_values
     Proxy::DhcpPlugin.load_test_settings({})
     assert_equal 'isc', Proxy::DhcpPlugin.settings.dhcp_provider
+    assert_equal '127.0.0.1', Proxy::DhcpPlugin.settings.dhcp_server
     assert_equal '7911', Proxy::DhcpPlugin.settings.dhcp_omapi_port
   end
 end
diff --git a/test/dhcp/server_isc_test.rb b/test/dhcp/server_isc_test.rb
index 22fe7d9..9a76b12 100644
--- a/test/dhcp/server_isc_test.rb
+++ b/test/dhcp/server_isc_test.rb
@@ -9,6 +9,18 @@ ENV['RACK_ENV'] = 'test'
 class ServerIscTest < Test::Unit::TestCase
   include Rack::Test::Methods
 
+  class OMIO
+    attr_reader :input_commands
+
+    def initialize
+      @input_commands = []
+    end
+
+    def puts str
+      @input_commands << str
+    end
+  end
+
   def app
     Proxy::DhcpApi.new
   end
@@ -36,11 +48,22 @@ class ServerIscTest < Test::Unit::TestCase
     Proxy::DhcpPlugin.load_test_settings(
       :enabled => true,
       :dhcp_vendor => 'isc',
+      :dhcp_omapi_port => 999,
       :dhcp_config => './test/fixtures/dhcp/dhcp.conf',
       :dhcp_leases => './test/fixtures/dhcp/dhcp.leases',
       :dhcp_subnets => '192.168.122.0/255')
   end
 
+  def test_omcmd_server_connect
+    srv = Proxy::DHCP::ISC.new :name => '1.2.3.4', :config => './test/fixtures/dhcp/dhcp.conf', :leases => './test/fixtures/dhcp/dhcp.leases'
+    srv.stubs(:which).returns('fakeshell')
+    omio = OMIO.new
+    IO.expects(:popen).with("/bin/sh -c 'fakeshell 2>&1'", "r+").returns(omio)
+    srv.send(:omcmd, 'connect')
+    assert_equal "port 999", omio.input_commands[1]
+    assert_equal "server 1.2.3.4", omio.input_commands[0]
+  end
+
   def test_sparc_host_creation
     s=Proxy::DHCP::Server.new('192.168.122.1')
     sub=Proxy::DHCP::Subnet.new(s,'192.168.122.0','255.255.255.0')
