Exemplo n.º 1
0
def validate_fields(fields):
    log.debug("Report fields are: %s" % fields)

    # check report version
    if fields['test_version'] not in valid_test_versions:
        raise InvalidReportField('test_version')

    # check report CC
    #XXX: confirm what value we use for default CC and whether
    # or not we should support > 2 character CC
    if fields['probe_cc'] is None:
        fields['probe_cc'] = default_probe_cc
    if not re.match('[A-Z\?]{2,4}', fields['probe_cc'].upper()):
        raise InvalidReportField('probe_cc')

    # check report ASN
    if fields['probe_asn'] is None:
        fields['probe_asn'] = 'AS0'
    if not re.match('^AS[0-9]{1,10}', fields['probe_asn'].upper()):
        raise InvalidReportField('probe_asn')

    # check report timestamp
    try:
        datetime_ts = datetime.fromtimestamp(fields['start_time'])
        datetime_str = timestamp(datetime_ts)
    except InvalidTimestampFormat:
        raise InvalidReportField('start_time')

    # check report IP
    try:
        IPAddress(fields['probe_ip'])
    except ValueError:
        raise InvalidReportField('probe_ip')
Exemplo n.º 2
0
    def generate_pcap_filename():
        if self.global_options.get('pcapfile'):
            self.reports.pcap = self.global_options['pcapfile']
        else:
            if self.global_options.get('test'):
                test_filename = os.path.basename(self.global_options['test'])
            else:
                test_filename = os.path.basename(self.global_options['testdeck'])

            test_name = '.'.join(test_filename.split(".")[:-1])
            frm_str = "report_%s_"+otime.timestamp()+".%s"
            self.reports.pcap = frm_str % (test_name, "pcap")
Exemplo n.º 3
0
def generatePcapFilename():
    if cmd_line_options['pcapfile']:
        reports.pcap = cmd_line_options['pcapfile']
    else:
        if cmd_line_options['test']:
            test_filename = os.path.basename(cmd_line_options['test'])
        else:
            test_filename = os.path.basename(cmd_line_options['testdeck'])

        test_name = '.'.join(test_filename.split(".")[:-1])
        frm_str = "report_%s_"+otime.timestamp()+".%s"
        reports.pcap = frm_str % (test_name, "pcap")
Exemplo n.º 4
0
    def __init__(self, test_details, report_destination='.'):
        self.reportDestination = report_destination

        if not os.path.isdir(report_destination):
            raise InvalidDestination

        report_filename = "report-" + \
                test_details['test_name'] + "-" + \
                otime.timestamp() + ".yamloo"

        report_path = os.path.join(self.reportDestination, report_filename)

        if os.path.exists(report_path):
            log.msg("Report already exists with filename %s" % report_path)
            pushFilenameStack(report_path)

        self.report_path = report_path
        OReporter.__init__(self, test_details)
Exemplo n.º 5
0
    def __init__(self, cmd_line_options):
        if cmd_line_options['reportfile'] is None:
            try:
                test_filename = os.path.basename(cmd_line_options['test'])
            except IndexError:
                raise TestFilenameNotSet

            test_name = '.'.join(test_filename.split(".")[:-1])
            frm_str = "report_%s_"+otime.timestamp()+".%s"
            reportfile = frm_str % (test_name, "yamloo")
        else:
            reportfile = cmd_line_options['reportfile']

        if os.path.exists(reportfile):
            log.msg("Report already exists with filename %s" % reportfile)
            pushFilenameStack(reportfile)

        log.debug("Creating %s" % reportfile)
        self._stream = open(reportfile, 'w+')
        OReporter.__init__(self, cmd_line_options)
Exemplo n.º 6
0
            raise web.HTTPError(400, "Invalid Request Field %s" % e)
        except MissingField, e:
            raise web.HTTPError(400, "Missing Request Field %s" % e)

        print "Parsed this data %s" % report_data
        software_name = report_data['software_name']
        software_version = report_data['software_version']
        test_name = report_data['test_name']
        test_version = report_data['test_version']
        probe_asn = report_data['probe_asn']
        content = report_data['content']

        if not probe_asn:
            probe_asn = "AS0"

        report_id = otime.timestamp() + '_' \
                + probe_asn + '_' \
                + randomStr(50)

        # The report filename contains the timestamp of the report plus a
        # random nonce
        report_filename = os.path.join(config.main.report_dir, report_id)

        response = {'backend_version': config.backend_version,
                'report_id': report_id
        }

        self.writeToReport(report_filename,
                report_data['content'])

        self.write(response)
Exemplo n.º 7
0
 def test_timestamp(self):
     self.assertEqual(otime.timestamp(test_date), "2002-06-26T224549Z")
Exemplo n.º 8
0
 def test_fromTimestamp(self):
     time_stamp = otime.timestamp(test_date)
     self.assertEqual(test_date, otime.fromTimestamp(time_stamp))
Exemplo n.º 9
0
 def test_timestamp(self):
     self.assertEqual(otime.timestamp(test_date), "2002-06-26T224549Z")
Exemplo n.º 10
0
 def test_fromTimestamp(self):
     time_stamp = otime.timestamp(test_date)
     self.assertEqual(test_date, otime.fromTimestamp(time_stamp))
Exemplo n.º 11
0
 def run(self):
     self.reportName = "report-%s-%s.yamloo" % (self.testfile, timestamp())
     self.output = runTest(self)
     self.parseResults()