From 3c049cd3e3676ff3ff60fcef547e3c688bda3ddb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com>
Date: Thu, 6 Sep 2012 16:18:05 +0200
Subject: [PATCH] Adapt gnt-debug iallocator
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add the new multi-alloc request to the test allocation framework. For
now we just create --count identical instances. This might need further
improvements later.

Signed-off-by: RenΓ© Nussbaumer <rn@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/client/gnt_debug.py |  5 ++++-
 lib/cmdlib.py           | 17 ++++++++++++++++-
 lib/opcodes.py          |  1 +
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/lib/client/gnt_debug.py b/lib/client/gnt_debug.py
index f7acc7405..ebc6af10f 100644
--- a/lib/client/gnt_debug.py
+++ b/lib/client/gnt_debug.py
@@ -175,7 +175,8 @@ def TestAllocator(opts, args):
                                allocator=opts.iallocator,
                                evac_mode=opts.evac_mode,
                                target_groups=target_groups,
-                               spindle_use=opts.spindle_use)
+                               spindle_use=opts.spindle_use,
+                               count=opts.count)
   result = SubmitOpCode(op, opts=opts)
   ToStdout("%s" % result)
   return 0
@@ -676,6 +677,8 @@ commands = {
                 default=[], action="append"),
      cli_option("--spindle-use", help="How many spindles to use",
                 default=1, type="int"),
+     cli_option("--count", help="How many instances to allocate",
+                default=2, type="int"),
      DRY_RUN_OPT, PRIORITY_OPT,
      ],
     "{opts...} <instance>", "Executes a TestAllocator OpCode"),
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 856d28317..606bfd60f 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -14824,7 +14824,8 @@ class LUTestAllocator(NoHooksLU):
     This checks the opcode parameters depending on the director and mode test.
 
     """
-    if self.op.mode == constants.IALLOCATOR_MODE_ALLOC:
+    if self.op.mode in (constants.IALLOCATOR_MODE_ALLOC,
+                        constants.IALLOCATOR_MODE_MULTI_ALLOC):
       for attr in ["memory", "disks", "disk_template",
                    "os", "tags", "nics", "vcpus"]:
         if not hasattr(self.op, attr):
@@ -14896,6 +14897,20 @@ class LUTestAllocator(NoHooksLU):
     elif self.op.mode == constants.IALLOCATOR_MODE_NODE_EVAC:
       req = iallocator.IAReqNodeEvac(instances=self.op.instances,
                                      evac_mode=self.op.evac_mode)
+    elif self.op.mode == constants.IALLOCATOR_MODE_MULTI_ALLOC:
+      disk_template = self.op.disk_template
+      insts = [iallocator.IAReqInstanceAlloc(name="%s%s" % (self.op.name, idx),
+                                             memory=self.op.memory,
+                                             disks=self.op.disks,
+                                             disk_template=disk_template,
+                                             os=self.op.os,
+                                             tags=self.op.tags,
+                                             nics=self.op.nics,
+                                             vcpus=self.op.vcpus,
+                                             spindle_use=self.op.spindle_use,
+                                             hypervisor=self.op.hypervisor)
+               for idx in range(self.op.count)]
+      req = iallocator.IAReqMultiInstanceAlloc(instances=insts)
     else:
       raise errors.ProgrammerError("Uncatched mode %s in"
                                    " LUTestAllocator.Exec", self.op.mode)
diff --git a/lib/opcodes.py b/lib/opcodes.py
index 9c2bbcd1f..e4ad078e2 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -1839,6 +1839,7 @@ class OpTestAllocator(OpCode):
      ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
     ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
     ("spindle_use", 1, ht.TPositiveInt, None),
+    ("count", 1, ht.TPositiveInt, None),
     ]
 
 
-- 
GitLab