Revision 90e234a6

b/lib/utils/__init__.py
66 66
from ganeti.utils.process import * # pylint: disable-msg=W0401
67 67

  
68 68

  
69
_RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
70

  
71 69
_VALID_SERVICE_NAME_RE = re.compile("^[-_.a-zA-Z0-9]{1,128}$")
72 70

  
73 71
UUID_RE = re.compile('^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-'
......
289 287
  return result.pw_dir
290 288

  
291 289

  
292
def NewUUID():
293
  """Returns a random UUID.
294

  
295
  @note: This is a Linux-specific method as it uses the /proc
296
      filesystem.
297
  @rtype: str
298

  
299
  """
300
  return ReadFile(_RANDOM_UUID_FILE, size=128).rstrip("\n")
301

  
302

  
303 290
def FirstFree(seq, base=0):
304 291
  """Returns the first non-existing integer from seq.
305 292

  
b/lib/utils/io.py
34 34
from ganeti.utils import filelock
35 35

  
36 36

  
37
#: Path generating random UUID
38
_RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
39

  
40

  
37 41
def ReadFile(file_name, size=-1):
38 42
  """Reads a file.
39 43

  
......
760 764
        value = None
761 765

  
762 766
  return value
767

  
768

  
769
def NewUUID():
770
  """Returns a random UUID.
771

  
772
  @note: This is a Linux-specific method as it uses the /proc
773
      filesystem.
774
  @rtype: str
775

  
776
  """
777
  return ReadFile(_RANDOM_UUID_FILE, size=128).rstrip("\n")
b/test/ganeti.utils.io_unittest.py
691 691
      " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n")
692 692

  
693 693

  
694
class TestNewUUID(unittest.TestCase):
695
  """Test case for NewUUID"""
696

  
697
  def runTest(self):
698
    self.failUnless(utils.UUID_RE.match(utils.NewUUID()))
699

  
700

  
694 701
if __name__ == "__main__":
695 702
  testutils.GanetiTestProgram()
b/test/ganeti.utils_unittest.py
81 81
        ("none", "/proc", "proc", "rw,nosuid,nodev,noexec,relatime"),
82 82
      ])
83 83

  
84
class TestNewUUID(unittest.TestCase):
85
  """Test case for NewUUID"""
86

  
87
  def runTest(self):
88
    self.failUnless(utils.UUID_RE.match(utils.NewUUID()))
89

  
90 84

  
91 85
class TestFirstFree(unittest.TestCase):
92 86
  """Test case for the FirstFree function"""

Also available in: Unified diff