Statistics
| Branch: | Tag: | Revision:

root / test / py / ganeti.client.gnt_cluster_unittest.py @ bc57fa8d

History | View | Annotate | Download (12.1 kB)

1 66d1f035 René Nussbaumer
#!/usr/bin/python
2 66d1f035 René Nussbaumer
#
3 66d1f035 René Nussbaumer
4 66d1f035 René Nussbaumer
# Copyright (C) 2011 Google Inc.
5 66d1f035 René Nussbaumer
#
6 66d1f035 René Nussbaumer
# This program is free software; you can redistribute it and/or modify
7 66d1f035 René Nussbaumer
# it under the terms of the GNU General Public License as published by
8 66d1f035 René Nussbaumer
# the Free Software Foundation; either version 2 of the License, or
9 66d1f035 René Nussbaumer
# (at your option) any later version.
10 66d1f035 René Nussbaumer
#
11 66d1f035 René Nussbaumer
# This program is distributed in the hope that it will be useful, but
12 66d1f035 René Nussbaumer
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 66d1f035 René Nussbaumer
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 66d1f035 René Nussbaumer
# General Public License for more details.
15 66d1f035 René Nussbaumer
#
16 66d1f035 René Nussbaumer
# You should have received a copy of the GNU General Public License
17 66d1f035 René Nussbaumer
# along with this program; if not, write to the Free Software
18 66d1f035 René Nussbaumer
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 66d1f035 René Nussbaumer
# 02110-1301, USA.
20 66d1f035 René Nussbaumer
21 66d1f035 René Nussbaumer
22 66d1f035 René Nussbaumer
"""Script for testing ganeti.client.gnt_cluster"""
23 66d1f035 René Nussbaumer
24 66d1f035 René Nussbaumer
import unittest
25 1ca7b773 Michael Hanselmann
import optparse
26 66d1f035 René Nussbaumer
27 c121d42f Helga Velroyen
from ganeti import errors
28 66d1f035 René Nussbaumer
from ganeti.client import gnt_cluster
29 66d1f035 René Nussbaumer
from ganeti import utils
30 66d1f035 René Nussbaumer
from ganeti import compat
31 1ca7b773 Michael Hanselmann
from ganeti import constants
32 66d1f035 René Nussbaumer
33 c121d42f Helga Velroyen
import mock
34 66d1f035 René Nussbaumer
import testutils
35 66d1f035 René Nussbaumer
36 66d1f035 René Nussbaumer
37 1ca7b773 Michael Hanselmann
class TestEpoUtilities(unittest.TestCase):
38 66d1f035 René Nussbaumer
  def setUp(self):
39 66d1f035 René Nussbaumer
    self.nodes2ip = dict(("node%s" % i, "192.0.2.%s" % i) for i in range(1, 10))
40 66d1f035 René Nussbaumer
    self.nodes = set(self.nodes2ip.keys())
41 66d1f035 René Nussbaumer
    self.ips2node = dict((v, k) for (k, v) in self.nodes2ip.items())
42 66d1f035 René Nussbaumer
43 66d1f035 René Nussbaumer
  def _FakeAction(*args):
44 66d1f035 René Nussbaumer
    return True
45 66d1f035 René Nussbaumer
46 66d1f035 René Nussbaumer
  def _FakePing(ip, port, live_port_needed=False):
47 66d1f035 René Nussbaumer
    self.assert_(live_port_needed)
48 66d1f035 René Nussbaumer
    self.assertEqual(port, 0)
49 66d1f035 René Nussbaumer
    return True
50 66d1f035 René Nussbaumer
51 66d1f035 René Nussbaumer
  def _FakeSleep(secs):
52 66d1f035 René Nussbaumer
    self.assert_(secs >= 0 and secs <= 5)
53 66d1f035 René Nussbaumer
    return
54 66d1f035 René Nussbaumer
55 8e74adce René Nussbaumer
  def _NoopFeedback(self, text):
56 8e74adce René Nussbaumer
    return
57 8e74adce René Nussbaumer
58 66d1f035 René Nussbaumer
  def testPingFnRemoveHostsUp(self):
59 66d1f035 René Nussbaumer
    seen = set()
60 66d1f035 René Nussbaumer
    def _FakeSeenPing(ip, *args, **kwargs):
61 66d1f035 René Nussbaumer
      node = self.ips2node[ip]
62 66d1f035 René Nussbaumer
      self.assertFalse(node in seen)
63 66d1f035 René Nussbaumer
      seen.add(node)
64 66d1f035 René Nussbaumer
      return True
65 66d1f035 René Nussbaumer
66 66d1f035 René Nussbaumer
    helper = gnt_cluster._RunWhenNodesReachableHelper(self.nodes,
67 66d1f035 René Nussbaumer
                                                      self._FakeAction,
68 8e74adce René Nussbaumer
                                                      self.nodes2ip, 0,
69 8e74adce René Nussbaumer
                                                      self._NoopFeedback,
70 66d1f035 René Nussbaumer
                                                      _ping_fn=_FakeSeenPing,
71 66d1f035 René Nussbaumer
                                                      _sleep_fn=self._FakeSleep)
72 66d1f035 René Nussbaumer
73 66d1f035 René Nussbaumer
    nodes_len = len(self.nodes)
74 66d1f035 René Nussbaumer
    for (num, _) in enumerate(self.nodes):
75 66d1f035 René Nussbaumer
      helper.Wait(5)
76 66d1f035 René Nussbaumer
      if num < nodes_len - 1:
77 66d1f035 René Nussbaumer
        self.assertRaises(utils.RetryAgain, helper)
78 66d1f035 René Nussbaumer
      else:
79 66d1f035 René Nussbaumer
        helper()
80 66d1f035 René Nussbaumer
81 66d1f035 René Nussbaumer
    self.assertEqual(seen, self.nodes)
82 66d1f035 René Nussbaumer
    self.assertFalse(helper.down)
83 66d1f035 René Nussbaumer
    self.assertEqual(helper.up, self.nodes)
84 66d1f035 René Nussbaumer
85 66d1f035 René Nussbaumer
  def testActionReturnFalseSetsHelperFalse(self):
86 66d1f035 René Nussbaumer
    called = False
87 66d1f035 René Nussbaumer
    def _FalseAction(*args):
88 66d1f035 René Nussbaumer
      return called
89 66d1f035 René Nussbaumer
90 66d1f035 René Nussbaumer
    helper = gnt_cluster._RunWhenNodesReachableHelper(self.nodes, _FalseAction,
91 8e74adce René Nussbaumer
                                                      self.nodes2ip, 0,
92 8e74adce René Nussbaumer
                                                      self._NoopFeedback,
93 66d1f035 René Nussbaumer
                                                      _ping_fn=self._FakePing,
94 66d1f035 René Nussbaumer
                                                      _sleep_fn=self._FakeSleep)
95 66d1f035 René Nussbaumer
    for _ in self.nodes:
96 66d1f035 René Nussbaumer
      try:
97 66d1f035 René Nussbaumer
        helper()
98 66d1f035 René Nussbaumer
      except utils.RetryAgain:
99 66d1f035 René Nussbaumer
        called = True
100 66d1f035 René Nussbaumer
101 66d1f035 René Nussbaumer
    self.assertFalse(helper.success)
102 66d1f035 René Nussbaumer
103 66d1f035 René Nussbaumer
  def testMaybeInstanceStartup(self):
104 66d1f035 René Nussbaumer
    instances_arg = []
105 66d1f035 René Nussbaumer
    def _FakeInstanceStart(opts, instances, start):
106 66d1f035 René Nussbaumer
      instances_arg.append(set(instances))
107 66d1f035 René Nussbaumer
      return None
108 66d1f035 René Nussbaumer
109 66d1f035 René Nussbaumer
    inst_map = {
110 66d1f035 René Nussbaumer
      "inst1": set(["node1", "node2"]),
111 66d1f035 René Nussbaumer
      "inst2": set(["node1", "node3"]),
112 66d1f035 René Nussbaumer
      "inst3": set(["node2", "node1"]),
113 66d1f035 René Nussbaumer
      "inst4": set(["node2", "node1", "node3"]),
114 66d1f035 René Nussbaumer
      "inst5": set(["node4"]),
115 66d1f035 René Nussbaumer
      }
116 66d1f035 René Nussbaumer
117 66d1f035 René Nussbaumer
    fn = _FakeInstanceStart
118 66d1f035 René Nussbaumer
    self.assert_(gnt_cluster._MaybeInstanceStartup(None, inst_map, set(),
119 66d1f035 René Nussbaumer
                                                   _instance_start_fn=fn))
120 66d1f035 René Nussbaumer
    self.assertFalse(instances_arg)
121 66d1f035 René Nussbaumer
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map, set(["node1"]),
122 66d1f035 René Nussbaumer
                                               _instance_start_fn=fn)
123 66d1f035 René Nussbaumer
    self.assert_(result)
124 66d1f035 René Nussbaumer
    self.assertFalse(instances_arg)
125 66d1f035 René Nussbaumer
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
126 66d1f035 René Nussbaumer
                                               set(["node1", "node3"]),
127 66d1f035 René Nussbaumer
                                               _instance_start_fn=fn)
128 66d1f035 René Nussbaumer
    self.assert_(result is None)
129 66d1f035 René Nussbaumer
    self.assertEqual(instances_arg.pop(0), set(["inst2"]))
130 66d1f035 René Nussbaumer
    self.assertFalse("inst2" in inst_map)
131 66d1f035 René Nussbaumer
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
132 66d1f035 René Nussbaumer
                                               set(["node1", "node3"]),
133 66d1f035 René Nussbaumer
                                               _instance_start_fn=fn)
134 66d1f035 René Nussbaumer
    self.assert_(result)
135 66d1f035 René Nussbaumer
    self.assertFalse(instances_arg)
136 66d1f035 René Nussbaumer
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
137 66d1f035 René Nussbaumer
                                               set(["node1", "node3", "node2"]),
138 66d1f035 René Nussbaumer
                                               _instance_start_fn=fn)
139 66d1f035 René Nussbaumer
    self.assertEqual(instances_arg.pop(0), set(["inst1", "inst3", "inst4"]))
140 66d1f035 René Nussbaumer
    self.assert_(result is None)
141 66d1f035 René Nussbaumer
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
142 66d1f035 René Nussbaumer
                                               set(["node1", "node3", "node2",
143 66d1f035 René Nussbaumer
                                                    "node4"]),
144 66d1f035 René Nussbaumer
                                               _instance_start_fn=fn)
145 66d1f035 René Nussbaumer
    self.assert_(result is None)
146 66d1f035 René Nussbaumer
    self.assertEqual(instances_arg.pop(0), set(["inst5"]))
147 66d1f035 René Nussbaumer
    self.assertFalse(inst_map)
148 66d1f035 René Nussbaumer
149 66d1f035 René Nussbaumer
150 1ca7b773 Michael Hanselmann
class _ClientForEpo:
151 1ca7b773 Michael Hanselmann
  def __init__(self, groups, nodes):
152 1ca7b773 Michael Hanselmann
    self._groups = groups
153 1ca7b773 Michael Hanselmann
    self._nodes = nodes
154 1ca7b773 Michael Hanselmann
155 1ca7b773 Michael Hanselmann
  def QueryGroups(self, names, fields, use_locking):
156 1ca7b773 Michael Hanselmann
    assert not use_locking
157 1ca7b773 Michael Hanselmann
    assert fields == ["node_list"]
158 1ca7b773 Michael Hanselmann
    return self._groups
159 1ca7b773 Michael Hanselmann
160 1ca7b773 Michael Hanselmann
  def QueryNodes(self, names, fields, use_locking):
161 1ca7b773 Michael Hanselmann
    assert not use_locking
162 1ca7b773 Michael Hanselmann
    assert fields == ["name", "master", "pinst_list", "sinst_list", "powered",
163 1ca7b773 Michael Hanselmann
                      "offline"]
164 1ca7b773 Michael Hanselmann
    return self._nodes
165 1ca7b773 Michael Hanselmann
166 1ca7b773 Michael Hanselmann
167 1ca7b773 Michael Hanselmann
class TestEpo(unittest.TestCase):
168 1ca7b773 Michael Hanselmann
  _ON_EXITCODE = 253
169 1ca7b773 Michael Hanselmann
  _OFF_EXITCODE = 254
170 1ca7b773 Michael Hanselmann
171 1ca7b773 Michael Hanselmann
  def _ConfirmForce(self, *args):
172 1ca7b773 Michael Hanselmann
    self.fail("Shouldn't need confirmation")
173 1ca7b773 Michael Hanselmann
174 1ca7b773 Michael Hanselmann
  def _Confirm(self, exp_names, result, names, ltype, text):
175 1ca7b773 Michael Hanselmann
    self.assertEqual(names, exp_names)
176 1ca7b773 Michael Hanselmann
    self.assertFalse(result is NotImplemented)
177 1ca7b773 Michael Hanselmann
    return result
178 1ca7b773 Michael Hanselmann
179 1ca7b773 Michael Hanselmann
  def _Off(self, exp_node_list, opts, node_list, inst_map):
180 1ca7b773 Michael Hanselmann
    self.assertEqual(node_list, exp_node_list)
181 1ca7b773 Michael Hanselmann
    self.assertFalse(inst_map)
182 1ca7b773 Michael Hanselmann
    return self._OFF_EXITCODE
183 1ca7b773 Michael Hanselmann
184 1ca7b773 Michael Hanselmann
  def _Test(self, *args, **kwargs):
185 1ca7b773 Michael Hanselmann
    defaults = dict(cl=NotImplemented, _on_fn=NotImplemented,
186 1ca7b773 Michael Hanselmann
                    _off_fn=NotImplemented,
187 1ca7b773 Michael Hanselmann
                    _stdout_fn=lambda *args: None,
188 1ca7b773 Michael Hanselmann
                    _stderr_fn=lambda *args: None)
189 1ca7b773 Michael Hanselmann
    defaults.update(kwargs)
190 1ca7b773 Michael Hanselmann
    return gnt_cluster.Epo(*args, **defaults)
191 1ca7b773 Michael Hanselmann
192 1ca7b773 Michael Hanselmann
  def testShowAllWithGroups(self):
193 1ca7b773 Michael Hanselmann
    opts = optparse.Values(dict(groups=True, show_all=True))
194 1ca7b773 Michael Hanselmann
    result = self._Test(opts, NotImplemented)
195 1ca7b773 Michael Hanselmann
    self.assertEqual(result, constants.EXIT_FAILURE)
196 1ca7b773 Michael Hanselmann
197 1ca7b773 Michael Hanselmann
  def testShowAllWithArgs(self):
198 1ca7b773 Michael Hanselmann
    opts = optparse.Values(dict(groups=False, show_all=True))
199 1ca7b773 Michael Hanselmann
    result = self._Test(opts, ["a", "b", "c"])
200 1ca7b773 Michael Hanselmann
    self.assertEqual(result, constants.EXIT_FAILURE)
201 1ca7b773 Michael Hanselmann
202 1ca7b773 Michael Hanselmann
  def testNoArgumentsNoParameters(self):
203 1ca7b773 Michael Hanselmann
    for (force, confirm_result) in [(True, NotImplemented), (False, False),
204 1ca7b773 Michael Hanselmann
                                    (False, True)]:
205 1ca7b773 Michael Hanselmann
      opts = optparse.Values(dict(groups=False, show_all=False, force=force,
206 1ca7b773 Michael Hanselmann
                                  on=False))
207 1ca7b773 Michael Hanselmann
      client = _ClientForEpo(NotImplemented, [
208 1ca7b773 Michael Hanselmann
        ("node1.example.com", False, [], [], True, False),
209 1ca7b773 Michael Hanselmann
        ])
210 1ca7b773 Michael Hanselmann
211 1ca7b773 Michael Hanselmann
      if force:
212 1ca7b773 Michael Hanselmann
        confirm_fn = self._ConfirmForce
213 1ca7b773 Michael Hanselmann
      else:
214 1ca7b773 Michael Hanselmann
        confirm_fn = compat.partial(self._Confirm, ["node1.example.com"],
215 1ca7b773 Michael Hanselmann
                                    confirm_result)
216 1ca7b773 Michael Hanselmann
217 1ca7b773 Michael Hanselmann
      off_fn = compat.partial(self._Off, ["node1.example.com"])
218 1ca7b773 Michael Hanselmann
219 bc57fa8d Helga Velroyen
      result = self._Test(opts, [], cl=client, qcl=client, _off_fn=off_fn,
220 1ca7b773 Michael Hanselmann
                          _confirm_fn=confirm_fn)
221 1ca7b773 Michael Hanselmann
      if force or confirm_result:
222 1ca7b773 Michael Hanselmann
        self.assertEqual(result, self._OFF_EXITCODE)
223 1ca7b773 Michael Hanselmann
      else:
224 1ca7b773 Michael Hanselmann
        self.assertEqual(result, constants.EXIT_FAILURE)
225 1ca7b773 Michael Hanselmann
226 1ca7b773 Michael Hanselmann
  def testPowerOn(self):
227 1ca7b773 Michael Hanselmann
    for master in [False, True]:
228 1ca7b773 Michael Hanselmann
      opts = optparse.Values(dict(groups=False, show_all=True,
229 1ca7b773 Michael Hanselmann
                                  force=True, on=True))
230 1ca7b773 Michael Hanselmann
      client = _ClientForEpo(NotImplemented, [
231 1ca7b773 Michael Hanselmann
        ("node1.example.com", False, [], [], True, False),
232 1ca7b773 Michael Hanselmann
        ("node2.example.com", False, [], [], False, False),
233 1ca7b773 Michael Hanselmann
        ("node3.example.com", False, [], [], True, True),
234 1ca7b773 Michael Hanselmann
        ("node4.example.com", False, [], [], None, True),
235 1ca7b773 Michael Hanselmann
        ("node5.example.com", master, [], [], False, False),
236 1ca7b773 Michael Hanselmann
        ])
237 1ca7b773 Michael Hanselmann
238 1ca7b773 Michael Hanselmann
      def _On(_, all_nodes, node_list, inst_map):
239 1ca7b773 Michael Hanselmann
        self.assertEqual(all_nodes,
240 1ca7b773 Michael Hanselmann
                         ["node%s.example.com" % i for i in range(1, 6)])
241 1ca7b773 Michael Hanselmann
        if master:
242 1ca7b773 Michael Hanselmann
          self.assertEqual(node_list, ["node2.example.com"])
243 1ca7b773 Michael Hanselmann
        else:
244 1ca7b773 Michael Hanselmann
          self.assertEqual(node_list, ["node2.example.com",
245 1ca7b773 Michael Hanselmann
                                       "node5.example.com"])
246 1ca7b773 Michael Hanselmann
        self.assertFalse(inst_map)
247 1ca7b773 Michael Hanselmann
        return self._ON_EXITCODE
248 1ca7b773 Michael Hanselmann
249 bc57fa8d Helga Velroyen
      result = self._Test(opts, [], cl=client, qcl=client, _on_fn=_On,
250 1ca7b773 Michael Hanselmann
                          _confirm_fn=self._ConfirmForce)
251 1ca7b773 Michael Hanselmann
      self.assertEqual(result, self._ON_EXITCODE)
252 1ca7b773 Michael Hanselmann
253 1ca7b773 Michael Hanselmann
  def testMasterWithoutShowAll(self):
254 1ca7b773 Michael Hanselmann
    opts = optparse.Values(dict(groups=False, show_all=False,
255 1ca7b773 Michael Hanselmann
                                force=True, on=False))
256 1ca7b773 Michael Hanselmann
    client = _ClientForEpo(NotImplemented, [
257 1ca7b773 Michael Hanselmann
      ("node1.example.com", True, [], [], True, False),
258 1ca7b773 Michael Hanselmann
      ])
259 bc57fa8d Helga Velroyen
    result = self._Test(opts, [], cl=client, qcl=client,
260 bc57fa8d Helga Velroyen
                        _confirm_fn=self._ConfirmForce)
261 1ca7b773 Michael Hanselmann
    self.assertEqual(result, constants.EXIT_FAILURE)
262 1ca7b773 Michael Hanselmann
263 1ca7b773 Michael Hanselmann
264 31ccfc0e Helga Velroyen
class DrbdHelperTestCase(unittest.TestCase):
265 c121d42f Helga Velroyen
266 7796e1f8 Helga Velroyen
  def setUp(self):
267 7796e1f8 Helga Velroyen
    unittest.TestCase.setUp(self)
268 7796e1f8 Helga Velroyen
    self.enabled_disk_templates = []
269 7796e1f8 Helga Velroyen
270 7796e1f8 Helga Velroyen
  def enableDrbd(self):
271 7796e1f8 Helga Velroyen
    self.enabled_disk_templates = [constants.DT_DRBD8]
272 7796e1f8 Helga Velroyen
273 7796e1f8 Helga Velroyen
  def disableDrbd(self):
274 7796e1f8 Helga Velroyen
    self.enabled_disk_templates = [constants.DT_DISKLESS]
275 7796e1f8 Helga Velroyen
276 31ccfc0e Helga Velroyen
277 31ccfc0e Helga Velroyen
class InitDrbdHelper(DrbdHelperTestCase):
278 31ccfc0e Helga Velroyen
279 c121d42f Helga Velroyen
  def testNoDrbdNoHelper(self):
280 c121d42f Helga Velroyen
    opts = mock.Mock()
281 c121d42f Helga Velroyen
    opts.drbd_helper = None
282 7796e1f8 Helga Velroyen
    self.disableDrbd()
283 7796e1f8 Helga Velroyen
    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
284 c121d42f Helga Velroyen
    self.assertEquals(None, helper)
285 c121d42f Helga Velroyen
286 c121d42f Helga Velroyen
  def testNoDrbdHelper(self):
287 c121d42f Helga Velroyen
    opts = mock.Mock()
288 7796e1f8 Helga Velroyen
    self.disableDrbd()
289 c121d42f Helga Velroyen
    opts.drbd_helper = "/bin/true"
290 38969795 Helga Velroyen
    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
291 38969795 Helga Velroyen
    self.assertEquals(opts.drbd_helper, helper)
292 c121d42f Helga Velroyen
293 7796e1f8 Helga Velroyen
  def testDrbdHelperNone(self):
294 c121d42f Helga Velroyen
    opts = mock.Mock()
295 7796e1f8 Helga Velroyen
    self.enableDrbd()
296 c121d42f Helga Velroyen
    opts.drbd_helper = None
297 7796e1f8 Helga Velroyen
    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
298 c121d42f Helga Velroyen
    self.assertEquals(constants.DEFAULT_DRBD_HELPER, helper)
299 c121d42f Helga Velroyen
300 7796e1f8 Helga Velroyen
  def testDrbdHelperEmpty(self):
301 7796e1f8 Helga Velroyen
    opts = mock.Mock()
302 7796e1f8 Helga Velroyen
    self.enableDrbd()
303 7796e1f8 Helga Velroyen
    opts.drbd_helper = ''
304 7796e1f8 Helga Velroyen
    self.assertRaises(errors.OpPrereqError, gnt_cluster._InitDrbdHelper, opts,
305 7796e1f8 Helga Velroyen
        self.enabled_disk_templates)
306 7796e1f8 Helga Velroyen
307 c121d42f Helga Velroyen
  def testDrbdHelper(self):
308 c121d42f Helga Velroyen
    opts = mock.Mock()
309 7796e1f8 Helga Velroyen
    self.enableDrbd()
310 c121d42f Helga Velroyen
    opts.drbd_helper = "/bin/true"
311 7796e1f8 Helga Velroyen
    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
312 c121d42f Helga Velroyen
    self.assertEquals(opts.drbd_helper, helper)
313 c121d42f Helga Velroyen
314 c121d42f Helga Velroyen
315 31ccfc0e Helga Velroyen
class GetDrbdHelper(DrbdHelperTestCase):
316 c121d42f Helga Velroyen
317 c121d42f Helga Velroyen
  def testNoDrbdNoHelper(self):
318 c121d42f Helga Velroyen
    opts = mock.Mock()
319 31ccfc0e Helga Velroyen
    self.disableDrbd()
320 31ccfc0e Helga Velroyen
    opts.drbd_helper = None
321 31ccfc0e Helga Velroyen
    helper = gnt_cluster._GetDrbdHelper(opts, self.enabled_disk_templates)
322 31ccfc0e Helga Velroyen
    self.assertEquals(None, helper)
323 31ccfc0e Helga Velroyen
324 31ccfc0e Helga Velroyen
  def testNoTemplateInfoNoHelper(self):
325 31ccfc0e Helga Velroyen
    opts = mock.Mock()
326 c121d42f Helga Velroyen
    opts.drbd_helper = None
327 31ccfc0e Helga Velroyen
    helper = gnt_cluster._GetDrbdHelper(opts, None)
328 31ccfc0e Helga Velroyen
    self.assertEquals(None, helper)
329 31ccfc0e Helga Velroyen
330 31ccfc0e Helga Velroyen
  def testNoTemplateInfoHelper(self):
331 31ccfc0e Helga Velroyen
    opts = mock.Mock()
332 31ccfc0e Helga Velroyen
    opts.drbd_helper = "/bin/true"
333 31ccfc0e Helga Velroyen
    helper = gnt_cluster._GetDrbdHelper(opts, None)
334 31ccfc0e Helga Velroyen
    self.assertEquals(opts.drbd_helper, helper)
335 c121d42f Helga Velroyen
336 c121d42f Helga Velroyen
  def testNoDrbdHelper(self):
337 c121d42f Helga Velroyen
    opts = mock.Mock()
338 31ccfc0e Helga Velroyen
    self.disableDrbd()
339 c121d42f Helga Velroyen
    opts.drbd_helper = "/bin/true"
340 38969795 Helga Velroyen
    helper = gnt_cluster._GetDrbdHelper(opts, None)
341 38969795 Helga Velroyen
    self.assertEquals(opts.drbd_helper, helper)
342 c121d42f Helga Velroyen
343 c121d42f Helga Velroyen
  def testDrbdNoHelper(self):
344 c121d42f Helga Velroyen
    opts = mock.Mock()
345 31ccfc0e Helga Velroyen
    self.enableDrbd()
346 c121d42f Helga Velroyen
    opts.drbd_helper = None
347 31ccfc0e Helga Velroyen
    helper = gnt_cluster._GetDrbdHelper(opts, self.enabled_disk_templates)
348 c121d42f Helga Velroyen
    self.assertEquals(None, helper)
349 c121d42f Helga Velroyen
350 c121d42f Helga Velroyen
  def testDrbdHelper(self):
351 c121d42f Helga Velroyen
    opts = mock.Mock()
352 31ccfc0e Helga Velroyen
    self.enableDrbd()
353 c121d42f Helga Velroyen
    opts.drbd_helper = "/bin/true"
354 31ccfc0e Helga Velroyen
    helper = gnt_cluster._GetDrbdHelper(opts, self.enabled_disk_templates)
355 c121d42f Helga Velroyen
    self.assertEquals(opts.drbd_helper, helper)
356 c121d42f Helga Velroyen
357 c121d42f Helga Velroyen
358 66d1f035 René Nussbaumer
if __name__ == "__main__":
359 66d1f035 René Nussbaumer
  testutils.GanetiTestProgram()