This patch adds few unit tests for _IsInstanceAlive method of hv_lxc.
Signed-off-by: Yuto KAWAMURA(kawamuray) <[email protected]>
---
test/py/ganeti.hypervisor.hv_lxc_unittest.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/test/py/ganeti.hypervisor.hv_lxc_unittest.py
b/test/py/ganeti.hypervisor.hv_lxc_unittest.py
index 6824308..5891eaf 100755
--- a/test/py/ganeti.hypervisor.hv_lxc_unittest.py
+++ b/test/py/ganeti.hypervisor.hv_lxc_unittest.py
@@ -26,8 +26,10 @@ import unittest
from ganeti import constants
from ganeti import objects
from ganeti import hypervisor
+from ganeti import utils
from ganeti.hypervisor import hv_lxc
+from ganeti.hypervisor.hv_lxc import LXCHypervisor
import testutils
@@ -49,6 +51,16 @@ class TestConsole(unittest.TestCase):
self.assertEqual(cons.host, node.name)
self.assertEqual(cons.command[-1], instance.name)
+class TestLXCIsInstanceAlive(unittest.TestCase):
+ @patch_object(utils, "RunCmd")
+ def testActive(self, runcmd_mock):
+ runcmd_mock.return_value = RunResultOk("inst1 inst2 inst3\ninst4 inst5")
+ self.assertTrue(LXCHypervisor._IsInstanceAlive("inst4"))
+
+ @patch_object(utils, "RunCmd")
+ def testInactive(self, runcmd_mock):
+ runcmd_mock.return_value = RunResultOk("inst1 inst2foo")
+ self.assertFalse(LXCHypervisor._IsInstanceAlive("inst2"))
if __name__ == "__main__":
testutils.GanetiTestProgram()
--
1.8.5.5