Exemple #1
0
    def test_initial_access(self):
        """Tests that initially, a non-authenticating server is accessible,
        but an authenticating one is not."""
        viewer_port = int(os.environ['CC_TEST_VIEWER_PORT'])
        client_unprivileged = CCViewerHelper(self.host,
                                             viewer_port,
                                             '/',
                                             True,
                                             None)
        client_privileged = CCViewerHelper(self.host,
                                           self.port,
                                           '/',
                                           True,
                                           None)

        self.assertIsNotNone(client_unprivileged.getAPIVersion(),
                             "Unprivileged client was not accessible.")

        try:
            client_privileged.getAPIVersion()
            success = False
        except TProtocolException as tpe:
            # The server reports a HTTP 401 error which
            # is not a valid Thrift response.
            # But if it does so, it passes the test!
            success = True
        self.assertTrue(success,
                        "Privileged client allowed access without session.")
 def setUp(self):
     host = 'localhost'
     port = int(os.environ['CC_TEST_VIEWER_PORT'])
     uri = '/'
     self._testproject_data = json.loads(os.environ['CC_TEST_PROJECT_INFO'])
     self.assertIsNotNone(self._testproject_data)
     self._cc_client = CCViewerHelper(host, port, uri)
Exemple #3
0
    def test_privileged_access(self):
        """Tests that initially, a non-authenticating server is accessible,
        but an authenticating one is not."""
        auth_client = CCAuthHelper(self.host, self.port, self.uri, True, None)

        handshake = auth_client.getAuthParameters()
        self.assertTrue(handshake.requiresAuthentication,
                        "Privileged server " +
                        "did not report that it requires authentication.")
        self.assertFalse(handshake.sessionStillActive, "Empty session was " +
                         "reported to be still active.")

        sessionToken = auth_client.performLogin("Username:Password",
                                                "invalid:invalid")
        self.assertIsNone(sessionToken, "Invalid credentials gave us a token!")

        self.sessionToken = auth_client.performLogin("Username:Password",
                                                     "cc:test")
        self.assertIsNotNone(self.sessionToken,
                             "Valid credentials didn't give us a token!")

        handshake = auth_client.getAuthParameters()
        self.assertTrue(handshake.requiresAuthentication,
                        "Privileged server " +
                        "did not report that it requires authentication.")
        self.assertFalse(handshake.sessionStillActive,
                         "Valid session was " + "reported not to be active.")

        client = CCViewerHelper(self.host,
                                self.port,
                                '/',
                                True,
                                self.sessionToken)

        self.assertIsNotNone(client.getAPIVersion(),
                             "Privileged server didn't respond properly.")

        auth_client = CCAuthHelper(self.host, self.port, self.uri, True,
                                   self.sessionToken)
        result = auth_client.destroySession()

        self.assertTrue(result, "Server did not allow us to destroy session.")

        try:
            client.getAPIVersion()
            success = False
        except TProtocolException as tpe:
            # The server reports a HTTP 401 error which
            # is not a valid Thrift response.
            # But if it does so, it passes the test!
            success = True
        self.assertTrue(success,
                        "Privileged client allowed access after logout.")

        handshake = auth_client.getAuthParameters()
        self.assertFalse(handshake.sessionStillActive,
                         "Destroyed session was " +
                         "reported to be still active.")
Exemple #4
0
def delete_results(host, port, run_id, performance_data):
    """
    Remove run result for a run and measure remove time.
    """

    with CCViewerHelper(host, port, '/') as viewer_client:

        run_perf = {}
        with Timer('removeRunResults', run_perf):
            viewer_client.removeRunResults([run_id])
        add_measurement_data(run_id, performance_data, run_perf)
Exemple #5
0
def main():

    # handle argument parsing
    parseArgs()

    #--- main part -------------------------------------------------------------
    reportTimeList = []
    getTimeList = []

    with CCReportHelper(args.address, args.check_port) as ccReporter, \
         CCViewerHelper(args.address, args.view_port, '/') as ccViewer, \
         open(args.output, 'r+') as outFile:

        outFile.truncate()
        for runCount in range(runNumber):
            before = datetime.datetime.now()
            run_id = ccReporter.addCheckerRun('command', 'name_' + str(runCount) + '_' + str(uuid4()),
                                         'version', False)
            report_ids = []
            for fileCount in range(fileNumber):
                print('\nrun: ' + str(runCount + 1) + '/' + str(runNumber) + '\nfile: ' + str(fileCount + 1) + '/' + str(fileNumber))

                file_id = ccReporter.needFileContent(run_id, 'file_' + str(fileCount)).fileId
                ccReporter.addFileContent(file_id, fileContent)

                build_action_id = ccReporter.addBuildAction(run_id,
                                                            'build_cmd_' + str(fileCount),
                                                            'check_cmd_' + str(fileCount),
                                                            'target_' + str(fileCount))

                ccReporter.finishBuildAction(build_action_id, '')
                for bugCount in range(bugPerFile):
                    bug_pathes = []
                    bug_events = []
                    for bugElementCount in range(bugLength):
                        line = bugCount * bugLength + bugElementCount + 1
                        bug_pathes.append(BugPathPos(line, 1, line, 10, file_id))
                        bug_events.append(BugPathEvent(line, 1, line, 10, 'event_msg', file_id))

                    report_id = ccReporter.addReport(build_action_id,
                                                     file_id,
                                                     'hash_' + str(run_id) + '_'  + str(fileCount) + '_' + str(bugCount),
                                                     1,
                                                     'checker_message',
                                                     bug_pathes,
                                                     bug_events,
                                                     'checker_name',
                                                     'checker_cat',
                                                     'bug_type',
                                                     1)
                    report_ids.append(report_id)

            #ccReporter.moduleToReport(run_id, 'module_id', report_ids)
            ccReporter.finishCheckerRun(run_id)

            after = datetime.datetime.now()

            time = (after - before).total_seconds()
            reportTimeList.append(time)

            before = datetime.datetime.now()
            runIDs = [rundata.runId for rundata in ccViewer.getRunData()]
            after = datetime.datetime.now()
            time = (after - before).total_seconds()
            getTimeList.append(time)

            before = datetime.datetime.now()
            res = ccViewer.getAllRunResults(runIDs[-1])
            after = datetime.datetime.now()
            time = (after - before).total_seconds()
            getTimeList.append(time)

            before = datetime.datetime.now()
            ccViewer.getReportDetails(res[-1].reportId)
            after = datetime.datetime.now()
            time = (after - before).total_seconds()
            getTimeList.append(time)

            s = str(runCount) + ';' + str(reportTimeList[-1]) + ';' + str(getTimeList[-3]) + ';' + str(getTimeList[-2]) + ';' + str(getTimeList[-1])
            print(s)
            outFile.write(s + '\n')
Exemple #6
0
def measure(test_conf,
            performance_data,
            store_done,
            proc_done_counter,
            proc_counter_lock,
            keep):
    """
    Fill up a run with the configured values.
    """

    try:

        log.debug("Generating and storing results ...")

        number_of_runs = test_conf.get("number_of_runs", 1)

        # TODO simulate append by using the same run name in multiple threads
        run_perf = {}
        for run_count in range(number_of_runs):
            run_name = 'name_' + str(run_count) + '_' + str(uuid4())
            file_line_size = test_conf.get("file_line_size")
            file_content = zlib.compress('\n'.join(['A' * 80] *
                                                   file_line_size),
                                         zlib.Z_BEST_COMPRESSION)

            with Timer('store', run_perf):
                run_id = store(test_conf, run_name, file_content)

            log.debug("Storing results for run " + str(run_id) + " done.")

            with proc_counter_lock:
                proc_done_counter.value -= 1

            # wait here for other processes to finish storing results
            # before measuiring queries
            store_done.wait()

            view_host, view_port = get_viewer_host_port(test_conf)

            with CCViewerHelper(view_host, view_port, '/') as viewer_client:

                with Timer('getRunData', run_perf):
                    run_data = viewer_client.getRunData()

                with Timer('getAllRunResulst', run_perf):
                    res = get_all_run_results(viewer_client, run_id)

                with Timer('getReportDetails', run_perf):
                    viewer_client.getReportDetails(res[-1].reportId)

                add_measurement_data(run_id, performance_data, run_perf)

                clean_after_fill = test_conf.get("clean_after_fill", True)
                if clean_after_fill and not keep:
                    delete_results(view_host,
                                   view_port,
                                   run_id,
                                   performance_data)

    except Exception as ex:
        log.error(ex)
        with proc_counter_lock:
            proc_done_counter.value -= 1
        sys.exit(1)