def test_choose_connectivity_unsupported(self): """Confirm exception when configured for unsupported ssh engine. """ factory.SSH_ENGINE = 'unsupported' machine = _gen_machine_dict(hostname='somehost') with self.assertRaises(error.AutoservError): factory.create_host(machine)
def _auto_detect_labels(afe, remote): """Automatically detect host labels and add them to the host in afe. Note that the label of board will not be auto-detected. This method assumes the host |remote| has already been added to afe. @param afe: A direct_afe object used to interact with local afe database. @param remote: The hostname of the remote device. """ cros_host = factory.create_host(remote) labels_to_create = [ label for label in cros_host.get_labels() if not label.startswith(constants.BOARD_PREFIX) ] labels_to_add_to_afe_host = [] for label in labels_to_create: new_label = afe.create_label(label) labels_to_add_to_afe_host.append(new_label.name) hosts = afe.get_hosts(hostname=remote) if not hosts: raise TestThatRunError('Unexpected error: %s has not ' 'been added to afe.' % remote) afe_host = hosts[0] afe_host.add_labels(labels_to_add_to_afe_host)
def test_choose_connectivity_ssh(self): """Confirm ssh connectivity class used when configured and hostname is not localhost. """ machine = _gen_machine_dict(hostname='somehost') host_obj = factory.create_host(machine) self.assertEqual(host_obj._conn_cls_name, 'ssh')
def test_detect_host_by_os_label(self): """Confirm that the host object is selected by the os label. """ machine = _gen_machine_dict(labels=['os:foo']) self.os_host_dict['foo'] = _gen_mock_host('foo') host_obj = factory.create_host(machine) self.assertEqual(host_obj._host_cls_name, 'foo')
def test_use_specified(self): """Confirm that the specified host and connectivity classes are used.""" machine = _gen_machine_dict() host_obj = factory.create_host(machine, _gen_mock_host('specified'), _gen_mock_conn('specified')) self.assertEqual(host_obj._host_cls_name, 'specified') self.assertEqual(host_obj._conn_cls_name, 'specified')
def test_use_specified(self): """Confirm that the specified host class is used.""" machine = _gen_machine_dict() host_obj = factory.create_host( machine, _gen_mock_host('specified'), ) self.assertEqual(host_obj._host_cls_name, 'specified')
def test_argument_passthrough(self): """Confirm that detected and specified arguments are passed through to the host object. """ machine = _gen_machine_dict(hostname='localhost') host_obj = factory.create_host(machine, foo='bar') self.assertEqual(host_obj._init_args['hostname'], 'localhost') self.assertTrue('afe_host' in host_obj._init_args) self.assertTrue('host_info_store' in host_obj._init_args) self.assertEqual(host_obj._init_args['foo'], 'bar')
def test_detect_host_by_check_host(self): """Confirm check_host logic chooses a host object when label/attribute detection fails. """ machine = _gen_machine_dict() self.host_types.append(_gen_mock_host('first', check_host=False)) self.host_types.append(_gen_mock_host('second', check_host=True)) self.host_types.append(_gen_mock_host('third', check_host=False)) host_obj = factory.create_host(machine) self.assertEqual(host_obj._host_cls_name, 'second')
def test_detect_host_by_os_type_attribute(self): """Confirm that the host object is selected by the os_type attribute and that the os_type attribute is preferred over the os label. """ machine = _gen_machine_dict(labels=['os:foo'], attributes={'os_type': 'bar'}) self.os_host_dict['foo'] = _gen_mock_host('foo') self.os_host_dict['bar'] = _gen_mock_host('bar') host_obj = factory.create_host(machine) self.assertEqual(host_obj._host_cls_name, 'bar')
def powerwash_dut(hostname): """Powerwash the dut with the given hostname. @param hostname: hostname of the dut. """ host = factory.create_host(hostname) host.run('echo "fast safe" > ' '/mnt/stateful_partition/factory_install_reset') host.run('reboot') host.close()
def test_host_attribute_ssh_params(self): """Confirm passing of ssh parameters from host attributes. """ machine = _gen_machine_dict(attributes={'ssh_user': '******', 'ssh_port': 100, 'ssh_verbosity_flag': 'verb', 'ssh_options': 'options'}) host_obj = factory.create_host(machine) self.assertEqual(host_obj._init_args['user'], 'somebody') self.assertEqual(host_obj._init_args['port'], 100) self.assertEqual(host_obj._init_args['ssh_verbosity_flag'], 'verb') self.assertEqual(host_obj._init_args['ssh_options'], 'options')
def _get_board_from_host(remote): """Get the board of the remote host. @param remote: string representing the IP of the remote host. @return: A string representing the board of the remote host. """ logging.info('Board unspecified, attempting to determine board from host.') host = factory.create_host(remote) try: board = host.get_board().replace(constants.BOARD_PREFIX, '') except error.AutoservRunError: raise test_runner_utils.TestThatRunError( 'Cannot determine board, please specify a --board option.') logging.info('Detected host board: %s', board) return board
def test_global_ssh_params(self): """Confirm passing of ssh parameters set as globals. """ factory.ssh_user = '******' factory.ssh_pass = '******' factory.ssh_port = 1 factory.ssh_verbosity_flag = 'baz' factory.ssh_options = 'zip' machine = _gen_machine_dict() try: host_obj = factory.create_host(machine) self.assertEqual(host_obj._init_args['user'], 'foo') self.assertEqual(host_obj._init_args['password'], 'bar') self.assertEqual(host_obj._init_args['port'], 1) self.assertEqual(host_obj._init_args['ssh_verbosity_flag'], 'baz') self.assertEqual(host_obj._init_args['ssh_options'], 'zip') finally: del factory.ssh_user del factory.ssh_pass del factory.ssh_port del factory.ssh_verbosity_flag del factory.ssh_options
#!/usr/bin/env python """ Usage: ./print_host_labels.py <IP.or.hostname> """ import sys import common from autotest_lib.server.hosts import factory if len(sys.argv) < 2: print 'Usage: %s <IP.or.hostname>' % sys.argv[0] exit(1) host = factory.create_host(sys.argv[1]) labels = host.get_labels() print 'Labels:' print labels
def test_choose_connectivity_local(self): """Confirm local connectivity class used when hostname is localhost. """ machine = _gen_machine_dict(hostname='localhost') host_obj = factory.create_host(machine) self.assertEqual(host_obj._conn_cls_name, 'local')
def test_detect_host_fallback_to_cros_host(self): """Confirm fallback to CrosHost when all other detection fails. """ machine = _gen_machine_dict() host_obj = factory.create_host(machine) self.assertEqual(host_obj._host_cls_name, 'cros_host')