Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: client/site_tests/factory_UploadLogs/factory_UploadLogs.py

Issue 3206001: the new test to upload factory logs to FTP site (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git
Patch Set: use dict.update() as reviewer suggested Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/site_tests/factory_UploadLogs/factory_UploadLogs.py
diff --git a/client/site_tests/factory_UploadLogs/factory_UploadLogs.py b/client/site_tests/factory_UploadLogs/factory_UploadLogs.py
new file mode 100644
index 0000000000000000000000000000000000000000..ed56615a1b6b5668ad3e9d61858ab8a9f795c1ca
--- /dev/null
+++ b/client/site_tests/factory_UploadLogs/factory_UploadLogs.py
@@ -0,0 +1,73 @@
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import ftplib
+import gzip
+import hashlib
+import os
+import StringIO
+
+from autotest_lib.client.bin import factory
+from autotest_lib.client.bin import test, utils
+from autotest_lib.client.common_lib import error
+
+class factory_UploadLogs(test.test):
+ version = 1
+
+ DEFAULT_DESTINATION_PARAM = {
+ 'method': 'ftp',
+ 'host': 'localhost',
+ 'port': ftplib.FTP.port,
+ 'user': 'anonymous',
+ 'passwd': '',
+ 'timeout': 3*60,
+ 'initdir': '',
+ }
+
+ USE_GZIP = True
+
+ def prepare_source_object(self, text_source_filename):
+ ''' prepares the source file object from logs '''
+ content = open(text_source_filename, 'r').read()
+ hashval = hashlib.sha1(content).hexdigest()
+ if self.USE_GZIP:
+ buf = StringIO.StringIO()
+ zbuf = gzip.GzipFile(fileobj=buf, mode='w')
+ zbuf.write(content)
+ zbuf.close() # force gzip flush to stringIO buffer
+ else:
+ buf.write(content)
+ buf.seek(0) # prepare for further read
+ return hashval, buf
+
+ def do_upload_file(self, dest, fileobj):
+ ''' uploads (via FTP) fileobj to dest '''
+ factory.log('upload destination: %s://%s:%s@%s:%s/%s' %
+ (dest['method'], dest['user'],
+ '*',
+ #dest['password'],
+ dest['host'], dest['port'], dest['filename']))
+
+ assert dest['method'] == 'ftp', "only FTP is supported now."
+ ftp = ftplib.FTP()
+ ftp.connect(host=dest['host'], port=dest['port'],
+ timeout=dest['timeout'])
+ ftp.login(user=dest['user'], passwd=dest['passwd'])
+ ftp.storbinary('STOR %s' % dest['filename'], fileobj)
+ ftp.quit()
+
+ def run_once(self, destination):
+ assert 'filename' not in destination, "file names must be generated"
+ if destination['host'] == '*':
+ factory.log('WARNING: FACTORY LOG UPLOADING IS BYPASSED.')
+ return
+ src_hash, src_obj = self.prepare_source_object(factory.LOG_PATH)
+ dest = {}
+ dest.update(DEFAULT_DESTINATION_PARAM)
+ dest.update(destination)
+ dest_name = src_hash + '.log'
+ if self.USE_GZIP:
+ dest_name = dest_name + '.gz'
+ dest['filename'] = os.path.join(dest['initdir'], dest_name)
+ self.do_upload_file(dest, src_obj)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698