Merge lp:~oreilldf/wicd/resolvconf2 into lp:wicd/1.6
- resolvconf2
- Merge into experimental
Status: | Superseded | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~oreilldf/wicd/resolvconf2 | ||||
Merge into: | lp:wicd/1.6 | ||||
Diff against target: | None lines | ||||
To merge this branch: | bzr merge lp:~oreilldf/wicd/resolvconf2 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Paleino | Needs Fixing | ||
Wicd-devel | Pending | ||
Review via email: mp+4474@code.launchpad.net |
This proposal has been superseded by a proposal from 2009-03-15.
Commit message
Description of the change
Dan O'Reilly (oreilldf) wrote : | # |
David Paleino (dpaleino) wrote : | # |
I suggest changing the last chunk of the patch as follows:
---8<---
@@ -518,7 +496,51 @@
return
if self.verbose: print cmd
-
+
+ def SetDNS(self, dns1=None, dns2=None, dns3=None,
+ dns_dom=None, search_dom=None):
+ """ Set the DNS of the system to the specified DNS servers.
+
+ Opens up resolv.conf and writes in the nameservers.
+
+ Keyword arguments:
+ dns1 -- IP address of DNS server 1
+ dns2 -- IP address of DNS server 2
+ dns3 -- IP address of DNS server 3
+ dns_dom -- DNS domain
+ search_dom -- DNS search domain
+
+ """
+ resolv_params = ""
+ if dns_dom:
+ resolv_params = ''.join(
+ if search_dom:
+ resolv_params = ''.join(
+ '\n'])
+ valid_dns_list = []
+ for dns in [dns1, dns2, dns3]:
+ if dns:
+ if misc.IsValidIP(
+ print 'Setting DNS : ' + dns
+ valid_dns_
+ else:
+ print 'DNS IP %s is not a valid IP address, skipping' % dns
+
+ if self.resolvconf
+ # Make sure we have at least one DNS in the list.
+ if valid_dns_list:
+ resolv_params += 'nameserver ' + ' '.join(
+
+ print "running resolvconf"
+ p = misc.Run(' '.join(
+ include_
+ p.communicate(
+ else:
+ resolv = open("/
+ resolv.
+ for dns in valid_dns_list:
+ resolv.
+ resolv.close()
def FlushRoutes(self):
""" Flush network routes for this device. """
--->8---
Let's go step-by-step.
Here:
+ else:
+ print 'DNS IP is not a valid IP address, skipping'
It would be rather useful printing *which* DNS is not a valid IP address.
Also, later we have:
In the same file:
+ # Make sure we have more than just 'nameserver' in the list.
+ if len(valid_dns_list) > 1:
+ resolv_params += ' '.join(
+
+ if self.resolvconf
+ print "running resolvconf"
+ p = misc.Run(' '.join(
+ include_
+ p.communicate(
+ else:
+ resolv = open("/
+ resolv.
+ resolv.close()
This is wrong. /etc/resolv.conf accepts maximum MAXNS (currently 3, see <resolv.h>) IPs listed after "nameserver", while resolvconf gracefully handles that by putting each IP on a separate line (i.e. "nameserver A B" used with resolvconf would actually give "nameserver A\nnameserver B" in /etc/resolv.conf).
O...
- 326. By Dan O'Reilly
-
Fix how we set nameserver entries after code review.
- 327. By Dan O'Reilly
-
Only print "Setting DNS" message if debug mode is on.
Unmerged revisions
Preview Diff
1 | === modified file 'wicd/misc.py' | |||
2 | --- wicd/misc.py 2009-03-09 03:39:41 +0000 | |||
3 | +++ wicd/misc.py 2009-03-09 04:07:39 +0000 | |||
4 | @@ -95,6 +95,10 @@ | |||
5 | 95 | else: | 95 | else: |
6 | 96 | err = None | 96 | err = None |
7 | 97 | fds = False | 97 | fds = False |
8 | 98 | if return_obj: | ||
9 | 99 | std_in = PIPE | ||
10 | 100 | else: | ||
11 | 101 | std_in = None | ||
12 | 98 | 102 | ||
13 | 99 | # We need to make sure that the results of the command we run | 103 | # We need to make sure that the results of the command we run |
14 | 100 | # are in English, so we set up a temporary environment. | 104 | # are in English, so we set up a temporary environment. |
15 | @@ -105,8 +109,8 @@ | |||
16 | 105 | tmpenv["LANG"] = __LANG | 109 | tmpenv["LANG"] = __LANG |
17 | 106 | 110 | ||
18 | 107 | try: | 111 | try: |
21 | 108 | f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds, | 112 | f = Popen(cmd, shell=False, stdout=PIPE, stdin=std_in, stderr=err, |
22 | 109 | cwd='/', env=tmpenv) | 113 | close_fds=fds, cwd='/', env=tmpenv) |
23 | 110 | except OSError, e: | 114 | except OSError, e: |
24 | 111 | print "Running command %s failed: %s" % (str(cmd), str(e)) | 115 | print "Running command %s failed: %s" % (str(cmd), str(e)) |
25 | 112 | return "" | 116 | return "" |
26 | 113 | 117 | ||
27 | === modified file 'wicd/networking.py' | |||
28 | --- wicd/networking.py 2009-03-09 03:39:41 +0000 | |||
29 | +++ wicd/networking.py 2009-03-09 04:07:39 +0000 | |||
30 | @@ -427,7 +427,7 @@ | |||
31 | 427 | return | 427 | return |
32 | 428 | 428 | ||
33 | 429 | @abortable | 429 | @abortable |
35 | 430 | def set_dns_addresses(self): | 430 | def set_dns_addresses(self, iface): |
36 | 431 | """ Set the DNS address(es). | 431 | """ Set the DNS address(es). |
37 | 432 | 432 | ||
38 | 433 | If static DNS servers or global DNS servers are specified, set them. | 433 | If static DNS servers or global DNS servers are specified, set them. |
39 | @@ -435,19 +435,19 @@ | |||
40 | 435 | 435 | ||
41 | 436 | """ | 436 | """ |
42 | 437 | if self.network.get('use_global_dns'): | 437 | if self.network.get('use_global_dns'): |
48 | 438 | BACKEND.SetDNS(misc.Noneify(self.global_dns_1), | 438 | iface.SetDNS(misc.Noneify(self.global_dns_1), |
49 | 439 | misc.Noneify(self.global_dns_2), | 439 | misc.Noneify(self.global_dns_2), |
50 | 440 | misc.Noneify(self.global_dns_3), | 440 | misc.Noneify(self.global_dns_3), |
51 | 441 | misc.Noneify(self.global_dns_dom), | 441 | misc.Noneify(self.global_dns_dom), |
52 | 442 | misc.Noneify(self.global_search_dom)) | 442 | misc.Noneify(self.global_search_dom)) |
53 | 443 | elif self.network.get('use_static_dns') and (self.network.get('dns1') or | 443 | elif self.network.get('use_static_dns') and (self.network.get('dns1') or |
54 | 444 | self.network.get('dns2') or self.network.get('dns3')): | 444 | self.network.get('dns2') or self.network.get('dns3')): |
55 | 445 | self.SetStatus('setting_static_dns') | 445 | self.SetStatus('setting_static_dns') |
61 | 446 | BACKEND.SetDNS(self.network.get('dns1'), | 446 | iface.SetDNS(self.network.get('dns1'), |
62 | 447 | self.network.get('dns2'), | 447 | self.network.get('dns2'), |
63 | 448 | self.network.get('dns3'), | 448 | self.network.get('dns3'), |
64 | 449 | self.network.get('dns_domain'), | 449 | self.network.get('dns_domain'), |
65 | 450 | self.network.get('search_domain')) | 450 | self.network.get('search_domain')) |
66 | 451 | 451 | ||
67 | 452 | @abortable | 452 | @abortable |
68 | 453 | def release_dhcp_clients(self, iface): | 453 | def release_dhcp_clients(self, iface): |
69 | @@ -837,7 +837,7 @@ | |||
70 | 837 | # Set up gateway, IP address, and DNS servers. | 837 | # Set up gateway, IP address, and DNS servers. |
71 | 838 | self.set_broadcast_address(wiface) | 838 | self.set_broadcast_address(wiface) |
72 | 839 | self.set_ip_address(wiface) | 839 | self.set_ip_address(wiface) |
74 | 840 | self.set_dns_addresses() | 840 | self.set_dns_addresses(wiface) |
75 | 841 | 841 | ||
76 | 842 | # Run post-connection script. | 842 | # Run post-connection script. |
77 | 843 | self.run_global_scripts_if_needed(wpath.postconnectscripts) | 843 | self.run_global_scripts_if_needed(wpath.postconnectscripts) |
78 | @@ -1025,7 +1025,7 @@ | |||
79 | 1025 | # Set gateway, IP adresses, and DNS servers. | 1025 | # Set gateway, IP adresses, and DNS servers. |
80 | 1026 | self.set_broadcast_address(liface) | 1026 | self.set_broadcast_address(liface) |
81 | 1027 | self.set_ip_address(liface) | 1027 | self.set_ip_address(liface) |
83 | 1028 | self.set_dns_addresses() | 1028 | self.set_dns_addresses(liface) |
84 | 1029 | 1029 | ||
85 | 1030 | # Run post-connection script. | 1030 | # Run post-connection script. |
86 | 1031 | self.run_global_scripts_if_needed(wpath.postconnectscripts) | 1031 | self.run_global_scripts_if_needed(wpath.postconnectscripts) |
87 | 1032 | 1032 | ||
88 | === modified file 'wicd/wnettools.py' | |||
89 | --- wicd/wnettools.py 2009-03-09 03:09:12 +0000 | |||
90 | +++ wicd/wnettools.py 2009-03-09 04:07:39 +0000 | |||
91 | @@ -74,7 +74,7 @@ | |||
92 | 74 | blacklist_norm = ";`$!*|><&\\" | 74 | blacklist_norm = ";`$!*|><&\\" |
93 | 75 | blank_trans = maketrans("", "") | 75 | blank_trans = maketrans("", "") |
94 | 76 | 76 | ||
96 | 77 | __all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces", | 77 | __all__ = ["GetDefaultGateway", "GetWiredInterfaces", |
97 | 78 | "GetWirelessInterfaces", "IsValidWpaSuppDriver"] | 78 | "GetWirelessInterfaces", "IsValidWpaSuppDriver"] |
98 | 79 | 79 | ||
99 | 80 | def _sanitize_string(string): | 80 | def _sanitize_string(string): |
100 | @@ -89,33 +89,6 @@ | |||
101 | 89 | else: | 89 | else: |
102 | 90 | return string | 90 | return string |
103 | 91 | 91 | ||
104 | 92 | def SetDNS(dns1=None, dns2=None, dns3=None, dns_dom=None, search_dom=None): | ||
105 | 93 | """ Set the DNS of the system to the specified DNS servers. | ||
106 | 94 | |||
107 | 95 | Opens up resolv.conf and writes in the nameservers. | ||
108 | 96 | |||
109 | 97 | Keyword arguments: | ||
110 | 98 | dns1 -- IP address of DNS server 1 | ||
111 | 99 | dns2 -- IP address of DNS server 2 | ||
112 | 100 | dns3 -- IP address of DNS server 3 | ||
113 | 101 | dns_dom -- DNS domain | ||
114 | 102 | search_dom -- DNS search domain | ||
115 | 103 | |||
116 | 104 | """ | ||
117 | 105 | resolv = open("/etc/resolv.conf", "w") | ||
118 | 106 | if dns_dom: | ||
119 | 107 | resolv.write("domain %s\n" % dns_dom) | ||
120 | 108 | if search_dom: | ||
121 | 109 | resolv.write('search %s\n' % search_dom) | ||
122 | 110 | for dns in [dns1, dns2, dns3]: | ||
123 | 111 | if dns: | ||
124 | 112 | if misc.IsValidIP(dns): | ||
125 | 113 | print 'Setting DNS : ' + dns | ||
126 | 114 | resolv.write('nameserver ' + dns + '\n') | ||
127 | 115 | else: | ||
128 | 116 | print 'DNS IP is not a valid IP address, not writing to resolv.conf' | ||
129 | 117 | resolv.close() | ||
130 | 118 | |||
131 | 119 | def GetDefaultGateway(): | 92 | def GetDefaultGateway(): |
132 | 120 | """ Attempts to determine the default gateway by parsing route -n. """ | 93 | """ Attempts to determine the default gateway by parsing route -n. """ |
133 | 121 | route_info = misc.Run("route -n") | 94 | route_info = misc.Run("route -n") |
134 | @@ -291,6 +264,11 @@ | |||
135 | 291 | self.CheckWirelessTools() | 264 | self.CheckWirelessTools() |
136 | 292 | self.CheckSudoApplications() | 265 | self.CheckSudoApplications() |
137 | 293 | self.CheckRouteFlushTool() | 266 | self.CheckRouteFlushTool() |
138 | 267 | self.CheckResolvConf() | ||
139 | 268 | |||
140 | 269 | def CheckResolvConf(self): | ||
141 | 270 | """ Checks for the existence of resolvconf.""" | ||
142 | 271 | self.resolvconf_cmd = self._find_program_path("resolvconf") | ||
143 | 294 | 272 | ||
144 | 295 | def CheckDHCP(self): | 273 | def CheckDHCP(self): |
145 | 296 | """ Check for the existence of valid DHCP clients. | 274 | """ Check for the existence of valid DHCP clients. |
146 | @@ -518,7 +496,48 @@ | |||
147 | 518 | return | 496 | return |
148 | 519 | if self.verbose: print cmd | 497 | if self.verbose: print cmd |
149 | 520 | misc.Run(cmd) | 498 | misc.Run(cmd) |
151 | 521 | 499 | ||
152 | 500 | def SetDNS(self, dns1=None, dns2=None, dns3=None, | ||
153 | 501 | dns_dom=None, search_dom=None): | ||
154 | 502 | """ Set the DNS of the system to the specified DNS servers. | ||
155 | 503 | |||
156 | 504 | Opens up resolv.conf and writes in the nameservers. | ||
157 | 505 | |||
158 | 506 | Keyword arguments: | ||
159 | 507 | dns1 -- IP address of DNS server 1 | ||
160 | 508 | dns2 -- IP address of DNS server 2 | ||
161 | 509 | dns3 -- IP address of DNS server 3 | ||
162 | 510 | dns_dom -- DNS domain | ||
163 | 511 | search_dom -- DNS search domain | ||
164 | 512 | |||
165 | 513 | """ | ||
166 | 514 | resolv_params = "" | ||
167 | 515 | if dns_dom: | ||
168 | 516 | resolv_params = ''.join([resolv_params, 'domain ', dns_dom, '\n']) | ||
169 | 517 | if search_dom: | ||
170 | 518 | resolv_params = ''.join([resolv_params, 'search ', search_dom, | ||
171 | 519 | '\n']) | ||
172 | 520 | valid_dns_list = ['nameserver'] | ||
173 | 521 | for dns in [dns1, dns2, dns3]: | ||
174 | 522 | if dns: | ||
175 | 523 | if misc.IsValidIP(dns): | ||
176 | 524 | print 'Setting DNS : ' + dns | ||
177 | 525 | valid_dns_list.append(dns) | ||
178 | 526 | else: | ||
179 | 527 | print 'DNS IP is not a valid IP address, skipping' | ||
180 | 528 | # Make sure we have more than just 'nameserver' in the list. | ||
181 | 529 | if len(valid_dns_list) > 1: | ||
182 | 530 | resolv_params += ' '.join(valid_dns_list) + '\n' | ||
183 | 531 | |||
184 | 532 | if self.resolvconf_cmd: | ||
185 | 533 | print "running resolvconf" | ||
186 | 534 | p = misc.Run(' '.join([self.resolvconf_cmd, '-a', self.iface]), | ||
187 | 535 | include_stderr=True, return_obj=True) | ||
188 | 536 | p.communicate(input=resolv_params)[0] | ||
189 | 537 | else: | ||
190 | 538 | resolv = open("/etc/resolv.conf", "w") | ||
191 | 539 | resolv.write(resolv_params + "\n") | ||
192 | 540 | resolv.close() | ||
193 | 522 | 541 | ||
194 | 523 | def FlushRoutes(self): | 542 | def FlushRoutes(self): |
195 | 524 | """ Flush network routes for this device. """ | 543 | """ Flush network routes for this device. """ |
Adds support for using resolvconf to set DNS settings instead of directly editing resolv.conf.