Uses the nameservers specified in resolv.conf and
uses them to query www.google.com and verifies the
answers.

---
 resolv/control   |   14 ++++++++
 resolv/resolv.py |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
 create mode 100644 resolv/control
 create mode 100755 resolv/resolv.py

diff --git a/resolv/control b/resolv/control
new file mode 100644
index 0000000..cb851a6
--- /dev/null
+++ b/resolv/control
@@ -0,0 +1,14 @@
+AUTHOR = "Rajeev S <[email protected]>"
+NAME = "resolv.conf"
+TEST_CATEGORY = "Functional"
+TEST_CLASS = "Linux Tools"
+TEST_TYPE = "client"
+TIME = 'SHORT'
+DOC = '''
+Test for testing the resolv.conf.
+'''
+import time
+
+LOGFILE = '/tmp/autotest_resolv-%s' % time.strftime('%Y-%m-%d-%H.%M.%S')
+
+job.run_test('resolv', test = 'resolv', wait_time = 65, tag = 'resolv', log = 
LOGFILE)
diff --git a/resolv/resolv.py b/resolv/resolv.py
new file mode 100755
index 0000000..57362c5
--- /dev/null
+++ b/resolv/resolv.py
@@ -0,0 +1,90 @@
+#!/bin/python
+import os, shutil, glob, logging, urllib
+from autotest.client import test, utils
+from autotest.client.shared import error,software_manager
+from time import sleep
+
+
+class resolv(test.test):
+    '''
+    Autotest module for testing resolv.conf
+
+    Checks the resolv.conf file for nameservers and
+    verifies their credibility,
+
+    @author :Rajeev S <[email protected]>
+    '''
+    version = 1
+    initial_count = 0
+    log = ''
+    nfail = 0
+
+    def setup(self):
+        ''' Install dnspython '''
+        backend=software_manager.SoftwareManager()
+        logging.info('\nInstalling python-dnspython')
+        backend.install('python-dnspython')
+
+    def initialize(self, test, log):
+        pass
+
+    def run_once(self, test):
+        ''' 
+            Test case reads the resolv.conf and extracts the DNS entries.
+            Followed by that,the testcase queries www.google.com and
+            waits for answers.The A records recieved are fetched and
+            from the reply header,it is verified wether the server header
+            is 'gws' or Google Web Server.
+        '''
+        ns = []
+        try:
+            f = open('/etc/resolv.conf')
+            for i in f.readlines():
+                ns.append(i.split()[1])
+            f.close()
+        except Exception as e:
+            #Cannot find/open reslov.conf
+            nfail = 1
+            raise error.TestError('\nCannot find file resolv.conf or 
resolv.conf empty')
+        try:
+            import dns.resolver as r,dns.exception
+        except Exception:
+            #Package not found
+            nfail = 1
+            raise error.TestError('\ndnspython module not found.Please 
install.')
+        try:
+            res = r.Resolver()
+            res.nameserver = ns
+            ans = res.query('www.google.com')
+        except dns.exception.Timeout:
+            #DNS address wrong,cannot fetch.
+            nfail = 1
+            raise error.TestError('''\nThe current nameservers cannot be 
reached.
+Your resolv.conf settings may be corrupted.''')
+        flag = 0
+        u = ''
+        for i in ans:
+            try:
+                #Fetch google IP recieved from DNS lookup
+                u = urllib.urlopen('http://'+str(i))
+            except:
+                pass
+            if u.info().getheader('server') == 'gws':
+                #check if reply header is from GWS
+                flag = 0
+                break
+            else:
+                flag = 1
+        if flag == 1:
+            #Reply header is not from GWS
+            nfail = 1
+            raise error.TestError('''\nThe IP returned by nameserver does not 
seem to be right''')
+
+    def cleanup(self):
+        pass
+
+    def postprocess(self):
+        if self.nfail != 0:
+            raise error.TestError('\nTest failed')
+        else:
+            logging.info('\nTest completed successfully')

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to