Commit e7124835 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix bug in group queries related to node/instance fields



Since we use the primitive string type for group UUIDs, the group
fields have a bug where we pass the group name as filter for node
tests, whereas the nodes themselves use the group UUID. This results
in zero node count, empty node list, and no instances being reported
as assigned to groups.

The patch fixes this and adds a test for the node count. It does some
test generation improvement, and also cleans up whitespace issues in
Test/G/Q/Query.hs (the functions case_queryNode_allfields,
prop_queryGroup_noUnknown and case_queryGroup_allfields are unchanged
but simply have indentation fixed).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent d5b2753a
......@@ -65,20 +65,20 @@ groupFields =
, (FieldDefinition "ndparams" "NDParams" QFTOther "Node parameters",
FieldConfig (\cfg ng -> rsNormal (getGroupNdParams cfg ng)), QffNormal)
, (FieldDefinition "node_cnt" "Nodes" QFTNumber "Number of nodes",
FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . groupName),
FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . groupUuid),
QffNormal)
, (FieldDefinition "node_list" "NodeList" QFTOther "List of nodes",
FieldConfig (\cfg -> rsNormal . map nodeName .
getGroupNodes cfg . groupName), QffNormal)
getGroupNodes cfg . groupUuid), QffNormal)
, (FieldDefinition "pinst_cnt" "Instances" QFTNumber
"Number of primary instances",
FieldConfig
(\cfg -> rsNormal . length . fst . getGroupInstances cfg . groupName),
(\cfg -> rsNormal . length . fst . getGroupInstances cfg . groupUuid),
QffNormal)
, (FieldDefinition "pinst_list" "InstanceList" QFTOther
"List of primary instances",
FieldConfig (\cfg -> rsNormal . map instName . fst .
getGroupInstances cfg . groupName), QffNormal)
getGroupInstances cfg . groupUuid), QffNormal)
] ++
map buildNdParamField allNDParamFields ++
timeStampFields ++
......
......@@ -213,7 +213,8 @@ genEmptyCluster :: Int -> Gen ConfigData
genEmptyCluster ncount = do
nodes <- vector ncount
version <- arbitrary
let guuid = "00"
grp <- arbitrary
let guuid = groupUuid grp
nodes' = zipWith (\n idx ->
let newname = nodeName n ++ "-" ++ show idx
in (newname, n { nodeGroup = guuid,
......@@ -227,7 +228,6 @@ genEmptyCluster ncount = do
else GenericContainer nodemap
continsts = GenericContainer Map.empty
networks = GenericContainer Map.empty
grp <- arbitrary
let contgroups = GenericContainer $ Map.singleton guuid grp
serial <- arbitrary
cluster <- resize 8 arbitrary
......@@ -400,7 +400,7 @@ genNodeGroup = do
-- timestamp fields
ctime <- arbitrary
mtime <- arbitrary
uuid <- arbitrary
uuid <- genFQDN `suchThat` (/= name)
serial <- arbitrary
tags <- Set.fromList <$> genTags
let group = NodeGroup name members ndparams alloc_policy ipolicy diskparams
......
......@@ -36,7 +36,7 @@ import Data.Function (on)
import Data.List
import qualified Data.Map as Map
import Data.Maybe
import Text.JSON (JSValue(..))
import Text.JSON (JSValue(..), showJSON)
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
......@@ -154,36 +154,36 @@ prop_queryNode_types =
-- | Test that queryFields with empty fields list returns all node fields.
case_queryNode_allfields :: Assertion
case_queryNode_allfields = do
fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRNode) []) of
Bad msg -> fail $ "Error in query all fields: " ++
formatError msg
Ok (QueryFieldsResult v) -> return v
let field_sort = compare `on` fdefName
assertEqual "Mismatch in all fields list"
(sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Node.fieldsMap)
(sortBy field_sort fdefs)
fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRNode) []) of
Bad msg -> fail $ "Error in query all fields: " ++
formatError msg
Ok (QueryFieldsResult v) -> return v
let field_sort = compare `on` fdefName
assertEqual "Mismatch in all fields list"
(sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Node.fieldsMap)
(sortBy field_sort fdefs)
-- ** Group queries
prop_queryGroup_noUnknown :: Property
prop_queryGroup_noUnknown =
forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
forAll (elements (Map.keys Group.fieldsMap)) $ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cluster False (Query (ItemTypeOpCode QRGroup)
[field] EmptyFilter)) >>=
resultProp
QueryFieldsResult fdefs' <-
resultProp $ queryFields (QueryFields (ItemTypeOpCode QRGroup) [field])
stop $ conjoin
[ printTestCase ("Got unknown fields via query (" ++ show fdefs ++ ")")
(hasUnknownFields fdefs)
, printTestCase ("Got unknown result status via query (" ++
show fdata ++ ")")
(all (all ((/= RSUnknown) . rentryStatus)) fdata)
, printTestCase ("Got unknown fields via query fields (" ++ show fdefs'
++ ")") (hasUnknownFields fdefs')
]
forAll (elements (Map.keys Group.fieldsMap)) $ \field -> monadicIO $ do
QueryResult fdefs fdata <-
run (query cluster False (Query (ItemTypeOpCode QRGroup)
[field] EmptyFilter)) >>=
resultProp
QueryFieldsResult fdefs' <-
resultProp $ queryFields (QueryFields (ItemTypeOpCode QRGroup) [field])
stop $ conjoin
[ printTestCase ("Got unknown fields via query (" ++ show fdefs ++ ")")
(hasUnknownFields fdefs)
, printTestCase ("Got unknown result status via query (" ++
show fdata ++ ")")
(all (all ((/= RSUnknown) . rentryStatus)) fdata)
, printTestCase ("Got unknown fields via query fields (" ++ show fdefs'
++ ")") (hasUnknownFields fdefs')
]
prop_queryGroup_Unknown :: Property
prop_queryGroup_Unknown =
......@@ -226,14 +226,30 @@ prop_queryGroup_types =
case_queryGroup_allfields :: Assertion
case_queryGroup_allfields = do
fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRGroup) []) of
Bad msg -> fail $ "Error in query all fields: " ++
formatError msg
Ok (QueryFieldsResult v) -> return v
let field_sort = compare `on` fdefName
assertEqual "Mismatch in all fields list"
(sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Group.fieldsMap)
(sortBy field_sort fdefs)
fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRGroup) []) of
Bad msg -> fail $ "Error in query all fields: " ++
formatError msg
Ok (QueryFieldsResult v) -> return v
let field_sort = compare `on` fdefName
assertEqual "Mismatch in all fields list"
(sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Group.fieldsMap)
(sortBy field_sort fdefs)
-- | Check that the node count reported by a group list is sane.
--
-- FIXME: also verify the node list, etc.
prop_queryGroup_nodeCount :: Property
prop_queryGroup_nodeCount =
forAll (choose (0, maxNodes)) $ \nodes ->
forAll (genEmptyCluster nodes) $ \cluster -> monadicIO $
do
QueryResult _ fdata <-
run (query cluster False (Query (ItemTypeOpCode QRGroup)
["node_cnt"] EmptyFilter)) >>= resultProp
stop $ conjoin
[ printTestCase "Invalid node count" $
map (map rentryValue) fdata ==? [[Just (showJSON nodes)]]
]
-- ** Job queries
......@@ -317,6 +333,7 @@ testSuite "Query/Query"
, 'prop_queryGroup_Unknown
, 'prop_queryGroup_types
, 'case_queryGroup_allfields
, 'prop_queryGroup_nodeCount
, 'prop_queryJob_noUnknown
, 'prop_queryJob_Unknown
, 'prop_getRequestedNames
......
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