Revision 64c7b383 test/ganeti.cmdlib_unittest.py

b/test/ganeti.cmdlib_unittest.py
27 27
import time
28 28
import tempfile
29 29
import shutil
30
import operator
30 31

  
31 32
from ganeti import constants
32 33
from ganeti import mcpu
......
207 208
    self.assertEqual(set(["inst3c"]), set(prev))
208 209

  
209 210

  
211
class TestClusterVerifySsh(unittest.TestCase):
212
  def testMultipleGroups(self):
213
    fn = cmdlib.LUClusterVerifyGroup._SelectSshCheckNodes
214
    mygroupnodes = [
215
      objects.Node(name="node20", group="my", offline=False),
216
      objects.Node(name="node21", group="my", offline=False),
217
      objects.Node(name="node22", group="my", offline=False),
218
      objects.Node(name="node23", group="my", offline=False),
219
      objects.Node(name="node24", group="my", offline=False),
220
      objects.Node(name="node25", group="my", offline=False),
221
      objects.Node(name="node26", group="my", offline=True),
222
      ]
223
    nodes = [
224
      objects.Node(name="node1", group="g1", offline=True),
225
      objects.Node(name="node2", group="g1", offline=False),
226
      objects.Node(name="node3", group="g1", offline=False),
227
      objects.Node(name="node4", group="g1", offline=True),
228
      objects.Node(name="node5", group="g1", offline=False),
229
      objects.Node(name="node10", group="xyz", offline=False),
230
      objects.Node(name="node11", group="xyz", offline=False),
231
      objects.Node(name="node40", group="alloff", offline=True),
232
      objects.Node(name="node41", group="alloff", offline=True),
233
      objects.Node(name="node50", group="aaa", offline=False),
234
      ] + mygroupnodes
235
    assert not utils.FindDuplicates(map(operator.attrgetter("name"), nodes))
236

  
237
    (online, perhost) = fn(mygroupnodes, "my", nodes)
238
    self.assertEqual(online, ["node%s" % i for i in range(20, 26)])
239
    self.assertEqual(set(perhost.keys()), set(online))
240

  
241
    self.assertEqual(perhost, {
242
      "node20": ["node10", "node2", "node50"],
243
      "node21": ["node11", "node3", "node50"],
244
      "node22": ["node10", "node5", "node50"],
245
      "node23": ["node11", "node2", "node50"],
246
      "node24": ["node10", "node3", "node50"],
247
      "node25": ["node11", "node5", "node50"],
248
      })
249

  
250
  def testSingleGroup(self):
251
    fn = cmdlib.LUClusterVerifyGroup._SelectSshCheckNodes
252
    nodes = [
253
      objects.Node(name="node1", group="default", offline=True),
254
      objects.Node(name="node2", group="default", offline=False),
255
      objects.Node(name="node3", group="default", offline=False),
256
      objects.Node(name="node4", group="default", offline=True),
257
      ]
258
    assert not utils.FindDuplicates(map(operator.attrgetter("name"), nodes))
259

  
260
    (online, perhost) = fn(nodes, "default", nodes)
261
    self.assertEqual(online, ["node2", "node3"])
262
    self.assertEqual(set(perhost.keys()), set(online))
263

  
264
    self.assertEqual(perhost, {
265
      "node2": [],
266
      "node3": [],
267
      })
268

  
269

  
210 270
if __name__ == "__main__":
211 271
  testutils.GanetiTestProgram()

Also available in: Unified diff