site_sysinfo.py revision 9a5bf359754af594b3bc62840505be1f2f1b7fec
1import os, shutil, re, logging 2 3from autotest_lib.client.common_lib import utils 4from autotest_lib.client.bin import base_sysinfo 5from autotest_lib.client.bin import chromeos_constants 6 7 8logfile = base_sysinfo.logfile 9command = base_sysinfo.command 10 11 12class logdir(base_sysinfo.loggable): 13 def __init__(self, directory): 14 super(logdir, self).__init__(directory, log_in_keyval=False) 15 self.dir = directory 16 17 18 def __repr__(self): 19 return "site_sysinfo.logdir(%r)" % self.dir 20 21 22 def __eq__(self, other): 23 if isinstance(other, logdir): 24 return self.dir == other.dir 25 elif isinstance(other, loggable): 26 return False 27 return NotImplemented 28 29 30 def __ne__(self, other): 31 result = self.__eq__(other) 32 if result is NotImplemented: 33 return result 34 return not result 35 36 37 def __hash__(self): 38 return hash(self.dir) 39 40 41 def run(self, log_dir): 42 if os.path.exists(self.dir): 43 parent_dir = os.path.dirname(self.dir) 44 utils.system("mkdir -p %s%s" % (log_dir, parent_dir)) 45 utils.system("rsync -a --exclude=autoserv* %s %s%s" % 46 (self.dir, log_dir, parent_dir)) 47 48 49class purgeable_logdir(logdir): 50 def __init__(self, directory): 51 super(purgeable_logdir, self).__init__(directory) 52 53 54 def run(self, log_dir): 55 super(purgeable_logdir, self).run(log_dir) 56 57 if os.path.exists(self.dir): 58 utils.system("rm -rf %s/*" % (self.dir)) 59 60 61 62class site_sysinfo(base_sysinfo.base_sysinfo): 63 def __init__(self, job_resultsdir): 64 super(site_sysinfo, self).__init__(job_resultsdir) 65 66 # add in some extra command logging 67 self.boot_loggables.add(command("ls -l /boot", 68 "boot_file_list")) 69 self.test_loggables.add(purgeable_logdir("/home/chronos/user/log")) 70 self.test_loggables.add(logdir("/var/log")) 71 # We only want to gather and purge crash reports after the client test 72 # runs in case a client test is checking that a crash found at boot 73 # (such as a kernel crash) is handled. 74 self.after_iteration_loggables.add(purgeable_logdir("/home/chronos/user/crash")) 75 self.after_iteration_loggables.add(purgeable_logdir("/var/spool/crash")) 76 self.test_loggables.add(logfile("/home/chronos/.Google/" 77 "Google Talk Plugin/gtbplugin.log")) 78 79 80 def log_test_keyvals(self, test_sysinfodir): 81 keyval = super(site_sysinfo, self).log_test_keyvals(test_sysinfodir) 82 83 lsb_lines = utils.system_output( 84 "cat /etc/lsb-release", 85 ignore_status=True).splitlines() 86 lsb_dict = dict(item.split("=") for item in lsb_lines) 87 88 for lsb_key in lsb_dict.keys(): 89 # Special handling for build number 90 if lsb_key == "CHROMEOS_RELEASE_DESCRIPTION": 91 keyval["CHROMEOS_BUILD"] = ( 92 lsb_dict[lsb_key].rstrip(")").split(" ")[3]) 93 keyval[lsb_key] = lsb_dict[lsb_key] 94 95 # return the updated keyvals 96 return keyval 97