Esempio n. 1
0
 def save(self, **pins):
   for k, v in pins.iteritems():
     assert isinstance(k, basestring)
     assert isinstance(v, basestring)
   LOGGER.debug('Writing pin file [%s]: %s', self._path, pins)
   with open(self._path, 'w') as fd:
     json.dump(pins, fd, indent=2, sort_keys=True)
Esempio n. 2
0
 def use(cls, *args, **kwargs):
     c = None
     try:
         c = cls.create(*args, **kwargs)
         LOGGER.debug('Using checkout at: %s', c.path)
         yield c
     finally:
         if c:
             c.teardown()
Esempio n. 3
0
  def _regenerate_slave_pool(self, master):
    LOGGER.debug('Regenerating slave pool for: %s', master)
    cmd = [
        os.path.join(*self.RUNIT_PY),
        os.path.join(*self.SLAVE_ALLOC_UPDATE),
    ]
    cmd += logging_verbosity()
    cmd.append(master)

    rv, stdout = execute.call(cmd, cwd=self._c.path)
    if rv != 0:
      LOGGER.exception('Failed to update slaves for master [%s] (%d):\n%s',
                       master, rv, stdout)
      raise SlavePoolUpdateError()
Esempio n. 4
0
  def _regenerate_slave_pool(self, master):
    LOGGER.debug('Regenerating slave pool for: %s', master)
    cmd = [
        os.path.join(*self.RUNIT_PY),
        os.path.join(*self.SLAVE_ALLOC_UPDATE),
    ]
    cmd += logging_verbosity()
    cmd.append(master)

    rv, stdout = execute.call(cmd, cwd=self._c.path)
    if rv != 0:
      LOGGER.exception('Failed to update slaves for master [%s] (%d):\n%s',
                       master, rv, stdout)
      raise SlavePoolUpdateError()
Esempio n. 5
0
def call(cmd, cwd=None, dry_run=False):
  LOGGER.info("Executing command %s (cwd=%s)", cmd, (cwd or os.getcwd()))
  if dry_run:
    LOGGER.info('Dry Run: Not actually executing.')
    return (0, "")

  output = []
  proc = subprocess.Popen(
      cmd,
      stdout=subprocess.PIPE,
      stderr=subprocess.STDOUT,
      cwd=cwd)

  for line in iter(proc.stdout.readline, b''):
    LOGGER.debug('[%s]: %s', cmd[0], line.rstrip())
    output.append(line)
  proc.wait()

  return proc.returncode, ''.join(output)
Esempio n. 6
0
    def update(self, pin_name, create=False, version=None):
      """Updates a single pin value."""
      if not version:
        LOGGER.debug('Resolving version for pin [%s]', pin_name)
        version = self._editor.get_commit(pin_name)
      elif self._editor._validate:
        LOGGER.debug('Validating pin [%s]', pin_name)
        self._editor.validate_pin(version)

      with self.edit() as pins:
        current = pins.get(pin_name)
        if current == version:
          LOGGER.warning('Pin [%s.%s] is already at version [%s]',
                         self._pin.name, pin_name, current)
          return None

        LOGGER.info('Updating pin [%s.%s]: [%s] => [%s]',
                    self._pin.name, pin_name, current, version)
        if not (current or create):
          raise ReadOnlyError("Pin does not exist [%s]" % (pin_name,))
        pins[pin_name] = version
      return PinUpdate(pin_name, current, version)
Esempio n. 7
0
        def update(self, pin_name, create=False, version=None):
            """Updates a single pin value."""
            if not version:
                LOGGER.debug('Resolving version for pin [%s]', pin_name)
                version = self._editor.get_commit(pin_name)
            elif self._editor._validate:
                LOGGER.debug('Validating pin [%s]', pin_name)
                self._editor.validate_pin(version)

            with self.edit() as pins:
                current = pins.get(pin_name)
                if current == version:
                    LOGGER.warning('Pin [%s.%s] is already at version [%s]',
                                   self._pin.name, pin_name, current)
                    return None

                LOGGER.info('Updating pin [%s.%s]: [%s] => [%s]',
                            self._pin.name, pin_name, current, version)
                if not (current or create):
                    raise ReadOnlyError("Pin does not exist [%s]" %
                                        (pin_name, ))
                pins[pin_name] = version
            return PinUpdate(pin_name, current, version)
Esempio n. 8
0
  def _upload_patch(self, repo_path, commit_msg):
    # Check if the Git repository actually has changes.
    diff_args = ['git', 'diff', '--no-ext-diff', '--exit-code']
    if not LOGGER.isEnabledFor(logging.DEBUG):
      diff_args.append('--quiet')
    rv, diff = execute.call(diff_args, cwd=repo_path)
    LOGGER.debug('Diff for [%s]:\n%s', repo_path, diff)
    if rv == 0:
      LOGGER.warning('No changes in repository; refusing to commit.')
      return

    commit_msg_file = self._c.mktempfile(commit_msg)

    LOGGER.warning('Creating commit in [%s] with message:\n%s',
                   repo_path, commit_msg)
    execute.check_call(
        ['git', 'checkout', '-b', '_cros_pin'],
        cwd=repo_path)
    execute.check_call(
        ['git', 'commit', '--all', '-F', commit_msg_file],
        cwd=repo_path)

    LOGGER.debug('Uploading CL!')
    args = [
        'git', 'cl', 'upload',
        '--bypass-hooks', # The CQ will take care of them!
        '--send-mail',
        '--message-file', commit_msg_file,
        '-f',
        ]
    if self._cq:
      print 'Commit? [Y/n]:',
      input_string = raw_input()
      if input_string != '' and not distutils.util.strtobool(input_string):
        LOGGER.warning('User opted not to commit; aborting.')
        return
      args.append('--use-commit-queue')
    if not self._reviewers:
      args.append('--tbr-owners')

    output = execute.check_call(args, cwd=repo_path, dry_run=self._dry_run)
    issue = None
    for line in output.splitlines():
      for rx in self.RE_ISSUE_CREATED:
        match = rx.match(line)
        if match:
          issue = match.group(1)
          LOGGER.debug('Extracted issue from output: %s', issue)
          self._issues.add(issue)
          break
    else:
      LOGGER.warning("Unable to extract issue from patch submission from:\n%s",
                     output)
Esempio n. 9
0
  def _upload_patch(self, repo_path, commit_msg):
    # Check if the Git repository actually has changes.
    diff_args = ['git', 'diff', '--no-ext-diff', '--exit-code']
    if not LOGGER.isEnabledFor(logging.DEBUG):
      diff_args.append('--quiet')
    rv, diff = execute.call(diff_args, cwd=repo_path)
    LOGGER.debug('Diff for [%s]:\n%s', repo_path, diff)
    if rv == 0:
      LOGGER.warning('No changes in repository; refusing to commit.')
      return

    LOGGER.warning('Creating commit in [%s] with message:\n%s',
                   repo_path, commit_msg)
    execute.check_call(
        ['git', 'checkout', '-b', '_cros_pin'],
        cwd=repo_path)
    execute.check_call(
        ['git', 'commit', '--all', '--message', commit_msg],
        cwd=repo_path)

    LOGGER.debug('Uploading CL!')
    args = [
        'git', 'cl', 'upload',
        '--bypass-hooks', # The CQ will take care of them!
        '-t', commit_msg,
        '-m', 'Auto-generated by `%s`' % (__name__,),
        '-f',
        ]
    if self._cq:
      print 'Commit? [Y/n]:',
      input_string = raw_input()
      if input_string != '' and not distutils.util.strtobool(input_string):
        LOGGER.warning('User opted not to commit; aborting.')
        return
      args.append('--use-commit-queue')
    if not self._reviewers:
      args.append('--tbr-owners')

    output = execute.check_call(args, cwd=repo_path, dry_run=self._dry_run)
    issue = None
    for line in output.splitlines():
      match = self.RE_ISSUE_CREATED.match(line)
      if match:
        issue = match.group(1)
        LOGGER.debug('Extracted issue from output: %s', issue)
        self._issues.add(issue)
        break
    else:
      LOGGER.warning("Unable to extract issue from patch submission.")
Esempio n. 10
0
def subcommand_update(args):
  """Update a single Chromite pin."""
  require = (args.target != 'existing')
  target_pins = []
  if args.target in ('external', 'both', 'existing'):
    target_pins.append(pinfile.EXTERNAL)
  if args.target in ('internal', 'both', 'existing'):
    target_pins.append(pinfile.INTERNAL)

  with checkout_for_args(args) as c:
    pfe = pinfile_editor_from_args(args, c)
    tracker = UpdateTracker.from_args(args, c)

    for pin in target_pins:
      logging.debug('Updating target pin [%s]', pin)

      # Update the pin.
      pf = pfe.load(pin)
      if not (require or pf.has_pin(args.name)):
        LOGGER.debug('Pin not found in [%s]. Only updating existing pins.', pin)
        continue

      update = pf.update(args.name, version=args.version, create=require)
      if not update:
        LOGGER.debug('Did not update pins for [%s]', pin)
        continue
      tracker.add(pin, update)
      LOGGER.debug('Updated pin set: %s', update)

    if not tracker:
      LOGGER.error('No pins were updated.')
      return 1

    # Regenerate slave pools for affected masters.
    tracker.update()
    for i in tracker.issues:
      LOGGER.warning('Created Issue: %s', i)
  return 0
Esempio n. 11
0
def subcommand_update(args):
  """Update a single Chromite pin."""
  require = (args.target != 'existing')
  target_pins = []
  if args.target in ('external', 'both', 'existing'):
    target_pins.append(pinfile.EXTERNAL)
  if args.target in ('internal', 'both', 'existing'):
    target_pins.append(pinfile.INTERNAL)

  with checkout_for_args(args) as c:
    pfe = pinfile_editor_from_args(args, c)
    tracker = UpdateTracker.from_args(args, c)

    for pin in target_pins:
      logging.debug('Updating target pin [%s]', pin)

      # Update the pin.
      pf = pfe.load(pin)
      if not (require or pf.has_pin(args.name)):
        LOGGER.debug('Pin not found in [%s]. Only updating existing pins.', pin)
        continue

      update = pf.update(args.name, version=args.version, create=require)
      if not update:
        LOGGER.debug('Did not update pins for [%s]', pin)
        continue
      tracker.add(pin, update)

    LOGGER.debug('Updated pin set: %s', update)
    if not tracker:
      LOGGER.error('No pins were updated.')
      return 1

    # Regenerate slave pools for affected masters.
    tracker.update()
    for i in tracker.issues:
      LOGGER.warning('Created Issue: %s', i)
  return 0