From 1fc3812cf951112d9d3a66570dff8d1b10bc8cd3 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 5 Oct 2012 01:05:20 +0100 Subject: [PATCH] Switch ordering of names on query to niceSort 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 <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- 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 1e9929717..6bb0c2ce2 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 68b100c76..0b4e7f6b4 100644 --- a/htools/Ganeti/Query/Query.hs +++ b/htools/Ganeti/Query/Query.hs @@ -161,7 +161,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 @@ -181,7 +182,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 -- GitLab