How to use _open_logfile method in autotest

Best Python code snippet using autotest_python

reduxio_storkit_flocker_log-collector.py

Source:reduxio_storkit_flocker_log-collector.py Github

copy

Full Screen

...44 def _logfile_path(self, name):45 return os.path.join(self._archive_name,46 name,47 )48 def _open_logfile(self, name):49 return open(self._logfile_path(name), 'w')50 def get_reduxio_logs(self):51 regex = '/var/log/reduxio_storkit_flocker.log*'52 for filename in get_files_with_regex(regex=regex):53 log_filename = filename.split('/')54 log_filename = log_filename[-1]55 # log_file_path = self._logfile_path(log_filename.replace('.', '_') + '_rdx.gz')56 if filename.endswith('.gz'):57 copyfile(filename, os.path.join(self._archive_path, log_filename, ))58 else:59 log_filename = log_filename.replace('.', '_')60 gzip_file(filename, os.path.join(self._archive_path, log_filename + '.gz', ))61 def create(self):62 os.makedirs(self._archive_path)63 args = sys.argv64 if not args[1:]:65 args.append("--all")66 for arg in args[1:]:67 if arg not in self._args:68 return ("Illegal argument,\n"69 "--docker-log Docker logs"70 "\n--flocker-log Flocker logs\n"71 "--application-log Reduxio-StorKit-Flocker logs\n"72 "--sys-log system logs along with other system information\n"73 "--all all logs including Flocker diagnosticlogs\n")74 try:75 if "--docker-log" in args or "--all" in args:76 # Docker Logs77 self._log_exporter.export_docker(service_name='docker', target_path=self._archive_path)78 # Docker version79 check_call(80 ['docker', 'version'],81 stdout=self._open_logfile('docker-version')82 )83 # Docker configuration84 check_call(85 ['docker', 'info'],86 stdout=self._open_logfile('docker-info')87 )88 if "--application-log" in args or "--all" in args:89 # Reduxio Flocker Driver Logs90 self.get_reduxio_logs()91 if "--flocker-log" in args or "--all" in args:92 # Flocker version93 with self._open_logfile('flocker-version') as output:94 output.write(__version__.encode('utf-8') + b'\n')95 # Flocker logs.96 services = self._service_manager.flocker_services()97 for service_name, service_status in services:98 self._log_exporter.export_flocker(99 service_name=service_name,100 target_path=self._logfile_path(service_name)101 )102 if "--sys-log" in args or "--all" in args:103 # Syslog.104 self._log_exporter.export_all(self._logfile_path('syslog'))105 # Status of all services.106 with self._open_logfile('service-status') as output:107 services = self._service_manager.all_services()108 for service_name, service_status in services:109 output.write(service_name + " " + service_status + "\n")110 # Kernel version111 self._open_logfile('uname').write(' '.join(os.uname()))112 # Distribution version113 self._open_logfile('os-release').write(114 open('/etc/os-release').read()115 )116 # Network configuration117 check_call(118 ['ip', 'addr'],119 stdout=self._open_logfile('ip-addr')120 )121 # Hostname122 self._open_logfile('hostname').write(gethostname() + '\n')123 # Partition information124 check_call(125 ['fdisk', '-l'],126 stdout=self._open_logfile('fdisk')127 )128 # Block Device and filesystem information129 check_call(130 ['lsblk', '--all'],131 stdout=self._open_logfile('lsblk')132 )133 # Hardware inventory134 self._open_logfile('lshw').write(list_hardware())135 # Create a single archive file136 archive_path = make_archive(137 base_name=self._archive_name,138 format='tar',139 root_dir=os.path.dirname(self._archive_path),140 base_dir=os.path.basename(self._archive_path),141 )142 finally:143 # Attempt to remove the source directory.144 rmtree(self._archive_path)145 return archive_path146class SystemdServiceManager(object):147 """148 List services managed by Systemd....

Full Screen

Full Screen

diagnostics.py

Source:diagnostics.py Github

copy

Full Screen

...64 return os.path.join(65 self._archive_name,66 name,67 )68 def _open_logfile(self, name):69 """70 :param str name: A unique label for the file.71 :return: An open ``file`` object with a name generated by72 `_logfile_path`.73 """74 return open(self._logfile_path(name), 'w')75 def create(self):76 """77 Create the archive by first creating a uniquely named directory in the78 current working directory, adding the log files and debug information,79 creating a ``tar`` archive from the directory and finally removing the80 directory.81 """82 os.makedirs(self._archive_path)83 try:84 # Flocker version85 with self._open_logfile('flocker-version') as output:86 output.write(__version__.encode('utf-8') + b'\n')87 # Flocker logs.88 services = self._service_manager.flocker_services()89 for service_name, service_status in services:90 self._log_exporter.export_flocker(91 service_name=service_name,92 target_path=self._logfile_path(service_name)93 )94 # Syslog.95 self._log_exporter.export_all(self._logfile_path('syslog'))96 # Status of all services.97 with self._open_logfile('service-status') as output:98 services = self._service_manager.all_services()99 for service_name, service_status in services:100 output.write(service_name + " " + service_status + "\n")101 # Docker version102 check_call(103 ['docker', 'version'],104 stdout=self._open_logfile('docker-version')105 )106 # Docker configuration107 check_call(108 ['docker', 'info'],109 stdout=self._open_logfile('docker-info')110 )111 # Kernel version112 self._open_logfile('uname').write(' '.join(os.uname()))113 # Distribution version114 self._open_logfile('os-release').write(115 open('/etc/os-release').read()116 )117 # Network configuration118 check_call(119 ['ip', 'addr'],120 stdout=self._open_logfile('ip-addr')121 )122 # Hostname123 self._open_logfile('hostname').write(gethostname() + '\n')124 # Partition information125 check_call(126 ['fdisk', '-l'],127 stdout=self._open_logfile('fdisk')128 )129 # Block Device and filesystem information130 check_call(131 ['lsblk', '--all'],132 stdout=self._open_logfile('lsblk')133 )134 # Hardware inventory135 self._open_logfile('lshw').write(list_hardware())136 # Create a single archive file137 archive_path = make_archive(138 base_name=self._archive_name,139 format='tar',140 root_dir=os.path.dirname(self._archive_path),141 base_dir=os.path.basename(self._archive_path),142 )143 finally:144 # Attempt to remove the source directory.145 rmtree(self._archive_path)146 return archive_path147class SystemdServiceManager(object):148 """149 List services managed by Systemd....

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful