Exemplo n.º 1
0
    def probe(cls, env=None):
        """Returns (ButlerBootstrap): The probed bootstrap environment.

    Args:
      env (dict): The environment to probe. If None, `os.getenv` will be used.

    Raises:
      NotBootstrappedError if the current environment is not boostrapped.
    """
        if env is None:
            env = os.environ
        project = env.get(cls._ENV_PROJECT)
        prefix = env.get(cls._ENV_PREFIX)

        if not project:
            raise NotBootstrappedError('Missing project [%s]' %
                                       (cls._ENV_PROJECT, ))

        if not prefix:
            raise NotBootstrappedError('Missing prefix [%s]' %
                                       (cls._ENV_PREFIX, ))
        try:
            streamname.validate_stream_name(prefix)
        except ValueError as e:
            raise NotBootstrappedError('Prefix (%s) is invalid: %s' %
                                       (prefix, e))

        return cls(project=project,
                   prefix=prefix,
                   streamserver_uri=env.get(cls._ENV_STREAM_SERVER_PATH))
 def testInvalidStreamNamesRaiseValueError(self):
     for name in (
             '',
             'a' * (streamname._MAX_STREAM_NAME_LENGTH + 1),
             ' s p a c e s ',
             '-hyphen',
             'stream/path/+/not/name',
     ):
         with self.assertRaises(ValueError):
             streamname.validate_stream_name(name)
Exemplo n.º 3
0
 def testValidStreamNamesDoNotRaise(self):
   for name in (
       'a',
       'a' * (streamname._MAX_STREAM_NAME_LENGTH),
       'foo/bar',
       'f123/four/five-_.:',
   ):
     raised = False
     try:
       streamname.validate_stream_name(name)
     except ValueError:
       raised = True
     self.assertFalse(raised, "Stream name '%s' raised ValueError" % (name,))
Exemplo n.º 4
0
    def upload_manifest(self, name, manifest_pb):
        if not isinstance(manifest_pb, Manifest):
            raise TypeError('expected source_manifest_pb2.Manifest, got %r' %
                            type(manifest_pb))

        if self._prod and not self._logdog_client:
            raise self.ManifestUploadException(
                'LogDog not configured; if debugging locally, set the '
                '"$recipe_engine/source_manifest"={"debug_dir": "some/local/directory"}'
                ' property. You may also set debug_dir to `null` to disable all source '
                ' manifest saving.')

        if name.startswith('luci/'):
            raise self.BadManifestName(
                'Manifest names beginning with "luci/" are '
                'reserved: %r' % name)

        try:
            streamname.validate_stream_name(name)
        except ValueError:
            raise self.BadManifestName(
                'Manifest name must be a valid LogDog name: '
                '%r' % name)

        if not self._engine.active_step:
            raise self.NoActiveStep(
                'Uploading a manifest requires an active step.')

        if name in self._manifest_names:
            raise self.DuplicateManifestException(name)

        self._manifest_names.add(name)

        data = manifest_pb.SerializeToString()
        sha256 = hashlib.sha256(data).digest()

        if self._debug_dir:
            path = os.path.join(self._debug, name)
            with open(path, 'wb') as f:
                f.write(data)
            with open(path + '.sha256', 'wb') as f:
                f.write(sha256)
        elif self._prod:
            logdog_name = '/'.join(['source_manifest', name])
            with self._logdog_client.binary(logdog_name) as bs:
                bs.write(data)
            host = self._logdog_client.coordinator_host
            project = self._logdog_client.project
            path = self._logdog_client.get_stream_path(logdog_name)
            self._engine.active_step.open_step.stream.set_manifest_link(
                name, sha256, 'logdog://%s/%s/%s' % (host, project, path))
Exemplo n.º 5
0
  def validate(self):
    """Raises (ValueError): if the parameters are not valid."""
    streamname.validate_stream_name(self.name)

    if self.type not in (self.TEXT, self.BINARY, self.DATAGRAM):
      raise ValueError('Invalid type (%s)' % (self.type,))

    if self.tags is not None:
      if not isinstance(self.tags, collections.Mapping):
        raise ValueError('Invalid tags type (%s)' % (self.tags,))
      for k, v in self.tags.iteritems():
        streamname.validate_tag(k, v)

    if self.tee not in (None, self.TEE_STDOUT, self.TEE_STDERR):
      raise ValueError('Invalid tee type (%s)' % (self.tee,))

    if not isinstance(self.binary_file_extension,
        (types.NoneType, types.StringTypes)):
      raise ValueError('Invalid binary file extension type (%s)' % (
          self.binary_file_extension,))