From 518a45e5d8f8c85d7cd9fd782058f3f6a5b0fba6 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 4 Dec 2012 16:17:05 +0100
Subject: [PATCH] Add error code for temporary lack of resources

When an instance creation uses opportunistic locks, the iallocator might
not be able to find an allocation solution if not enough node locks (or
a suboptimal subset thereof) were acquired. As per the design document
<doc/design-opportunistic-locking.rst> a new error code denoting
temporary failures is added.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/cmdlib.py | 9 ++++++++-
 lib/errors.py | 4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 3aed19022..d29631aea 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -9957,10 +9957,17 @@ class LUInstanceCreate(LogicalUnit):
     ial.Run(self.op.iallocator)
 
     if not ial.success:
+      # When opportunistic locks are used only a temporary failure is generated
+      if self.op.opportunistic_locking:
+        ecode = errors.ECODE_TEMP_NORES
+      else:
+        ecode = errors.ECODE_NORES
+
       raise errors.OpPrereqError("Can't compute nodes using"
                                  " iallocator '%s': %s" %
                                  (self.op.iallocator, ial.info),
-                                 errors.ECODE_NORES)
+                                 ecode)
+
     self.op.pnode = ial.result[0]
     self.LogInfo("Selected nodes for instance %s via iallocator %s: %s",
                  self.op.instance_name, self.op.iallocator,
diff --git a/lib/errors.py b/lib/errors.py
index 3d2a33d51..7fc3efed3 100644
--- a/lib/errors.py
+++ b/lib/errors.py
@@ -30,6 +30,9 @@ ECODE_RESOLVER = "resolver_error"
 #: Not enough resources (iallocator failure, disk space, memory, etc.)
 ECODE_NORES = "insufficient_resources"
 
+#: Temporarily out of resources; operation can be tried again
+ECODE_TEMP_NORES = "insufficient_resources"
+
 #: Wrong arguments (at syntax level)
 ECODE_INVAL = "wrong_input"
 
@@ -55,6 +58,7 @@ ECODE_ENVIRON = "environment_error"
 ECODE_ALL = frozenset([
   ECODE_RESOLVER,
   ECODE_NORES,
+  ECODE_TEMP_NORES,
   ECODE_INVAL,
   ECODE_STATE,
   ECODE_NOENT,
-- 
GitLab