Add THP test variants to tests_base.cfg.sample
[autotest-zwu.git] / server / hosts / factory.py
blob7a2a724b72397afc993d94da71ad928a75aaf356
1 from autotest_lib.client.common_lib import utils, error, global_config
2 from autotest_lib.server import autotest, utils as server_utils
3 from autotest_lib.server.hosts import site_factory, ssh_host, serial
4 from autotest_lib.server.hosts import logfile_monitor
6 DEFAULT_FOLLOW_PATH = '/var/log/kern.log'
7 DEFAULT_PATTERNS_PATH = 'console_patterns'
8 SSH_ENGINE = global_config.global_config.get_config_value('AUTOSERV',
9 'ssh_engine',
10 type=str)
12 # for tracking which hostnames have already had job_start called
13 _started_hostnames = set()
15 def create_host(
16 hostname, auto_monitor=True, follow_paths=None, pattern_paths=None,
17 netconsole=False, **args):
18 # by default assume we're using SSH support
19 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)
30 # by default mix in run_test support
31 classes.append(autotest.AutotestHostMixin)
33 # if the user really wants to use netconsole, let them
34 if netconsole:
35 classes.append(netconsole.NetconsoleHost)
37 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)
45 else:
46 # no serial available, fall back to direct dmesg logging
47 if follow_paths is None:
48 follow_paths = [DEFAULT_FOLLOW_PATH]
49 else:
50 follow_paths = list(follow_paths) + [DEFAULT_FOLLOW_PATH]
52 if pattern_paths is None:
53 pattern_paths = [DEFAULT_PATTERNS_PATH]
54 else:
55 pattern_paths = (
56 list(pattern_paths) + [DEFAULT_PATTERNS_PATH])
58 logfile_monitor_class = logfile_monitor.NewLogfileMonitorMixin(
59 follow_paths, pattern_paths)
60 classes.append(logfile_monitor_class)
62 elif follow_paths:
63 logfile_monitor_class = logfile_monitor.NewLogfileMonitorMixin(
64 follow_paths, pattern_paths)
65 classes.append(logfile_monitor_class)
67 # do any site-specific processing of the classes list
68 site_factory.postprocess_classes(classes, hostname,
69 auto_monitor=auto_monitor, **args)
71 hostname, args['user'], args['password'], args['port'] = \
72 server_utils.parse_machine(hostname, ssh_user, ssh_pass, ssh_port)
74 # create a custom host class for this machine and return an instance of it
75 host_class = type("%s_host" % hostname, tuple(classes), {})
76 host_instance = host_class(hostname, **args)
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)
83 return host_instance