From fa2c927c407f355f2c4365d96cd15c490193b091 Mon Sep 17 00:00:00 2001 From: Agata Murawska <agatamurawska@google.com> Date: Wed, 26 Sep 2012 15:00:41 +0200 Subject: [PATCH] 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: Agata Murawska <agatamurawska@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- htest/Test/Ganeti/Query/Filter.hs | 4 ++-- htest/Test/Ganeti/Query/Query.hs | 12 ++++++------ htools/Ganeti/Query/Query.hs | 7 ++++--- htools/Ganeti/Query/Server.hs | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/htest/Test/Ganeti/Query/Filter.hs b/htest/Test/Ganeti/Query/Filter.hs index 841173d06..1e9929717 100644 --- a/htest/Test/Ganeti/Query/Filter.hs +++ b/htest/Test/Ganeti/Query/Filter.hs @@ -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 ++ diff --git a/htest/Test/Ganeti/Query/Query.hs b/htest/Test/Ganeti/Query/Query.hs index d2eac1b9e..74258ec62 100644 --- a/htest/Test/Ganeti/Query/Query.hs +++ b/htest/Test/Ganeti/Query/Query.hs @@ -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" diff --git a/htools/Ganeti/Query/Query.hs b/htools/Ganeti/Query/Query.hs index d348be16c..af13c9cd2 100644 --- a/htools/Ganeti/Query/Query.hs +++ b/htools/Ganeti/Query/Query.hs @@ -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. diff --git a/htools/Ganeti/Query/Server.hs b/htools/Ganeti/Query/Server.hs index ff940dd94..ca4409c20 100644 --- a/htools/Ganeti/Query/Server.hs +++ b/htools/Ganeti/Query/Server.hs @@ -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 -- GitLab