def test(self): cfg = mocks.FakeConfig() ssh.WriteKnownHostsFile(cfg, self.tmpfile) self.assertFileContent( self.tmpfile, "%s ssh-rsa %s\n%s ssh-dss %s\n" % (cfg.GetClusterName(), mocks.FAKE_CLUSTER_KEY, cfg.GetClusterName(), mocks.FAKE_CLUSTER_KEY))
def __init__(self, opcode): self.cfg = mocks.FakeConfig() self.op = opcode
def testFunction(self): class TestLU(object): def __init__(self, opcode): self.cfg = mocks.FakeConfig() self.op = opcode class OpTest(opcodes.OpCode): OP_PARAMS = [ ("iallocator", None, ht.TAny, None), ("node", None, ht.TAny, None), ] default_iallocator = mocks.FakeConfig().GetDefaultIAllocator() other_iallocator = default_iallocator + "_not" op = OpTest() lu = TestLU(op) c_i = lambda: common.CheckIAllocatorOrNode(lu, "iallocator", "node") # Neither node nor iallocator given for n in (None, []): op.iallocator = None op.node = n c_i() self.assertEqual(lu.op.iallocator, default_iallocator) self.assertEqual(lu.op.node, n) # Both, iallocator and node given for a in ("test", constants.DEFAULT_IALLOCATOR_SHORTCUT): op.iallocator = a op.node = "test" self.assertRaises(errors.OpPrereqError, c_i) # Only iallocator given for n in (None, []): op.iallocator = other_iallocator op.node = n c_i() self.assertEqual(lu.op.iallocator, other_iallocator) self.assertEqual(lu.op.node, n) # Only node given op.iallocator = None op.node = "node" c_i() self.assertEqual(lu.op.iallocator, None) self.assertEqual(lu.op.node, "node") # Asked for default iallocator, no node given op.iallocator = constants.DEFAULT_IALLOCATOR_SHORTCUT op.node = None c_i() self.assertEqual(lu.op.iallocator, default_iallocator) self.assertEqual(lu.op.node, None) # No node, iallocator or default iallocator op.iallocator = None op.node = None lu.cfg.GetDefaultIAllocator = lambda: None self.assertRaises(errors.OpPrereqError, c_i)