Revision c4beba1c lib/jqueue.py

b/lib/jqueue.py
309 309
    finally:
310 310
      version_fd.close()
311 311

  
312
    serial_fd = open(constants.JOB_QUEUE_SERIAL_FILE, "r")
312
    self._last_serial = self._ReadSerial()
313
    if self._last_serial is None:
314
      raise errors.ConfigurationError("Can't read/parse the job queue serial"
315
                                      " file")
316

  
317
  @staticmethod
318
  def _ReadSerial():
319
    """Try to read the job serial file.
320

  
321
    @rtype: None or int
322
    @return: If the serial can be read, then it is returned. Otherwise None
323
             is returned.
324

  
325
    """
313 326
    try:
314
      # Read last serial
315
      self._last_serial = int(serial_fd.read(1024).strip())
316
    finally:
317
      serial_fd.close()
327
      serial_fd = open(constants.JOB_QUEUE_SERIAL_FILE, "r")
328
      try:
329
        # Read last serial
330
        serial = int(serial_fd.read(1024).strip())
331
      finally:
332
        serial_fd.close()
333
    except (ValueError, EnvironmentError):
334
      serial = None
335

  
336
    return serial
318 337

  
319 338
  def Close(self):
320 339
    assert self.lock_fd, "Queue should be open"
......
327 346

  
328 347
    utils.WriteFile(constants.JOB_QUEUE_VERSION_FILE,
329 348
                    data="%s\n" % constants.JOB_QUEUE_VERSION)
330
    utils.WriteFile(constants.JOB_QUEUE_SERIAL_FILE,
331
                    data="%s\n" % 0)
349
    if self._ReadSerial() is None:
350
      utils.WriteFile(constants.JOB_QUEUE_SERIAL_FILE,
351
                      data="%s\n" % 0)
332 352

  
333 353
  def _NewSerialUnlocked(self):
334 354
    """Generates a new job identifier.

Also available in: Unified diff