Exemple #1
0
def load_suite(directory, suite_name):
  if '/' in suite_name:
    raise YBError('Unrecognized suite: %s', suite_name, exit = 1)

  suite_file = os.path.join(directory, suite_name + '.suite')

  if not os.path.isfile(suite_file):
    raise YBError('Unrecognized suite: %s', suite_name, exit = 1)

  try:
    return Suite(suite_name, suite_file)
  except OSError, e:
    raise YBError("Can't access %s: %s", directory, e.args[1], exit = 1)
Exemple #2
0
 def sync(self):
     try:
         return self._proc.stdin.sync()
     except IOError:
         self.close()
         # close() probably already raised an error, but if the command did
         # exit(0), let's die
         raise YBError('"%s" exited unexpectedly', self._cmd, exit=1)
Exemple #3
0
def list_suites(directory):
  try:
    result = [fn[:-6] for fn in os.listdir(directory) if fn.endswith('.suite')]
    result.sort()
    return result
  except OSError, e:
    if e.errno == errno.ENOENT:
      return []
    raise YBError("Can't access %s: %s", directory, e.args[1], exit = 1)
Exemple #4
0
 def close(self):
     proc = self._proc
     self._proc = None
     try:
         proc.communicate()
         check_error(self._cmd, proc.returncode)
     except IOError:
         # it would be weird if I/O error happened on close(), but it could be
         # flushing buffers or something
         raise YBError('"%s" exited unexpectedly', self._cmd, exit=1)
Exemple #5
0
  def read(self, filename):
    f = open(filename)
    lineno = 0
    line = None
    section = self._main # start with main section
    section_name = None


    while True:
      line = f.readline()
      if line == '':
        return
      line = line.strip()
      lineno += 1

      if line == '' or line.startswith("#") or line.startswith(";"):
        continue

      if line[0] == '[' and line[-1] == ']':
        section_name = line[1:-1]
        if section_name == 'repositories':
          section = self._repositories
        elif section_name == 'environment':
          section = self._environment
        elif section_name == 'post_install':
          section = self._post_install
        elif section_name in self._sections:
          section = self._sections[section_name]
        else:
          section = self._sections[section_name] = Section()
        continue

      match = section.LINE.match(line)
      if not match:
        if section_name is None:
          raise YBError('Invalid config line %d: %s', lineno, line, exit = 1)
        else:
          raise YBError('Invalid config line %d (section %s): %s',
                        lineno, section_name, line, exit = 1)

      groups = match.groupdict()
      section.add(**groups)
Exemple #6
0
def check_error(cmd, code):
    if code < 0:
        raise YBError('"%s" got signal %d', cmd, -code, exit=1)
    if code > 0:
        raise YBError('"%s" exited with code %d', cmd, code, exit=1)