Commit 037762a9 authored by Iustin Pop's avatar Iustin Pop

Change makeSimpleFilter accept NumericValues as well

This is required for QueryJobs implementation; we change
makeSimpleFilter to support both string and integers as names.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent aa79e62e
......@@ -181,10 +181,14 @@ prop_node_bad_filter rndname rndint =
prop_makeSimpleFilter :: Property
prop_makeSimpleFilter =
forAll (resize 10 $ listOf1 genName) $ \names ->
forAll (resize 10 $ listOf1 arbitrary) $ \ids ->
forAll genName $ \namefield ->
conjoin [ printTestCase "test expected names" $
makeSimpleFilter namefield names ==?
makeSimpleFilter namefield (map Left names) ==?
OrFilter (map (EQFilter namefield . QuotedString) names)
, printTestCase "test expected IDs" $
makeSimpleFilter namefield (map Right ids) ==?
OrFilter (map (EQFilter namefield . NumericValue) ids)
, printTestCase "test empty names" $
makeSimpleFilter namefield [] ==? EmptyFilter
]
......
......@@ -216,7 +216,7 @@ requestedNames namefield (EQFilter fld val) =
requestedNames _ _ = Nothing
-- | Builds a simple filter from a list of names.
makeSimpleFilter :: String -> [String] -> Filter FilterField
makeSimpleFilter :: String -> [Either String Integer] -> Filter FilterField
makeSimpleFilter _ [] = EmptyFilter
makeSimpleFilter namefield vals =
OrFilter $ map (EQFilter namefield . QuotedString) vals
OrFilter $ map (EQFilter namefield . either QuotedString NumericValue) vals
......@@ -62,7 +62,8 @@ type ConfigReader = IO (Result ConfigData)
-- | Helper for classic queries.
handleClassicQuery :: ConfigData -- ^ Cluster config
-> Qlang.ItemType -- ^ Query type
-> [String] -- ^ Requested names (empty means all)
-> [Either String Integer] -- ^ Requested names
-- (empty means all)
-> [String] -- ^ Requested fields
-> Bool -- ^ Whether to do sync queries or not
-> IO (GenericResult GanetiException JSValue)
......@@ -155,10 +156,12 @@ handleCall _ (QueryFields qkind qfields) = do
return $ J.showJSON <$> result
handleCall cfg (QueryNodes names fields lock) =
handleClassicQuery cfg (Qlang.ItemTypeOpCode Qlang.QRNode) names fields lock
handleClassicQuery cfg (Qlang.ItemTypeOpCode Qlang.QRNode)
(map Left names) fields lock
handleCall cfg (QueryGroups names fields lock) =
handleClassicQuery cfg (Qlang.ItemTypeOpCode Qlang.QRGroup) names fields lock
handleClassicQuery cfg (Qlang.ItemTypeOpCode Qlang.QRGroup)
(map Left names) fields lock
handleCall _ op =
return . Bad $
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment