Commit fa2c927c authored by Agata Murawska's avatar Agata Murawska
Browse files

Add live parameter to query



The tests we currently have assume, that all the data required for
running the query is available - once we add live data, this will no
longer be the case.

This patch adds boolean parameter to query function, which tells it
whether to ignore live parameters gathering.
Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 4393e075
......@@ -51,7 +51,7 @@ import Ganeti.Query.Query
checkQueryResults :: ConfigData -> Query -> String
-> [[ResultEntry]] -> Property
checkQueryResults cfg qr descr expected = monadicIO $ do
result <- run (query cfg qr) >>= resultProp
result <- run (query cfg False qr) >>= resultProp
stop $ printTestCase ("Inconsistent results in " ++ descr)
(qresData result ==? expected)
......@@ -62,7 +62,7 @@ makeNodeQuery = Query QRNode ["name"]
-- | Checks if a given operation failed.
expectBadQuery :: ConfigData -> Query -> String -> Property
expectBadQuery cfg qr descr = monadicIO $ do
result <- run (query cfg qr)
result <- run (query cfg False qr)
case result of
Bad _ -> return ()
Ok a -> stop . failTest $ "Expected failure in " ++ descr ++
......
......@@ -65,7 +65,7 @@ prop_queryNode_noUnknown =
forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
forAll (elements (Map.keys nodeFieldsMap)) $ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cluster (Query QRNode [field] EmptyFilter)) >>= resultProp
run (query cluster False (Query QRNode [field] EmptyFilter)) >>= resultProp
QueryFieldsResult fdefs' <-
resultProp $ queryFields (QueryFields QRNode [field])
stop $ printTestCase ("Got unknown fields via query (" ++ show fdefs ++ ")")
......@@ -83,7 +83,7 @@ prop_queryNode_Unknown =
forAll (arbitrary `suchThat` (`notElem` Map.keys nodeFieldsMap))
$ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cluster (Query QRNode [field] EmptyFilter)) >>= resultProp
run (query cluster False (Query QRNode [field] EmptyFilter)) >>= resultProp
QueryFieldsResult fdefs' <-
resultProp $ queryFields (QueryFields QRNode [field])
stop $ printTestCase ("Got known fields via query (" ++ show fdefs ++ ")")
......@@ -127,7 +127,7 @@ prop_queryNode_types =
forAll (genEmptyCluster numnodes) $ \cfg ->
forAll (elements (Map.keys nodeFieldsMap)) $ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cfg (Query QRNode [field] EmptyFilter)) >>= resultProp
run (query cfg False (Query QRNode [field] EmptyFilter)) >>= resultProp
stop $ printTestCase ("Inconsistent result entries (" ++ show fdata ++ ")")
(conjoin $ map (conjoin . zipWith checkResultType fdefs) fdata) .&&.
printTestCase "Wrong field definitions length"
......@@ -155,7 +155,7 @@ prop_queryGroup_noUnknown =
forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
forAll (elements (Map.keys groupFieldsMap)) $ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cluster (Query QRGroup [field] EmptyFilter)) >>= resultProp
run (query cluster False (Query QRGroup [field] EmptyFilter)) >>= resultProp
QueryFieldsResult fdefs' <-
resultProp $ queryFields (QueryFields QRGroup [field])
stop $ printTestCase ("Got unknown fields via query (" ++ show fdefs ++ ")")
......@@ -172,7 +172,7 @@ prop_queryGroup_Unknown =
forAll (arbitrary `suchThat` (`notElem` Map.keys groupFieldsMap))
$ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cluster (Query QRGroup [field] EmptyFilter)) >>= resultProp
run (query cluster False (Query QRGroup [field] EmptyFilter)) >>= resultProp
QueryFieldsResult fdefs' <-
resultProp $ queryFields (QueryFields QRGroup [field])
stop $ printTestCase ("Got known fields via query (" ++ show fdefs ++ ")")
......@@ -192,7 +192,7 @@ prop_queryGroup_types =
forAll (genEmptyCluster numnodes) $ \cfg ->
forAll (elements (Map.keys groupFieldsMap)) $ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cfg (Query QRGroup [field] EmptyFilter)) >>= resultProp
run (query cfg False (Query QRGroup [field] EmptyFilter)) >>= resultProp
stop $ printTestCase ("Inconsistent result entries (" ++ show fdata ++ ")")
(conjoin $ map (conjoin . zipWith checkResultType fdefs) fdata) .&&.
printTestCase "Wrong field definitions length"
......
......@@ -92,10 +92,11 @@ getSelectedFields defined =
-- | Main query execution function.
query :: ConfigData -- ^ The current configuration
-> Bool -- ^ Whether to collect live data
-> Query -- ^ The query (item, fields, filter)
-> IO (Result QueryResult) -- ^ Result
query cfg (Query QRNode fields qfilter) = return $ do
query cfg _ (Query QRNode fields qfilter) = return $ do
cfilter <- compileFilter nodeFieldsMap qfilter
let selected = getSelectedFields nodeFieldsMap fields
(fdefs, fgetters) = unzip selected
......@@ -110,7 +111,7 @@ query cfg (Query QRNode fields qfilter) = return $ do
fnodes
return QueryResult { qresFields = fdefs, qresData = fdata }
query cfg (Query QRGroup fields qfilter) = return $ do
query cfg _ (Query QRGroup fields qfilter) = return $ do
-- FIXME: want_diskparams is defaulted to false and not taken as parameter
-- This is because the type for DiskParams is right now too generic for merges
-- (or else I cannot see how to do this with curent implementation)
......@@ -124,7 +125,7 @@ query cfg (Query QRGroup fields qfilter) = return $ do
map (execGetter cfg GroupRuntime node) fgetters) fgroups
return QueryResult {qresFields = fdefs, qresData = fdata }
query _ (Query qkind _ _) =
query _ _ (Query qkind _ _) =
return . Bad $ "Query '" ++ show qkind ++ "' not supported"
-- | Query fields call.
......
......@@ -129,7 +129,7 @@ handleCall cfg (QueryTags kind name) =
in return (J.showJSON <$> tags)
handleCall cfg (Query qkind qfields qfilter) = do
result <- query cfg (Qlang.Query qkind qfields qfilter)
result <- query cfg True (Qlang.Query qkind qfields qfilter)
return $ J.showJSON <$> result
handleCall _ (QueryFields qkind qfields) = do
......
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