def update_crash_count(self, system_id, crash, crash_count): self.auth_system(system_id) log_debug(1, self.server_id, "Updating crash count for %s to %s" % (crash, crash_count)) server_org_id = self.server.server['org_id'] server_crash_dir = get_crash_path(str(server_org_id), str(self.server_id), crash) if not server_crash_dir: log_debug(1, self.server_id, "Error composing crash directory path") raise rhnFault(5002) h = rhnSQL.prepare(_query_update_crash_count) r = h.execute( crash_count=crash_count, server_id=self.server_id, crash=crash) rhnSQL.commit() if r == 0: log_debug(1, self.server_id, "No record for crash: %s" % crash) raise rhnFault(5005, "Invalid crash name: %s" % crash) absolute_dir = os.path.join(CFG.MOUNT_POINT, server_crash_dir) absolute_file = os.path.join(absolute_dir, 'count') log_debug(1, self.server_id, "Updating crash count file: %s" % absolute_file) f = open(absolute_file, 'w+') f.write(crash_count) f.close() return 1
def update_crash_count(self, system_id, crash, crash_count): self.auth_system(system_id) log_debug(1, self.server_id, "Updating crash count for %s to %s" % (crash, crash_count)) server_org_id = self.server.server['org_id'] server_crash_dir = get_crash_path(str(server_org_id), str(self.server_id), crash) if not server_crash_dir: log_debug(1, self.server_id, "Error composing crash directory path") raise rhnFault(5002) h = rhnSQL.prepare(_query_update_crash_count) r = h.execute(crash_count=crash_count, server_id=self.server_id, crash=crash) rhnSQL.commit() if r == 0: log_debug(1, self.server_id, "No record for crash: %s" % crash) raise rhnFault(5005, "Invalid crash name: %s" % crash) absolute_dir = os.path.join(CFG.MOUNT_POINT, server_crash_dir) absolute_file = os.path.join(absolute_dir, 'count') log_debug(1, self.server_id, "Updating crash count file: %s" % absolute_file) f = open(absolute_file, 'w+') f.write(crash_count) f.close() return 1
def create_crash(self, system_id, crash_data, pkg_data): self.auth_system(system_id) log_debug(1, self.server_id, crash_data, pkg_data) self._check_crash_reporting_setting() if not ('crash' in crash_data and 'path' in crash_data) or \ not (crash_data['crash'] and crash_data['path']): log_debug( 1, self.server_id, "The crash information is invalid or incomplete: %s" % str(crash_data)) raise rhnFault(5000) server_org_id = self.server.server['org_id'] server_crash_dir = get_crash_path(str(server_org_id), str(self.server_id), crash_data['crash']) if not server_crash_dir: log_debug(1, self.server_id, "Error composing crash directory path") raise rhnFault(5002) crash_id = self._get_crash_id(self.server_id, crash_data['crash']) log_debug(1, "crash_id: %s" % crash_id) if (crash_id is None): if 'count' not in crash_data: crash_data['count'] = 1 h = rhnSQL.prepare(_query_create_crash) h.execute(server_id=self.server_id, crash=crash_data['crash'], path=crash_data['path'], crash_count=crash_data['count'], storage_path=server_crash_dir) rhnSQL.commit() self._update_package_data( self._get_crash_id(self.server_id, crash_data['crash']), pkg_data) return 1 else: return 0
def create_crash(self, system_id, crash_data, pkg_data): self.auth_system(system_id) log_debug(1, self.server_id, crash_data, pkg_data) self._check_crash_reporting_setting() if not ('crash' in crash_data and 'path' in crash_data) or \ not (crash_data['crash'] and crash_data['path']): log_debug(1, self.server_id, "The crash information is invalid or incomplete: %s" % str(crash_data)) raise rhnFault(5000) server_org_id = self.server.server['org_id'] server_crash_dir = get_crash_path(str(server_org_id), str(self.server_id), crash_data['crash']) if not server_crash_dir: log_debug(1, self.server_id, "Error composing crash directory path") raise rhnFault(5002) crash_id = self._get_crash_id(self.server_id, crash_data['crash']) log_debug(1, "crash_id: %s" % crash_id) if (crash_id is None): if 'count' not in crash_data: crash_data['count'] = 1 h = rhnSQL.prepare(_query_create_crash) h.execute( server_id=self.server_id, crash=crash_data['crash'], path=crash_data['path'], crash_count=crash_data['count'], storage_path=server_crash_dir) rhnSQL.commit() self._update_package_data(self._get_crash_id(self.server_id, crash_data['crash']), pkg_data) return 1 else: return 0
def upload_crash_file(self, system_id, crash, crash_file): self.auth_system(system_id) self._check_crash_reporting_setting() required_keys = ['filename', 'path', 'filesize', 'filecontent', 'content-encoding'] for k in required_keys: if k not in crash_file: log_debug(1, self.server_id, "The crash file data is invalid or incomplete: %s" % crash_file) raise rhnFault(5001, "Missing or invalid key: %s" % k) log_debug(1, self.server_id, crash, crash_file['filename']) server_org_id = self.server.server['org_id'] server_crash_dir = get_crash_path(str(server_org_id), str(self.server_id), crash) if not server_crash_dir: log_debug(1, self.server_id, "Error composing crash directory path") raise rhnFault(5002) server_filename = get_crashfile_path(str(server_org_id), str(self.server_id), crash, crash_file['filename']) if not server_filename: log_debug(1, self.server_id, "Error composing crash file path") raise rhnFault(5003) if not crash_file['content-encoding'] == 'base64': log_debug(1, self.server_id, "Invalid content encoding: %s" % crash_file['content-encoding']) raise rhnFault(5004, "Invalid content encodig: %s" % crash_file['content-encoding']) crash_id = self._get_crash_id(self.server_id, crash) if not crash_id: log_debug(1, self.server_id, "No record for crash: %s" % crash) raise rhnFault(5005, "Invalid crash name: %s" % crash) # Create or update the crash file record in DB self._create_or_update_crash_file(self.server_id, crash_id, crash_file['filename'], crash_file['path'], crash_file['filesize']) rhnSQL.commit() # Create the file on filer if not self._is_crashfile_uploading_enabled(server_org_id): return 1 filecontent = base64.decodestring(crash_file['filecontent']) claimed_filesize = crash_file['filesize'] filesize = len(filecontent) sizelimit = self._get_crashfile_sizelimit() if (claimed_filesize > sizelimit or filesize > sizelimit) and sizelimit != 0: if filesize == 0: filesize = claimed_filesize log_debug(1, "The file [%s] size (%s bytes) is more than allowed (%s bytes), skipping." % (crash_file['path'], filesize, sizelimit)) return 0 absolute_dir = os.path.join(CFG.MOUNT_POINT, server_crash_dir) absolute_file = os.path.join(absolute_dir, crash_file['filename']) if not os.path.exists(absolute_dir): log_debug(1, self.server_id, "Creating crash directory: %s" % absolute_dir) os.makedirs(absolute_dir) mode = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH os.chmod(absolute_dir, mode) os.chmod(os.path.dirname(os.path.normpath(absolute_dir)), mode) log_debug(1, self.server_id, "Creating crash file: %s" % absolute_file) f = open(absolute_file, 'w+') f.write(filecontent) f.close() self._set_crashfile_upload_flag(self.server_id, crash_id, crash_file['filename'], crash_file['path'], crash_file['filesize']) if crash_file['filename'] in self.watched_items: # 'username' contains an extra '\n' at the end if crash_file['filename'] == 'username': filecontent = filecontent.strip() st = rhnSQL.Statement(_query_update_watched_items % crash_file['filename']) h = rhnSQL.prepare(st) h.execute(filecontent=filecontent, crash_id=crash_id) rhnSQL.commit() return 1
def upload_crash_file(self, system_id, crash, crash_file): self.auth_system(system_id) self._check_crash_reporting_setting() required_keys = [ 'filename', 'path', 'filesize', 'filecontent', 'content-encoding' ] for k in required_keys: if k not in crash_file: log_debug( 1, self.server_id, "The crash file data is invalid or incomplete: %s" % crash_file) raise rhnFault(5001, "Missing or invalid key: %s" % k) log_debug(1, self.server_id, crash, crash_file['filename']) server_org_id = self.server.server['org_id'] server_crash_dir = get_crash_path(str(server_org_id), str(self.server_id), crash) if not server_crash_dir: log_debug(1, self.server_id, "Error composing crash directory path") raise rhnFault(5002) server_filename = get_crashfile_path(str(server_org_id), str(self.server_id), crash, crash_file['filename']) if not server_filename: log_debug(1, self.server_id, "Error composing crash file path") raise rhnFault(5003) if not crash_file['content-encoding'] == 'base64': log_debug( 1, self.server_id, "Invalid content encoding: %s" % crash_file['content-encoding']) raise rhnFault( 5004, "Invalid content encodig: %s" % crash_file['content-encoding']) crash_id = self._get_crash_id(self.server_id, crash) if not crash_id: log_debug(1, self.server_id, "No record for crash: %s" % crash) raise rhnFault(5005, "Invalid crash name: %s" % crash) # Create or update the crash file record in DB self._create_or_update_crash_file(self.server_id, crash_id, crash_file['filename'], crash_file['path'], crash_file['filesize']) rhnSQL.commit() # Create the file on filer if not self._is_crashfile_uploading_enabled(server_org_id): return 1 filecontent = base64.decodestring(crash_file['filecontent']) claimed_filesize = crash_file['filesize'] filesize = len(filecontent) sizelimit = self._get_crashfile_sizelimit() if (claimed_filesize > sizelimit or filesize > sizelimit) and sizelimit != 0: if filesize == 0: filesize = claimed_filesize log_debug( 1, "The file [%s] size (%s bytes) is more than allowed (%s bytes), skipping." % (crash_file['path'], filesize, sizelimit)) return 0 absolute_dir = os.path.join(CFG.MOUNT_POINT, server_crash_dir) absolute_file = os.path.join(absolute_dir, crash_file['filename']) if not os.path.exists(absolute_dir): log_debug(1, self.server_id, "Creating crash directory: %s" % absolute_dir) os.makedirs(absolute_dir) mode = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH os.chmod(absolute_dir, mode) os.chmod(os.path.dirname(os.path.normpath(absolute_dir)), mode) log_debug(1, self.server_id, "Creating crash file: %s" % absolute_file) f = open(absolute_file, 'w+') f.write(filecontent) f.close() self._set_crashfile_upload_flag(self.server_id, crash_id, crash_file['filename'], crash_file['path'], crash_file['filesize']) if crash_file['filename'] in self.watched_items: # 'username' contains an extra '\n' at the end if crash_file['filename'] == 'username': filecontent = filecontent.strip() st = rhnSQL.Statement(_query_update_watched_items % crash_file['filename']) h = rhnSQL.prepare(st) h.execute(filecontent=filecontent, crash_id=crash_id) rhnSQL.commit() return 1