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',
12 # for tracking which hostnames have already had job_start called
13 _started_hostnames
= set()
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
]
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." %
30 # by default mix in run_test support
31 classes
.append(autotest
.AutotestHostMixin
)
33 # if the user really wants to use netconsole, let them
35 classes
.append(netconsole
.NetconsoleHost
)
38 # use serial console support if it's available
40 for key
in ("conmux_server", "conmux_attach"):
42 conmux_args
[key
] = args
[key
]
43 if serial
.SerialHost
.host_is_supported(hostname
, **conmux_args
):
44 classes
.append(serial
.SerialHost
)
46 # no serial available, fall back to direct dmesg logging
47 if follow_paths
is None:
48 follow_paths
= [DEFAULT_FOLLOW_PATH
]
50 follow_paths
= list(follow_paths
) + [DEFAULT_FOLLOW_PATH
]
52 if pattern_paths
is None:
53 pattern_paths
= [DEFAULT_PATTERNS_PATH
]
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
)
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
)