Best Python code snippet using autotest_python
drones.py
Source:drones.py
...38 def usable_by(self, user):39 if self.allowed_users is None:40 return True41 return user in self.allowed_users42 def _execute_calls_impl(self, calls):43 raise NotImplementedError44 def _execute_calls(self, calls):45 return_message = self._execute_calls_impl(calls)46 for warning in return_message['warnings']:47 subject = 'Warning from drone %s' % self.hostname48 logging.warn(subject + '\n' + warning)49 email_manager.manager.enqueue_notify_email(subject, warning)50 return return_message['results']51 def call(self, method, *args, **kwargs):52 return self._execute_calls(53 [drone_utility.call(method, *args, **kwargs)])54 def queue_call(self, method, *args, **kwargs):55 self._calls.append(drone_utility.call(method, *args, **kwargs))56 def clear_call_queue(self):57 self._calls = []58 def execute_queued_calls(self):59 if not self._calls:60 return61 self._execute_calls(self._calls)62 self.clear_call_queue()63 def set_autotest_install_dir(self, path):64 pass65class _LocalDrone(_AbstractDrone):66 def __init__(self):67 super(_LocalDrone, self).__init__()68 self.hostname = 'localhost'69 self._drone_utility = drone_utility.DroneUtility()70 def _execute_calls_impl(self, calls):71 return self._drone_utility.execute_calls(calls)72 def send_file_to(self, drone, source_path, destination_path,73 can_fail=False):74 if drone.hostname == self.hostname:75 self.queue_call('copy_file_or_directory', source_path,76 destination_path)77 else:78 self.queue_call('send_file_to', drone.hostname, source_path,79 destination_path, can_fail)80class _RemoteDrone(_AbstractDrone):81 def __init__(self, hostname):82 super(_RemoteDrone, self).__init__()83 self.hostname = hostname84 self._host = drone_utility.create_host(hostname)85 if not self._host.is_up():86 logging.error('Drone %s is unpingable, kicking out', hostname)87 raise DroneUnreachable88 self._autotest_install_dir = AUTOTEST_INSTALL_DIR89 def set_autotest_install_dir(self, path):90 self._autotest_install_dir = path91 def shutdown(self):92 super(_RemoteDrone, self).shutdown()93 self._host.close()94 def _execute_calls_impl(self, calls):95 logging.info("Running drone_utility on %s", self.hostname)96 drone_utility_path = os.path.join(self._autotest_install_dir,97 'scheduler', 'drone_utility.py')98 result = self._host.run('python %s' % drone_utility_path,99 stdin=cPickle.dumps(calls), connect_timeout=300)100 try:101 return cPickle.loads(result.stdout)102 except Exception: # cPickle.loads can throw all kinds of exceptions103 logging.critical('Invalid response:\n---\n%s\n---', result.stdout)104 raise105 def send_file_to(self, drone, source_path, destination_path,106 can_fail=False):107 if drone.hostname == self.hostname:108 self.queue_call('copy_file_or_directory', source_path,...
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!!