Exemple #1
0
    def testMaybeInstanceStartup(self):
        instances_arg = []

        def _FakeInstanceStart(opts, instances, start):
            instances_arg.append(set(instances))
            return None

        inst_map = {
            "inst1": set(["node1", "node2"]),
            "inst2": set(["node1", "node3"]),
            "inst3": set(["node2", "node1"]),
            "inst4": set(["node2", "node1", "node3"]),
            "inst5": set(["node4"]),
        }

        fn = _FakeInstanceStart
        self.assertTrue(
            gnt_cluster._MaybeInstanceStartup(None,
                                              inst_map,
                                              set(),
                                              _instance_start_fn=fn))
        self.assertFalse(instances_arg)
        result = gnt_cluster._MaybeInstanceStartup(None,
                                                   inst_map,
                                                   set(["node1"]),
                                                   _instance_start_fn=fn)
        self.assertTrue(result)
        self.assertFalse(instances_arg)
        result = gnt_cluster._MaybeInstanceStartup(None,
                                                   inst_map,
                                                   set(["node1", "node3"]),
                                                   _instance_start_fn=fn)
        self.assertTrue(result is None)
        self.assertEqual(instances_arg.pop(0), set(["inst2"]))
        self.assertFalse("inst2" in inst_map)
        result = gnt_cluster._MaybeInstanceStartup(None,
                                                   inst_map,
                                                   set(["node1", "node3"]),
                                                   _instance_start_fn=fn)
        self.assertTrue(result)
        self.assertFalse(instances_arg)
        result = gnt_cluster._MaybeInstanceStartup(
            None,
            inst_map,
            set(["node1", "node3", "node2"]),
            _instance_start_fn=fn)
        self.assertEqual(instances_arg.pop(0), set(["inst1", "inst3",
                                                    "inst4"]))
        self.assertTrue(result is None)
        result = gnt_cluster._MaybeInstanceStartup(
            None,
            inst_map,
            set(["node1", "node3", "node2", "node4"]),
            _instance_start_fn=fn)
        self.assertTrue(result is None)
        self.assertEqual(instances_arg.pop(0), set(["inst5"]))
        self.assertFalse(inst_map)
  def testMaybeInstanceStartup(self):
    instances_arg = []
    def _FakeInstanceStart(opts, instances, start):
      instances_arg.append(set(instances))
      return None

    inst_map = {
      "inst1": set(["node1", "node2"]),
      "inst2": set(["node1", "node3"]),
      "inst3": set(["node2", "node1"]),
      "inst4": set(["node2", "node1", "node3"]),
      "inst5": set(["node4"]),
      }

    fn = _FakeInstanceStart
    self.assert_(gnt_cluster._MaybeInstanceStartup(None, inst_map, set(),
                                                   _instance_start_fn=fn))
    self.assertFalse(instances_arg)
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map, set(["node1"]),
                                               _instance_start_fn=fn)
    self.assert_(result)
    self.assertFalse(instances_arg)
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
                                               set(["node1", "node3"]),
                                               _instance_start_fn=fn)
    self.assert_(result is None)
    self.assertEqual(instances_arg.pop(0), set(["inst2"]))
    self.assertFalse("inst2" in inst_map)
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
                                               set(["node1", "node3"]),
                                               _instance_start_fn=fn)
    self.assert_(result)
    self.assertFalse(instances_arg)
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
                                               set(["node1", "node3", "node2"]),
                                               _instance_start_fn=fn)
    self.assertEqual(instances_arg.pop(0), set(["inst1", "inst3", "inst4"]))
    self.assert_(result is None)
    result = gnt_cluster._MaybeInstanceStartup(None, inst_map,
                                               set(["node1", "node3", "node2",
                                                    "node4"]),
                                               _instance_start_fn=fn)
    self.assert_(result is None)
    self.assertEqual(instances_arg.pop(0), set(["inst5"]))
    self.assertFalse(inst_map)