Project

General

Profile

« Previous | Next » 

Revision 77e0262c

Added by Lukas Zapletal over 8 years ago

Fixes #11676 - added dhcp_server option

View differences:

config/settings.d/dhcp.yml.example
# - 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]
......
#:dhcp_leases: /var/lib/dhcpd/dhcpd.leases
#:dhcp_key_name: secret_key_name
#:dhcp_key_secret: secret_key
#:dhcp_omapi_port: 7911
modules/dhcp/dhcp_api.rb
&& 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"
modules/dhcp/dhcp_plugin.rb
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
test/dhcp/dhcp_config_test.rb
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
test/dhcp/server_isc_test.rb
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
......
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')

Also available in: Unified diff