Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split resolv.conf in lines #618

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Fixed

- Error loading policy chain configuration JSON with null value [PR #626](https://github.com/3scale/apicast/pull/626)
- Splitted `resolv.conf` in lines,to avoid commented lines [PR #618](https://github.com/3scale/apicast/pull/618)
Copy link
Contributor

@mikz mikz Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick. Changelog should focus on "what" and not "how".
Here would be better fit: Skip lines starting with a comment when parsing resolv.conf

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bear that in mind. Thanks


## [3.2.0-beta1] - 2018-02-20

Expand Down
24 changes: 15 additions & 9 deletions gateway/src/resty/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ function _M.parse_nameservers(path)

local search = { }
local nameservers = { search = search }
local domains = match(resolv_conf, 'search%s+([^\n]+)')

ngx.log(ngx.DEBUG, 'search ', domains)
for domain in gmatch(domains or '', '([^%s]+)') do
ngx.log(ngx.DEBUG, 'search domain: ', domain)
insert(search, domain)
end

local resolver
resolver, err = _M.parse_resolver(resty_env.value('RESOLVER'))
Expand All @@ -131,10 +124,23 @@ function _M.parse_nameservers(path)
-- see https://github.com/3scale/apicast/issues/321 for more details
insert(nameservers, resolver)
end

for _,line in ipairs(re.split(resolv_conf, "\n+")) do

local domains = match(line, '^search%s+([^\n]+)')

if domains then
ngx.log(ngx.DEBUG, 'search ', domains)

for domain in gmatch(domains or '', '([^%s]+)') do
ngx.log(ngx.DEBUG, 'search domain: ', domain)
insert(search, domain)
end
end

for server in gmatch(resolv_conf, 'nameserver%s+([^%s]+)') do
local server = match(line, '^nameserver%s+([^%s]+)')
-- TODO: implement port matching based on https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549190
if server ~= resolver then
if server and server ~= resolver then
Copy link
Contributor

@davidor davidor Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't have tests for the case where server == resolver.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual this test case fails.

We have agreed (me and @davidor) that we should address those problems in another PR.

The issue which treat this case is #630

insert(nameservers, nameserver.new(server))
end
end
Expand Down
16 changes: 13 additions & 3 deletions spec/resty/resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,19 @@ describe('resty.resolver', function()
before_each(function()
tmpname = io.tmpfile()

tmpname:write('search localdomain.example.com local\n')
tmpname:write('nameserver 127.0.0.2\n')
tmpname:write('nameserver 127.0.0.1\n')
tmpname:write([[
# nameserver updated in comentary
#nameserver updated in comentary
#comentary nameserver 1.2.3.4
#comentary nameserver
# search updated.example.com in comentary
#search updated in comentary
#search nameserver 1.2.3.4
#search nameserver
search localdomain.example.com local
nameserver 127.0.0.2
nameserver 127.0.0.1
]])
end)

it('returns nameserver touples', function()
Expand Down
13 changes: 12 additions & 1 deletion t/resolver.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ run_tests();
__DATA__

=== TEST 1: uses all resolvers
both RESOLVER env variable and resolvers in resolv.conf should be used
both RESOLVER env variable and resolvers in resolv.conf should be used.
checking if commented 'nameserver' and 'search' keywords impact on the
resolv.conf file parsing.
--- main_config
env RESOLVER=$TEST_NGINX_RESOLVER;
--- http_config
Expand All @@ -34,6 +36,15 @@ GET /t
nameservers: 3 127.0.1.15353 1.2.3.453 4.5.6.753
--- user_files
>>> resolv.conf
# nameserver updated in comentary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. It's testing more things than before, so I think it's worth expanding the description of the test (line 16).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in d49b712

#nameserver updated in comentary
#comentary nameserver 1.2.3.4
#comentary nameserver
# search updated.example.com in comentary
#search updated in comentary
#search nameserver 1.2.3.4
#search nameserver
search localdomain.example.com local
nameserver 1.2.3.4
nameserver 4.5.6.7

Expand Down