Revision e7124835

b/src/Ganeti/Query/Group.hs
65 65
  , (FieldDefinition "ndparams" "NDParams" QFTOther "Node parameters",
66 66
     FieldConfig (\cfg ng -> rsNormal (getGroupNdParams cfg ng)), QffNormal)
67 67
  , (FieldDefinition "node_cnt" "Nodes" QFTNumber "Number of nodes",
68
     FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . groupName),
68
     FieldConfig (\cfg -> rsNormal . length . getGroupNodes cfg . groupUuid),
69 69
     QffNormal)
70 70
  , (FieldDefinition "node_list" "NodeList" QFTOther "List of nodes",
71 71
     FieldConfig (\cfg -> rsNormal . map nodeName .
72
                          getGroupNodes cfg . groupName), QffNormal)
72
                          getGroupNodes cfg . groupUuid), QffNormal)
73 73
  , (FieldDefinition "pinst_cnt" "Instances" QFTNumber
74 74
       "Number of primary instances",
75 75
     FieldConfig
76
       (\cfg -> rsNormal . length . fst . getGroupInstances cfg . groupName),
76
       (\cfg -> rsNormal . length . fst . getGroupInstances cfg . groupUuid),
77 77
     QffNormal)
78 78
  , (FieldDefinition "pinst_list" "InstanceList" QFTOther
79 79
       "List of primary instances",
80 80
     FieldConfig (\cfg -> rsNormal . map instName . fst .
81
                          getGroupInstances cfg . groupName), QffNormal)
81
                          getGroupInstances cfg . groupUuid), QffNormal)
82 82
  ] ++
83 83
  map buildNdParamField allNDParamFields ++
84 84
  timeStampFields ++
b/test/hs/Test/Ganeti/Objects.hs
213 213
genEmptyCluster ncount = do
214 214
  nodes <- vector ncount
215 215
  version <- arbitrary
216
  let guuid = "00"
216
  grp <- arbitrary
217
  let guuid = groupUuid grp
217 218
      nodes' = zipWith (\n idx ->
218 219
                          let newname = nodeName n ++ "-" ++ show idx
219 220
                          in (newname, n { nodeGroup = guuid,
......
227 228
                    else GenericContainer nodemap
228 229
      continsts = GenericContainer Map.empty
229 230
      networks = GenericContainer Map.empty
230
  grp <- arbitrary
231 231
  let contgroups = GenericContainer $ Map.singleton guuid grp
232 232
  serial <- arbitrary
233 233
  cluster <- resize 8 arbitrary
......
400 400
  -- timestamp fields
401 401
  ctime <- arbitrary
402 402
  mtime <- arbitrary
403
  uuid <- arbitrary
403
  uuid <- genFQDN `suchThat` (/= name)
404 404
  serial <- arbitrary
405 405
  tags <- Set.fromList <$> genTags
406 406
  let group = NodeGroup name members ndparams alloc_policy ipolicy diskparams
b/test/hs/Test/Ganeti/Query/Query.hs
36 36
import Data.List
37 37
import qualified Data.Map as Map
38 38
import Data.Maybe
39
import Text.JSON (JSValue(..))
39
import Text.JSON (JSValue(..), showJSON)
40 40

  
41 41
import Test.Ganeti.TestHelper
42 42
import Test.Ganeti.TestCommon
......
154 154
-- | Test that queryFields with empty fields list returns all node fields.
155 155
case_queryNode_allfields :: Assertion
156 156
case_queryNode_allfields = do
157
   fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRNode) []) of
158
              Bad msg -> fail $ "Error in query all fields: " ++
159
                         formatError msg
160
              Ok (QueryFieldsResult v) -> return v
161
   let field_sort = compare `on` fdefName
162
   assertEqual "Mismatch in all fields list"
163
     (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Node.fieldsMap)
164
     (sortBy field_sort fdefs)
157
  fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRNode) []) of
158
             Bad msg -> fail $ "Error in query all fields: " ++
159
                        formatError msg
160
             Ok (QueryFieldsResult v) -> return v
161
  let field_sort = compare `on` fdefName
162
  assertEqual "Mismatch in all fields list"
163
    (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Node.fieldsMap)
164
    (sortBy field_sort fdefs)
165 165

  
166 166
-- ** Group queries
167 167

  
168 168
prop_queryGroup_noUnknown :: Property
169 169
prop_queryGroup_noUnknown =
170 170
  forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
171
   forAll (elements (Map.keys Group.fieldsMap)) $ \field -> monadicIO $ do
172
   QueryResult fdefs fdata <-
173
     run (query cluster False (Query (ItemTypeOpCode QRGroup)
174
                               [field] EmptyFilter)) >>=
175
         resultProp
176
   QueryFieldsResult fdefs' <-
177
     resultProp $ queryFields (QueryFields (ItemTypeOpCode QRGroup) [field])
178
   stop $ conjoin
179
    [ printTestCase ("Got unknown fields via query (" ++ show fdefs ++ ")")
180
         (hasUnknownFields fdefs)
181
    , printTestCase ("Got unknown result status via query (" ++
182
                     show fdata ++ ")")
183
      (all (all ((/= RSUnknown) . rentryStatus)) fdata)
184
    , printTestCase ("Got unknown fields via query fields (" ++ show fdefs'
185
                     ++ ")") (hasUnknownFields fdefs')
186
    ]
171
  forAll (elements (Map.keys Group.fieldsMap)) $ \field -> monadicIO $ do
172
    QueryResult fdefs fdata <-
173
      run (query cluster False (Query (ItemTypeOpCode QRGroup)
174
                                [field] EmptyFilter)) >>=
175
           resultProp
176
    QueryFieldsResult fdefs' <-
177
      resultProp $ queryFields (QueryFields (ItemTypeOpCode QRGroup) [field])
178
    stop $ conjoin
179
     [ printTestCase ("Got unknown fields via query (" ++ show fdefs ++ ")")
180
          (hasUnknownFields fdefs)
181
     , printTestCase ("Got unknown result status via query (" ++
182
                      show fdata ++ ")")
183
       (all (all ((/= RSUnknown) . rentryStatus)) fdata)
184
     , printTestCase ("Got unknown fields via query fields (" ++ show fdefs'
185
                      ++ ")") (hasUnknownFields fdefs')
186
     ]
187 187

  
188 188
prop_queryGroup_Unknown :: Property
189 189
prop_queryGroup_Unknown =
......
226 226

  
227 227
case_queryGroup_allfields :: Assertion
228 228
case_queryGroup_allfields = do
229
   fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRGroup) []) of
230
              Bad msg -> fail $ "Error in query all fields: " ++
231
                         formatError msg
232
              Ok (QueryFieldsResult v) -> return v
233
   let field_sort = compare `on` fdefName
234
   assertEqual "Mismatch in all fields list"
235
     (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Group.fieldsMap)
236
     (sortBy field_sort fdefs)
229
  fdefs <- case queryFields (QueryFields (ItemTypeOpCode QRGroup) []) of
230
             Bad msg -> fail $ "Error in query all fields: " ++
231
                        formatError msg
232
             Ok (QueryFieldsResult v) -> return v
233
  let field_sort = compare `on` fdefName
234
  assertEqual "Mismatch in all fields list"
235
    (sortBy field_sort . map (\(f, _, _) -> f) $ Map.elems Group.fieldsMap)
236
    (sortBy field_sort fdefs)
237

  
238
-- | Check that the node count reported by a group list is sane.
239
--
240
-- FIXME: also verify the node list, etc.
241
prop_queryGroup_nodeCount :: Property
242
prop_queryGroup_nodeCount =
243
  forAll (choose (0, maxNodes)) $ \nodes ->
244
  forAll (genEmptyCluster nodes) $ \cluster -> monadicIO $
245
  do
246
    QueryResult _ fdata <-
247
      run (query cluster False (Query (ItemTypeOpCode QRGroup)
248
                                ["node_cnt"] EmptyFilter)) >>= resultProp
249
    stop $ conjoin
250
      [ printTestCase "Invalid node count" $
251
        map (map rentryValue) fdata ==? [[Just (showJSON nodes)]]
252
      ]
237 253

  
238 254
-- ** Job queries
239 255

  
......
317 333
  , 'prop_queryGroup_Unknown
318 334
  , 'prop_queryGroup_types
319 335
  , 'case_queryGroup_allfields
336
  , 'prop_queryGroup_nodeCount
320 337
  , 'prop_queryJob_noUnknown
321 338
  , 'prop_queryJob_Unknown
322 339
  , 'prop_getRequestedNames

Also available in: Unified diff