Best Python code snippet using autotest_python
monitor_db_functional_test.py
Source:monitor_db_functional_test.py
...90 self._set_pidfile_exit_status_queue = []91 # utility APIs for use by the test92 def finish_process(self, pidfile_type, exit_status=0):93 pidfile_id = self._last_pidfile_id[pidfile_type]94 self._set_pidfile_exit_status(pidfile_id, exit_status)95 def finish_specific_process(self, working_directory, pidfile_name):96 pidfile_id = self.pidfile_from_path(working_directory, pidfile_name)97 self._set_pidfile_exit_status(pidfile_id, 0)98 def finish_active_process_on_host(self, host_id):99 match = 'hosts/host%d/' % host_id100 for pidfile_id in self.nonfinished_pidfile_ids():101 if pidfile_id._working_directory.startswith(match):102 self._set_pidfile_exit_status(pidfile_id, 0)103 break104 else:105 raise KeyError('No active process matched %s' % match)106 def _set_pidfile_exit_status(self, pidfile_id, exit_status):107 assert pidfile_id is not None108 contents = self._pidfiles[pidfile_id]109 contents.exit_status = exit_status110 contents.num_tests_failed = 0111 def was_last_process_killed(self, pidfile_type, sigs):112 pidfile_id = self._last_pidfile_id[pidfile_type]113 return sigs == self._pids_to_signals_received[pidfile_id]114 def nonfinished_pidfile_ids(self):115 return [pidfile_id for pidfile_id, pidfile_contents116 in self._pidfiles.iteritems()117 if pidfile_contents.exit_status is None]118 def running_pidfile_ids(self):119 return [pidfile_id for pidfile_id in self.nonfinished_pidfile_ids()120 if self._pidfiles[pidfile_id].process is not None]121 def pidfile_from_path(self, working_directory, pidfile_name):122 return self._pidfile_index[(working_directory, pidfile_name)]123 def attached_files(self, working_directory):124 """125 Return dict mapping path to contents for attached files with specified126 paths.127 """128 return dict((path, contents) for path, contents129 in self._attached_files.get(working_directory, [])130 if path is not None)131 # DroneManager emulation APIs for use by monitor_db132 def get_orphaned_autoserv_processes(self):133 return set()134 def total_running_processes(self):135 return sum(pidfile_id._num_processes136 for pidfile_id in self.nonfinished_pidfile_ids())137 def max_runnable_processes(self, username, drone_hostnames_allowed):138 return self.process_capacity - self.total_running_processes()139 def refresh(self):140 for pidfile_id in self._unregistered_pidfiles:141 # intentionally handle non-registered pidfiles silently142 self._pidfiles.pop(pidfile_id, None)143 self._unregistered_pidfiles = set()144 def execute_actions(self):145 # executing an "execute_command" causes a pidfile to be created146 for pidfile_id in self._future_pidfiles:147 # Process objects are opaque to monitor_db148 process = object()149 self._pidfiles[pidfile_id].process = process150 self._process_index[process] = pidfile_id151 self._future_pidfiles = []152 for pidfile_id in self._set_pidfile_exit_status_queue:153 self._set_pidfile_exit_status(pidfile_id, 271)154 self._set_pidfile_exit_status_queue = []155 def attach_file_to_execution(self, result_dir, file_contents,156 file_path=None):157 self._attached_files.setdefault(result_dir, set()).add((file_path,158 file_contents))159 return 'attach_path'160 def _initialize_pidfile(self, pidfile_id):161 if pidfile_id not in self._pidfiles:162 assert pidfile_id.key() not in self._pidfile_index163 self._pidfiles[pidfile_id] = drone_manager.PidfileContents()164 self._pidfile_index[pidfile_id.key()] = pidfile_id165 def _set_last_pidfile(self, pidfile_id, working_directory, pidfile_name):166 if working_directory.startswith('hosts/'):167 # such paths look like hosts/host1/1-verify, we'll grab the end...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!