(experiment, exp_data, mach_uuid)
return ret
Determine if a given experiment is enabled for a certname.

  Args:
    experiment: a string identifier for the experiment.
    exp_data: a dict containing experiment data (yaml.load(...))
    mach_uuid: A machine UUID provided by sendsysinfo.

  Returns:
    an instance with three attributes, status, source, and rollout_percent
  Raises:
    InvalidExperiment: an invalid experiment
    ExperimentsError: couldn't coerce hash to integer
Determine if a given experiment is enabled for a certname.
Determine if a given experiment is enabled for a certname .
def ExperimentIsBucket(experiment, exp_data, mach_uuid):
  """Determine if a given experiment is enabled for a certname.

  Args:
    experiment: a string identifier for the experiment.
    exp_data: a dict containing experiment data (yaml.load(...))
    mach_uuid: A machine UUID provided by sendsysinfo.

  Returns:
    an instance with three attributes, status, source, and rollout_percent
  Raises:
    InvalidExperiment: an invalid experiment
    ExperimentsError: couldn't coerce hash to integer
  """

  ret = type('obj', (object,), dict(status=None, source=AUTO))
  data = exp_data.get(experiment)
  if not data:
    raise InvalidExperiment('%s is not in %s.' % (experiment, exp_data))

  try:
    rollout_percent = float(data.get(PERCENT_KEY, 0))
    logging.debug('Got rollout_percent: %s.', rollout_percent)
  except ValueError:
    logging.warning('Could not parse rollout_percent, using 0.')
    rollout_percent = 0

  ret.rollout_percent = rollout_percent

  try:
    exp_hash = int(hashlib.sha256(experiment + mach_uuid).hexdigest(), 16)
  except ValueError:
    logging.warning('Could not coerce hash to integer.')
    raise ExperimentsError('Could not determine bucket for host.')

  bucket = exp_hash % MOD_VALUE
  logging.debug('Bucket is %s, rollout_percent is %s.', bucket, rollout_percent)
  if bucket * 100 / float(MOD_VALUE) < rollout_percent:
    ret.status = ENABLED
  else:
    ret.status = DISABLED
  return ret
def ExperimentIsBucket ( experiment , exp_data , mach_uuid ) : ret = type ( 'obj' , ( object , ) , dict ( status = None , source = AUTO ) ) data = exp_data . get ( experiment ) if not data : raise InvalidExperiment ( '%s is not in %s.' % ( experiment , exp_data ) ) try : rollout_percent = float ( data . get ( PERCENT_KEY , 0 ) ) logging . debug ( 'Got rollout_percent: %s.' , rollout_percent ) except ValueError : logging . warning ( 'Could not parse rollout_percent, using 0.' ) rollout_percent = 0 ret . rollout_percent = rollout_percent try : exp_hash = int ( hashlib . sha256 ( experiment + mach_uuid ) . hexdigest ( ) , 16 ) except ValueError : logging . warning ( 'Could not coerce hash to integer.' ) raise ExperimentsError ( 'Could not determine bucket for host.' ) bucket = exp_hash % MOD_VALUE logging . debug ( 'Bucket is %s, rollout_percent is %s.' , bucket , rollout_percent ) if bucket * 100 / float ( MOD_VALUE ) < rollout_percent : ret . status = ENABLED else : ret . status = DISABLED return ret