Revision e37f47d3 test/ganeti.tools.ensure_dirs_unittest.py

b/test/ganeti.tools.ensure_dirs_unittest.py
24 24
import unittest
25 25
import os.path
26 26

  
27
from ganeti import utils
27 28
from ganeti.tools import ensure_dirs
28 29

  
29 30
import testutils
30 31

  
31 32

  
32
class TestEnsureDirsFunctions(unittest.TestCase):
33
  def testPaths(self):
33
class TestGetPaths(unittest.TestCase):
34
  def testEntryOrder(self):
34 35
    paths = [(path[0], path[1]) for path in ensure_dirs.GetPaths()]
35 36

  
36
    seen = []
37
    last_dirname = ""
38
    for path, pathtype in paths:
37
    # Directories for which permissions have been set
38
    seen = set()
39

  
40
    # Current directory (changes when an entry of type C{DIR} or C{QUEUE_DIR}
41
    # is encountered)
42
    current_dir = None
43

  
44
    for (path, pathtype) in paths:
39 45
      self.assertTrue(pathtype in ensure_dirs.ALL_TYPES)
46
      self.assertTrue(utils.IsNormAbsPath(path),
47
                      msg=("Path '%s' is not absolute and/or normalized" %
48
                           path))
49

  
40 50
      dirname = os.path.dirname(path)
41
      if dirname != last_dirname or pathtype == ensure_dirs.DIR:
42
        if pathtype == ensure_dirs.FILE:
43
          self.assertFalse(dirname in seen,
44
                           msg="path %s; dirname %s seen in %s" % (path,
45
                                                                   dirname,
46
                                                                   seen))
47
          last_dirname = dirname
48
          seen.append(dirname)
49
        elif pathtype == ensure_dirs.DIR:
50
          self.assertFalse(path in seen)
51
          last_dirname = path
52
          seen.append(path)
51

  
52
      if pathtype == ensure_dirs.DIR:
53
        self.assertFalse(path in seen,
54
                         msg=("Directory '%s' was seen before" % path))
55
        current_dir = path
56
        seen.add(path)
57

  
58
      elif pathtype == ensure_dirs.QUEUE_DIR:
59
        self.assertTrue(dirname in seen,
60
                        msg=("Queue directory '%s' was not seen before" %
61
                             path))
62
        current_dir = path
63

  
64
      elif pathtype == ensure_dirs.FILE:
65
        self.assertFalse(current_dir is None)
66
        self.assertTrue(dirname in seen,
67
                        msg=("Directory '%s' of path '%s' has not been seen"
68
                             " yet" % (dirname, path)))
69
        self.assertTrue((utils.IsBelowDir(current_dir, path) and
70
                         current_dir == dirname),
71
                        msg=("File '%s' not below current directory '%s'" %
72
                             (path, current_dir)))
73

  
74
      else:
75
        self.fail("Unknown path type '%s'" % (pathtype, ))
53 76

  
54 77

  
55 78
if __name__ == "__main__":

Also available in: Unified diff