From 746b7aa60e6d574a66a29549d0e40d4c34cb0cf8 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 13 Jan 2012 15:43:37 +0100
Subject: [PATCH] Fix one bad unit-test data generation case
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

It could happen that the node is generated with 0 disk available, in
which case the operation will fail due to disk issues, not CPU. Fix
this by using the recently-introduced genOnlineNode helper.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 htools/Ganeti/HTools/QC.hs | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index 055ba17b3..231baf575 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -881,14 +881,14 @@ prop_Node_addPriFD node inst =
           inst' = setInstanceSmallerThanNode node inst
           inst'' = inst' { Instance.dsk = Instance.dsk inst }
 
-prop_Node_addPriFC node inst (Positive extra) =
-  not (Node.failN1 node) && not (Instance.instanceOffline inst) ==>
-      case Node.addPri node inst'' of
-        Types.OpFail Types.FailCPU -> True
-        _ -> False
-    where _types = (node::Node.Node, inst::Instance.Instance)
-          inst' = setInstanceSmallerThanNode node inst
-          inst'' = inst' { Instance.vcpus = Node.availCpu node + extra }
+prop_Node_addPriFC (Positive extra) =
+  forAll genOnlineNode $ \node ->
+  forAll (arbitrary `suchThat` Instance.instanceNotOffline) $ \inst ->
+  let inst' = setInstanceSmallerThanNode node inst
+      inst'' = inst' { Instance.vcpus = Node.availCpu node + extra }
+  in case Node.addPri node inst'' of
+       Types.OpFail Types.FailCPU -> property True
+       v -> failTest $ "Expected OpFail FailCPU, but got " ++ show v
 
 -- | Check that an instance add with too high memory or disk will be
 -- rejected.
-- 
GitLab