Merge lp:~hggdh2/ubuntu-server-iso-testing/fix-dns-test into lp:ubuntu-server-iso-testing

Proposed by C de-Avillez
Status: Needs review
Proposed branch: lp:~hggdh2/ubuntu-server-iso-testing/fix-dns-test
Merge into: lp:ubuntu-server-iso-testing
Diff against target: 71 lines (+22/-9)
1 file modified
templates/test_cases/dns-server/test (+22/-9)
To merge this branch: bzr merge lp:~hggdh2/ubuntu-server-iso-testing/fix-dns-test
Reviewer Review Type Date Requested Status
Jean-Baptiste Lallement Needs Fixing
Review via email: [email protected]

Description of the change

1. there were some tabs mixed in the test code, I replaced them with spaces
2. adjust to actually run the DNS tests (find the current name server from /etc/resolv.conf, and add it in /etc/bind9/named.conf.options

To post a comment you must log in.
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

* The right place for the dns configuration setup would be in a setUp method of the class DnsServerTest
* The following code can be more concise with readlines() instead of read() + splitlines()
content = resolver.read()
      for line in content.splitlines():
* You fixed indentation but introduced broken indentation lines 92 to 95, it should be 8, 12 and 16 spaces instead of 6,8 and 10 respectively
* ns_address = line.split(' ')[1] will fail if there is more than 1 space between the name of the option and the IP, split() without explicit separator, consecutive spaces will be considered as 1 separator.
* If there is more than 1 nameserver in resolv.conf the last entry will be used. Is it ok since the resolver uses them in order ?
* If there is no nameserver entry, /etc/bind/named.conf.options will be rewritten with a 'None' in it which will fail. The setup should be aborted in this case because the test cannot pass without it.
* Catch the returncode of subprocess.call(['sudo', 'service', 'bind9', 'restart']) or use check_call and catch the exception, and cancel if it failed. If the DNS doesn't start properly the test will fail.
* The test changes the configuration of the DNS server of the host it is running on and it should be documented.

review: Needs Fixing

Unmerged revisions

262. By C de-Avillez

templates/test_cases/dns-server:
  * correct mix of \t and spaces
  * adjust for actually using named on the localhost

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'templates/test_cases/dns-server/test'
2--- templates/test_cases/dns-server/test 2011-11-16 17:00:07 +0000
3+++ templates/test_cases/dns-server/test 2012-10-10 15:56:25 +0000
4@@ -41,7 +41,7 @@
5 logging.debug("Cmd: %s" % (cmd))
6 output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
7 logging.debug("Cmd output: %s" % (output))
8- output2 = filter(lambda l: l.split()[6].split('/')[1] == 'named',
9+ output2 = filter(lambda l: l.split()[6].split('/')[1] == 'named',
10 output.strip().split('\n')[2:])
11 self.assertEquals(len(output2), 5, output2)
12
13@@ -52,8 +52,8 @@
14 stderr=subprocess.STDOUT)
15 output = proc.communicate()[0]
16 logging.debug("Cmd output: %s" % (output))
17- ret = proc.returncode
18- self.assertEquals(ret, 0)
19+ ret = proc.returncode
20+ self.assertEquals(ret, 0)
21
22 def testResolveUdp6(self):
23 cmd = ["host", "-6", "www.ubuntu.com", "ip6-localhost"]
24@@ -62,8 +62,8 @@
25 stderr=subprocess.STDOUT)
26 output = proc.communicate()[0]
27 logging.debug("Cmd output: %s" % (output))
28- ret = proc.returncode
29- self.assertEquals(ret, 0)
30+ ret = proc.returncode
31+ self.assertEquals(ret, 0)
32
33 def testResolveTcp(self):
34 cmd = ["host", "-T", "www.ubuntu.com", "localhost"]
35@@ -72,8 +72,8 @@
36 stderr=subprocess.STDOUT)
37 output = proc.communicate()[0]
38 logging.debug("Cmd output: %s" % (output))
39- ret = proc.returncode
40- self.assertEquals(ret, 0)
41+ ret = proc.returncode
42+ self.assertEquals(ret, 0)
43
44 def testResolveTcp6(self):
45 cmd = ["host", "-T", "-6", "www.ubuntu.com", "ip6-localhost"]
46@@ -82,10 +82,23 @@
47 stderr=subprocess.STDOUT)
48 output = proc.communicate()[0]
49 logging.debug("Cmd output: %s" % (output))
50- ret = proc.returncode
51- self.assertEquals(ret, 0)
52+ ret = proc.returncode
53+ self.assertEquals(ret, 0)
54
55 if __name__ == '__main__':
56+ # find out where we are resolving addresses
57+ ns_address = None
58+ with open('/etc/resolv.conf', 'r') as resolver:
59+ content = resolver.read()
60+ for line in content.splitlines():
61+ if line.startswith('nameserver'):
62+ ns_address = line.split(' ')[1]
63+ # set resolv.conf to use our local nameserver (not really needed, the tests force the server to localhost
64+ # subprocess.call(['sudo', 'sed', '-i', 's/^nameserver.*/nameserver 127.0.0.1/', '/etc/resolv.conf'])
65+ # set named forwarders to our resolver in the original resolv.conf
66+ forwarder = 's/^}/\tforwarders {%s;};}/' % ns_address
67+ subprocess.call(['sudo', 'sed', '-i', forwarder, '/etc/bind/named.conf.options'])
68 # give the system some time to finish startup
69 time.sleep(5)
70+ subprocess.call(['sudo', 'service', 'bind9', 'restart'])
71 unittest.main()

Subscribers

People subscribed via source and target branches