Commit 28a7318f authored by Iustin Pop's avatar Iustin Pop
Browse files

Add unittests for TemporaryReservationManager

And fix an error message.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent a7359d91
......@@ -88,8 +88,8 @@ class TemporaryReservationManager:
def Reserve(self, ec_id, resource):
if self.Reserved(resource):
raise errors.ReservationError("Duplicate reservation for resource: %s." %
raise errors.ReservationError("Duplicate reservation for resource '%s'"
% str(resource))
if ec_id not in self._ec_reserved:
self._ec_reserved[ec_id] = set([resource])
......@@ -37,6 +37,8 @@ from ganeti import objects
from ganeti import utils
from ganeti import netutils
from ganeti.config import TemporaryReservationManager
import testutils
import mocks
......@@ -186,5 +188,23 @@ class TestConfigRunner(unittest.TestCase):
CheckSyntax, {mode: m_bridged, link: ''})
class TestTRM(unittest.TestCase):
EC_ID = 1
def testEmpty(self):
t = TemporaryReservationManager()
t.Reserve(self.EC_ID, "a")
self.assertEqual(len(t.GetReserved()), 1)
def testDuplicate(self):
t = TemporaryReservationManager()
t.Reserve(self.EC_ID, "a")
self.assertRaises(errors.ReservationError, t.Reserve, 2, "a")
if __name__ == '__main__':
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment