Revision 55ba3ad6

b/Makefile.am
1325 1325
	test/py/cmdlib/instance_migration_unittest.py \
1326 1326
	test/py/cmdlib/instance_query_unittest.py \
1327 1327
	test/py/cmdlib/instance_storage_unittest.py \
1328
	test/py/cmdlib/node_unittest.py \
1328 1329
	test/py/cmdlib/test_unittest.py \
1329 1330
	test/py/cfgupgrade_unittest.py \
1330 1331
	test/py/docs_unittest.py \
b/test/py/cmdlib/node_unittest.py
1
#!/usr/bin/python
2
#
3

  
4
# Copyright (C) 2013 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

  
21

  
22
"""Tests for LUNode*
23

  
24
"""
25

  
26
from collections import defaultdict
27

  
28
from ganeti import constants
29
from ganeti import objects
30
from ganeti import opcodes
31

  
32
from testsupport import *
33

  
34
import testutils
35

  
36

  
37
class TestLUNodeAdd(CmdlibTestCase):
38
  def setUp(self):
39
    super(TestLUNodeAdd, self).setUp()
40

  
41
    # One node for testing readding:
42
    self.node_readd = self.cfg.AddNewNode()
43
    self.op_readd = opcodes.OpNodeAdd(node_name=self.node_readd.name,
44
                                      readd=True,
45
                                      primary_ip=self.node_readd.primary_ip,
46
                                      secondary_ip=self.node_readd.secondary_ip)
47

  
48
    # One node for testing adding:
49
    # don't add to configuration now!
50
    self.node_add = objects.Node(name="node_add",
51
                                 primary_ip="192.0.2.200",
52
                                 secondary_ip="203.0.113.200")
53

  
54
    self.op_add = opcodes.OpNodeAdd(node_name=self.node_add.name,
55
                                    primary_ip=self.node_add.primary_ip,
56
                                    secondary_ip=self.node_add.secondary_ip)
57

  
58
    self.netutils_mod.TcpPing.return_value = True
59

  
60
    self.mocked_dns_rpc = self.rpc_mod.DnsOnlyRunner.return_value
61

  
62
    self.mocked_dns_rpc.call_version.return_value = \
63
      self.RpcResultsBuilder(use_node_names=True) \
64
        .AddSuccessfulNode(self.node_add, constants.CONFIG_VERSION) \
65
        .AddSuccessfulNode(self.node_readd, constants.CONFIG_VERSION) \
66
        .Build()
67

  
68
    node_verify_result = \
69
      self.RpcResultsBuilder() \
70
        .CreateSuccessfulNodeResult(self.node_add, {constants.NV_NODELIST: []})
71
    # we can't know the node's UUID in advance, so use defaultdict here
72
    self.rpc.call_node_verify.return_value = \
73
      defaultdict(lambda: node_verify_result, {})
74

  
75
  def testOvsParamsButNotEnabled(self):
76
    ndparams = {
77
      constants.ND_OVS: False,
78
      constants.ND_OVS_NAME: "testswitch",
79
    }
80

  
81
    op = self.CopyOpCode(self.op_add,
82
                         ndparams=ndparams)
83

  
84
    self.ExecOpCodeExpectOpPrereqError(op, "OpenvSwitch is not enabled")
85

  
86
  def testOvsNoLink(self):
87
    ndparams = {
88
      constants.ND_OVS: True,
89
      constants.ND_OVS_NAME: "testswitch",
90
      constants.ND_OVS_LINK: None,
91
    }
92

  
93
    op = self.CopyOpCode(self.op_add,
94
                         ndparams=ndparams)
95

  
96
    self.ExecOpCode(op)
97
    self.assertLogContainsRegex(
98
      "No physical interface for OpenvSwitch was given."
99
      " OpenvSwitch will not have an outside connection."
100
      " This might not be what you want")
101

  
102
    created_node = self.cfg.GetNodeInfoByName(op.node_name)
103
    self.assertEqual(ndparams[constants.ND_OVS],
104
                     created_node.ndparams.get(constants.ND_OVS, None))
105
    self.assertEqual(ndparams[constants.ND_OVS_NAME],
106
                     created_node.ndparams.get(constants.ND_OVS_NAME, None))
107
    self.assertEqual(ndparams[constants.ND_OVS_LINK],
108
                     created_node.ndparams.get(constants.ND_OVS_LINK, None))
109

  
110
  def testWithoutOVS(self):
111
    self.ExecOpCode(self.op_add)
112

  
113
    created_node = self.cfg.GetNodeInfoByName(self.op_add.node_name)
114
    self.assertEqual(None,
115
                     created_node.ndparams.get(constants.ND_OVS, None))
116

  
117
  def testWithOVS(self):
118
    ndparams = {
119
      constants.ND_OVS: True,
120
      constants.ND_OVS_LINK: "eth2",
121
    }
122

  
123
    op = self.CopyOpCode(self.op_add,
124
                         ndparams=ndparams)
125

  
126
    self.ExecOpCode(op)
127

  
128
    created_node = self.cfg.GetNodeInfoByName(op.node_name)
129
    self.assertEqual(ndparams[constants.ND_OVS],
130
                     created_node.ndparams.get(constants.ND_OVS, None))
131
    self.assertEqual(ndparams[constants.ND_OVS_LINK],
132
                     created_node.ndparams.get(constants.ND_OVS_LINK, None))
133

  
134
if __name__ == "__main__":
135
  testutils.GanetiTestProgram()

Also available in: Unified diff