def _run_perf(self, test_case, inputs):
        _log.info('Running test case: %s', test_case)

        output_file = '%s/run-%s/result-%s.out' % \
          (self.args.out_dir, test_case.run_id, test_case.run_subid)
        _log.info('Writing to output file %s', output_file)

        header = '''### run_id {run_id}:{run_subid}
### date {now}
### settings {test_case}
'''.format(run_id=test_case.run_id,
           run_subid=test_case.run_subid,
           now=time.ctime(),
           test_case=json.dumps(test_case.to_yaml()))

        with open(output_file + '.raw', 'w') as fh:
            fh.write(header)
            cmdline = inputs.dnsperf_cmdline
            code, out, err = self._kubectl(
                *([None, 'exec', _client_podname, '--'] +
                  [str(x) for x in cmdline]))
            fh.write('%s\n' % add_prefix('out | ', out))
            fh.write('%s\n' % add_prefix('err | ', err))

            if code != 0:
                raise Exception('error running dnsperf')

        with open(output_file, 'w') as fh:
            results = {}
            results['params'] = test_case.to_yaml()
            results['code'] = code
            results['stdout'] = out.split('\n')
            results['stderr'] = err.split('\n')
            results['data'] = {}

            try:
                parser = Parser(out)
                parser.parse()

                _log.info('Test results parsed')

                results['data']['ok'] = True
                results['data']['msg'] = None

                for key, value in parser.results.items():
                    results['data'][key] = value
                results['data']['histogram'] = parser.histogram
            except Exception, exc:
                _log.error('Error parsing results: %s', exc)
                results['data']['ok'] = False
                results['data'][
                    'msg'] = 'parsing error:\n%s' % traceback.format_exc()

            fh.write(yaml.dump(results))

            if self.db is not None and results['data']['ok']:
                self.db.put(results)
 def test_parser(self):
     raw = open('fixtures/raw.txt').read()
     parser = Parser(raw)
     parser.parse()
     # Check a subset of fields
     self.assertEquals(1000, parser.results['queries_sent'])
Beispiel #3
0
  def _run_perf(self, test_case, inputs, podname):
    _log.info('Running test case: %s', test_case)

    output_file = '%s/run-%s/result-%s-%s.out' % \
      (self.args.out_dir, test_case.run_id, test_case.run_subid, test_case.pod_name)
    _log.info('Writing to output file %s', output_file)
    res_usage = queue.Queue()
    dt = threading.Thread(target=self._run_top,args=[res_usage])
    dt.start()
    header = '''### run_id {run_id}:{run_subid}
### date {now}
### settings {test_case}
'''.format(run_id=test_case.run_id,
           run_subid=test_case.run_subid,
           now=time.ctime(),
           test_case=json.dumps(test_case.to_yaml()))

    with open(output_file + '.raw', 'w') as fh:
      fh.write(header)
      cmdline = inputs.dnsperf_cmdline
      code, out, err = self._kubectl(
          *([None, 'exec', podname, '--'] + [str(x) for x in cmdline]))
      fh.write('%s\n' % add_prefix('out | ', out))
      fh.write('%s\n' % add_prefix('err | ', err))

      if code != 0:
        raise Exception('error running dnsperf - %s, podname %s', err, podname)

    dt.join()

    with open(output_file, 'w') as fh:
      results = {}
      results['params'] = test_case.to_yaml()
      results['code'] = code
      results['stdout'] = out.split('\n')
      results['stderr'] = err.split('\n')
      results['data'] = {}

      try:
        parser = Parser(out)
        parser.parse()

        _log.info('Test results parsed')

        results['data']['ok'] = True
        results['data']['msg'] = None

        for key, value in list(parser.results.items()):
          results['data'][key] = value
        results['data']['max_perfserver_cpu'] = res_usage.get()
        results['data']['max_perfserver_memory'] = res_usage.get()
        results['data']['max_kubedns_cpu'] = res_usage.get()
        results['data']['max_kubedns_memory'] = res_usage.get()
        results['data']['histogram'] = parser.histogram
      except Exception:
        _log.exception('Error parsing results.')
        results['data']['ok'] = False
        results['data']['msg'] = 'parsing error:\n%s' % traceback.format_exc()

      fh.write(yaml.dump(results))

      if self.db is not None and results['data']['ok']:
        self.db.put(results)