blob: 7a2a724b72397afc993d94da71ad928a75aaf356 [file] [log] [blame]
mbligh55552bf2009-11-06 03:12:38 +00001from autotest_lib.client.common_lib import utils, error, global_config
jadmanskic6136e92010-07-19 16:41:49 +00002from autotest_lib.server import autotest, utils as server_utils
jadmanskiaf959a42008-11-11 18:34:43 +00003from autotest_lib.server.hosts import site_factory, ssh_host, serial
mblighe48bcfb2008-11-11 17:09:44 +00004from autotest_lib.server.hosts import logfile_monitor
5
6DEFAULT_FOLLOW_PATH = '/var/log/kern.log'
7DEFAULT_PATTERNS_PATH = 'console_patterns'
mbligh55552bf2009-11-06 03:12:38 +00008SSH_ENGINE = global_config.global_config.get_config_value('AUTOSERV',
9 'ssh_engine',
10 type=str)
jadmanski635b06f2008-09-05 20:26:44 +000011
jadmanskid60321a2008-10-28 20:32:05 +000012# for tracking which hostnames have already had job_start called
13_started_hostnames = set()
14
mblighe48bcfb2008-11-11 17:09:44 +000015def create_host(
jadmanskicb4aac72008-11-24 22:31:38 +000016 hostname, auto_monitor=True, follow_paths=None, pattern_paths=None,
17 netconsole=False, **args):
jadmanski635b06f2008-09-05 20:26:44 +000018 # by default assume we're using SSH support
mbligh55552bf2009-11-06 03:12:38 +000019 if SSH_ENGINE == 'paramiko':
20 from autotest_lib.server.hosts import paramiko_host
21 classes = [paramiko_host.ParamikoHost]
22 elif SSH_ENGINE == 'raw_ssh':
23 classes = [ssh_host.SSHHost]
24 else:
25 raise error.AutoServError("Unknown SSH engine %s. Please verify the "
26 "value of the configuration key 'ssh_engine' "
27 "on autotest's global_config.ini file." %
28 SSH_ENGINE)
jadmanski635b06f2008-09-05 20:26:44 +000029
jadmanskic6136e92010-07-19 16:41:49 +000030 # by default mix in run_test support
31 classes.append(autotest.AutotestHostMixin)
32
jadmanskicb4aac72008-11-24 22:31:38 +000033 # if the user really wants to use netconsole, let them
34 if netconsole:
35 classes.append(netconsole.NetconsoleHost)
36
jadmanski54f90af2008-10-10 16:20:55 +000037 if auto_monitor:
38 # use serial console support if it's available
39 conmux_args = {}
40 for key in ("conmux_server", "conmux_attach"):
41 if key in args:
42 conmux_args[key] = args[key]
43 if serial.SerialHost.host_is_supported(hostname, **conmux_args):
44 classes.append(serial.SerialHost)
jadmanski635b06f2008-09-05 20:26:44 +000045 else:
jadmanskiaf959a42008-11-11 18:34:43 +000046 # no serial available, fall back to direct dmesg logging
47 if follow_paths is None:
48 follow_paths = [DEFAULT_FOLLOW_PATH]
jadmanski54f90af2008-10-10 16:20:55 +000049 else:
jadmanskiaf959a42008-11-11 18:34:43 +000050 follow_paths = list(follow_paths) + [DEFAULT_FOLLOW_PATH]
mblighe48bcfb2008-11-11 17:09:44 +000051
jadmanskiaf959a42008-11-11 18:34:43 +000052 if pattern_paths is None:
53 pattern_paths = [DEFAULT_PATTERNS_PATH]
54 else:
55 pattern_paths = (
56 list(pattern_paths) + [DEFAULT_PATTERNS_PATH])
mblighe48bcfb2008-11-11 17:09:44 +000057
jadmanskiaf959a42008-11-11 18:34:43 +000058 logfile_monitor_class = logfile_monitor.NewLogfileMonitorMixin(
59 follow_paths, pattern_paths)
60 classes.append(logfile_monitor_class)
mblighe48bcfb2008-11-11 17:09:44 +000061
62 elif follow_paths:
63 logfile_monitor_class = logfile_monitor.NewLogfileMonitorMixin(
64 follow_paths, pattern_paths)
65 classes.append(logfile_monitor_class)
jadmanski635b06f2008-09-05 20:26:44 +000066
67 # do any site-specific processing of the classes list
jadmanskid60321a2008-10-28 20:32:05 +000068 site_factory.postprocess_classes(classes, hostname,
jadmanskiea902262008-10-16 15:51:00 +000069 auto_monitor=auto_monitor, **args)
jadmanski635b06f2008-09-05 20:26:44 +000070
Eric Li7edb3042011-01-06 17:57:17 -080071 hostname, args['user'], args['password'], args['port'] = \
72 server_utils.parse_machine(hostname, ssh_user, ssh_pass, ssh_port)
Eric Li10222b82010-11-24 09:33:15 -080073
jadmanski635b06f2008-09-05 20:26:44 +000074 # create a custom host class for this machine and return an instance of it
75 host_class = type("%s_host" % hostname, tuple(classes), {})
jadmanskid60321a2008-10-28 20:32:05 +000076 host_instance = host_class(hostname, **args)
77
78 # call job_start if this is the first time this host is being used
79 if hostname not in _started_hostnames:
80 host_instance.job_start()
81 _started_hostnames.add(hostname)
82
83 return host_instance