This makes the "all" names queries consistent with the Python
results. The change requires updating the unittests, at which point a
duplicate error message is simplified.

Signed-off-by: Iustin Pop <[email protected]>
---
 htest/Test/Ganeti/Query/Filter.hs |    9 +++++----
 htools/Ganeti/Query/Query.hs      |    6 ++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/htest/Test/Ganeti/Query/Filter.hs 
b/htest/Test/Ganeti/Query/Filter.hs
index 1e99297..6bb0c2c 100644
--- a/htest/Test/Ganeti/Query/Filter.hs
+++ b/htest/Test/Ganeti/Query/Filter.hs
@@ -44,6 +44,7 @@ import Ganeti.JSON
 import Ganeti.Objects
 import Ganeti.Query.Language
 import Ganeti.Query.Query
+import Ganeti.Utils (niceSort)
 
 -- * Helpers
 
@@ -76,7 +77,7 @@ prop_node_single_filter :: Property
 prop_node_single_filter =
   forAll (choose (1, maxNodes)) $ \numnodes ->
   forAll (genEmptyCluster numnodes) $ \cfg ->
-  let allnodes = Map.keys . fromContainer $ configNodes cfg in
+  let allnodes = niceSort . Map.keys . fromContainer $ configNodes cfg in
   forAll (elements allnodes) $ \nname ->
   let fvalue = QuotedString nname
       buildflt n = n "name" fvalue
@@ -102,7 +103,7 @@ prop_node_many_filter :: Property
 prop_node_many_filter =
   forAll (choose (2, maxNodes)) $ \numnodes ->
   forAll (genEmptyCluster numnodes) $ \cfg ->
-  let nnames = Map.keys . fromContainer $ configNodes cfg
+  let nnames = niceSort . Map.keys . fromContainer $ configNodes cfg
       eqfilter = map (EQFilter "name" . QuotedString) nnames
       alln = map ((:[]) . ResultEntry RSNormal . Just . showJSON) nnames
       test_query = checkQueryResults cfg . makeNodeQuery
@@ -121,14 +122,14 @@ prop_node_regex_filter :: Property
 prop_node_regex_filter =
   forAll (choose (0, maxNodes)) $ \numnodes ->
   forAll (genEmptyCluster numnodes) $ \cfg ->
-  let nnames = Map.keys . fromContainer $ configNodes cfg
+  let nnames = niceSort . Map.keys . fromContainer $ configNodes cfg
       expected = map ((:[]) . ResultEntry RSNormal . Just . showJSON) nnames
       regex = mkRegex ".*"::Result FilterRegex
   in case regex of
        Bad msg -> failTest $ "Can't build regex?! Error: " ++ msg
        Ok rx ->
          checkQueryResults cfg (makeNodeQuery (RegexpFilter "name" rx))
-           "Inconsistent result rows for all nodes regexp filter"
+           "rows for all nodes regexp filter"
            expected
 
 -- | Tests node regex filtering. This is a very basic test :(
diff --git a/htools/Ganeti/Query/Query.hs b/htools/Ganeti/Query/Query.hs
index 875e870..afb5830 100644
--- a/htools/Ganeti/Query/Query.hs
+++ b/htools/Ganeti/Query/Query.hs
@@ -163,7 +163,8 @@ queryInner cfg live (Query QRNode fields qfilter) wanted = 
runResultT $ do
       (fdefs, fgetters) = unzip selected
       live' = live && needsLiveData fgetters
   nodes <- resultT $ case wanted of
-             [] -> Ok . Map.elems . fromContainer $ configNodes cfg
+             [] -> Ok . niceSortKey nodeName .
+                   Map.elems . fromContainer $ configNodes cfg
              _  -> mapM (getNode cfg) wanted
   -- runs first pass of the filter, without a runtime context; this
   -- will limit the nodes that we'll contact for runtime data
@@ -183,7 +184,8 @@ queryInner cfg _ (Query QRGroup fields qfilter) wanted = 
return $ do
   let selected = getSelectedFields groupFieldsMap fields
       (fdefs, fgetters) = unzip selected
   groups <- case wanted of
-              [] -> Ok . Map.elems . fromContainer $ configNodegroups cfg
+              [] -> Ok . niceSortKey groupName .
+                    Map.elems . fromContainer $ configNodegroups cfg
               _  -> mapM (getGroup cfg) wanted
   -- there is no live data for groups, so filtering is much simpler
   fgroups <- filterM (\n -> evaluateFilter cfg Nothing n cfilter) groups
-- 
1.7.10.4

Reply via email to