Revision 850be460 test/py/cmdlib/cluster_unittest.py

b/test/py/cmdlib/cluster_unittest.py
23 23

  
24 24
"""
25 25

  
26
import OpenSSL
27

  
26 28
import unittest
27 29
import operator
28 30
import os
......
718 720

  
719 721
  def testNicparamsInvalidConf(self):
720 722
    nicparams = {
721
      constants.NIC_MODE: constants.NIC_MODE_BRIDGED
723
      constants.NIC_MODE: constants.NIC_MODE_BRIDGED,
724
      constants.NIC_LINK: ""
722 725
    }
723 726
    op = opcodes.OpClusterSetParams(nicparams=nicparams)
724 727
    self.ExecOpCodeExpectException(op, errors.ConfigurationError, "NIC link")
......
1015 1018

  
1016 1019
    self.assertEqual(1, len(result["jobs"]))
1017 1020

  
1021

  
1022
class TestLUClusterVerifyConfig(CmdlibTestCase):
1023

  
1024
  def setUp(self):
1025
    super(TestLUClusterVerifyConfig, self).setUp()
1026

  
1027
    self._load_cert_patcher = testutils \
1028
      .patch_object(OpenSSL.crypto, "load_certificate")
1029
    self._load_cert_mock = self._load_cert_patcher.start()
1030
    self._verify_cert_patcher = testutils \
1031
      .patch_object(utils, "VerifyX509Certificate")
1032
    self._verify_cert_mock = self._verify_cert_patcher.start()
1033
    self._read_file_patcher = testutils.patch_object(utils, "ReadFile")
1034
    self._read_file_mock = self._read_file_patcher.start()
1035
    self._can_read_patcher = testutils.patch_object(utils, "CanRead")
1036
    self._can_read_mock = self._can_read_patcher.start()
1037

  
1038
    self._can_read_mock.return_value = True
1039
    self._read_file_mock.return_value = True
1040
    self._verify_cert_mock.return_value = (None, "")
1041
    self._load_cert_mock.return_value = True
1042

  
1043
  def tearDown(self):
1044
    super(TestLUClusterVerifyConfig, self).tearDown()
1045

  
1046
    self._can_read_patcher.stop()
1047
    self._read_file_patcher.stop()
1048
    self._verify_cert_patcher.stop()
1049
    self._load_cert_patcher.stop()
1050

  
1051
  def testSuccessfulRun(self):
1052
    self.cfg.AddNewInstance()
1053
    op = opcodes.OpClusterVerifyConfig()
1054
    result = self.ExecOpCode(op)
1055

  
1056
    self.assertTrue(result)
1057

  
1058
  def testDanglingNode(self):
1059
    node = self.cfg.AddNewNode()
1060
    self.cfg.AddNewInstance(primary_node=node)
1061
    node.group = "invalid"
1062
    op = opcodes.OpClusterVerifyConfig()
1063
    result = self.ExecOpCode(op)
1064

  
1065
    self.mcpu.assertLogContainsRegex(
1066
      "following nodes \(and their instances\) belong to a non existing group")
1067
    self.assertFalse(result)
1068

  
1069
  def testDanglingInstance(self):
1070
    inst = self.cfg.AddNewInstance()
1071
    inst.primary_node = "invalid"
1072
    op = opcodes.OpClusterVerifyConfig()
1073
    result = self.ExecOpCode(op)
1074

  
1075
    self.mcpu.assertLogContainsRegex(
1076
      "following instances have a non-existing primary-node")
1077
    self.assertFalse(result)
1078

  
1079

  
1018 1080
if __name__ == "__main__":
1019 1081
  testutils.GanetiTestProgram()

Also available in: Unified diff