Revision 9f73b342 test/hs/Test/Ganeti/Objects.hs

b/test/hs/Test/Ganeti/Objects.hs
49 49
import Test.Ganeti.Types ()
50 50

  
51 51
import qualified Ganeti.Constants as C
52
import Ganeti.Network
52
-- import Ganeti.Network
53 53
import Ganeti.Objects as Objects
54 54
import Ganeti.JSON
55 55
import Ganeti.Types
......
168 168
  netmask <- choose (24::Int, 30)
169 169
  name <- genName >>= mkNonEmpty
170 170
  mac_prefix <- genMaybe genName
171
  net <- genIp4NetWithNetmask netmask
171
  net <- genMaybe $ genIp4NetWithNetmask netmask
172 172
  net6 <- genMaybe genIp6Net
173 173
  -- gateway <- genMaybe genIp4AddrStr
174 174
  -- gateway6 <- genMaybe genIp6Addr
......
270 270
case_py_compat_networks = do
271 271
  let num_networks = 500::Int
272 272
  networks <- genSample (vectorOf num_networks genValidNetwork)
273
  let networks_with_properties = map getNetworkProperties networks
274
      serialized = J.encode networks
273
  let serialized = J.encode networks
275 274
  -- check for non-ASCII fields, usually due to 'arbitrary :: String'
276 275
  mapM_ (\net -> when (any (not . isAscii) (J.encode net)) .
277 276
                 HUnit.assertFailure $
......
286 285
              \decoded = [objects.Network.FromDict(n) for n in net_data]\n\
287 286
              \encoded = []\n\
288 287
              \for net in decoded:\n\
289
              \  a = network.AddressPool(net)\n\
290
              \  encoded.append((a._GetFreeCount(), a._GetReservedCount(), \\\n\
291
              \    net.ToDict()))\n\
288
              \  a = network.Network(net)\n\
289
              \  encoded.append((net.ToDict()))\n\
292 290
              \print serializer.Dump(encoded)" serialized
293 291
    >>= checkPythonResult
294
  let deserialised = J.decode py_stdout::J.Result [(Int, Int, Network)]
292
  let deserialised = J.decode py_stdout::J.Result [Network]
295 293
  decoded <- case deserialised of
296 294
               J.Ok ops -> return ops
297 295
               J.Error msg ->
......
300 298
                 -- for proper types
301 299
                 >> fail "Unable to decode networks"
302 300
  HUnit.assertEqual "Mismatch in number of returned networks"
303
    (length decoded) (length networks_with_properties)
301
    (length decoded) (length networks)
304 302
  mapM_ (uncurry (HUnit.assertEqual "Different result after encoding/decoding")
305
        ) $ zip decoded networks_with_properties
303
        ) $ zip decoded networks
306 304

  
307 305
-- | Creates a tuple of the given network combined with some of its properties
308 306
-- to be compared against the same properties generated by the python code.
309
getNetworkProperties :: Network -> (Int, Int, Network)
310
getNetworkProperties net =
311
  let maybePool = createAddressPool net
312
  in  case maybePool of
313
           (Just pool) -> (getFreeCount pool, getReservedCount pool, net)
314
           Nothing -> (-1, -1, net)
307
-- getNetworkProperties :: Network -> (Map.Map String String, Network)
308
-- getNetworkProperties net = (getStats net, net)
315 309

  
316 310
-- | Tests the compatibility between Haskell-serialized node groups and their
317 311
-- python-decoded and encoded version.

Also available in: Unified diff