Skip to content
Snippets Groups Projects
Commit 13d62481 authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Instance generators


This patch introduces and enhances generators for
instances:
- 'genInstWithNets' is split into the generation of an
  arbitrary instance and enhancing an instance with nets
- 'genInst' calls 'genInstWithNets' with an empty set
  of initial networks to provide a reasonable default
- the Arbitrary instance of 'Instance' uses now 'genDisks'
  to create instances with a reasonable set of disks

Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent 6b168d4a
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ module Test.Ganeti.Objects
, genDisk
, genDiskWithChildren
, genEmptyCluster
, genInst
, genInstWithNets
, genValidNetwork
, genBitStringMaxLen
......@@ -127,7 +128,7 @@ instance Arbitrary Instance where
-- nics
<*> arbitrary
-- disks
<*> arbitrary
<*> vectorOf 5 genDisk
-- disk template
<*> arbitrary
-- network port
......@@ -146,6 +147,16 @@ instance Arbitrary Instance where
genInstWithNets :: [String] -> Gen Instance
genInstWithNets nets = do
plain_inst <- arbitrary
enhanceInstWithNets plain_inst nets
-- | Generates an instance that is connected to some networks
genInst :: Gen Instance
genInst = genInstWithNets []
-- | Enhances a given instance with network information, by connecting it to the
-- given networks and possibly some other networks
enhanceInstWithNets :: Instance -> [String] -> Gen Instance
enhanceInstWithNets inst nets = do
mac <- arbitrary
ip <- arbitrary
nicparams <- arbitrary
......@@ -157,7 +168,7 @@ genInstWithNets nets = do
let genNic net = PartialNic mac ip nicparams net name uuid
partial_nics = map (genNic . Just)
(List.nub (nets ++ more_nets))
new_inst = plain_inst { instNics = partial_nics }
new_inst = inst { instNics = partial_nics }
return new_inst
genDiskWithChildren :: Int -> Gen Disk
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment