4 # Copyright (C) 2011 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Script for testing ganeti.tools.ensure_dirs"""
27 from ganeti import utils
28 from ganeti.tools import ensure_dirs
33 class TestGetPaths(unittest.TestCase):
34 def testEntryOrder(self):
35 paths = [(path[0], path[1]) for path in ensure_dirs.GetPaths()]
37 # Directories for which permissions have been set
40 # Current directory (changes when an entry of type C{DIR} or C{QUEUE_DIR}
44 for (path, pathtype) in paths:
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" %
50 dirname = os.path.dirname(path)
52 if pathtype == ensure_dirs.DIR:
53 self.assertFalse(path in seen,
54 msg=("Directory '%s' was seen before" % path))
58 elif pathtype == ensure_dirs.QUEUE_DIR:
59 self.assertTrue(dirname in seen,
60 msg=("Queue directory '%s' was not seen before" %
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'" %
75 self.fail("Unknown path type '%s'" % (pathtype, ))
78 if __name__ == "__main__":
79 testutils.GanetiTestProgram()