Exemplo n.º 1
0
 def testNoHvparams(self):
     expected_xen_cmd = "xm"
     mock_run_cmd = mock.Mock(return_value=self.RESULT_OK)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     self.assertRaises(errors.HypervisorError, hv._GetInstanceList, True,
                       None)
Exemplo n.º 2
0
    def testCommandExplicit(self):
        """Test the case when the command is given as class parameter explicitly.

    """
        expected_cmd = "xl"
        hv = hv_xen.XenHypervisor(_cmd=constants.XEN_CMD_XL)
        self.assertEqual(hv._GetCommand(None), expected_cmd)
Exemplo n.º 3
0
 def testBinaryNotFound(self):
     RESULT_FAILED = utils.RunResult(1, None, "", "", "", None, None)
     mock_run_cmd = mock.Mock(return_value=RESULT_FAILED)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     result = hv._CheckToolstackBinary("xl")
     self.assertFalse(result)
Exemplo n.º 4
0
 def testCheckToolstackXlConfigured(self):
     RESULT_OK = utils.RunResult(0, None, "", "", "", None, None)
     mock_run_cmd = mock.Mock(return_value=RESULT_OK)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     result = hv._CheckToolstackXlConfigured()
     self.assertTrue(result)
Exemplo n.º 5
0
 def testCommandUnknown(self):
     cmd = "#unknown command#"
     self.assertFalse(cmd in constants.KNOWN_XEN_COMMANDS)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=NotImplemented,
                               _cmd=cmd)
     self.assertRaises(errors.ProgrammerError, hv._RunXen, [], None)
Exemplo n.º 6
0
 def testHvparamsXl(self):
     expected_xen_cmd = "xl"
     hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
     mock_run_cmd = mock.Mock(return_value=self.RESULT_OK)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     hv.ListInstances(hvparams=hvparams)
     mock_run_cmd.assert_called_with([expected_xen_cmd, self.XEN_LIST])
Exemplo n.º 7
0
 def testVerifyFailing(self):
     result_failed = utils.RunResult(1, None, "", "", "", None, None)
     mock_run_cmd = mock.Mock(return_value=result_failed)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     hv._CheckToolstack = mock.Mock(return_value=True)
     result = hv.Verify()
     self.assertTrue(result is not None)
Exemplo n.º 8
0
 def testVerify(self):
     hvparams = {}
     mock_run_cmd = mock.Mock(return_value=self._result_ok)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     hv._CheckToolstackXlConfigured = mock.Mock(return_value=True)
     result = hv.Verify(hvparams)
     self.assertTrue(result is None)
Exemplo n.º 9
0
 def testFromHvparams(self):
     expected_xen_cmd = "xl"
     hvparams = {}
     mock_run_cmd = mock.Mock(return_value=self.RESULT_OK)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     hv._GetInstanceList(True)
     mock_run_cmd.assert_called_with([expected_xen_cmd, self.XEN_LIST])
Exemplo n.º 10
0
 def testVerify(self):
     hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
     mock_run_cmd = mock.Mock(return_value=self._result_ok)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     hv._CheckToolstack = mock.Mock(return_value=True)
     result = hv.Verify(hvparams)
     self.assertTrue(result is None)
Exemplo n.º 11
0
 def testCommandFromHvparams(self):
     expected_xen_cmd = "xl"
     hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
     mock_run_cmd = mock.Mock()
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     hv._RunXen([self.XEN_SUB_CMD], hvparams=hvparams)
     mock_run_cmd.assert_called_with([expected_xen_cmd, self.XEN_SUB_CMD])
Exemplo n.º 12
0
 def testVerifyToolstackNotOk(self):
     hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
     mock_run_cmd = mock.Mock(return_value=self._result_ok)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     hv._CheckToolstack = mock.Mock()
     hv._CheckToolstack.side_effect = errors.HypervisorError("foo")
     result = hv.Verify(hvparams)
     self.assertTrue(result is not None)
Exemplo n.º 13
0
 def testCheckToolstackXlFails(self):
     RESULT_FAILED = utils.RunResult(
         1, None, "", "ERROR: The pink bunny hid the binary.", "", None,
         None)
     mock_run_cmd = mock.Mock(return_value=RESULT_FAILED)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     self.assertRaises(errors.HypervisorError,
                       hv._CheckToolstackXlConfigured)
Exemplo n.º 14
0
 def testHVVersionsLikelySafeForMigration(self):
     hv = hv_xen.XenHypervisor()
     self.assertTrue(hv.VersionsSafeForMigration([4, 0], [4, 1]))
     self.assertFalse(hv.VersionsSafeForMigration([4, 1], [4, 0]))
     self.assertFalse(hv.VersionsSafeForMigration([4, 0], [4, 2]))
     self.assertTrue(hv.VersionsSafeForMigration([4, 2, 7], [4, 2, 9]))
     self.assertTrue(hv.VersionsSafeForMigration([4, 2, 9], [4, 2, 7]))
     self.assertTrue(hv.VersionsSafeForMigration([4], [4]))
     self.assertFalse(hv.VersionsSafeForMigration([4], [5]))
Exemplo n.º 15
0
 def testCheckToolstackXlNotConfigured(self):
     RESULT_FAILED = utils.RunResult(
         1, None, "",
         "ERROR:  A different toolstack (xm) has been selected!", "", None,
         None)
     mock_run_cmd = mock.Mock(return_value=RESULT_FAILED)
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=mock_run_cmd)
     result = hv._CheckToolstackXlConfigured()
     self.assertFalse(result)
Exemplo n.º 16
0
    def testWriteError(self):
        cfgdir = utils.PathJoin(self.tmpdir, "foobar")

        hv = hv_xen.XenHypervisor(_cfgdir=cfgdir,
                                  _run_cmd_fn=NotImplemented,
                                  _cmd=NotImplemented)

        self.assertFalse(os.path.exists(cfgdir))

        try:
            hv._WriteConfigFile("name", "data")
        except errors.HypervisorError, err:
            self.assertTrue(str(err).startswith("Cannot write Xen instance"))
Exemplo n.º 17
0
 def testCommandHvparams(self):
     expected_cmd = "xl"
     test_hvparams = {constants.HV_XEN_CMD: constants.XEN_CMD_XL}
     hv = hv_xen.XenHypervisor()
     self.assertEqual(hv._GetCommand(test_hvparams), expected_cmd)
Exemplo n.º 18
0
 def testCommandHvparamsInvalid(self):
     test_hvparams = {}
     hv = hv_xen.XenHypervisor()
     self.assertRaises(errors.HypervisorError, hv._GetCommand,
                       test_hvparams)
Exemplo n.º 19
0
 def testCommandHvparamsCmdInvalid(self):
     test_hvparams = {constants.HV_XEN_CMD: "invalidcommand"}
     hv = hv_xen.XenHypervisor()
     self.assertRaises(errors.ProgrammerError, hv._GetCommand,
                       test_hvparams)
Exemplo n.º 20
0
 def testCommandNoHvparams(self):
     hv = hv_xen.XenHypervisor(_cfgdir=NotImplemented,
                               _run_cmd_fn=NotImplemented)
     hvparams = None
     self.assertRaises(errors.HypervisorError, hv._RunXen,
                       [self.XEN_SUB_CMD], hvparams)
Exemplo n.º 21
0
    def testCommandInvalid(self):
        """Test the case an invalid command is given as class parameter explicitly.

    """
        hv = hv_xen.XenHypervisor(_cmd="invalidcommand")
        self.assertRaises(errors.ProgrammerError, hv._GetCommand, None)
Exemplo n.º 22
0
 def setUp(self):
     self.tmpdir = tempfile.mkdtemp()
     self.cfg_name = "xen_config"
     self.cfg_path = utils.PathJoin(self.tmpdir, self.cfg_name)
     self.hv = hv_xen.XenHypervisor()