Fix the small amount of issues that require the autotest
client to require super user rights:
 * Symlinking init scripts
 * Logging system files

They are not critical to the test results, making non-root
runs more pleasant. Of course, tests themselves still need
to be disciplined with not requiring superuser operations
themselves.

Now running the local code with a regular user will only
print INFO messages saying it couldn't perform some
operations:

[lmr@freedom autotest.lmr]$ client/bin/autotest-local run sleeptest
16:26:39 INFO | Writing results to 
/home/lmr/Code/autotest.lmr/client/results/default
16:26:39 INFO | Could not symlink init scripts (lack of permissions)
16:26:39 INFO | Not logging /proc/slabinfo (lack of permissions)
16:26:40 INFO | START   ----    ----    timestamp=1328639200 localtime=Feb 07 
16:26:40
16:26:40 INFO |         START   sleeptest       sleeptest timestamp=1328639200  
localtime=Feb 07 16:26:40
16:26:40 INFO | Not logging /proc/slabinfo (lack of permissions)
16:26:41 INFO | Not logging /proc/slabinfo (lack of permissions)
16:26:41 ERROR| System log collection failed with [Errno 13] Permission denied: 
'/var/log/messages'
16:26:41 INFO |                 GOOD    sleeptest       sleeptest 
timestamp=1328639201  localtime=Feb 07 16:26:41 completed successfully
16:26:41 INFO |         END GOOD        sleeptest       sleeptest 
timestamp=1328639201  localtime=Feb 07 16:26:41
16:26:41 INFO | END GOOD        ----    ----    timestamp=1328639201 
localtime=Feb 07 16:26:41

This is part of the work described on github issue #151:

   https://github.com/autotest/autotest/issues/151

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 client/bin/base_sysinfo.py       |    8 ++++++--
 client/bin/harness_standalone.py |   16 ++++++++--------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/client/bin/base_sysinfo.py b/client/bin/base_sysinfo.py
index a195c95..eac013d 100644
--- a/client/bin/base_sysinfo.py
+++ b/client/bin/base_sysinfo.py
@@ -80,7 +80,11 @@ class logfile(loggable):
 
     def run(self, logdir):
         if os.path.exists(self.path):
-            shutil.copyfile(self.path, os.path.join(logdir, self.logf))
+            try:
+                shutil.copyfile(self.path, os.path.join(logdir, self.logf))
+            except IOError:
+                logging.info("Not logging %s (lack of permissions)",
+                             self.path)
 
 
 class command(loggable):
@@ -359,7 +363,7 @@ class base_sysinfo(object):
                 out_messages.close()
                 in_messages.close()
         except Exception, e:
-            logging.error("system log collection failed with %s", e)
+            logging.error("System log collection failed with %s", e)
 
 
     @staticmethod
diff --git a/client/bin/harness_standalone.py b/client/bin/harness_standalone.py
index 9ef5524..6cbc266 100644
--- a/client/bin/harness_standalone.py
+++ b/client/bin/harness_standalone.py
@@ -47,18 +47,18 @@ class harness_standalone(harness.harness):
         else:
             initdefault = '2'
 
+        vendor = utils.get_os_vendor()
+        service = '/etc/init.d/autotest'
+        if vendor == 'SUSE':
+            service_link = '/etc/init.d/rc%s.d/S99autotest' % initdefault
+        else:
+            service_link = '/etc/rc%s.d/S99autotest' % initdefault
         try:
-            vendor = utils.get_os_vendor()
-            service = '/etc/init.d/autotest'
-            if vendor == 'SUSE':
-                service_link = '/etc/init.d/rc%s.d/S99autotest' % initdefault
-            else:
-                service_link = '/etc/rc%s.d/S99autotest' % initdefault
             if os.path.islink(service):
                 os.remove(service)
             if os.path.islink(service_link):
                 os.remove(service_link)
             os.symlink(rc, service)
             os.symlink(rc, service_link)
-        except Exception, e:
-            logging.error("Symlink init scripts failed with %s", e)
+        except (OSError, IOError):
+            logging.info("Could not symlink init scripts (lack of 
permissions)")
-- 
1.7.7.6

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to