Exemple #1
0
    def run_once(self, pair, udp, bidirectional, time, stream_list):
        print "running on %s and %s\n" % (pair[0], pair[1])

        # Designate a lable for the server side tests.
        server_label = 'net_server'

        tagname = "%s_%s" % (pair[0], pair[1])
        server = hosts.create_host(pair[0])
        client = hosts.create_host(pair[1])

        # Ensure the client doesn't have the server label.
        platform_label = client.get_platform_label()
        if platform_label == server_label:
            (server, client) = (client, server)

        # Disable IPFilters if they are present.
        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.disable_ipfilters()

        server_at = autotest.Autotest(server)
        client_at = autotest.Autotest(client)

        template = ''.join([
            "job.run_test('iperf', server_ip='%s', client_ip=",
            "'%s', role='%s', udp=%s, bidirectional=%s,",
            "test_time=%d, stream_list=%s, tag='%s')"
        ])

        server_control_file = template % (server.ip, client.ip, 'server', udp,
                                          bidirectional, time, stream_list,
                                          tagname)
        client_control_file = template % (server.ip, client.ip, 'client', udp,
                                          bidirectional, time, stream_list,
                                          tagname)

        server_command = subcommand.subcommand(
            server_at.run, [server_control_file, server.hostname])
        client_command = subcommand.subcommand(
            client_at.run, [client_control_file, client.hostname])

        subcommand.parallel([server_command, client_command])

        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.enable_ipfilters()
Exemple #2
0
    def execute(self):
        # Check to see if the platform or any other labels can be grabbed from
        # the hosts.
        self.host_info_map = {}
        for host in self.hosts:
            try:
                if utils.ping(host, tries=1, deadline=1) == 0:
                    if self.serials and len(self.serials) > 1:
                        host_dut = hosts.create_testbed(
                            host, adb_serials=self.serials)
                    else:
                        adb_serial = None
                        if self.serials:
                            adb_serial = self.serials[0]
                        host_dut = hosts.create_host(host,
                                                     adb_serial=adb_serial)
                    host_info = host_information(host, host_dut.get_platform(),
                                                 host_dut.get_labels())
                else:
                    # Can't ping the host, use default information.
                    host_info = host_information(host, None, [])
            except (socket.gaierror, error.AutoservRunError,
                    error.AutoservSSHTimeout):
                # We may be adding a host that does not exist yet or we can't
                # reach due to hostname/address issues or if the host is down.
                host_info = host_information(host, None, [])
            self.host_info_map[host] = host_info
        # We need to check if these labels & ACLs exist,
        # and create them if not.
        if self.platform:
            self.check_and_create_items('get_labels',
                                        'add_label', [self.platform],
                                        platform=True)
        else:
            # No platform was provided so check and create the platform label
            # for each host.
            platforms = []
            for host_info in self.host_info_map.values():
                if host_info.platform and host_info.platform not in platforms:
                    platforms.append(host_info.platform)
            if platforms:
                self.check_and_create_items('get_labels',
                                            'add_label',
                                            platforms,
                                            platform=True)
        labels_to_check_and_create = self.labels[:]
        for host_info in self.host_info_map.values():
            labels_to_check_and_create = (host_info.labels +
                                          labels_to_check_and_create)
        if labels_to_check_and_create:
            self.check_and_create_items('get_labels',
                                        'add_label',
                                        labels_to_check_and_create,
                                        platform=False)

        if self.acls:
            self.check_and_create_items('get_acl_groups', 'add_acl_group',
                                        self.acls)

        return self._execute_add_hosts()
    def run_once(self, client_ip=None, ethname='eth0'):
        """Run the test.

        Args:
          client_ip: string of client's ip address
          ethname: string of ethernet device under test
        """
        if not client_ip:
            error.TestError("Must provide client's IP address to test")

        sleep_secs = 20

        self._ethname = ethname
        self._client_ip = client_ip
        self._client = hosts.create_host(client_ip)
        client_at = autotest.Autotest(self._client)

        # retrieve ifconfig info for mac address of client
        cmd = "ifconfig %s" % self._ethname
        ifconfig_filename = self._client_cmd(cmd, results="ifconfig.log")
        self._parse_ifconfig(ifconfig_filename)

        # thread to wake the device using WOL
        wol_wake = WolWake(self._client_ip, self._mac_addr, sleep_secs)
        wol_wake.start()

        # create and run client test to prepare and suspend device
        client_at.run_test("network_EthCaps",
                           ethname=ethname,
                           threshold_secs=sleep_secs * 2)

        wol_wake.join()
    def run_once(self,
                 client_ip,
                 client_tag='',
                 crypto_runtime=CRYPTO_RUNTIME,
                 cq=False):

        # in a cq run, do not execute the test, just output
        # the order that the test would have run in
        if cq:
            self.write_test_keyval({
                'storage_qual_cq':
                ('%f hardware_StorageQualBase_%s' % (time.time(), client_tag))
            })
            return

        client = hosts.create_host(client_ip)
        client_at = autotest.Autotest(client)
        for test_name, argv in self.CLIENT_FUNCTIONAL_TESTS:
            client_at.run_test(test_name,
                               disable_sysinfo=True,
                               tag=client_tag,
                               **argv)

        # Test real life performance
        for script in self.CRYPTO_TESTS:
            client_at.run_test('platform_CryptohomeFio',
                               disable_sysinfo=True,
                               from_internal_disk_only=True,
                               script=script,
                               tag='_'.join([client_tag, script]),
                               runtime=crypto_runtime,
                               disk_configs=['crypto', 'plain'])
Exemple #5
0
    def __init__(self, server_job, machine, work_dir, test_queue, queue_lock,
                 continuous_parsing=False):
        """Creates an instance of machine_worker to run tests on a remote host.

        Retrieves that host attributes for this machine and creates the set of
        True attributes to validate against test include/exclude attributes.

        Creates a directory to hold the log files for tests run and writes the
        hostname and tko parser version into keyvals file.

        Args:
            server_job: run tests for this server_job.
            machine: name of remote host.
            work_dir: directory server job is using.
            test_queue: queue of tests.
            queue_lock: lock protecting test_queue.
            continuous_parsing: bool, enable continuous parsing.
        """
        self._server_job = server_job
        self._test_queue = test_queue
        self._test_queue_lock = queue_lock
        self._continuous_parsing = continuous_parsing
        self._tests_run = 0
        self._machine = machine
        self._host = hosts.create_host(self._machine)
        self._client_at = autotest.Autotest(self._host)
        client_attributes = host_attributes.host_attributes(machine)
        self.attribute_set = set(client_attributes.get_attributes())
        self._results_dir = work_dir
        if not os.path.exists(self._results_dir):
            os.makedirs(self._results_dir)
        machine_data = {'hostname': self._machine,
                        'status_version': str(1)}
        utils.write_keyval(self._results_dir, machine_data)
Exemple #6
0
    def prepare_work_client(self, work_client_machine):
        """Prepare the SSHHost object into WiFiClient object

        @param work_client_machine: a SSHHost object to be wrapped

        """
        work_client_host = hosts.create_host(work_client_machine.hostname)
        # All packet captures in chaos lab have dual NICs. Let us use phy1 to
        # be a radio dedicated for work client
        iw = iw_runner.IwRunner(remote_host=work_client_host)
        phys = iw.list_phys()
        devs = iw.list_interfaces(desired_if_type='managed')
        if len(devs) > 0:
            logging.debug('Removing interfaces in work host machine %s', devs)
            for i in range(len(devs)):
                iw.remove_interface(devs[i].if_name)
        if len(phys) > 1:
            logging.debug('Adding interfaces in work host machine')
            iw.add_interface('phy1', 'work0', 'managed')
            logging.debug('Interfaces in work client %s', iw.list_interfaces())
        elif len(phys) == 1:
            raise error.TestError('Not enough phys available to create a'
                                  'work client interface %s.' %
                                   work_client_host.hostname)
        self.work_client = wifi_client.WiFiClient(
                work_client_host, './debug', False)
        # Make the host object easily accessible
        self.host = self.work_client.host
    def run_once(self, client_ip=None, seconds=3600, size=0, suspend=True):
        """
        Run the test
        Use ram drive and hardware_Storage fio verify feature to verify the
        integrity of memory system. The test will write data to memory and then
        idle or suspend for specify time and verify the integrity of that data.

        @param client_ip: string of client's ip address (required)
        @param seconds:   seconds to idle / suspend. default = 3600 (1 hour)
        @param size:      size to used. 0 means use all tesable memory (default)
        @param suspend:   set to suspend between write and verify phase.
        """

        if not client_ip:
            error.TestError("Must provide client's IP address to test")

        self._client = hosts.create_host(client_ip)
        self._client_at = autotest.Autotest(self._client)

        if size == 0:
            size = self._determine_usable_memory()
        logging.info('size: %d', size)

        self._create_ramfs()

        self._write_test_data(size)

        self._check_alive()
        self._wait(seconds, suspend)
        self._check_alive()

        self._verify_test_data(size)

        self._check_alive()
        self._clean_up()
Exemple #8
0
def build_router_proxy(test_name='', client_hostname=None, router_addr=None,
                       enable_avahi=False):
    """Build up a LinuxRouter object.

    Verifies that the remote host responds to ping.
    Either client_hostname or router_addr must be specified.

    @param test_name: string name of this test (e.g. 'network_WiFi_TestName').
    @param client_hostname: string hostname of DUT if we're in the lab.
    @param router_addr: string DNS/IPv4 address to use for router host object.
    @param enable_avahi: boolean True iff avahi should be started on the router.

    @return LinuxRouter or raise error.TestError on failure.

    """
    router_hostname = build_router_hostname(client_hostname=client_hostname,
                                            router_hostname=router_addr)
    logging.info('Connecting to router at %s', router_hostname)
    ping_helper = ping_runner.PingRunner()
    if not ping_helper.simple_ping(router_hostname):
        raise error.TestError('Router at %s is not pingable.' %
                              router_hostname)

    # Use CrosHost for all router hosts and avoid host detection.
    # Host detection would use JetstreamHost for Whirlwind routers.
    # JetstreamHost assumes ap-daemons are running.
    # Testbed routers run the testbed-ap profile with no ap-daemons.
    # TODO(ecgh): crbug.com/757075 Fix testbed-ap JetstreamHost detection.
    return LinuxRouter(hosts.create_host(router_hostname,
                                         host_class=hosts.CrosHost),
                       test_name,
                       enable_avahi=enable_avahi)
def build_router_proxy(test_name='', client_hostname=None, router_addr=None,
                       enable_avahi=False):
    """Build up a LinuxRouter object.

    Verifies that the remote host responds to ping.
    Either client_hostname or router_addr must be specified.

    @param test_name: string name of this test (e.g. 'network_WiFi_TestName').
    @param client_hostname: string hostname of DUT if we're in the lab.
    @param router_addr: string DNS/IPv4 address to use for router host object.
    @param enable_avahi: boolean True iff avahi should be started on the router.

    @return LinuxRouter or raise error.TestError on failure.

    """
    router_hostname = build_router_hostname(client_hostname=client_hostname,
                                            router_hostname=router_addr)
    logging.info('Connecting to router at %s', router_hostname)
    ping_helper = ping_runner.PingRunner()
    if not ping_helper.simple_ping(router_hostname):
        raise error.TestError('Router at %s is not pingable.' %
                              router_hostname)

    return LinuxRouter(hosts.create_host(router_hostname), test_name,
                       enable_avahi=enable_avahi)
Exemple #10
0
    def _install(self):
        if not self.host:
            from autotest_lib.server import hosts, autotest
            self.host = hosts.create_host(self.job.machines[0],
                                          auto_monitor=False)
            try:
                tmp_dir = self.host.get_tmp_dir(parent="/tmp/sysinfo")
                self.autotest = autotest.Autotest(self.host)
                self.autotest.install(autodir=tmp_dir)
                self.outputdir = self.host.get_tmp_dir()
            except:
                # if installation fails roll back the host
                try:
                    self.host.close()
                except:
                    logging.exception("Unable to close host %s",
                                      self.host.hostname)
                self.host = None
                self.autotest = None
                raise
        else:
            host = self.host

            # if autotest client dir does not exist, reinstall (it may have
            # been removed by the test code)
            autodir = host.get_autodir()
            if not autodir or not host.path_exists(autodir):
                self.autotest.install(autodir=autodir)

            # if the output dir does not exist, recreate it
            if not host.path_exists(self.outputdir):
                host.run('mkdir -p %s' % self.outputdir)

        return self.host, self.autotest, self.outputdir
Exemple #11
0
    def run_once(self, host, is_pcap=False):
        """Update router / packet capture associated with host.

        @param host DUT connected to AP/Pcap that needs update

        """
        if is_pcap:
            device_hostname = dnsname_mangler.get_pcap_addr(
                client_hostname=host.hostname)
        else:
            device_hostname = site_linux_router.build_router_hostname(
                client_hostname=host.hostname,
                router_hostname=self._router_hostname_from_cmdline)

        ping_helper = ping_runner.PingRunner()
        if not ping_helper.simple_ping(device_hostname):
            # Pcap devices aren't always present. Just claim Not Applicable if
            # we couldn't find it.
            e = error.TestNAError if is_pcap else error.TestError
            raise e('%s not found / is down.' % device_hostname)

        # Use CrosHost for all router/pcap hosts and avoid host detection.
        # Host detection would use JetstreamHost for Whirlwind routers.
        # JetstreamHost assumes ap-daemons are running.
        # Testbed routers run the testbed-ap profile with no ap-daemons.
        # TODO(ecgh): crbug.com/757075 Fix testbed-ap JetstreamHost detection.
        device_host = hosts.create_host(device_hostname,
                                        host_class=hosts.CrosHost,
                                        allow_failure=True)
        self.update_device(device_host)
Exemple #12
0
    def _install(self):
        if not self.host:
            from autotest_lib.server import hosts, autotest
            self.host = hosts.create_host(self.job.machines[0],
                                          auto_monitor=False)
            try:
                tmp_dir = self.host.get_tmp_dir(parent="/tmp/sysinfo")
                self.autotest = autotest.Autotest(self.host)
                self.autotest.install(autodir=tmp_dir)
                self.outputdir = self.host.get_tmp_dir()
            except:
                # if installation fails roll back the host
                try:
                    self.host.close()
                except:
                    logging.exception("Unable to close host %s",
                                      self.host.hostname)
                self.host = None
                self.autotest = None
                raise
        else:
            host = self.host

            # if autotest client dir does not exist, reinstall (it may have
            # been removed by the test code)
            autodir = host.get_autodir()
            if not autodir or not host.path_exists(autodir):
                self.autotest.install(autodir=autodir)

            # if the output dir does not exist, recreate it
            if not host.path_exists(self.outputdir):
                host.run('mkdir -p %s' % self.outputdir)

        return self.host, self.autotest, self.outputdir
 def run_once(self, client_ip, testname, loops):
     host = hosts.create_host(client_ip)
     autotest_client = autotest.Autotest(host)
     for i in xrange(loops):
         logging.debug('Starting loop #%d', i)
         autotest_client.run_test(testname)
         host.reboot()
    def initialize_camerabox(self, camera_facing, cmdline_args):
        """Configure DUT and chart running in camerabox environment.
        @param camera_facing: the facing of the DUT used in testing
                              (e.g. 'front', 'back').
        """
        chart_address = camerabox_utils.get_chart_address(
                [h.hostname for h in self._hosts], cmdline_args)
        if chart_address is None:
            raise error.TestFail(
                    'Error: missing option --args="chart=<CHART IP>"')
        chart_hosts = [hosts.create_host(ip) for ip in chart_address]

        self.chart_fixtures = [
                camerabox_utils.ChartFixture(h, self._SCENE_URI)
                for h in chart_hosts
        ]
        self.dut_fixtures = [
                camerabox_utils.DUTFixture(self, h, camera_facing)
                for h in self._hosts
        ]

        for chart in self.chart_fixtures:
            chart.initialize()

        for dut in self.dut_fixtures:
            dut.initialize()
    def run_once(self, client_addr):
        """
        Test main loop.

        @param client_addr DUT hostname or IP address.
        """
        self._client = hosts.create_host(client_addr)
        client_autotest = autotest.Autotest(self._client)

        disk_filler_src = os.path.join(self.bindir, self.DISK_FILL_SCRIPT)
        disk_filler_dst = os.path.join(self.CLIENT_TMP_DIR,
                                       os.path.basename(self.DISK_FILL_SCRIPT))
        self._client.send_file(disk_filler_src, disk_filler_dst)

        disk_filler_command = '%s %s %d' % (
            disk_filler_dst, self.STATEFUL_PATH, self.TEST_TIMEOUT_SECONDS)

        with remote_command.Command(self._client, disk_filler_command) \
                as disk_filler_process:
            if not self.wait_until_full(self.STATEFUL_PATH, self.MAX_FREE_KB):
                logging.debug(disk_filler_process.result)
                raise error.TestFail(
                    'did not fill %s within %d seconds' % (
                        self.STATEFUL_PATH, self.FILL_TIMEOUT_SECONDS))

            client_autotest.run_test('network_CheckCriticalProcesses',
                                     tag='before_client_tests')
            passed_with_failsafe = []

            for name, kwargs in self.CLIENT_TEST_LIST:
                # Autotest goes to /mnt/stateful_partition/dev_image,
                # while /var is on /mnt/stateful_partition/encrypted.
                #
                # These are separate partitions, so we can copy
                # the tests onto the DUT even when /var is full.
                client_autotest.run_test(name, **kwargs)

                if 'tag' in kwargs:
                    full_test_name = '%s.%s' % (name, kwargs['tag'])
                else:
                    full_test_name = name

                # To avoid leaving the system in a bad state, the disk
                # filler times out eventually. This means a test can
                # "pass" due to the failsafe. Check if the failsafe
                # kicked in, by checking if the disk is still full.
                if (self.get_free_kilobytes(self.STATEFUL_PATH) >
                    self.MAX_FREE_KB):
                    passed_with_failsafe.append(full_test_name)

                client_autotest.run_test('network_CheckCriticalProcesses',
                                         tag='after_%s' % full_test_name)

            if len(passed_with_failsafe):
                raise error.TestFail(
                    '%d test(s) triggered the fail-safe: %s. '
                    'They may be incorrectly listed as passing.' % (
                        len(passed_with_failsafe),
                        ', '.join(passed_with_failsafe)))
Exemple #16
0
    def run_once(self, pair, udp, bidirectional, time, stream_list):
        print "running on %s and %s\n" % (pair[0], pair[1])

        # Designate a lable for the server side tests.
        server_label = 'net_server'

        tagname = "%s_%s" % (pair[0], pair[1])
        server = hosts.create_host(pair[0])
        client = hosts.create_host(pair[1])

        # Ensure the client doesn't have the server label.
        platform_label = client.get_platform_label()
        if platform_label == server_label:
            (server, client) = (client, server)

        # Disable IPFilters if they are present.
        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.disable_ipfilters()

        server_at = autotest.Autotest(server)
        client_at = autotest.Autotest(client)

        template = ''.join(["job.run_test('iperf', server_ip='%s', client_ip=",
                            "'%s', role='%s', udp=%s, bidirectional=%s,",
                            "test_time=%d, stream_list=%s, tag='%s')"])

        server_control_file = template % (server.ip, client.ip, 'server', udp,
                                          bidirectional, time, stream_list,
                                          tagname)
        client_control_file = template % (server.ip, client.ip, 'client', udp,
                                          bidirectional, time, stream_list,
                                          tagname)

        server_command = subcommand.subcommand(server_at.run,
                         [server_control_file, server.hostname])
        client_command = subcommand.subcommand(client_at.run,
                         [client_control_file, client.hostname])

        subcommand.parallel([server_command, client_command])

        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.enable_ipfilters()
Exemple #17
0
    def run_once(self, pair, buffer, upper_bound, variance):
        print "running on %s and %s\n" % (pair[0], pair[1])

        # Designate a platform label for the server side of tests.
        server_label = 'net_server'

        server = hosts.create_host(pair[0])
        client = hosts.create_host(pair[1])

        # If client has the server_label, then swap server and client.
        platform_label = client.get_platform_label()
        if platform_label == server_label:
            (server, client) = (client, server)

        # Disable IP Filters if they are enabled.
        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.disable_ipfilters()

        server_at = autotest_remote.Autotest(server)
        client_at = autotest_remote.Autotest(client)

        template = ''.join([
            "job.run_test('netpipe', server_ip='%s', ",
            "client_ip='%s', role='%s', bidirectional=True, ",
            "buffer_size=%d, upper_bound=%d,"
            "perturbation_size=%d)"
        ])

        server_control_file = template % (server.ip, client.ip, 'server',
                                          buffer, upper_bound, variance)
        client_control_file = template % (server.ip, client.ip, 'client',
                                          buffer, upper_bound, variance)

        server_command = subcommand.subcommand(
            server_at.run, [server_control_file, server.hostname])
        client_command = subcommand.subcommand(
            client_at.run, [client_control_file, client.hostname])

        subcommand.parallel([server_command, client_command])

        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.enable_ipfilters()
Exemple #18
0
    def run_once(self, pair, test, time, stream_list, cycles):
        print "running on %s and %s\n" % (pair[0], pair[1])

        # Designate a label for the server side tests.
        server_label = 'net_server'

        server = hosts.create_host(pair[0])
        client = hosts.create_host(pair[1])

        # If client has the server_label, then swap server and client.
        platform_label = client.get_platform_label()
        if platform_label == server_label:
            (server, client) = (client, server)


        # Disable IPFilters if they are enabled.
        for m in [client, server]:
            status = m.run('/sbin/iptables -L')
            if not status.exit_status:
                m.disable_ipfilters()

        server_at = autotest_remote.Autotest(server)
        client_at = autotest_remote.Autotest(client)

        template = ''.join(["job.run_test('netperf2', server_ip='%s', ",
                            "client_ip='%s', role='%s', test='%s', ",
                            "test_time=%d, stream_list=%s, tag='%s', ",
                            "iterations=%d)"])

        server_control_file = template % (server.ip, client.ip, 'server', test,
                                          time, stream_list, test, cycles)
        client_control_file = template % (server.ip, client.ip, 'client', test,
                                          time, stream_list, test, cycles)

        server_command = subcommand.subcommand(server_at.run,
                                    [server_control_file, server.hostname])
        client_command = subcommand.subcommand(client_at.run,
                                    [client_control_file, client.hostname])

        subcommand.parallel([server_command, client_command])

        for m in [client, server]:
            status = m.run('/sbin/iptables -L')
            if not status.exit_status:
                m.enable_ipfilters()
Exemple #19
0
    def run_once(self, pair, buffer, upper_bound, variance):
        print "running on %s and %s\n" % (pair[0], pair[1])

        # Designate a platform label for the server side of tests.
        server_label = 'net_server'

        server = hosts.create_host(pair[0])
        client = hosts.create_host(pair[1])

        # If client has the server_label, then swap server and client.
        platform_label = client.get_platform_label()
        if platform_label == server_label:
            (server, client) = (client, server)

        # Disable IP Filters if they are enabled.
        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.disable_ipfilters()

        server_at = autotest_remote.Autotest(server)
        client_at = autotest_remote.Autotest(client)

        template = ''.join(["job.run_test('netpipe', server_ip='%s', ",
                            "client_ip='%s', role='%s', bidirectional=True, ",
                            "buffer_size=%d, upper_bound=%d,"
                            "perturbation_size=%d)"])

        server_control_file = template % (server.ip, client.ip, 'server',
                                          buffer, upper_bound, variance)
        client_control_file = template % (server.ip, client.ip, 'client',
                                          buffer, upper_bound, variance)

        server_command = subcommand.subcommand(server_at.run,
                                    [server_control_file, server.hostname])
        client_command = subcommand.subcommand(client_at.run,
                                    [client_control_file, client.hostname])

        subcommand.parallel([server_command, client_command])

        for m in [client, server]:
            status = m.run('iptables -L')
            if not status.exit_status:
                m.enable_ipfilters()
Exemple #20
0
def create_host(hostname,
                board,
                model,
                servo_hostname,
                servo_port,
                servo_serial=None,
                logs_dir=None):
    """Yield a server.hosts.CrosHost object to use for DUT preparation.

    This object contains just enough inventory data to be able to prepare the
    DUT for lab deployment. It does not contain any reference to AFE / Skylab so
    that DUT preparation is guaranteed to be isolated from the scheduling
    infrastructure.

    @param hostname:        FQDN of the host to prepare.
    @param board:           The autotest board label for the DUT.
    @param model:           The autotest model label for the DUT.
    @param servo_hostname:  FQDN of the servo host controlling the DUT.
    @param servo_port:      Servo host port used for the controlling servo.
    @param servo_serial:    (Optional) Serial number of the controlling servo.
    @param logs_dir:        (Optional) Directory to save logs obtained from the
                            host.

    @yield a server.hosts.Host object.
    """
    labels = [
        'board:%s' % board,
        'model:%s' % model,
    ]
    attributes = {
        servo_host.SERVO_HOST_ATTR: servo_hostname,
        servo_host.SERVO_PORT_ATTR: servo_port,
    }
    if servo_serial is not None:
        attributes[servo_host.SERVO_SERIAL_ATTR] = servo_serial

    store = host_info.InMemoryHostInfoStore(info=host_info.HostInfo(
        labels=labels,
        attributes=attributes,
    ))
    machine_dict = {
        'hostname': hostname,
        'host_info_store': store,
        'afe_host': server_utils.EmptyAFEHost(),
    }
    host = hosts.create_host(machine_dict)
    servohost = servo_host.ServoHost(
        **servo_host.get_servo_args_for_host(host))
    _prepare_servo(servohost)
    host.set_servo_host(servohost)
    host.servo.uart_logs_dir = logs_dir
    try:
        yield host
    finally:
        host.close()
 def run_once(self, client_ip, duration):
     client = hosts.create_host(client_ip)
     client_at = autotest.Autotest(client)
     control = """job.parallel(
         [lambda: job.run_test('power_SuspendStress', tag='disk',
             duration=%d, init_delay=10, min_suspend=7, min_resume=30,
             check_connection=True)],
         [lambda: job.run_test('hardware_StorageFio', test_length=%d,
             disable_sysinfo=True, requirements=[('write_stress', [])],
             tag='qual_suspend')])""" % (duration, duration)
     client_at.run(control, '.', None)
 def run_once(self, client_ip, duration):
     client = hosts.create_host(client_ip)
     client_at = autotest.Autotest(client)
     control = """job.parallel(
         [lambda: job.run_test('power_SuspendStress', tag='disk',
             duration=%d, init_delay=10, min_suspend=7, min_resume=30,
             interface='eth0')],
         [lambda: job.run_test('hardware_TrimIntegrity', test_length=%d+30,
             disable_sysinfo=True,
             tag='qual_trim')])""" % (duration, duration - 30)
     client_at.run(control, '.', None)
Exemple #23
0
    def _create_dut_object(host_name):
        """Create the DUTObject tuple for the DUT.

        @param host_name: Host name for the DUT.

        @return: Tuple of Host and Wifi client objects representing DUTObject
                 for invoking RPC calls.
        """
        dut_host = hosts.create_host(host_name)
        dut_wifi_client = wifi_client.WiFiClient(dut_host, './debug', False)
        return DUTObject(dut_host, dut_wifi_client)
def _create_host(hostname, afe, afe_host):
    """Create a CrosHost object for a DUT to be installed.

    @param hostname  Hostname of the target DUT.
    @param afe       A frontend.AFE object.
    @param afe_host  AFE Host object for the DUT.
    """
    machine_dict = {
        'hostname': hostname,
        'afe_host': afe_host,
        'host_info_store': afe_store.AfeStore(hostname, afe),
    }
    servo_args = hosts.CrosHost.get_servo_arguments({})
    return hosts.create_host(machine_dict, servo_args=servo_args)
Exemple #25
0
def get_moblab_and_devserver_port(moblab_hostname):
    """Initializes and returns a MobLab Host Object.

    @params moblab_hostname: The Moblab hostname, None if using a local virtual
                             machine.

    @returns A pair consisting of a MoblabHost and a devserver port.

    @raise BrilloMoblabInitializationError: Failed to set up the Moblab.
    """
    if moblab_hostname:
        web_address = moblab_hostname
        devserver_port = _PHYS_MACHINE_DEVSERVER_PORT
        rpc_timeout_min = 2
    else:
        moblab_hostname = _VIRT_MACHINE_SSH_ADDR
        web_address = _VIRT_MACHINE_AFE_ADDR
        devserver_port = _VIRT_MACHINE_DEVSERVER_PORT
        rpc_timeout_min = 5

    try:
        host = hosts.create_host(moblab_hostname,
                                 host_class=moblab_host.MoblabHost,
                                 connectivity_class=ssh_host.SSHHost,
                                 web_address=web_address,
                                 retain_image_storage=True,
                                 rpc_timeout_min=rpc_timeout_min)
    except error.AutoservRunError as e:
        raise BrilloMoblabInitializationError(
                'Unable to connect to the MobLab: %s' % e)

    moblab_version = int(host.get_release_version().split('.')[0])
    if moblab_version < _MOBLAB_MIN_VERSION:
        raise BrilloMoblabInitializationError(
                'The Moblab version (%s) is older than the minimum required '
                '(%s). Download a current version from URL: %s' %
                (moblab_version, _MOBLAB_MIN_VERSION,
                _MOBLAB_IMAGE_DOWNLOAD_URL))

    try:
        host.afe.get_hosts()
    except Exception as e:
        raise BrilloMoblabInitializationError(
                "Unable to communicate with the MobLab's web frontend, "
                "please verify that it is up and running at http://%s/\n"
                "Error: %s" % (host.web_address, e))

    return host, devserver_port
Exemple #26
0
    def initialize(self, host, client_ip, cmdline_args):
        self._client = hosts.create_host(client_ip)
        self.ensure_battery_present()

        args = {}
        for arg in cmdline_args:
            match = re.search("^(\w+)=(.+)", arg)
            if match:
                args[match.group(1)] = match.group(2)
        self.power_control = args.get('power_control', host.POWER_CONTROL_RPM)
        if self.power_control not in host.POWER_CONTROL_VALID_ARGS:
            raise error.TestError('Valid values for --args=power_control '
                                  'are %s. But you entered wrong argument '
                                  'as "%s".'
                                   % (host.POWER_CONTROL_VALID_ARGS,
                                   self.power_control))
    def run_once(self, client_ip):
        """Check to see if a DUT at the given address wakes from suspend
        on USB HID events

        @param client_ip: ip address (string) at which the DUT may be found"""
        self.check_dependencies()
        if not client_ip:
            raise error.TestError('Must have test client IP address')
        self._client = hosts.create_host(client_ip)
        if not self.have_hid_device():
            raise error.TestError('No HID devices found, please attach one')
        self.suspend()
        self.prompt(banner=press_button_banner)
        if not self.wait_for_host(host=client_ip, timeout=10):
            self.prompt(banner=bored_now)
            raise error.TestFail('DUT did not wake up on HID event')
    def _install_clients(self):
        """
        Install autotest on any current job hosts.
        """
        in_use_hosts = set()
        # find hosts in use but not used by us
        for host in self.job.hosts:
            if host.hostname not in self.job.machines:
                # job.hosts include all host instances created on the fly.
                # We only care DUTs in job.machines which are
                # piped in from autoserv -m option.
                continue
            autodir = host.get_autodir()
            if not (autodir and autodir.startswith(PROFILER_TMPDIR)):
                in_use_hosts.add(host.hostname)
        logging.debug('Hosts currently in use: %s', in_use_hosts)

        # determine what valid host objects we already have installed
        profiler_hosts = set()
        for host, at, profiler_dir in self.installed_hosts.values():
            if host.path_exists(profiler_dir):
                profiler_hosts.add(host.hostname)
            else:
                # the profiler was wiped out somehow, drop this install
                logging.warning('The profiler client on %s at %s was deleted',
                                host.hostname, profiler_dir)
                host.close()
                del self.installed_hosts[host.hostname]
        logging.debug('Hosts with profiler clients already installed: %s',
                      profiler_hosts)

        # install autotest on any new hosts in use
        for hostname in in_use_hosts - profiler_hosts:
            host = hosts.create_host(hostname)
            tmp_dir = host.get_tmp_dir(parent=PROFILER_TMPDIR)
            at = autotest.Autotest(host)
            at.install_no_autoserv(autodir=tmp_dir)
            self.installed_hosts[host.hostname] = (host, at, tmp_dir)

        # drop any installs from hosts no longer in job.hosts
        hostnames_to_drop = profiler_hosts - in_use_hosts
        hosts_to_drop = [self.installed_hosts[hostname][0]
                         for hostname in hostnames_to_drop]
        for host in hosts_to_drop:
            host.close()
            del self.installed_hosts[host.hostname]
    def run_once(self, machine, server_videos_dir, videos):
        host = hosts.create_host(machine)
        host_at = autotest.Autotest(host)
        for video in videos:
            # Copy test vidoes from the server to the client.
            file_name, sep, video_arg = video.partition(':')
            file_path_at_server = os.path.join(server_videos_dir, file_name)
            file_path_at_client = '/tmp/%s' % file_name
            host.send_file(file_path_at_server, file_path_at_client)
            logging.info("Copied to the client: %s" % file_path_at_client)

            # Run the client test with the downloaded video.
            host_at.run_test(
                'video_VideoDecodeAccelerator',
                videos=['%s%s%s' % (file_path_at_client, sep, video_arg)],
                use_cr_source_dir=False,
                gtest_filter='DecodeVariations*\/0')
            host.run('rm %s' % file_path_at_client)
Exemple #30
0
def _create_host(hostname, board):
    """Create a CrosHost object for a DUT to be installed.

    @param hostname  Hostname of the target DUT.
    @param board     Board name of the target DUT.
    """
    host = hosts.create_host(hostname, try_lab_servo=True)
    # Monkey patch our host object to think there's a board label
    # in the AFE.  The horror!  The horror!
    #
    # TODO(jrbarnette):  This is wrong; we patch the method because
    # CrosHost._servo_repair_reinstall() calls it, but that means
    # we're coupled to the implementation of CrosHost.  Alas, it's
    # hard to do better without either 1) copying large chunks of
    # _servo_repair_reinstall(), or 2) extensively refactoring
    # CrosHost.
    host._get_board_from_afe = lambda: board
    return host
Exemple #31
0
    def _detect_host_info(self, host):
        """Detect platform and labels from the host.

        @param host: hostname

        @return: HostInfo object
        """
        # Mock an afe_host object so that the host is constructed as if the
        # data was already in afe
        data = {'attributes': self.attributes, 'labels': self.labels}
        afe_host = frontend.Host(None, data)
        store = host_info.InMemoryHostInfoStore(
            host_info.HostInfo(labels=self.labels, attributes=self.attributes))
        machine = {
            'hostname': host,
            'afe_host': afe_host,
            'host_info_store': store
        }
        try:
            if bin_utils.ping(host, tries=1, deadline=1) == 0:
                serials = self.attributes.get('serials', '').split(',')
                if serials and len(serials) > 1:
                    host_dut = hosts.create_testbed(machine,
                                                    adb_serials=serials)
                else:
                    adb_serial = self.attributes.get('serials')
                    host_dut = hosts.create_host(machine,
                                                 adb_serial=adb_serial)

                info = HostInfo(host, host_dut.get_platform(),
                                host_dut.get_labels())
                # Clean host to make sure nothing left after calling it,
                # e.g. tunnels.
                if hasattr(host_dut, 'close'):
                    host_dut.close()
            else:
                # Can't ping the host, use default information.
                info = HostInfo(host, None, [])
        except (socket.gaierror, error.AutoservRunError,
                error.AutoservSSHTimeout):
            # We may be adding a host that does not exist yet or we can't
            # reach due to hostname/address issues or if the host is down.
            info = HostInfo(host, None, [])
        return info
    def run_once(self, client_ip):
        """
        Run the test.
        """
        if not client_ip:
            error.TestError("Must provide client's IP address to test")

        self._client = hosts.create_host(client_ip)
        self._client_at = autotest.Autotest(self._client)

        self._run_test(self._do_reboot, '.*Restarting system.*$')

        if self._client.check_for_lkdtm():
            self._run_test(self._do_kernel_panic, '.*lkdtm:.*PANIC$')
            self._run_test(self._do_kernel_bug, '.*lkdtm:.*BUG$')
        else:
            logging.warn('DUT did not have kernel dump test module')

        self._run_test(self._do_reboot_with_suspend, '.*Restarting system.*$')
Exemple #33
0
    def _install_clients(self):
        """
        Install autotest_remote on any current job hosts.
        """
        in_use_hosts = set()
        # find hosts in use but not used by us
        for host in self.job.hosts:
            autodir = host.get_autodir()
            if not (autodir and autodir.startswith(PROFILER_TMPDIR)):
                in_use_hosts.add(host.hostname)
        logging.debug('Hosts currently in use: %s', in_use_hosts)

        # determine what valid host objects we already have installed
        profiler_hosts = set()
        for host, at, profiler_dir in self.installed_hosts.values():
            if host.path_exists(profiler_dir):
                profiler_hosts.add(host.hostname)
            else:
                # the profiler was wiped out somehow, drop this install
                logging.warning('The profiler client on %s at %s was deleted',
                                host.hostname, profiler_dir)
                host.close()
                del self.installed_hosts[host.hostname]
        logging.debug('Hosts with profiler clients already installed: %s',
                      profiler_hosts)

        # install autotest_remote on any new hosts in use
        for hostname in in_use_hosts - profiler_hosts:
            host = hosts.create_host(hostname, auto_monitor=False)
            tmp_dir = host.get_tmp_dir(parent=PROFILER_TMPDIR)
            at = autotest_remote.Autotest(host)
            at.install_no_autoserv(autodir=tmp_dir)
            self.installed_hosts[host.hostname] = (host, at, tmp_dir)

        # drop any installs from hosts no longer in job.hosts
        hostnames_to_drop = profiler_hosts - in_use_hosts
        hosts_to_drop = [self.installed_hosts[hostname][0]
                         for hostname in hostnames_to_drop]
        for host in hosts_to_drop:
            host.close()
            del self.installed_hosts[host.hostname]
def create_host_from(device_host, args=None):
    """Creates a host object for the Tester associated with a DUT.

    The IP address or the hostname can be specified in the 'tester' member of
    the argument dictionary. When not present it is derived from the hostname
    of the DUT by appending '-router' to the first part.

    Will raise an exception if there isn't a tester for the DUT, or if the DUT
    is specified as an IP address and thus the hostname cannot be derived.

    @param device_host: Autotest host object for the DUT.
    @param args: Dictionary of arguments passed to the test.

    @return Autotest host object for the Tester.

    """
    cmdline_override = args.get('tester', None)
    hostname = dnsname_mangler.get_tester_addr(
            device_host.hostname,
            cmdline_override=cmdline_override)
    return hosts.create_host(hostname)
Exemple #35
0
    def _install(self):
        if not self.host:
            from autotest_lib.server import hosts, autotest

            self.host = hosts.create_host(self.job.machines[0], auto_monitor=False)
            tmp_dir = self.host.get_tmp_dir(parent="/tmp/sysinfo")
            self.autotest = autotest.Autotest(self.host)
            self.autotest.install_base(autodir=tmp_dir)
            self.outputdir = self.host.get_tmp_dir()
        else:
            host = self.host

            # if autotest client dir does not exist, reinstall (it may have
            # been removed by the test code)
            autodir = host.get_autodir()
            if not autodir or not host.path_exists(autodir):
                self.autotest.install_base(autodir=autodir)

            # if the output dir does not exist, recreate it
            if not host.path_exists(self.outputdir):
                host.run("mkdir -p %s" % self.outputdir)

        return self.host, self.autotest, self.outputdir
Exemple #36
0
    def _install(self):
        """ Install autotest on any current job hosts. """
        in_use_hosts = set(host.hostname for host in self.job.hosts
                           if not
                           (host.get_autodir() and
                            host.get_autodir().startswith(PROFILER_TMPDIR)))
        profiler_hosts = set(self.installed_hosts.keys())

        # install autotest on any new hosts in use
        for hostname in in_use_hosts - profiler_hosts:
            host = hosts.create_host(hostname, auto_monitor=False)
            tmp_dir = host.get_tmp_dir(parent=PROFILER_TMPDIR)
            at = autotest.Autotest(host)
            at.install(autodir=tmp_dir)
            self.installed_hosts[host] = (at, tmp_dir)

        # drop any installs from hosts no longer in job.hosts
        hostnames_to_drop = profiler_hosts - in_use_hosts
        hosts_to_drop = [host for host in self.installed_hosts.iterkeys()
                         if host.hostname in hostnames_to_drop]
        for host in hosts_to_drop:
            host.close()
            del self.installed_hosts[host]