Revision 07e68848

b/lib/cmdlib/cluster.py
196 196
                   " OpenvSwitch will not have an outside connection. This"
197 197
                   " might not be what you want.")
198 198

  
199
    # OpenvSwitch: Warn if parameters are given, but OVS is not enabled.
200
    if (not self.master_ndparams[constants.ND_OVS] and
201
        (self.master_ndparams[constants.ND_OVS_NAME] or
202
         self.master_ndparams.get(constants.ND_OVS_LINK, None))):
203
      self.LogInfo("OpenvSwitch name or link were given, but"
204
                   " OpenvSwitch is not enabled. Please enable"
205
                   " OpenvSwitch with 'ovs=true' or create it manually")
206

  
207 199
  def BuildHooksEnv(self):
208 200
    """Build hooks env.
209 201

  
b/lib/cmdlib/instance.py
183 183
                                   " is allowed to be passed",
184 184
                                   errors.ECODE_INVAL)
185 185

  
186
    if vlan is not None and nic_mode != constants.NIC_MODE_OVS:
187
      raise errors.OpPrereqError("VLAN is given, but network mode is not"
188
                                 " openvswitch", errors.ECODE_INVAL)
189

  
190 186
    # ip validity checks
191 187
    if ip is None or ip.lower() == constants.VALUE_NONE:
192 188
      nic_ip = None
b/lib/cmdlib/node.py
112 112
      raise errors.OpPrereqError("Cannot pass a node group when a node is"
113 113
                                 " being readded", errors.ECODE_INVAL)
114 114

  
115
    if self.op.ndparams:
116
      ovs = self.op.ndparams.get(constants.ND_OVS, None)
117
      ovs_name = self.op.ndparams.get(constants.ND_OVS_NAME, None)
118
      ovs_link = self.op.ndparams.get(constants.ND_OVS_LINK, None)
119

  
120
      # OpenvSwitch: Warn user if link is missing
121
      if ovs and not ovs_link:
122
        self.LogInfo("No physical interface for OpenvSwitch was given."
123
                     " OpenvSwitch will not have an outside connection. This"
124
                     " might not be what you want.")
125
      # OpenvSwitch: Fail if parameters are given, but OVS is not enabled.
126
      if not ovs and (ovs_name or ovs_link):
127
        raise errors.OpPrereqError("OpenvSwitch name or link were given, but"
128
                                   " OpenvSwitch is not enabled. Please enable"
129
                                   " OpenvSwitch with --ovs",
130
                                   errors.ECODE_INVAL)
131

  
132 115
  def BuildHooksEnv(self):
133 116
    """Build hooks env.
134 117

  
......
319 302
        raise errors.OpPrereqError("Checks on node PVs failed: %s" %
320 303
                                   "; ".join(errmsgs), errors.ECODE_ENVIRON)
321 304

  
305
  def _InitOpenVSwitch(self):
306
    filled_ndparams = self.cfg.GetClusterInfo().FillND(
307
      self.new_node, self.cfg.GetNodeGroup(self.new_node.group))
308

  
309
    ovs = filled_ndparams.get(constants.ND_OVS, None)
310
    ovs_name = filled_ndparams.get(constants.ND_OVS_NAME, None)
311
    ovs_link = filled_ndparams.get(constants.ND_OVS_LINK, None)
312

  
313
    if ovs:
314
      if not ovs_link:
315
        self.LogInfo("No physical interface for OpenvSwitch was given."
316
                     " OpenvSwitch will not have an outside connection. This"
317
                     " might not be what you want.")
318

  
319
      result = self.rpc.call_node_configure_ovs(
320
                 self.new_node.name, ovs_name, ovs_link)
321
      result.Raise("Failed to initialize OpenVSwitch on new node")
322

  
322 323
  def Exec(self, feedback_fn):
323 324
    """Adds the new node to the cluster.
324 325

  
......
392 393
                      (verifier, nl_payload[failed]))
393 394
        raise errors.OpExecError("ssh/hostname verification failed")
394 395

  
395
    # OpenvSwitch initialization on the node
396
    ovs = self.new_node.ndparams.get(constants.ND_OVS, None)
397
    ovs_name = self.new_node.ndparams.get(constants.ND_OVS_NAME, None)
398
    ovs_link = self.new_node.ndparams.get(constants.ND_OVS_LINK, None)
399

  
400
    if ovs:
401
      result = self.rpc.call_node_configure_ovs(
402
                 self.new_node.name, ovs_name, ovs_link)
396
    self._InitOpenVSwitch()
403 397

  
404 398
    if self.op.readd:
405 399
      self.context.ReaddNode(self.new_node)
b/lib/utils/__init__.py
99 99

  
100 100
    if ktype in (constants.VTYPE_STRING, constants.VTYPE_MAYBE_STRING):
101 101
      if target[key] is None and ktype == constants.VTYPE_MAYBE_STRING:
102
        msg = ("'None' is not a valid Maybe value for '%s'. "
103
               "Use 'VALUE_HS_NOTHING'") % (key, )
104
        logging.warning(msg)
105
      elif (target[key] == constants.VALUE_HS_NOTHING
106
            and ktype == constants.VTYPE_MAYBE_STRING):
107 102
        pass
108 103
      elif not isinstance(target[key], basestring):
109 104
        if isinstance(target[key], bool) and not target[key]:
b/src/Ganeti/Constants.hs
42 42
import qualified Data.Map as Map (empty, fromList, keys, insert)
43 43

  
44 44
import qualified AutoConf
45
import Ganeti.ConstantUtils (PythonChar(..), PythonNone(..), FrozenSet,
46
                             Protocol(..), buildVersion)
45
import Ganeti.ConstantUtils (PythonChar(..), FrozenSet, Protocol(..),
46
                             buildVersion)
47 47
import qualified Ganeti.ConstantUtils as ConstantUtils
48 48
import Ganeti.HTools.Types (AutoRepairResult(..), AutoRepairType(..))
49 49
import qualified Ganeti.HTools.Types as Types
......
600 600
valueFalse :: String
601 601
valueFalse = "false"
602 602

  
603
valueHsNothing :: Map String PythonNone
604
valueHsNothing = Map.fromList [("Nothing", PythonNone)]
605

  
606 603
-- * Hooks
607 604

  
608 605
hooksNameCfgupdate :: String
......
2249 2246
nicsParameterTypes =
2250 2247
  Map.fromList [(nicMode, vtypeString),
2251 2248
                (nicLink, vtypeString),
2252
                (nicVlan, vtypeMaybeString)]
2249
                (nicVlan, vtypeString)]
2253 2250

  
2254 2251
nicsParameters :: FrozenSet String
2255 2252
nicsParameters = ConstantUtils.mkSet (Map.keys nicsParameterTypes)
......
3795 3792
  Map.fromList
3796 3793
  [ (nicMode, PyValueEx nicModeBridged)
3797 3794
  , (nicLink, PyValueEx defaultBridge)
3798
  , (nicVlan, PyValueEx valueHsNothing)
3795
  , (nicVlan, PyValueEx "")
3799 3796
  ]
3800 3797

  
3801 3798
-- | All of the following values are quite arbitrary - there are no
b/src/Ganeti/Objects.hs
245 245
$(buildParam "Nic" "nicp"
246 246
  [ simpleField "mode" [t| NICMode |]
247 247
  , simpleField "link" [t| String  |]
248
  , simpleField "vlan" [t| Maybe String |]
248
  , simpleField "vlan" [t| String |]
249 249
  ])
250 250

  
251 251
$(buildObject "PartialNic" "nic" $
b/test/py/cmdlib/instance_unittest.py
180 180
    self.ExecOpCodeExpectOpPrereqError(
181 181
      op, "If network is given, no mode or link is allowed to be passed")
182 182

  
183
  def testVlanWithWrongMode(self):
184
    op = self.CopyOpCode(self.diskless_op,
185
                         nics=[{
186
                           constants.INIC_VLAN: ":1",
187
                           constants.INIC_MODE: constants.NIC_MODE_BRIDGED
188
                         }])
189
    self.ExecOpCodeExpectOpPrereqError(
190
      op, "VLAN is given, but network mode is not openvswitch")
191

  
192 183
  def testAutoIpNoNameCheck(self):
193 184
    op = self.CopyOpCode(self.diskless_op,
194 185
                         nics=[{
b/test/py/cmdlib/node_unittest.py
35 35

  
36 36
import testutils
37 37

  
38

  
38 39
# pylint: disable=W0613
39 40
def _TcpPingFailSecondary(cfg, mock_fct, target, port, timeout=None,
40 41
                          live_port_needed=None, source=None):
......
42 43
  # and False if not.
43 44
  return "192.0.2." in target
44 45

  
46

  
45 47
class TestLUNodeAdd(CmdlibTestCase):
46 48
  def setUp(self):
47 49
    super(TestLUNodeAdd, self).setUp()
......
80 82
    self.rpc.call_node_verify.return_value = \
81 83
      defaultdict(lambda: node_verify_result, {})
82 84

  
83
  def testOvsParamsButNotEnabled(self):
84
    ndparams = {
85
      constants.ND_OVS: False,
86
      constants.ND_OVS_NAME: "testswitch",
87
    }
88

  
89
    op = self.CopyOpCode(self.op_add,
90
                         ndparams=ndparams)
91

  
92
    self.ExecOpCodeExpectOpPrereqError(op, "OpenvSwitch is not enabled")
93

  
94 85
  def testOvsNoLink(self):
95 86
    ndparams = {
96 87
      constants.ND_OVS: True,
b/test/py/ganeti.utils_unittest.py
192 192
    self.assertEqual(self._fdt({"b": "True"}), {"b": True})
193 193
    self.assertEqual(self._fdt({"d": "4"}), {"d": 4})
194 194
    self.assertEqual(self._fdt({"d": "4M"}), {"d": 4})
195
    self.assertEqual(self._fdt({"e": constants.VALUE_HS_NOTHING, }), {"e":
196
                               constants.VALUE_HS_NOTHING, })
195
    self.assertEqual(self._fdt({"e": None, }), {"e": None, })
197 196
    self.assertEqual(self._fdt({"e": "Hello World", }), {"e": "Hello World", })
198 197
    self.assertEqual(self._fdt({"e": False, }), {"e": "", })
199 198
    self.assertEqual(self._fdt({"b": "hello", }, ["hello"]), {"b": "hello"})

Also available in: Unified diff