Add the ability to clear out known hosts file for a specific host, and for all hosts in a job.
This is useful when we reinstall the machine to reduce the "REMOTE HOST IDENTIFICATION HAS CHANGED" spam warnings. Signed-off-by: Girts Folkmanis <[email protected]> --- autotest/server/hosts/abstract_ssh.py 2010-04-09 10:49:40.000000000 -0700 +++ autotest/server/hosts/abstract_ssh.py 2010-04-09 10:49:40.000000000 -0700 @@ -570,3 +570,17 @@ master_cmd = self.ssh_command(options="-N -o ControlMaster=yes") logging.info("Starting master ssh connection '%s'" % master_cmd) self.master_ssh_job = utils.BgJob(master_cmd) + + + def clear_known_hosts(self): + """Clears out the temporary ssh known_hosts file. + + This is useful if the test SSHes to the machine, then reinstalls it, + then SSHes to it again. It can be called after the reinstall to + reduce the spam in the logs. + """ + logging.info("Clearing known hosts for host '%s', file '%s'.", + self.hostname, self.known_hosts_fd) + # Clear out the file by opening it for writing and then closing. + fh = open(self.known_hosts_fd, "w") + fh.close() --- autotest/server/server_job.py 2010-04-09 10:49:40.000000000 -0700 +++ autotest/server/server_job.py 2010-04-09 10:49:40.000000000 -0700 @@ -13,6 +13,7 @@ from autotest_lib.client.common_lib import error, log, utils, packages from autotest_lib.client.common_lib import logging_manager from autotest_lib.server import test, subcommand, profilers +from autotest_lib.server.hosts import abstract_ssh from autotest_lib.tko import db as tko_db, status_lib, utils as tko_utils @@ -1140,6 +1141,13 @@ self._state.discard_namespace('client') + def clear_all_known_hosts(self): + """Clears known hosts files for all AbstractSSHHosts.""" + for host in self.hosts: + if isinstance(host, abstract_ssh.AbstractSSHHost): + host.clear_known_hosts() + + site_server_job = utils.import_site_class( __file__, "autotest_lib.server.site_server_job", "site_server_job", base_server_job) _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
