4 # Copyright (C) 2012 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.jstore"""
28 from ganeti import constants
29 from ganeti import utils
30 from ganeti import compat
31 from ganeti import errors
32 from ganeti import jstore
37 class TestFormatJobID(testutils.GanetiTestCase):
39 self.assertEqual(jstore.FormatJobID(0), "0")
40 self.assertEqual(jstore.FormatJobID(30498), "30498")
41 self.assertEqual(jstore.FormatJobID(319472592764518609),
45 for i in [-1, -2288, -9667, -0.205641, 0.0, 0.1, 13041.4472, "", "Hello",
47 self.assertRaises(errors.ProgrammerError, jstore.FormatJobID, i)
50 class TestGetArchiveDirectory(testutils.GanetiTestCase):
53 ("0", [0, 1, 3343, 9712, 9999]),
54 ("1", [10000, 13188, 19999]),
55 ("29", [290000, 296041, 298796, 299999]),
56 ("30", [300000, 309384]),
59 for (exp, job_ids) in tests:
60 for job_id in job_ids:
61 fmt_id = jstore.FormatJobID(job_id)
62 self.assertEqual(jstore.GetArchiveDirectory(fmt_id), exp)
63 self.assertEqual(jstore.ParseJobId(fmt_id), job_id)
66 self.assertRaises(errors.ParameterError, jstore.GetArchiveDirectory, None)
67 self.assertRaises(errors.ParameterError, jstore.GetArchiveDirectory, "foo")
70 class TestParseJobId(testutils.GanetiTestCase):
72 self.assertEqual(jstore.ParseJobId(29981), 29981)
73 self.assertEqual(jstore.ParseJobId("12918"), 12918)
76 self.assertRaises(errors.ParameterError, jstore.ParseJobId, "")
77 self.assertRaises(errors.ParameterError, jstore.ParseJobId, "MXXI")
78 self.assertRaises(errors.ParameterError, jstore.ParseJobId, [])
81 if __name__ == "__main__":
82 testutils.GanetiTestProgram()