Exemplo n.º 1
0
def real_main(base_dir, expected):
  expected = expected.copy()
  parser = optparse.OptionParser()
  parser.add_option('-v', '--verbose', action='count', default=0)
  options, args = parser.parse_args()
  if args:
    parser.error('Unsupported args %s' % ' '.join(args))
  levels = (logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG)
  logging.basicConfig(level=levels[min(options.verbose, len(levels)-1)])

  start = time.time()
  base = os.path.join(base_dir, 'masters')
  master_classes = do_master_imports()
  # Here we look for a slaves.cfg file in the directory to ensure that
  # the directory actually contains a master, as opposed to having existed
  # at one time but later having been removed.  In the latter case, it's
  # no longer an actual master that should be 'discovered' by this test.
  masters = sorted(
      p for p in os.listdir(base)
      if (os.path.isfile(os.path.join(base, p, 'slaves.cfg')) and
          not p.startswith('.'))
  )

  failed = set()
  skipped = 0
  success = 0

  # First make sure no master is started. Otherwise it could interfere with
  # conflicting port binding.
  if not masters_util.check_for_no_masters():
    return 1
  for master in masters:
    pid_path = os.path.join(base, master, 'twistd.pid')
    if os.path.isfile(pid_path):
      pid_value = int(open(pid_path).read().strip())
      if masters_util.pid_exists(pid_value):
        print >> sys.stderr, ('%s is still running as pid %d.' %
            (master, pid_value))
        print >> sys.stderr, 'Please stop it before running the test.'
        return 1

  bot_pwd_path = os.path.join(
      base_dir, '..', 'build', 'site_config', '.bot_password')
  with masters_util.temporary_password(bot_pwd_path):
    for master in masters[:]:
      if not master in expected:
        continue
      masters.remove(master)
      classname = expected.pop(master)
      if not classname:
        skipped += 1
        continue
      master_class = getattr(master_classes, classname)
      apply_issue_pwd_path = os.path.join(base, master, '.apply_issue_password')
      with masters_util.temporary_password(apply_issue_pwd_path):
        if not test_master(master, master_class, os.path.join(base, master)):
          failed.add(master)
        else:
          success += 1

  if failed:
    print >> sys.stderr, (
        '%d masters failed:\n%s' % (len(failed), '\n'.join(sorted(failed))))
  if masters:
    print >> sys.stderr, (
        '%d masters were not expected:\n%s' %
        (len(masters), '\n'.join(sorted(masters))))
  if expected:
    print >> sys.stderr, (
        '%d masters were expected but not found:\n%s' %
        (len(expected), '\n'.join(sorted(expected))))
  print >> sys.stderr, (
      '%s masters succeeded, %d failed, %d skipped in %1.1fs.' % (
        success, len(failed), skipped, time.time() - start))
  return int(bool(masters or expected or failed))
Exemplo n.º 2
0
def real_main(all_expected):
  start = time.time()
  master_classes = do_master_imports()
  all_masters = {}
  for base in all_expected:
    base_dir = os.path.join(base, 'masters')
    all_masters[base] = sorted(p for p in
        os.listdir(base_dir) if
        os.path.exists(os.path.join(base_dir, p, 'master.cfg')))
  failed = set()
  skipped = 0
  success = 0

  # First make sure no master is started. Otherwise it could interfere with
  # conflicting port binding.
  if not masters_util.check_for_no_masters():
    return 1
  for base, masters in all_masters.iteritems():
    for master in masters:
      pid_path = os.path.join(base, 'masters', master, 'twistd.pid')
      if os.path.isfile(pid_path):
        pid_value = int(open(pid_path).read().strip())
        if masters_util.pid_exists(pid_value):
          print >> sys.stderr, ('%s is still running as pid %d.' %
              (master, pid_value))
          print >> sys.stderr, 'Please stop it before running the test.'
          return 1


  with master_cfg_utils.TemporaryMasterPasswords():
    master_threads = []
    for base, masters in all_masters.iteritems():
      for master in masters[:]:
        if not master in all_expected[base]:
          continue
        masters.remove(master)
        classname = all_expected[base].pop(master)
        if not classname:
          skipped += 1
          continue
        cur_thread = MasterTestThread(
            master=master,
            master_class=getattr(master_classes, classname),
            master_path=os.path.join(base, 'masters', master))
        cur_thread.start()
        master_threads.append(cur_thread)
      for cur_thread in master_threads:
        cur_thread.join(20)
        if cur_thread.result:
          print '\n=== Error running %s === ' % cur_thread.master
          print cur_thread.result
          failed.add(cur_thread.master)
        else:
          success += 1

  if failed:
    print >> sys.stderr, (
        '%d masters failed:\n%s' % (len(failed), '\n'.join(sorted(failed))))
  remaining_masters = []
  for masters in all_masters.itervalues():
    remaining_masters.extend(masters)
  if any(remaining_masters):
    print >> sys.stderr, (
        '%d masters were not expected:\n%s' %
        (len(remaining_masters), '\n'.join(sorted(remaining_masters))))
  outstanding_expected = []
  for expected in all_expected.itervalues():
    outstanding_expected.extend(expected)
  if outstanding_expected:
    print >> sys.stderr, (
        '%d masters were expected but not found:\n%s' %
        (len(outstanding_expected), '\n'.join(sorted(outstanding_expected))))
  print >> sys.stderr, (
      '%s masters succeeded, %d failed, %d skipped in %1.1fs.' % (
        success, len(failed), skipped, time.time() - start))
  return int(bool(remaining_masters or outstanding_expected or failed))
Exemplo n.º 3
0
def real_main(base_dir, expected):
    expected = expected.copy()
    parser = optparse.OptionParser()
    parser.add_option('-v', '--verbose', action='count', default=0)
    options, args = parser.parse_args()
    if args:
        parser.error('Unsupported args %s' % ' '.join(args))
    levels = (logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG)
    logging.basicConfig(level=levels[min(options.verbose, len(levels) - 1)])

    start = time.time()
    base = os.path.join(base_dir, 'masters')
    # Here we look for a slaves.cfg file in the directory to ensure that
    # the directory actually contains a master, as opposed to having existed
    # at one time but later having been removed.  In the latter case, it's
    # no longer an actual master that should be 'discovered' by this test.
    masters = sorted(p for p in os.listdir(base)
                     if (os.path.isfile(os.path.join(base, p, 'slaves.cfg'))
                         and not p.startswith('.')))

    failed = set()
    skipped = 0
    success = 0

    # First make sure no master is started. Otherwise it could interfere with
    # conflicting port binding.
    if not masters_util.check_for_no_masters():
        return 1
    for master in masters:
        pid_path = os.path.join(base, master, 'twistd.pid')
        if os.path.isfile(pid_path):
            pid_value = int(open(pid_path).read().strip())
            if masters_util.pid_exists(pid_value):
                print >> sys.stderr, ('%s is still running as pid %d.' %
                                      (master, pid_value))
                print >> sys.stderr, 'Please stop it before running the test.'
                return 1

    bot_pwd_path = os.path.join(base_dir, '..', 'build', 'site_config',
                                '.bot_password')
    need_bot_pwd = not os.path.isfile(bot_pwd_path)
    try:
        if need_bot_pwd:
            with open(bot_pwd_path, 'w') as f:
                f.write('foo\n')
        for master in masters[:]:
            if not master in expected:
                continue
            masters.remove(master)
            name = expected.pop(master)
            if not name:
                skipped += 1
                continue
            if not test_master(master, name, os.path.join(base, master)):
                failed.add(master)
            else:
                success += 1
    finally:
        if need_bot_pwd:
            os.remove(bot_pwd_path)

    if failed:
        print >> sys.stderr, ('%d masters failed:\n%s' %
                              (len(failed), '\n'.join(sorted(failed))))
    if masters:
        print >> sys.stderr, ('%d masters were not expected:\n%s' %
                              (len(masters), '\n'.join(sorted(masters))))
    if expected:
        print >> sys.stderr, ('%d masters were expected but not found:\n%s' %
                              (len(expected), '\n'.join(sorted(expected))))
    print >> sys.stderr, (
        '%s masters succeeded, %d failed, %d skipped in %1.1fs.' %
        (success, len(failed), skipped, time.time() - start))
    return int(bool(masters or expected or failed))