示例#1
0
def isolated_handle_options(options, args):
  """Handles '--isolated <isolated>', '<isolated>' and '-- <args...>' arguments.

  Returns:
    tuple(command, inputs_ref).
  """
  isolated_cmd_args = []
  is_file = False
  if not options.isolated:
    if '--' in args:
      index = args.index('--')
      isolated_cmd_args = args[index+1:]
      args = args[:index]
    else:
      # optparse eats '--' sometimes.
      isolated_cmd_args = args[1:]
      args = args[:1]
    if len(args) != 1:
      raise ValueError(
          'Use --isolated, --raw-cmd or \'--\' to pass arguments to the called '
          'process.')
    # Old code. To be removed eventually.
    options.isolated, is_file = isolated_to_hash(
        args[0], isolated_format.get_hash_algo(options.namespace))
    if not options.isolated:
      raise ValueError('Invalid argument %s' % args[0])
  elif args:
    if '--' in args:
      index = args.index('--')
      isolated_cmd_args = args[index+1:]
      if index != 0:
        raise ValueError('Unexpected arguments.')
    else:
      # optparse eats '--' sometimes.
      isolated_cmd_args = args

  # If a file name was passed, use its base name of the isolated hash.
  # Otherwise, use user name as an approximation of a task name.
  if not options.task_name:
    if is_file:
      key = os.path.splitext(os.path.basename(args[0]))[0]
    else:
      key = options.user
    options.task_name = u'%s/%s/%s' % (
        key,
        '_'.join(
            '%s=%s' % (k, v)
            for k, v in sorted(options.dimensions.iteritems())),
        options.isolated)

  inputs_ref = FilesRef(
    isolated=options.isolated,
    isolatedserver=options.isolate_server,
    namespace=options.namespace)
  return isolated_cmd_args, inputs_ref
示例#2
0
 def setUp(self):
   super(DiskCacheTest, self).setUp()
   self._algo = isolated_format.get_hash_algo('default-gzip')
   self._free_disk = 1000
   # Max: 100 bytes, 2 items
   # Min free disk: 1000 bytes.
   self._policies = isolateserver.CachePolicies(100, 1000, 2)
   def get_free_space(p):
     self.assertEqual(p, self.tempdir)
     return self._free_disk
   self.mock(file_path, 'get_free_space', get_free_space)
示例#3
0
 def test_get_hash_algo(self):
     self.assertIs(isolated_format.get_hash_algo('default'), hashlib.sha1)
     self.assertIs(isolated_format.get_hash_algo('default-gzip'),
                   hashlib.sha1)
     self.assertIs(isolated_format.get_hash_algo('sha-1-flat'),
                   hashlib.sha1)
     self.assertIs(isolated_format.get_hash_algo('sha-1-deflate'),
                   hashlib.sha1)
     self.assertIs(isolated_format.get_hash_algo('sha-256-flat'),
                   hashlib.sha256)
     self.assertIs(isolated_format.get_hash_algo('sha-256-deflate'),
                   hashlib.sha256)
     self.assertIs(isolated_format.get_hash_algo('sha-512-flat'),
                   hashlib.sha512)
     self.assertIs(isolated_format.get_hash_algo('sha-512-deflate'),
                   hashlib.sha512)
 def test_get_hash_algo(self):
   # Tests here assume ALGO is used for default namespaces, check this
   # assumption.
   self.assertIs(isolated_format.get_hash_algo('default'), ALGO)
   self.assertIs(isolated_format.get_hash_algo('default-gzip'), ALGO)
示例#5
0
def isolated_handle_options(options, args):
  """Handles '--isolated <isolated>', '<isolated>' and '-- <args...>' arguments.

  Returns:
    tuple(command, data).
  """
  isolated_cmd_args = []
  if not options.isolated:
    if '--' in args:
      index = args.index('--')
      isolated_cmd_args = args[index+1:]
      args = args[:index]
    else:
      # optparse eats '--' sometimes.
      isolated_cmd_args = args[1:]
      args = args[:1]
    if len(args) != 1:
      raise ValueError(
          'Use --isolated, --raw-cmd or \'--\' to pass arguments to the called '
          'process.')
    # Old code. To be removed eventually.
    options.isolated, is_file = isolated_to_hash(
        options.isolate_server, options.namespace, args[0],
        isolated_format.get_hash_algo(options.namespace), options.verbose)
    if not options.isolated:
      raise ValueError('Invalid argument %s' % args[0])
  elif args:
    is_file = False
    if '--' in args:
      index = args.index('--')
      isolated_cmd_args = args[index+1:]
      if index != 0:
        raise ValueError('Unexpected arguments.')
    else:
      # optparse eats '--' sometimes.
      isolated_cmd_args = args

  command = isolated_get_run_commands(
      options.isolate_server, options.namespace, options.isolated,
      isolated_cmd_args, options.verbose)

  # If a file name was passed, use its base name of the isolated hash.
  # Otherwise, use user name as an approximation of a task name.
  if not options.task_name:
    if is_file:
      key = os.path.splitext(os.path.basename(args[0]))[0]
    else:
      key = options.user
    options.task_name = u'%s/%s/%s' % (
        key,
        '_'.join(
            '%s=%s' % (k, v)
            for k, v in sorted(options.dimensions.iteritems())),
        options.isolated)

  try:
    data = isolated_get_data(options.isolate_server)
  except (IOError, OSError):
    on_error.report('Failed to upload the zip file')
    raise ValueError('Failed to upload the zip file')

  return command, data
示例#6
0
 def hash_algo(self):  # pylint: disable=R0201
   return isolated_format.get_hash_algo(namespace)