Skip to content

Commit

Permalink
Disabling dnsmasq for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Jun 10, 2016
1 parent 161ec68 commit 11e41e1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
40 changes: 22 additions & 18 deletions kong/cmd/utils/dnsmasq_signals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,38 @@ local function is_running(pid_path)
end

function _M.start(kong_config, nginx_prefix)
-- is dnsmasq already running in this prefix?
local pid_path = pl_path.join(nginx_prefix, dnsmasq_pid_name)
if is_running(pid_path) then
log.verbose("dnsmasq already running at %s", pid_path)
return true
else
log.verbose("dnsmasq not running, deleting %s", pid_path)
pl_file.delete(pid_path)
end
if kong_config.dnsmasq then
-- is dnsmasq already running in this prefix?
local pid_path = pl_path.join(nginx_prefix, dnsmasq_pid_name)
if is_running(pid_path) then
log.verbose("dnsmasq already running at %s", pid_path)
return true
else
log.verbose("dnsmasq not running, deleting %s", pid_path)
pl_file.delete(pid_path)
end

-- make sure Serf is in PATH
local dnsmasq_bin, err = _M.find_bin()
if not dnsmasq_bin then return nil, err end
local dnsmasq_bin, err = _M.find_bin()
if not dnsmasq_bin then return nil, err end

local cmd = fmt("%s -p %d --pid-file=%s -N -o --listen-address=127.0.0.1", dnsmasq_bin, kong_config.dnsmasq_port, pid_path)
local cmd = fmt("%s -p %d --pid-file=%s -N -o --listen-address=127.0.0.1", dnsmasq_bin, kong_config.dnsmasq_port, pid_path)

log.debug("starting dnsmasq: %s", cmd)
log.debug("starting dnsmasq: %s", cmd)

local ok, _, _, stderr = pl_utils.executeex(cmd)
if not ok then return nil, stderr end
local ok, _, _, stderr = pl_utils.executeex(cmd)
if not ok then return nil, stderr end
end

return true
end

function _M.stop(nginx_prefix)
local pid_path = pl_path.join(nginx_prefix, dnsmasq_pid_name)
log.verbose("stopping dnsmasq at %s", pid_path)
return kill(pid_path, "-9")
if pl_path.exists(pid_path) then
log.verbose("stopping dnsmasq at %s", pid_path)
return kill(pid_path, "-9")
end
return true
end

return _M
14 changes: 10 additions & 4 deletions spec/02-integration/01-cmd/02-start_stop_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ local helpers = require "spec.helpers"

local KILL_ALL = "pkill nginx; pkill serf; pkill dnsmasq"

local function exec(args)
local function exec(args, env)
args = args or ""
return helpers.execute(helpers.bin_path.." "..args)
env = env or {}

local env_vars = ""
for k, v in pairs(env) do
env_vars = string.format("%s KONG_%s=%s", env_vars, k:upper(), v)
end
return helpers.execute(env_vars.." "..helpers.bin_path.." "..args)
end

describe("kong start/stop", function()
Expand Down Expand Up @@ -110,7 +116,7 @@ describe("kong start/stop", function()

describe("dnsmasq", function()
it("starts dnsmasq daemon", function()
local ok = exec("start --conf "..helpers.test_conf_path)
local ok = exec("start --conf "..helpers.test_conf_path, {dnsmasq=true, dns_resolver = ""})
assert.True(ok)

local dnsmasq_pid_path = helpers.path.join(helpers.test_conf.prefix, "dnsmasq.pid")
Expand All @@ -126,7 +132,7 @@ describe("kong start/stop", function()
local ok = helpers.execute("touch "..dnsmasq_pid_path) -- dumb pid
assert.True(ok)

assert.True(exec("start --conf "..helpers.test_conf_path))
assert.True(exec("start --conf "..helpers.test_conf_path, {dnsmasq=true, dns_resolver = ""}))

local cmd = string.format("kill -0 `cat %s` >/dev/null 2>&1", dnsmasq_pid_path)
local ok, code = helpers.execute(cmd)
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/invalid.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dnsmasq = on
dns_resolver = "8.8.8.8"
dns_resolver = 8.8.8.8
cassandra_repl_strategy = foo
4 changes: 2 additions & 2 deletions spec/kong_tests.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cluster_listen = 0.0.0.0:9946
cluster_listen_rpc = 127.0.0.1:9373
ssl_cert = spec/fixtures/kong_spec.crt
ssl_cert_key = spec/fixtures/kong_spec.key
dnsmasq = on
dnsmasq_port = 9053
dnsmasq = off
dns_resolver = 8.8.8.8
database = postgres
pg_host = 127.0.0.1
pg_port = 5432
Expand Down

0 comments on commit 11e41e1

Please sign in to comment.