On Fri, Sep 25, 2015 at 06:18:45PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
Most failure modes in allocating an instance indicate a lack
of some resource, and we want to know which resource we're running
short of. In this case, shrinking the instance to be allocated
on this resource might solve the problem.

However, there is one case that is qualitatively different: an
allocation might not be possible if the instance is smaller than
the minimal requirement set by the policy. Create a new failure
mode for this case. Besides beeing more informative, we also
ensure that all components of the failure statistics are monotone
(either increasing or decreasing) with the instance size.

Signed-off-by: Klaus Aehlig <[email protected]>
---
src/Ganeti/HTools/Instance.hs       |  4 +++-
src/Ganeti/HTools/Types.hs          |  2 ++
test/hs/shelltests/htools-hail.test | 12 ++++++------
3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/Ganeti/HTools/Instance.hs b/src/Ganeti/HTools/Instance.hs
index 63b3024..33e40be 100644
--- a/src/Ganeti/HTools/Instance.hs
+++ b/src/Ganeti/HTools/Instance.hs
@@ -338,7 +338,9 @@ instBelowISpec = instCompareISpec GT

-- | Checks if an instance is bigger than a given spec.
instAboveISpec :: Instance -> T.ISpec -> Bool -> T.OpResult ()
-instAboveISpec = instCompareISpec LT
+instAboveISpec inst spec exclstore =
+  genericResult (const $ Bad T.FailTooSmall) Ok
+  $ instCompareISpec LT inst spec exclstore

-- | Checks if an instance matches a min/max specs pair
instMatchesMinMaxSpecs :: Instance -> T.MinMaxISpecs -> Bool -> T.OpResult ()
diff --git a/src/Ganeti/HTools/Types.hs b/src/Ganeti/HTools/Types.hs
index 5b395b7..c8881a9 100644
--- a/src/Ganeti/HTools/Types.hs
+++ b/src/Ganeti/HTools/Types.hs
@@ -358,6 +358,8 @@ data FailMode = FailMem  -- ^ Failed due to not enough RAM
              | FailDisk -- ^ Failed due to not enough disk
              | FailCPU  -- ^ Failed due to not enough CPU capacity
              | FailN1   -- ^ Failed due to not passing N1 checks
+              | FailTooSmall -- ^ Failed due to the instance being smaller
+                             -- than allowed
              | FailTags -- ^ Failed due to tag exclusion
              | FailMig  -- ^ Failed due to migration restrictions
              | FailDiskCount -- ^ Failed due to wrong number of disks
diff --git a/test/hs/shelltests/htools-hail.test 
b/test/hs/shelltests/htools-hail.test
index 9402a34..c1dccaa 100644
--- a/test/hs/shelltests/htools-hail.test
+++ b/test/hs/shelltests/htools-hail.test
@@ -44,7 +44,7 @@ echo '{"request": 0}' | ./test/hs/hail -
>>>= 0

./test/hs/hail $TESTDATA_DIR/hail-alloc-invalid-twodisks.json
->>> /"success":false,.*FailDisk: 1/
+>>> /"success":false,.*FailTooSmall: 1/
>>>= 0

# check that hail honors network requirements
@@ -84,12 +84,12 @@ cat $TESTDATA_DIR/hail-alloc-invalid-network.json | grep -v -e 
'"network":"uuid-
>>>= 0

./test/hs/hail $T/hail-alloc-invalid-twodisks.json.excl-stor
->>> /"success":false,.*FailDisk: 1"/
+>>> /"success":false,.*FailTooSmall: 1"/
>>>= 0

# Same tests with exclusive storage enabled, but no spindles info in instances
./test/hs/hail $T/hail-alloc-drbd.json.fail-excl-stor
->>> /"success":false,.*FailSpindles: 12"/
+>>> /"success":false,.*FailTooSmall: 12"/
>>>= 0

./test/hs/hail $T/hail-reloc-drbd.json.fail-excl-stor
@@ -101,11 +101,11 @@ cat $TESTDATA_DIR/hail-alloc-invalid-network.json | grep -v -e 
'"network":"uuid-
>>>= 0

./test/hs/hail $T/hail-change-group.json.fail-excl-stor
->>> /"success":true,"info":"Request successful: 1 instances failed to move and 0 were 
moved successfully",.*FailSpindles: 2"/
+>>> /"success":true,"info":"Request successful: 1 instances failed to move and 0 were 
moved successfully",.*FailTooSmall: 2"/
>>>= 0

./test/hs/hail $T/hail-alloc-twodisks.json.fail-excl-stor
->>> /"success":false,.*FailSpindles: 1"/
+>>> /"success":false,.*FailTooSmall: 1"/
>>>= 0

# check that hail can use the simu backend
@@ -160,7 +160,7 @@ cat $TESTDATA_DIR/hail-alloc-invalid-network.json | grep -v -e 
'"network":"uuid-
>>>= 0

./test/hs/hail $T/hail-alloc-spindles.json.excl-stor
->>> /"success":true,"info":"Request successful: Selected group: group1,.*FailSpindles: 
2",.*"result":\["node1"\]/
+>>> /"success":true,"info":"Request successful: Selected group: group1,.*FailTooSmall: 
2",.*"result":\["node1"\]/
>>>= 0

# Check that --ignore-soft-errors works and ignores tag errors
--
2.6.0.rc2.230.g3dd15c0


LGTM, thanks

Reply via email to