Best Python code snippet using autotest_python
install_server.py
Source: install_server.py
2Install server interfaces, for autotest client machine OS provisioning.3"""4import os, xmlrpclib, logging, time5from autotest_lib.client.common_lib import error6def remove_hosts_file():7 """8 Remove the ssh known hosts file for a machine.9 Sometimes it is useful to have this done since on a test lab, SSH10 fingerprints of the test machines keep changing all the time due11 to frequent reinstalls.12 """13 known_hosts_file = "%s/.ssh/known_hosts" % os.getenv("HOME")14 if os.path.isfile(known_hosts_file):15 logging.debug("Deleting known hosts file %s", known_hosts_file)16 os.remove(known_hosts_file)17class CobblerInterface(object):18 """19 Implements interfacing with the Cobbler install server.20 @see: https://fedorahosted.org/cobbler/21 """22 def __init__(self, **kwargs):23 """24 Sets class attributes from the keyword arguments passed to constructor.25 @param **kwargs: Dict of keyword arguments passed to constructor.26 """27 self.xmlrpc_url = kwargs['xmlrpc_url']28 self.user = kwargs['user']29 self.password = kwargs['password']30 self.fallback_profile = kwargs['fallback_profile']31 if self.xmlrpc_url:32 self.server = xmlrpclib.Server(self.xmlrpc_url)33 self.token = self.server.login(self.user, self.password)34 def get_system_handle(self, host):35 """36 Get a system handle, needed to perform operations on the given host37 @param host: Host name38 @return: Tuple (system, system_handle)39 """40 try:41 system = self.server.find_system({"name" : host.hostname})[0]42 except IndexError, detail:43 ### TODO: Method to register this system as brand new44 logging.error("Error finding %s: %s", host.hostname, detail)45 raise ValueError("No system %s registered on install server" %46 host.hostname)47 system_handle = self.server.get_system_handle(system, self.token)48 return (system, system_handle)49 def install_host(self, host, profile=None, timeout=None):50 """51 Install a host object with profile name defined by distro.52 @param host: Autotest host object.53 @param profile: String with cobbler profile name.54 @param timeout: Amount of time to wait for the install.55 """56 if self.xmlrpc_url:57 step_time = 6058 if timeout is None:59 # 1 hour of timeout by default60 timeout = 1 * 360061 logging.info("Setting up machine %s install", host.hostname)62 remove_hosts_file()63 system, system_handle = self.get_system_handle(host)64 if profile is None:65 profile = self.fallback_profile66 system_info = self.server.get_system(system)67 current_profile = system_info.get('profile')68 # If no fallback profile is enabled, we don't want to mess69 # with the currently profile set for that machine.70 if profile and (profile != current_profile):71 self.server.modify_system(system_handle, 'profile', profile,72 self.token)73 else:74 profile = current_profile75 # Enable netboot for that machine (next time it'll reboot and be76 # reinstalled)...
test_unit.py
Source: test_unit.py
...10def setup_and_teardown():11 unit_box.create()12 unit_test_config.write_to_hosts_file(unit_box.ssh_config())13 yield14 unit_test_config.remove_hosts_file()15 unit_box.destroy()16def test_check_openvswitch_playbook():17 unit_playbook = playbook.AnsiblePlaybook('playbook', 'site.yml', HOSTS_FILE)18 unit_playbook.add_extra_vars('container_network', 'test')...
Check out the latest blogs from LambdaTest on this topic:
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
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!!