def _symbolicate_minidump_with_devserver(minidump_path, resultdir,
                                         crashserver_name):
    """
    Generates a stack trace for the specified minidump by consulting devserver.

    This function assumes the debug symbols have been staged on the devserver.

    @param minidump_path: absolute path to minidump to by symbolicated.
    @param resultdir: server job's result directory.
    @param crashserver_name: Name of crashserver to attempt to symbolicate with.
    @raise DevServerException upon failure, HTTP or otherwise.
    """
    # First, look up what build we tested.  If we can't find this, we can't
    # get the right debug symbols, so we might as well give up right now.
    keyvals = client_utils.read_keyval(resultdir)
    if JOB_BUILD_KEY not in keyvals:
        raise dev_server.DevServerException(
            'Cannot determine build being tested.')

    devserver = dev_server.CrashServer(crashserver_name)

    with metrics.SecondsTimer(
            'chromeos/autotest/crashcollect/symbolicate_duration',
            fields={'crash_server': crashserver_name}):
        trace_text = devserver.symbolicate_dump(minidump_path,
                                                keyvals[JOB_BUILD_KEY])

    if not trace_text:
        raise dev_server.DevServerException('Unknown error!!')
    with open(minidump_path + '.txt', 'w') as trace_file:
        trace_file.write(trace_text)
def symbolicate_minidump_with_devserver(minidump_path, resultdir):
    """
    Generates a stack trace for the specified minidump by consulting devserver.

    This function assumes the debug symbols have been staged on the devserver.

    @param minidump_path: absolute path to minidump to by symbolicated.
    @param resultdir: server job's result directory.
    @raise DevServerException upon failure, HTTP or otherwise.
    """
    # First, look up what build we tested.  If we can't find this, we can't
    # get the right debug symbols, so we might as well give up right now.
    keyvals = client_utils.read_keyval(resultdir)
    if JOB_BUILD_KEY not in keyvals:
        raise dev_server.DevServerException(
            'Cannot determine build being tested.')

    crashserver_name = dev_server.get_least_loaded_devserver(
        devserver_type=dev_server.CrashServer)
    if not crashserver_name:
        autotest_stats.Counter(CRASH_SERVER_OVERLOAD).increment()
        raise dev_server.DevServerException(
            'No crash server has the capacity to symbolicate the dump.')
    else:
        autotest_stats.Counter(CRASH_SERVER_FOUND).increment()
    devserver = dev_server.CrashServer(crashserver_name)
    trace_text = devserver.symbolicate_dump(minidump_path,
                                            keyvals[JOB_BUILD_KEY])
    if not trace_text:
        raise dev_server.DevServerException('Unknown error!!')
    with open(minidump_path + '.txt', 'w') as trace_file:
        trace_file.write(trace_text)
Пример #3
0
    def testStageBuildFail(self):
        """Ensure that a failure to stage the desired build fails the RPC."""
        self._setupDevserver()

        self.dev_server.url().AndReturn('mox_url')
        self.dev_server.get_server_name(mox.IgnoreArg()).AndReturn('mox_url')
        self.dev_server.stage_artifacts(self._BUILD, ['test_suites']).AndRaise(
            dev_server.DevServerException())
        self.mox.ReplayAll()
        self.assertRaises(error.StageControlFileFailure,
                          site_rpc_interface.create_suite_job,
                          name=self._NAME,
                          board=self._BOARD,
                          build=self._BUILD,
                          pool=None)
Пример #4
0
    def testResolveWithFailure(self):
        """Ensure we rehash on a failed ping on a bad_host."""
        self.mox.StubOutWithMock(dev_server, '_get_dev_server_list')
        bad_host, good_host = 'http://bad_host:99', 'http://good_host:8080'
        dev_server._get_dev_server_list().MultipleTimes().AndReturn(
            [bad_host, good_host])

        # Mock out bad ping failure to bad_host by raising devserver exception.
        urllib2.urlopen(mox.StrContains(bad_host),
                        data=None).AndRaise(dev_server.DevServerException())
        # Good host is good.
        to_return = StringIO.StringIO('{"free_disk": 1024}')
        urllib2.urlopen(mox.StrContains(good_host),
                        data=None).AndReturn(to_return)

        self.mox.ReplayAll()
        host = dev_server.ImageServer.resolve(0)  # Using 0 as it'll hash to 0.
        self.assertEquals(host.url(), good_host)
        self.mox.VerifyAll()
def _resolve_crashserver():
    """
    Attempts to find a devserver / crashserver that has capacity to
    symbolicate a crashdump.

    @raises DevServerException if no server with capacity could be found.
    @returns Hostname of resolved server, if found.
    """
    crashserver_name = dev_server.get_least_loaded_devserver(
        devserver_type=dev_server.CrashServer)
    if not crashserver_name:
        metrics.Counter(
            'chromeos/autotest/crashcollect/could_not_resolve').increment()
        raise dev_server.DevServerException(
            'No crash server has the capacity to symbolicate the dump.')
    else:
        metrics.Counter('chromeos/autotest/crashcollect/resolved').increment(
            fields={'crash_server': crashserver_name})
    return crashserver_name
class DevServerGetterTest(mox.MoxTestBase):
    """Unit tests for control_file_getter.DevServerGetter.

    @var _HOST: fake dev server host address.
    """

    _BUILD = 'fake/build'
    _FILES = ['a/b/control', 'b/c/control']
    _CONTENTS = 'Multi-line\nControl File Contents\n'
    _403 = dev_server.DevServerException('HTTP 403 Forbidden!')

    def setUp(self):
        super(DevServerGetterTest, self).setUp()
        self.dev_server = self.mox.CreateMock(dev_server.ImageServer)
        self.getter = control_file_getter.DevServerGetter(
            self._BUILD, self.dev_server)

    def testListControlFiles(self):
        """Should successfully list control files from the dev server."""
        self.dev_server.list_control_files(
            self._BUILD, suite_name='').AndReturn(self._FILES)
        self.mox.ReplayAll()
        self.assertEquals(self.getter.get_control_file_list(), self._FILES)
        self.assertEquals(self.getter._files, self._FILES)

    def testListControlFilesFail(self):
        """Should fail to list control files from the dev server."""
        self.dev_server.list_control_files(self._BUILD,
                                           suite_name='').AndRaise(self._403)
        self.mox.ReplayAll()
        self.assertRaises(error.NoControlFileList,
                          self.getter.get_control_file_list)

    def testGetControlFile(self):
        """Should successfully get a control file from the dev server."""
        path = self._FILES[0]
        self.dev_server.get_control_file(self._BUILD,
                                         path).AndReturn(self._CONTENTS)
        self.mox.ReplayAll()
        self.assertEquals(self.getter.get_control_file_contents(path),
                          self._CONTENTS)

    def testGetSuiteInfo(self):
        """
        Should successfully list control files' path and contents from the
        dev server.
        """
        file_contents = {f: self._CONTENTS for f in self._FILES}
        self.dev_server.list_suite_controls(
            self._BUILD, suite_name='').AndReturn(file_contents)
        self.mox.ReplayAll()
        suite_info = self.getter.get_suite_info()
        for k in suite_info.keys():
            self.assertEquals(suite_info[k], file_contents[k])
        self.assertEquals(sorted(self.getter._files), sorted(self._FILES))

    def testListSuiteControlisFail(self):
        """
        Should fail to list all control file's contents from the dev server.
        """
        self.dev_server.list_suite_controls(self._BUILD,
                                            suite_name='').AndRaise(self._403)
        self.mox.ReplayAll()
        self.assertRaises(error.SuiteControlFileException,
                          self.getter.get_suite_info, '')

    def testGetControlFileFail(self):
        """Should fail to get a control file from the dev server."""
        path = self._FILES[0]
        self.dev_server.get_control_file(self._BUILD, path).AndRaise(self._403)
        self.mox.ReplayAll()
        self.assertRaises(error.ControlFileNotFound,
                          self.getter.get_control_file_contents, path)

    def testGetControlFileByNameCached(self):
        """\
        Should successfully get a cf by name from the dev server, using a cache.
        """
        name = 'one'
        path = "file/%s/control" % name

        self.getter._files = self._FILES + [path]
        self.dev_server.get_control_file(self._BUILD,
                                         path).AndReturn(self._CONTENTS)
        self.mox.ReplayAll()
        self.assertEquals(self.getter.get_control_file_contents_by_name(name),
                          self._CONTENTS)

    def testGetControlFileByName(self):
        """\
        Should successfully get a control file from the dev server by name.
        """
        name = 'one'
        path = "file/%s/control" % name

        files = self._FILES + [path]
        self.dev_server.list_control_files(self._BUILD,
                                           suite_name='').AndReturn(files)
        self.dev_server.get_control_file(self._BUILD,
                                         path).AndReturn(self._CONTENTS)
        self.mox.ReplayAll()
        self.assertEquals(self.getter.get_control_file_contents_by_name(name),
                          self._CONTENTS)

    def testGetSuiteControlFileByName(self):
        """\
        Should successfully get a suite control file from the devserver by name.
        """
        name = 'control.bvt'
        path = "file/" + name

        files = self._FILES + [path]
        self.dev_server.list_control_files(self._BUILD,
                                           suite_name='').AndReturn(files)
        self.dev_server.get_control_file(self._BUILD,
                                         path).AndReturn(self._CONTENTS)
        self.mox.ReplayAll()
        self.assertEquals(self.getter.get_control_file_contents_by_name(name),
                          self._CONTENTS)

    def testGetControlFileByNameFail(self):
        """Should fail to get a control file from the dev server by name."""
        name = 'one'

        self.dev_server.list_control_files(
            self._BUILD, suite_name='').AndReturn(self._FILES)
        self.mox.ReplayAll()
        self.assertRaises(error.ControlFileNotFound,
                          self.getter.get_control_file_contents_by_name, name)