How to use remove_hosts_file method in autotest

Best Python code snippet using autotest_python Github


Full Screen

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: """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"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)...

Full Screen

Full Screen Github


Full Screen

...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')...

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:


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?